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 55 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 648 of file tgbgauss.cc.

649 {
650  mp=(mac_poly*) omAlloc(i*sizeof (mac_poly));;
651  int z;
652  for(z=0;z<i;z++)
653  {
654  mp[z]=NULL;
655  }
656  columns=j;
657  rows=i;
659  r=rarg;
660 }
#define FALSE
Definition: auxiliary.h:94
#define omAlloc(size)
Definition: omAllocDecl.h:210
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
BOOLEAN free_numbers
Definition: tgbgauss.h:61
mac_poly * mp
Definition: tgbgauss.h:58

§ ~tgb_sparse_matrix()

tgb_sparse_matrix::~tgb_sparse_matrix ( )

Definition at line 662 of file tgbgauss.cc.

663 {
664  int z;
665  for(z=0;z<rows;z++)
666  {
667  if(mp[z]!=NULL)
668  {
669  if(free_numbers)
670  {
671  mac_destroy(mp[z]);
672  }
673  else {
674  while(mp[z]!=NULL)
675  {
676  mac_poly next=mp[z]->next;
677  delete mp[z];
678  mp[z]=next;
679  }
680  }
681  }
682  }
683  omfree(mp);
684 }
mac_poly_r * next
Definition: tgbgauss.h:46
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:116
#define omfree(addr)
Definition: omAllocDecl.h:237
#define NULL
Definition: omList.c:10
BOOLEAN free_numbers
Definition: tgbgauss.h:61
mac_poly * mp
Definition: tgbgauss.h:58
ListNode * next
Definition: janet.h:31

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 912 of file tgbgauss.cc.

913 {
914  mp[add_to]= mac_p_add_ff_qq(mp[add_to], factor,mp[summand]);
915 }
mac_poly mac_p_add_ff_qq(mac_poly a, number f, mac_poly b)
Definition: tgbgauss.cc:19
CanonicalForm factor
Definition: facAbsFact.cc:101
mac_poly * mp
Definition: tgbgauss.h:58

§ free_row()

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

Definition at line 931 of file tgbgauss.cc.

932 {
933  if(free_non_zeros)
934  mac_destroy(mp[row]);
935  else
936  {
937  while(mp[row]!=NULL)
938  {
939  mac_poly next=mp[row]->next;
940  delete mp[row];
941  mp[row]=next;
942  }
943  }
944  mp[row]=NULL;
945 }
mac_poly_r * next
Definition: tgbgauss.h:46
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:116
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58
ListNode * next
Definition: janet.h:31

§ get()

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

Definition at line 769 of file tgbgauss.cc.

770 {
771  assume(i<rows);
772  assume(j<columns);
773  mac_poly rr=mp[i];
774  while((rr!=NULL)&&(rr->exp<j))
775  rr=rr->next;
776  if ((rr==NULL)||(rr->exp>j))
777  {
778  number n=nInit(0);
779  return n;
780  }
781  assume(rr->exp==j);
782  return rr->coef;
783 }
int exp
Definition: tgbgauss.h:47
number coef
Definition: tgbgauss.h:45
mac_poly_r * next
Definition: tgbgauss.h:46
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
#define nInit(i)
Definition: numbers.h:24
mac_poly * mp
Definition: tgbgauss.h:58

§ get_columns()

int tgb_sparse_matrix::get_columns ( )

Definition at line 764 of file tgbgauss.cc.

765 {
766  return columns;
767 }

§ get_rows()

int tgb_sparse_matrix::get_rows ( )

Definition at line 759 of file tgbgauss.cc.

760 {
761  return rows;
762 }

§ is_zero_entry()

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

Definition at line 785 of file tgbgauss.cc.

786 {
787  assume(i<rows);
788  assume(j<columns);
789  mac_poly rr=mp[i];
790  while((rr!=NULL)&&(rr->exp<j))
791  rr=rr->next;
792  if ((rr==NULL)||(rr->exp>j))
793  {
794  return TRUE;
795  }
796  assume(!nIsZero(rr->coef));
797  assume(rr->exp==j);
798  return FALSE;
799 }
#define FALSE
Definition: auxiliary.h:94
int exp
Definition: tgbgauss.h:47
#define TRUE
Definition: auxiliary.h:98
number coef
Definition: tgbgauss.h:45
mac_poly_r * next
Definition: tgbgauss.h:46
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

§ min_col_not_zero_in_row()

int tgb_sparse_matrix::min_col_not_zero_in_row ( int  row)

Definition at line 801 of file tgbgauss.cc.

802 {
803  if(mp[row]!=NULL)
804  {
805  assume(!nIsZero(mp[row]->coef));
806  return mp[row]->exp;
807  }
808  else
809  return columns;//error code
810 }
int exp
Definition: tgbgauss.h:47
#define assume(x)
Definition: mod2.h:394
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

§ mult_row()

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

Definition at line 917 of file tgbgauss.cc.

918 {
919  if (nIsZero(factor))
920  {
921  mac_destroy(mp[row]);
922  mp[row]=NULL;
923 
924  return;
925  }
926  if(nIsOne(factor))
927  return;
928  mac_mult_cons(mp[row],factor);
929 }
#define nIsOne(n)
Definition: numbers.h:25
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:116
CanonicalForm factor
Definition: facAbsFact.cc:101
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:10
void mac_mult_cons(mac_poly p, number c)
Definition: tgbgauss.cc:94
mac_poly * mp
Definition: tgbgauss.h:58

§ next_col_not_zero()

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

Definition at line 812 of file tgbgauss.cc.

813 {
814  mac_poly rr=mp[row];
815  while((rr!=NULL)&&(rr->exp<=pre))
816  rr=rr->next;
817  if(rr!=NULL)
818  {
819  assume(!nIsZero(rr->coef));
820  return rr->exp;
821  }
822  return columns;//error code
823 }
int exp
Definition: tgbgauss.h:47
number coef
Definition: tgbgauss.h:45
mac_poly_r * next
Definition: tgbgauss.h:46
#define assume(x)
Definition: mod2.h:394
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

§ non_zero_entries()

int tgb_sparse_matrix::non_zero_entries ( int  row)

Definition at line 906 of file tgbgauss.cc.

907 {
908  return mac_length(mp[row]);
909 }
int mac_length(mac_poly p)
Definition: tgbgauss.cc:105
mac_poly * mp
Definition: tgbgauss.h:58

§ perm_rows()

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

Definition at line 74 of file tgbgauss.h.

74  {
75  mac_poly h;
76  h=mp[i];
77  mp[i]=mp[j];
78  mp[j]=h;
79  }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
static Poly * h
Definition: janet.cc:978
mac_poly * mp
Definition: tgbgauss.h:58

§ print()

void tgb_sparse_matrix::print ( )

Definition at line 701 of file tgbgauss.cc.

702 {
703  int i;
704  int j;
705  PrintLn();
706  for(i=0;i<rows;i++)
707  {
708  PrintS("(");
709  for(j=0;j<columns;j++)
710  {
711  StringSetS("");
712  number n=get(i,j);
713  n_Write(n,currRing->cf);
714  char *s=StringEndS();
715  PrintS(s);
716  omFree(s);
717  PrintS("\t");
718  }
719  PrintS(")\n");
720  }
721 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void PrintLn()
Definition: reporter.cc:310
char * StringEndS()
Definition: reporter.cc:151
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
int j
Definition: myNF.cc:70
#define omFree(addr)
Definition: omAllocDecl.h:261
void StringSetS(const char *st)
Definition: reporter.cc:128
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:595
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:284

§ row_content()

void tgb_sparse_matrix::row_content ( int  row)

Definition at line 850 of file tgbgauss.cc.

851 {
852  mac_poly ph=mp[row];
853  number h,d;
854  mac_poly p;
855 
856  if(TEST_OPT_CONTENTSB) return;
857  if(ph->next==NULL)
858  {
859  nDelete(&ph->coef);
860  ph->coef=nInit(1);
861  }
862  else
863  {
864  nNormalize(ph->coef);
865  if(!nGreaterZero(ph->coef))
866  {
867  //ph = pNeg(ph);
868  p=ph;
869  while(p!=NULL)
870  {
871  p->coef=nInpNeg(p->coef);
872  p=p->next;
873  }
874  }
875 
876  h=nCopy(ph->coef);
877  p = ph->next;
878 
879  while (p!=NULL)
880  {
881  nNormalize(p->coef);
882  d=n_Gcd(h,p->coef,currRing->cf);
883  nDelete(&h);
884  h = d;
885  if(nIsOne(h))
886  {
887  break;
888  }
889  p=p->next;
890  }
891  p = ph;
892  //number tmp;
893  if(!nIsOne(h))
894  {
895  while (p!=NULL)
896  {
897  d = nExactDiv(p->coef,h);
898  nDelete(&p->coef);
899  p->coef=d;
900  p=p->next;
901  }
902  }
903  nDelete(&h);
904  }
905 }
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of &#39;a&#39; and &#39;b&#39; in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ...
Definition: coeffs.h:690
#define nNormalize(n)
Definition: numbers.h:30
return P p
Definition: myNF.cc:203
#define TEST_OPT_CONTENTSB
Definition: options.h:121
#define nIsOne(n)
Definition: numbers.h:25
#define nExactDiv(a, b)
Definition: numbers.h:34
number coef
Definition: tgbgauss.h:45
mac_poly_r * next
Definition: tgbgauss.h:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
#define nGreaterZero(n)
Definition: numbers.h:27
#define nInpNeg(n)
Definition: numbers.h:21
#define nDelete(n)
Definition: numbers.h:16
#define NULL
Definition: omList.c:10
#define nCopy(n)
Definition: numbers.h:15
#define nInit(i)
Definition: numbers.h:24
static Poly * h
Definition: janet.cc:978
mac_poly * mp
Definition: tgbgauss.h:58

§ row_normalize()

void tgb_sparse_matrix::row_normalize ( int  row)

Definition at line 834 of file tgbgauss.cc.

835 {
836  if (!rField_has_simple_inverse(r)) /* Z/p, GF(p,n), R, long R/C */
837  {
838  mac_poly m=mp[row];
839  while (m!=NULL)
840  {
841  #ifndef SING_NDEBUG
842  if (currRing==r) {nTest(m->coef);}
843  #endif
844  n_Normalize(m->coef,r->cf);
845  m=m->next;
846  }
847  }
848 }
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:582
number coef
Definition: tgbgauss.h:45
mac_poly_r * next
Definition: tgbgauss.h:46
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:540
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
#define nTest(a)
Definition: numbers.h:35
int m
Definition: cfEzgcd.cc:119
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

§ set()

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

Definition at line 724 of file tgbgauss.cc.

725 {
726  assume(i<rows);
727  assume(j<columns);
728  mac_poly* set_this=&mp[i];
729  // while(((*set_this)!=NULL)&&((*set_this)\AD>exp<j))
730  while(((*set_this)!=NULL) && ((*set_this)->exp<j))
731  set_this=&((*set_this)->next);
732 
733  if (((*set_this)==NULL)||((*set_this)->exp>j))
734  {
735  if (nIsZero(n)) return;
736  mac_poly old=(*set_this);
737  (*set_this)=new mac_poly_r();
738  (*set_this)->exp=j;
739  (*set_this)->coef=n;
740  (*set_this)->next=old;
741  return;
742  }
743  assume((*set_this)->exp==j);
744  if(!nIsZero(n))
745  {
746  nDelete(&(*set_this)->coef);
747  (*set_this)->coef=n;
748  }
749  else
750  {
751  nDelete(&(*set_this)->coef);
752  mac_poly dt=(*set_this);
753  (*set_this)=dt->next;
754  delete dt;
755  }
756  return;
757 }
mac_poly_r * next
Definition: tgbgauss.h:46
int j
Definition: myNF.cc:70
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
#define nDelete(n)
Definition: numbers.h:16
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

§ sort_rows()

void tgb_sparse_matrix::sort_rows ( )

Definition at line 696 of file tgbgauss.cc.

697 {
698  qsort(mp,rows,sizeof(mac_poly),row_cmp_gen);
699 }
static int row_cmp_gen(const void *a, const void *b)
Definition: tgbgauss.cc:686
mac_poly * mp
Definition: tgbgauss.h:58

§ zero_row()

BOOLEAN tgb_sparse_matrix::zero_row ( int  row)

Definition at line 825 of file tgbgauss.cc.

826 {
827  assume((mp[row]==NULL)||(!nIsZero(mp[row]->coef)));
828  if (mp[row]==NULL)
829  return TRUE;
830  else
831  return FALSE;
832 }
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
#define assume(x)
Definition: mod2.h:394
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

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 3101 of file tgb.cc.

3103 {
3104  poly p = NULL;
3105  poly *set_this = &p;
3106  mac_poly r = mat->mp[row];
3107  mat->mp[row] = NULL;
3108  while(r)
3109  {
3110  (*set_this) = pLmInit (monoms[monom_index - 1 - r->exp]);
3111  pSetCoeff ((*set_this), r->coef);
3112  set_this = &((*set_this)->next);
3113  mac_poly old = r;
3114  r = r->next;
3115  delete old;
3116 
3117  }
3118  return p;
3119 }
return P p
Definition: myNF.cc:203
int exp
Definition: tgbgauss.h:47
number coef
Definition: tgbgauss.h:45
mac_poly_r * next
Definition: tgbgauss.h:46
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
#define NULL
Definition: omList.c:10
polyrec * poly
Definition: hilb.h:10
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
mac_poly * mp
Definition: tgbgauss.h:58

§ init_with_mac_poly

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

Definition at line 3086 of file tgb.cc.

3087 {
3088  assume (mat->mp[row] == NULL);
3089  mat->mp[row] = m;
3090 #ifdef TGB_DEBUG
3091  mac_poly r = m;
3092  while(r)
3093  {
3094  assume (r->exp < mat->columns);
3095  r = r->next;
3096  }
3097 #endif
3098 }
int exp
Definition: tgbgauss.h:47
mac_poly_r * next
Definition: tgbgauss.h:46
#define assume(x)
Definition: mod2.h:394
int m
Definition: cfEzgcd.cc:119
#define NULL
Definition: omList.c:10
mac_poly * mp
Definition: tgbgauss.h:58

Field Documentation

§ columns

int tgb_sparse_matrix::columns
private

Definition at line 59 of file tgbgauss.h.

§ free_numbers

BOOLEAN tgb_sparse_matrix::free_numbers
private

Definition at line 61 of file tgbgauss.h.

§ mp

mac_poly* tgb_sparse_matrix::mp
private

Definition at line 58 of file tgbgauss.h.

§ r

ring tgb_sparse_matrix::r
private

Definition at line 57 of file tgbgauss.h.

§ rows

int tgb_sparse_matrix::rows
private

Definition at line 60 of file tgbgauss.h.


The documentation for this class was generated from the following files: