My Project
Loading...
Searching...
No Matches
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}
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
BOOLEAN free_numbers
Definition: tgbgauss.h:67
mac_poly * mp
Definition: tgbgauss.h:64
int j
Definition: facHensel.cc:110
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define NULL
Definition: omList.c:12

◆ ~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
ListNode * next
Definition: janet.h:31
#define omfree(addr)
Definition: omAllocDecl.h:237
void mac_destroy(mac_poly p)
Definition: tgbgauss.cc:113

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}
CanonicalForm factor
Definition: facAbsFact.cc:97
mac_poly mac_p_add_ff_qq(mac_poly a, number f, mac_poly b)
Definition: tgbgauss.cc:16

◆ 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}

◆ get()

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

Definition at line 766 of file tgbgauss.cc.

767{
768 assume(i<rows);
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}
number coef
Definition: tgbgauss.h:50
int exp
Definition: tgbgauss.h:52
#define assume(x)
Definition: mod2.h:389
#define nInit(i)
Definition: numbers.h:24

◆ 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);
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}
#define TRUE
Definition: auxiliary.h:100
#define nIsZero(n)
Definition: numbers.h:19

◆ 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}

◆ 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_mult_cons(mac_poly p, number c)
Definition: tgbgauss.cc:91

◆ 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}

◆ 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

◆ 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 }
STATIC_VAR Poly * h
Definition: janet.cc:971

◆ 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}
number get(int i, int j)
Definition: tgbgauss.cc:766
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:588
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define omFree(addr)
Definition: omAllocDecl.h:261
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void StringSetS(const char *st)
Definition: reporter.cc:128
void PrintS(const char *s)
Definition: reporter.cc:284
char * StringEndS()
Definition: reporter.cc:151
void PrintLn()
Definition: reporter.cc:310

◆ 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 p=ph;
865 while(p!=NULL)
866 {
867 p->coef=nInpNeg(p->coef);
868 p=p->next;
869 }
870 }
871 if (currRing->cf->cfGcd==ndGcd) return;
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}
int p
Definition: cfModGcd.cc:4078
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:661
number ndGcd(number, number, const coeffs r)
Definition: numbers.cc:189
#define nDelete(n)
Definition: numbers.h:16
#define nInpNeg(n)
Definition: numbers.h:21
#define nCopy(n)
Definition: numbers.h:15
#define nExactDiv(a, b)
Definition: numbers.h:34
#define nGreaterZero(n)
Definition: numbers.h:27
#define nNormalize(n)
Definition: numbers.h:30
#define TEST_OPT_CONTENTSB
Definition: options.h:128

◆ 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}
int m
Definition: cfEzgcd.cc:128
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
Definition: coeffs.h:575
#define nTest(a)
Definition: numbers.h:35
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition: ring.h:548

◆ 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);
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}

◆ 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

◆ 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}

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

3120{
3121 poly p = NULL;
3122 poly *set_this = &p;
3123 mac_poly r = mat->mp[row];
3124 mat->mp[row] = NULL;
3125 while(r)
3126 {
3127 (*set_this) = pLmInit (monoms[monom_index - 1 - r->exp]);
3128 pSetCoeff ((*set_this), r->coef);
3129 set_this = &((*set_this)->next);
3130 mac_poly old = r;
3131 r = r->next;
3132 delete old;
3133
3134 }
3135 return p;
3136}
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64

◆ init_with_mac_poly

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

Definition at line 3103 of file tgb.cc.

3104{
3105 assume (mat->mp[row] == NULL);
3106 mat->mp[row] = m;
3107#ifdef TGB_DEBUG
3108 mac_poly r = m;
3109 while(r)
3110 {
3111 assume (r->exp < mat->columns);
3112 r = r->next;
3113 }
3114#endif
3115}

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: