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

646 {
647  mp=(mac_poly*) omAlloc(i*sizeof (mac_poly));;
648  int z;
649  for(z=0;z<i;z++)
650  {
651  mp[z]=NULL;
652  }
653  columns=j;
654  rows=i;
656  r=rarg;
657 }
int j
Definition: facHensel.cc:105
#define FALSE
Definition: auxiliary.h:96
#define omAlloc(size)
Definition: omAllocDecl.h:210
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:12
BOOLEAN free_numbers
Definition: tgbgauss.h:67
mac_poly * mp
Definition: tgbgauss.h:64

◆ ~tgb_sparse_matrix()

tgb_sparse_matrix::~tgb_sparse_matrix ( )

Definition at line 659 of file tgbgauss.cc.

660 {
661  int z;
662  for(z=0;z<rows;z++)
663  {
664  if(mp[z]!=NULL)
665  {
666  if(free_numbers)
667  {
668  mac_destroy(mp[z]);
669  }
670  else {
671  while(mp[z]!=NULL)
672  {
673  mac_poly next=mp[z]->next;
674  delete mp[z];
675  mp[z]=next;
676  }
677  }
678  }
679  }
680  omfree(mp);
681 }
mac_poly_r * next
Definition: tgbgauss.h:51
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:113
#define omfree(addr)
Definition: omAllocDecl.h:237
#define NULL
Definition: omList.c:12
BOOLEAN free_numbers
Definition: tgbgauss.h:67
mac_poly * mp
Definition: tgbgauss.h:64
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 909 of file tgbgauss.cc.

910 {
911  mp[add_to]= mac_p_add_ff_qq(mp[add_to], factor,mp[summand]);
912 }
mac_poly mac_p_add_ff_qq(mac_poly a, number f, mac_poly b)
Definition: tgbgauss.cc:16
CanonicalForm factor
Definition: facAbsFact.cc:101
mac_poly * mp
Definition: tgbgauss.h:64

◆ free_row()

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

Definition at line 928 of file tgbgauss.cc.

929 {
930  if(free_non_zeros)
931  mac_destroy(mp[row]);
932  else
933  {
934  while(mp[row]!=NULL)
935  {
936  mac_poly next=mp[row]->next;
937  delete mp[row];
938  mp[row]=next;
939  }
940  }
941  mp[row]=NULL;
942 }
mac_poly_r * next
Definition: tgbgauss.h:51
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:113
#define NULL
Definition: omList.c:12
mac_poly * mp
Definition: tgbgauss.h:64
ListNode * next
Definition: janet.h:31

◆ get()

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

Definition at line 766 of file tgbgauss.cc.

767 {
768  assume(i<rows);
769  assume(j<columns);
770  mac_poly rr=mp[i];
771  while((rr!=NULL)&&(rr->exp<j))
772  rr=rr->next;
773  if ((rr==NULL)||(rr->exp>j))
774  {
775  number n=nInit(0);
776  return n;
777  }
778  assume(rr->exp==j);
779  return rr->coef;
780 }
int j
Definition: facHensel.cc:105
int exp
Definition: tgbgauss.h:52
number coef
Definition: tgbgauss.h:50
mac_poly_r * next
Definition: tgbgauss.h:51
#define assume(x)
Definition: mod2.h:390
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:12
#define nInit(i)
Definition: numbers.h:24
mac_poly * mp
Definition: tgbgauss.h:64

◆ get_columns()

int tgb_sparse_matrix::get_columns ( )

Definition at line 761 of file tgbgauss.cc.

762 {
763  return columns;
764 }

◆ get_rows()

int tgb_sparse_matrix::get_rows ( )

Definition at line 756 of file tgbgauss.cc.

757 {
758  return rows;
759 }

◆ is_zero_entry()

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

Definition at line 782 of file tgbgauss.cc.

783 {
784  assume(i<rows);
785  assume(j<columns);
786  mac_poly rr=mp[i];
787  while((rr!=NULL)&&(rr->exp<j))
788  rr=rr->next;
789  if ((rr==NULL)||(rr->exp>j))
790  {
791  return TRUE;
792  }
793  assume(!nIsZero(rr->coef));
794  assume(rr->exp==j);
795  return FALSE;
796 }
int j
Definition: facHensel.cc:105
#define FALSE
Definition: auxiliary.h:96
int exp
Definition: tgbgauss.h:52
#define TRUE
Definition: auxiliary.h:100
number coef
Definition: tgbgauss.h:50
mac_poly_r * next
Definition: tgbgauss.h:51
#define assume(x)
Definition: mod2.h:390
int i
Definition: cfEzgcd.cc:125
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:12
mac_poly * mp
Definition: tgbgauss.h:64

◆ min_col_not_zero_in_row()

int tgb_sparse_matrix::min_col_not_zero_in_row ( int  row)

Definition at line 798 of file tgbgauss.cc.

799 {
800  if(mp[row]!=NULL)
801  {
802  assume(!nIsZero(mp[row]->coef));
803  return mp[row]->exp;
804  }
805  else
806  return columns;//error code
807 }
int exp
Definition: tgbgauss.h:52
#define assume(x)
Definition: mod2.h:390
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:12
mac_poly * mp
Definition: tgbgauss.h:64

◆ mult_row()

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

Definition at line 914 of file tgbgauss.cc.

915 {
916  if (nIsZero(factor))
917  {
918  mac_destroy(mp[row]);
919  mp[row]=NULL;
920 
921  return;
922  }
923  if(nIsOne(factor))
924  return;
925  mac_mult_cons(mp[row],factor);
926 }
#define nIsOne(n)
Definition: numbers.h:25
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:113
CanonicalForm factor
Definition: facAbsFact.cc:101
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:12
void mac_mult_cons(mac_poly p, number c)
Definition: tgbgauss.cc:91
mac_poly * mp
Definition: tgbgauss.h:64

◆ next_col_not_zero()

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

Definition at line 809 of file tgbgauss.cc.

810 {
811  mac_poly rr=mp[row];
812  while((rr!=NULL)&&(rr->exp<=pre))
813  rr=rr->next;
814  if(rr!=NULL)
815  {
816  assume(!nIsZero(rr->coef));
817  return rr->exp;
818  }
819  return columns;//error code
820 }
int exp
Definition: tgbgauss.h:52
number coef
Definition: tgbgauss.h:50
mac_poly_r * next
Definition: tgbgauss.h:51
#define assume(x)
Definition: mod2.h:390
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:12
mac_poly * mp
Definition: tgbgauss.h:64

◆ non_zero_entries()

int tgb_sparse_matrix::non_zero_entries ( int  row)

Definition at line 903 of file tgbgauss.cc.

904 {
905  return mac_length(mp[row]);
906 }
int mac_length(mac_poly p)
Definition: tgbgauss.cc:102
mac_poly * mp
Definition: tgbgauss.h:64

◆ 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  }
int j
Definition: facHensel.cc:105
int i
Definition: cfEzgcd.cc:125
STATIC_VAR Poly * h
Definition: janet.cc:971
mac_poly * mp
Definition: tgbgauss.h:64

◆ print()

void tgb_sparse_matrix::print ( )

Definition at line 698 of file tgbgauss.cc.

699 {
700  int i;
701  int j;
702  PrintLn();
703  for(i=0;i<rows;i++)
704  {
705  PrintS("(");
706  for(j=0;j<columns;j++)
707  {
708  StringSetS("");
709  number n=get(i,j);
710  n_Write(n,currRing->cf);
711  char *s=StringEndS();
712  PrintS(s);
713  omFree(s);
714  PrintS("\t");
715  }
716  PrintS(")\n");
717  }
718 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int j
Definition: facHensel.cc:105
void PrintLn()
Definition: reporter.cc:310
char * StringEndS()
Definition: reporter.cc:151
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#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:591
int i
Definition: cfEzgcd.cc:125
void PrintS(const char *s)
Definition: reporter.cc:284

◆ row_content()

void tgb_sparse_matrix::row_content ( int  row)

Definition at line 847 of file tgbgauss.cc.

848 {
849  mac_poly ph=mp[row];
850  number h,d;
851  mac_poly p;
852 
853  if(TEST_OPT_CONTENTSB) return;
854  if(ph->next==NULL)
855  {
856  nDelete(&ph->coef);
857  ph->coef=nInit(1);
858  }
859  else
860  {
861  nNormalize(ph->coef);
862  if(!nGreaterZero(ph->coef))
863  {
864  //ph = pNeg(ph);
865  p=ph;
866  while(p!=NULL)
867  {
868  p->coef=nInpNeg(p->coef);
869  p=p->next;
870  }
871  }
872 
873  h=nCopy(ph->coef);
874  p = ph->next;
875 
876  while (p!=NULL)
877  {
878  nNormalize(p->coef);
879  d=n_Gcd(h,p->coef,currRing->cf);
880  nDelete(&h);
881  h = d;
882  if(nIsOne(h))
883  {
884  break;
885  }
886  p=p->next;
887  }
888  p = ph;
889  //number tmp;
890  if(!nIsOne(h))
891  {
892  while (p!=NULL)
893  {
894  d = nExactDiv(p->coef,h);
895  nDelete(&p->coef);
896  p->coef=d;
897  p=p->next;
898  }
899  }
900  nDelete(&h);
901  }
902 }
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:686
#define nNormalize(n)
Definition: numbers.h:30
#define TEST_OPT_CONTENTSB
Definition: options.h:124
#define nIsOne(n)
Definition: numbers.h:25
#define nExactDiv(a, b)
Definition: numbers.h:34
number coef
Definition: tgbgauss.h:50
mac_poly_r * next
Definition: tgbgauss.h:51
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#define nGreaterZero(n)
Definition: numbers.h:27
#define nInpNeg(n)
Definition: numbers.h:21
#define nDelete(n)
Definition: numbers.h:16
STATIC_VAR Poly * h
Definition: janet.cc:971
#define NULL
Definition: omList.c:12
#define nCopy(n)
Definition: numbers.h:15
int p
Definition: cfModGcd.cc:4019
#define nInit(i)
Definition: numbers.h:24
mac_poly * mp
Definition: tgbgauss.h:64

◆ row_normalize()

void tgb_sparse_matrix::row_normalize ( int  row)

Definition at line 831 of file tgbgauss.cc.

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

◆ set()

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

Definition at line 721 of file tgbgauss.cc.

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

◆ sort_rows()

void tgb_sparse_matrix::sort_rows ( )

Definition at line 693 of file tgbgauss.cc.

694 {
695  qsort(mp,rows,sizeof(mac_poly),row_cmp_gen);
696 }
static int row_cmp_gen(const void *a, const void *b)
Definition: tgbgauss.cc:683
mac_poly * mp
Definition: tgbgauss.h:64

◆ zero_row()

BOOLEAN tgb_sparse_matrix::zero_row ( int  row)

Definition at line 822 of file tgbgauss.cc.

823 {
824  assume((mp[row]==NULL)||(!nIsZero(mp[row]->coef)));
825  if (mp[row]==NULL)
826  return TRUE;
827  else
828  return FALSE;
829 }
#define FALSE
Definition: auxiliary.h:96
#define TRUE
Definition: auxiliary.h:100
#define assume(x)
Definition: mod2.h:390
#define nIsZero(n)
Definition: numbers.h:19
#define NULL
Definition: omList.c:12
mac_poly * mp
Definition: tgbgauss.h:64

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 }
int exp
Definition: tgbgauss.h:52
number coef
Definition: tgbgauss.h:50
mac_poly_r * next
Definition: tgbgauss.h:51
#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:12
int p
Definition: cfModGcd.cc:4019
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
mac_poly * mp
Definition: tgbgauss.h:64

◆ 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 }
int exp
Definition: tgbgauss.h:52
mac_poly_r * next
Definition: tgbgauss.h:51
#define assume(x)
Definition: mod2.h:390
int m
Definition: cfEzgcd.cc:121
#define NULL
Definition: omList.c:12
mac_poly * mp
Definition: tgbgauss.h:64

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: