My Project  debian-1:4.1.1-p2+ds-4build2
Public Member Functions | Private Attributes | Friends
tgb_sparse_matrix Class Reference

#include <tgbgauss.h>

Public Member Functions

void sort_rows ()
 
 tgb_sparse_matrix (int i, int j, ring rarg)
 
 ~tgb_sparse_matrix ()
 
int get_rows ()
 
int get_columns ()
 
void print ()
 
void row_normalize (int row)
 
void row_content (int row)
 
void perm_rows (int i, int j)
 
void set (int i, int j, number n)
 
number get (int i, int j)
 
BOOLEAN is_zero_entry (int i, int j)
 
void free_row (int row, BOOLEAN free_non_zeros=TRUE)
 
int min_col_not_zero_in_row (int row)
 
int next_col_not_zero (int row, int pre)
 
BOOLEAN zero_row (int row)
 
void mult_row (int row, number factor)
 
void add_lambda_times_row (int add_to, int summand, number factor)
 
int non_zero_entries (int row)
 

Private Attributes

ring r
 
mac_polymp
 
int columns
 
int rows
 
BOOLEAN free_numbers
 

Friends

poly free_row_to_poly (tgb_sparse_matrix *mat, int row, poly *monoms, int monom_index)
 
void init_with_mac_poly (tgb_sparse_matrix *mat, int row, mac_poly m)
 

Detailed Description

Definition at line 60 of file tgbgauss.h.

Constructor & Destructor Documentation

◆ tgb_sparse_matrix()

tgb_sparse_matrix::tgb_sparse_matrix ( int  i,
int  j,
ring  rarg 
)

Definition at line 646 of file tgbgauss.cc.

647 {
648  mp=(mac_poly*) omAlloc(i*sizeof (mac_poly));;
649  int z;
650  for(z=0;z<i;z++)
651  {
652  mp[z]=NULL;
653  }
654  columns=j;
655  rows=i;
657  r=rarg;
658 }

◆ ~tgb_sparse_matrix()

tgb_sparse_matrix::~tgb_sparse_matrix ( )

Definition at line 660 of file tgbgauss.cc.

661 {
662  int z;
663  for(z=0;z<rows;z++)
664  {
665  if(mp[z]!=NULL)
666  {
667  if(free_numbers)
668  {
669  mac_destroy(mp[z]);
670  }
671  else {
672  while(mp[z]!=NULL)
673  {
674  mac_poly next=mp[z]->next;
675  delete mp[z];
676  mp[z]=next;
677  }
678  }
679  }
680  }
681  omfree(mp);
682 }

Member Function Documentation

◆ add_lambda_times_row()

void tgb_sparse_matrix::add_lambda_times_row ( int  add_to,
int  summand,
number  factor 
)

Definition at line 910 of file tgbgauss.cc.

911 {
912  mp[add_to]= mac_p_add_ff_qq(mp[add_to], factor,mp[summand]);
913 }

◆ free_row()

void tgb_sparse_matrix::free_row ( int  row,
BOOLEAN  free_non_zeros = TRUE 
)

Definition at line 929 of file tgbgauss.cc.

930 {
931  if(free_non_zeros)
932  mac_destroy(mp[row]);
933  else
934  {
935  while(mp[row]!=NULL)
936  {
937  mac_poly next=mp[row]->next;
938  delete mp[row];
939  mp[row]=next;
940  }
941  }
942  mp[row]=NULL;
943 }

◆ get()

number tgb_sparse_matrix::get ( int  i,
int  j 
)

Definition at line 767 of file tgbgauss.cc.

768 {
769  assume(i<rows);
770  assume(j<columns);
771  mac_poly rr=mp[i];
772  while((rr!=NULL)&&(rr->exp<j))
773  rr=rr->next;
774  if ((rr==NULL)||(rr->exp>j))
775  {
776  number n=nInit(0);
777  return n;
778  }
779  assume(rr->exp==j);
780  return rr->coef;
781 }

◆ get_columns()

int tgb_sparse_matrix::get_columns ( )

Definition at line 762 of file tgbgauss.cc.

763 {
764  return columns;
765 }

◆ get_rows()

int tgb_sparse_matrix::get_rows ( )

Definition at line 757 of file tgbgauss.cc.

758 {
759  return rows;
760 }

◆ is_zero_entry()

BOOLEAN tgb_sparse_matrix::is_zero_entry ( int  i,
int  j 
)

Definition at line 783 of file tgbgauss.cc.

784 {
785  assume(i<rows);
786  assume(j<columns);
787  mac_poly rr=mp[i];
788  while((rr!=NULL)&&(rr->exp<j))
789  rr=rr->next;
790  if ((rr==NULL)||(rr->exp>j))
791  {
792  return TRUE;
793  }
794  assume(!nIsZero(rr->coef));
795  assume(rr->exp==j);
796  return FALSE;
797 }

◆ min_col_not_zero_in_row()

int tgb_sparse_matrix::min_col_not_zero_in_row ( int  row)

Definition at line 799 of file tgbgauss.cc.

800 {
801  if(mp[row]!=NULL)
802  {
803  assume(!nIsZero(mp[row]->coef));
804  return mp[row]->exp;
805  }
806  else
807  return columns;//error code
808 }

◆ mult_row()

void tgb_sparse_matrix::mult_row ( int  row,
number  factor 
)

Definition at line 915 of file tgbgauss.cc.

916 {
917  if (nIsZero(factor))
918  {
919  mac_destroy(mp[row]);
920  mp[row]=NULL;
921 
922  return;
923  }
924  if(nIsOne(factor))
925  return;
926  mac_mult_cons(mp[row],factor);
927 }

◆ next_col_not_zero()

int tgb_sparse_matrix::next_col_not_zero ( int  row,
int  pre 
)

Definition at line 810 of file tgbgauss.cc.

811 {
812  mac_poly rr=mp[row];
813  while((rr!=NULL)&&(rr->exp<=pre))
814  rr=rr->next;
815  if(rr!=NULL)
816  {
817  assume(!nIsZero(rr->coef));
818  return rr->exp;
819  }
820  return columns;//error code
821 }

◆ non_zero_entries()

int tgb_sparse_matrix::non_zero_entries ( int  row)

Definition at line 904 of file tgbgauss.cc.

905 {
906  return mac_length(mp[row]);
907 }

◆ perm_rows()

void tgb_sparse_matrix::perm_rows ( int  i,
int  j 
)
inline

Definition at line 80 of file tgbgauss.h.

80  {
81  mac_poly h;
82  h=mp[i];
83  mp[i]=mp[j];
84  mp[j]=h;
85  }

◆ print()

void tgb_sparse_matrix::print ( )

Definition at line 699 of file tgbgauss.cc.

700 {
701  int i;
702  int j;
703  PrintLn();
704  for(i=0;i<rows;i++)
705  {
706  PrintS("(");
707  for(j=0;j<columns;j++)
708  {
709  StringSetS("");
710  number n=get(i,j);
711  n_Write(n,currRing->cf);
712  char *s=StringEndS();
713  PrintS(s);
714  omFree(s);
715  PrintS("\t");
716  }
717  PrintS(")\n");
718  }
719 }

◆ row_content()

void tgb_sparse_matrix::row_content ( int  row)

Definition at line 848 of file tgbgauss.cc.

849 {
850  mac_poly ph=mp[row];
851  number h,d;
852  mac_poly p;
853 
854  if(TEST_OPT_CONTENTSB) return;
855  if(ph->next==NULL)
856  {
857  nDelete(&ph->coef);
858  ph->coef=nInit(1);
859  }
860  else
861  {
862  nNormalize(ph->coef);
863  if(!nGreaterZero(ph->coef))
864  {
865  //ph = pNeg(ph);
866  p=ph;
867  while(p!=NULL)
868  {
869  p->coef=nInpNeg(p->coef);
870  p=p->next;
871  }
872  }
873 
874  h=nCopy(ph->coef);
875  p = ph->next;
876 
877  while (p!=NULL)
878  {
879  nNormalize(p->coef);
880  d=n_Gcd(h,p->coef,currRing->cf);
881  nDelete(&h);
882  h = d;
883  if(nIsOne(h))
884  {
885  break;
886  }
887  p=p->next;
888  }
889  p = ph;
890  //number tmp;
891  if(!nIsOne(h))
892  {
893  while (p!=NULL)
894  {
895  d = nExactDiv(p->coef,h);
896  nDelete(&p->coef);
897  p->coef=d;
898  p=p->next;
899  }
900  }
901  nDelete(&h);
902  }
903 }

◆ row_normalize()

void tgb_sparse_matrix::row_normalize ( int  row)

Definition at line 832 of file tgbgauss.cc.

833 {
834  if (!rField_has_simple_inverse(r)) /* Z/p, GF(p,n), R, long R/C */
835  {
836  mac_poly m=mp[row];
837  while (m!=NULL)
838  {
839  #ifndef SING_NDEBUG
840  if (currRing==r) {nTest(m->coef);}
841  #endif
842  n_Normalize(m->coef,r->cf);
843  m=m->next;
844  }
845  }
846 }

◆ set()

void tgb_sparse_matrix::set ( int  i,
int  j,
number  n 
)

Definition at line 722 of file tgbgauss.cc.

723 {
724  assume(i<rows);
725  assume(j<columns);
726  mac_poly* set_this=&mp[i];
727  // while(((*set_this)!=NULL)&&((*set_this)\AD>exp<j))
728  while(((*set_this)!=NULL) && ((*set_this)->exp<j))
729  set_this=&((*set_this)->next);
730 
731  if (((*set_this)==NULL)||((*set_this)->exp>j))
732  {
733  if (nIsZero(n)) return;
734  mac_poly old=(*set_this);
735  (*set_this)=new mac_poly_r();
736  (*set_this)->exp=j;
737  (*set_this)->coef=n;
738  (*set_this)->next=old;
739  return;
740  }
741  assume((*set_this)->exp==j);
742  if(!nIsZero(n))
743  {
744  nDelete(&(*set_this)->coef);
745  (*set_this)->coef=n;
746  }
747  else
748  {
749  nDelete(&(*set_this)->coef);
750  mac_poly dt=(*set_this);
751  (*set_this)=dt->next;
752  delete dt;
753  }
754  return;
755 }

◆ sort_rows()

void tgb_sparse_matrix::sort_rows ( )

Definition at line 694 of file tgbgauss.cc.

695 {
696  qsort(mp,rows,sizeof(mac_poly),row_cmp_gen);
697 }

◆ zero_row()

BOOLEAN tgb_sparse_matrix::zero_row ( int  row)

Definition at line 823 of file tgbgauss.cc.

824 {
825  assume((mp[row]==NULL)||(!nIsZero(mp[row]->coef)));
826  if (mp[row]==NULL)
827  return TRUE;
828  else
829  return FALSE;
830 }

Friends And Related Function Documentation

◆ free_row_to_poly

poly free_row_to_poly ( tgb_sparse_matrix mat,
int  row,
poly *  monoms,
int  monom_index 
)
friend

Definition at line 3064 of file tgb.cc.

3066 {
3067  poly p = NULL;
3068  poly *set_this = &p;
3069  mac_poly r = mat->mp[row];
3070  mat->mp[row] = NULL;
3071  while(r)
3072  {
3073  (*set_this) = pLmInit (monoms[monom_index - 1 - r->exp]);
3074  pSetCoeff ((*set_this), r->coef);
3075  set_this = &((*set_this)->next);
3076  mac_poly old = r;
3077  r = r->next;
3078  delete old;
3079 
3080  }
3081  return p;
3082 }

◆ init_with_mac_poly

void init_with_mac_poly ( tgb_sparse_matrix mat,
int  row,
mac_poly  m 
)
friend

Definition at line 3049 of file tgb.cc.

3050 {
3051  assume (mat->mp[row] == NULL);
3052  mat->mp[row] = m;
3053 #ifdef TGB_DEBUG
3054  mac_poly r = m;
3055  while(r)
3056  {
3057  assume (r->exp < mat->columns);
3058  r = r->next;
3059  }
3060 #endif
3061 }

Field Documentation

◆ columns

int tgb_sparse_matrix::columns
private

Definition at line 65 of file tgbgauss.h.

◆ free_numbers

BOOLEAN tgb_sparse_matrix::free_numbers
private

Definition at line 67 of file tgbgauss.h.

◆ mp

mac_poly* tgb_sparse_matrix::mp
private

Definition at line 64 of file tgbgauss.h.

◆ r

ring tgb_sparse_matrix::r
private

Definition at line 63 of file tgbgauss.h.

◆ rows

int tgb_sparse_matrix::rows
private

Definition at line 66 of file tgbgauss.h.


The documentation for this class was generated from the following files:
FALSE
#define FALSE
Definition: auxiliary.h:94
mac_mult_cons
void mac_mult_cons(mac_poly p, number c)
Definition: tgbgauss.cc:92
mac_poly_r::next
mac_poly_r * next
Definition: tgbgauss.h:51
nNormalize
#define nNormalize(n)
Definition: numbers.h:31
j
int j
Definition: facHensel.cc:105
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
tgb_sparse_matrix::rows
int rows
Definition: tgbgauss.h:66
tgb_sparse_matrix::columns
int columns
Definition: tgbgauss.h:65
TEST_OPT_CONTENTSB
#define TEST_OPT_CONTENTSB
Definition: options.h:125
tgb_sparse_matrix::r
ring r
Definition: tgbgauss.h:63
StringEndS
char * StringEndS()
Definition: reporter.cc:151
tgb_sparse_matrix::mp
mac_poly * mp
Definition: tgbgauss.h:64
n_Normalize
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:579
nTest
#define nTest(a)
Definition: numbers.h:36
nGreaterZero
#define nGreaterZero(n)
Definition: numbers.h:28
tgb_sparse_matrix::free_numbers
BOOLEAN free_numbers
Definition: tgbgauss.h:67
next
ListNode * next
Definition: janet.h:31
nInpNeg
#define nInpNeg(n)
Definition: numbers.h:22
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
nIsOne
#define nIsOne(n)
Definition: numbers.h:26
mac_poly_r
Definition: tgbgauss.h:44
n_Write
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:592
mac_destroy
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:114
PrintS
void PrintS(const char *s)
Definition: reporter.cc:284
nExactDiv
#define nExactDiv(a, b)
Definition: numbers.h:35
h
static Poly * h
Definition: janet.cc:972
mac_p_add_ff_qq
mac_poly mac_p_add_ff_qq(mac_poly a, number f, mac_poly b)
Definition: tgbgauss.cc:17
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
pLmInit
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
pSetCoeff
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
mac_length
int mac_length(mac_poly p)
Definition: tgbgauss.cc:103
mac_poly_r::exp
int exp
Definition: tgbgauss.h:52
nIsZero
#define nIsZero(n)
Definition: numbers.h:20
factor
CanonicalForm factor
Definition: facAbsFact.cc:101
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:128
n_Gcd
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
Definition: coeffs.h:687
rField_has_simple_inverse
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:540
m
int m
Definition: cfEzgcd.cc:121
assume
#define assume(x)
Definition: mod2.h:390
NULL
#define NULL
Definition: omList.c:10
nDelete
#define nDelete(n)
Definition: numbers.h:17
tgb_sparse_matrix::get
number get(int i, int j)
Definition: tgbgauss.cc:767
p
int p
Definition: cfModGcd.cc:4019
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
nInit
#define nInit(i)
Definition: numbers.h:25
mac_poly_r::coef
number coef
Definition: tgbgauss.h:50
PrintLn
void PrintLn()
Definition: reporter.cc:310
row_cmp_gen
static int row_cmp_gen(const void *a, const void *b)
Definition: tgbgauss.cc:684
nCopy
#define nCopy(n)
Definition: numbers.h:16
omfree
#define omfree(addr)
Definition: omAllocDecl.h:237