source: git/kernel/GBEngine/tgbgauss.cc @ 5aba1a

fieker-DuValspielwiese
Last change on this file since 5aba1a was aae39f, checked in by Hans Schoenemann <hannes@…>, 10 years ago
fix: HAVE_EIGENVAL
  • Property mode set to 100644
File size: 18.2 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: gauss implementation for F4
6*/
7
8
9
10#include <kernel/mod2.h>
11#include <misc/options.h>
12#include <kernel/GBEngine/tgbgauss.h>
13#include <omalloc/omalloc.h>
14#include <stdlib.h>
15#include <kernel/GBEngine/kutil.h>
16#include <kernel/polys.h>
17static const int bundle_size=100;
18
19mac_poly mac_p_add_ff_qq(mac_poly a, number f,mac_poly b)
20{
21  mac_poly erg;
22  mac_poly* set_this;
23  set_this=&erg;
24  while((a!=NULL) &&(b!=NULL))
25  {
26    if (a->exp<b->exp)
27    {
28      (*set_this)=a;
29      a=a->next;
30      set_this= &((*set_this)->next);
31    }
32    else
33    {
34      if (a->exp>b->exp)
35      {
36        mac_poly in =new mac_poly_r();
37        in->exp=b->exp;
38        in->coef=nMult(b->coef,f);
39        (*set_this)=in;
40        b=b->next;
41        set_this= &((*set_this)->next);
42      }
43      else
44      {
45        //a->exp==b->ecp
46        number n=nMult(b->coef,f);
47        number n2=nAdd(a->coef,n);
48        nDelete(&n);
49        nDelete(&(a->coef));
50        if (nIsZero(n2))
51        {
52          nDelete(&n2);
53          mac_poly ao=a;
54          a=a->next;
55          delete ao;
56          b=b->next;
57        }
58        else
59        {
60          a->coef=n2;
61          b=b->next;
62          (*set_this)=a;
63          a=a->next;
64          set_this= &((*set_this)->next);
65        }
66      }
67    }
68  }
69  if((a==NULL)&&(b==NULL))
70  {
71    (*set_this)=NULL;
72    return erg;
73  }
74  if (b==NULL)
75  {
76    (*set_this=a);
77    return erg;
78  }
79
80  //a==NULL
81  while(b!=NULL)
82  {
83    mac_poly mp= new mac_poly_r();
84    mp->exp=b->exp;
85    mp->coef=nMult(f,b->coef);
86    (*set_this)=mp;
87    set_this=&(mp->next);
88    b=b->next;
89  }
90  (*set_this)=NULL;
91  return erg;
92}
93
94void mac_mult_cons(mac_poly p,number c)
95{
96  while(p)
97  {
98    number m=nMult(p->coef,c);
99    nDelete(&(p->coef));
100    p->coef=m;
101    p=p->next;
102  }
103}
104
105int mac_length(mac_poly p)
106{
107  int l=0;
108  while(p){
109    l++;
110    p=p->next;
111  }
112  return l;
113}
114
115//contrary to delete on the mac_poly_r, the coefficients are also destroyed here
116void mac_destroy(mac_poly p)
117{
118  mac_poly iter=p;
119  while(iter)
120  {
121    mac_poly next=iter->next;
122    nDelete(&iter->coef);
123    delete iter;
124    iter=next;
125  }
126}
127
128void simple_gauss(tgb_sparse_matrix* mat, slimgb_alg* /*c*/)
129{
130  int col, row;
131  int* row_cache=(int*) omAlloc(mat->get_rows()*sizeof(int));
132  col=0;
133  row=0;
134  int i;
135  int pn=mat->get_rows();
136  int matcol=mat->get_columns();
137  int* area=(int*) omAlloc(sizeof(int)*((matcol-1)/bundle_size+1));
138  const int max_area_index=(matcol-1)/bundle_size;
139    //rows are divided in areas
140  //if row begins with columns col, it is located in [area[col/bundle_size],area[col/bundle_size+1]-1]
141  assume(pn>0);
142  //first clear zeroes
143  for(i=0;i<pn;i++)
144  {
145    if(mat->zero_row(i))
146    {
147      mat->perm_rows(i,pn-1);
148      pn--;
149      if(i!=pn){i--;}
150    }
151
152  }
153  mat->sort_rows();
154  for(i=0;i<pn;i++)
155  {
156      row_cache[i]=mat->min_col_not_zero_in_row(i);
157      // Print("row_cache:%d\n",row_cache[i]);
158  }
159  int last_area=-1;
160  for(i=0;i<pn;i++)
161  {
162    int this_area=row_cache[i]/bundle_size;
163    assume(this_area>=last_area);
164    if(this_area>last_area)
165    {
166      int j;
167      for(j=last_area+1;j<=this_area;j++)
168        area[j]=i;
169      last_area=this_area;
170    }
171  }
172  for(i=last_area+1;i<=max_area_index;i++)
173  {
174    area[i]=pn;
175  }
176  while(row<pn-1)
177  {
178    //row is the row where pivot should be
179    // row== pn-1 means we have only to act on one row so no red nec.
180    //we assume further all rows till the pn-1 row are non-zero
181
182    //select column
183
184    //col=mat->min_col_not_zero_in_row(row);
185    int max_in_area;
186    {
187      int tai=row_cache[row]/bundle_size;
188      assume(tai<=max_area_index);
189      if(tai==max_area_index)
190        max_in_area=pn-1;
191      else
192        max_in_area=area[tai+1]-1;
193    }
194    assume(row_cache[row]==mat->min_col_not_zero_in_row(row));
195    col=row_cache[row];
196
197    assume(col!=matcol);
198    int found_in_row;
199
200    found_in_row=row;
201    BOOLEAN must_reduce=FALSE;
202    assume(pn<=mat->get_rows());
203    for(i=row+1;i<=max_in_area;i++)
204    {
205      int first;//=mat->min_col_not_zero_in_row(i);
206      assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
207      first=row_cache[i];
208      assume(first!=matcol);
209      if(first<col)
210      {
211        col=first;
212        found_in_row=i;
213        must_reduce=FALSE;
214      }
215      else
216      {
217        if(first==col)
218          must_reduce=TRUE;
219      }
220    }
221    //select pivot
222    int act_l=nSize(mat->get(found_in_row,col))*mat->non_zero_entries(found_in_row);
223    if(must_reduce)
224    {
225      for(i=found_in_row+1;i<=max_in_area;i++)
226      {
227        assume(mat->min_col_not_zero_in_row(i)>=col);
228        assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
229#ifndef SING_NDEBUG
230        int first=row_cache[i];
231        assume(first!=matcol);
232#endif
233        //      if((!(mat->is_zero_entry(i,col)))&&(mat->non_zero_entries(i)<act_l))
234        int nz;
235        if((row_cache[i]==col)&&((nz=nSize(mat->get(i,col))*mat->non_zero_entries(i))<act_l))
236        {
237          found_in_row=i;
238          act_l=nz;
239        }
240
241      }
242    }
243    mat->perm_rows(row,found_in_row);
244    int h=row_cache[row];
245    row_cache[row]=row_cache[found_in_row];
246    row_cache[found_in_row]=h;
247
248    if(!must_reduce)
249    {
250      row++;
251      continue;
252    }
253    //reduction
254    //must extract content and normalize here
255    mat->row_content(row);
256    mat->row_normalize(row);
257
258    //for(i=row+1;i<pn;i++){
259    for(i=max_in_area;i>row;i--)
260    {
261      int col_area_index=col/bundle_size;
262      assume(col_area_index<=max_area_index);
263      assume(mat->min_col_not_zero_in_row(i)>=col);
264      assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
265#ifndef SING_NDEBUG
266      int first=row_cache[i];
267      assume(first!=matcol);
268#endif
269      if(row_cache[i]==col)
270      {
271
272        number c1=mat->get(i,col);
273        number c2=mat->get(row,col);
274        number n1=c1;
275        number n2=c2;
276
277        ksCheckCoeff(&n1,&n2,currRing->cf);
278        //nDelete(&c1);
279        n1=nInpNeg(n1);
280        mat->mult_row(i,n2);
281        mat->add_lambda_times_row(i,row,n1);
282        nDelete(&n1);
283        nDelete(&n2);
284        assume(mat->is_zero_entry(i,col));
285        row_cache[i]=mat->min_col_not_zero_in_row(i);
286        assume(mat->min_col_not_zero_in_row(i)>col);
287        if(row_cache[i]==matcol)
288        {
289          int index;
290          index=i;
291          int last_in_area;
292          int this_cai=col_area_index;
293          while(this_cai<max_area_index)
294          {
295            last_in_area=area[this_cai+1]-1;
296            int h_c=row_cache[last_in_area];
297            row_cache[last_in_area]=row_cache[index];
298            row_cache[index]=h_c;
299            mat->perm_rows(index,last_in_area);
300            index=last_in_area;
301            this_cai++;
302            area[this_cai]--;
303          }
304          mat->perm_rows(index,pn-1);
305          row_cache[index]=row_cache[pn-1];
306          row_cache[pn-1]=matcol;
307          pn--;
308        }
309        else
310        {
311          int index;
312          index=i;
313          int last_in_area;
314          int this_cai=col_area_index;
315          int final_cai=row_cache[index]/bundle_size;
316          assume(final_cai<=max_area_index);
317          while(this_cai<final_cai)
318          {
319            last_in_area=area[this_cai+1]-1;
320            int h_c=row_cache[last_in_area];
321            row_cache[last_in_area]=row_cache[index];
322            row_cache[index]=h_c;
323            mat->perm_rows(index,last_in_area);
324            index=last_in_area;
325            this_cai++;
326            area[this_cai]--;
327          }
328        }
329      }
330      else
331        assume(mat->min_col_not_zero_in_row(i)>col);
332    }
333//     for(i=row+1;i<pn;i++)
334//     {
335//       assume(mat->min_col_not_zero_in_row(i)==row_cache[i]);
336//       // if(mat->zero_row(i))
337//       assume(matcol==mat->get_columns());
338//       if(row_cache[i]==matcol)
339//       {
340//         assume(mat->zero_row(i));
341//         mat->perm_rows(i,pn-1);
342//         row_cache[i]=row_cache[pn-1];
343//         row_cache[pn-1]=matcol;
344//         pn--;
345//         if(i!=pn){i--;}
346//       }
347//     }
348#ifdef TGB_DEBUG
349  {
350    int last=-1;
351    for(i=0;i<pn;i++)
352    {
353      int act=mat->min_col_not_zero_in_row(i);
354      assume(act>last);
355    }
356    for(i=pn;i<mat->get_rows();i++)
357    {
358      assume(mat->zero_row(i));
359    }
360  }
361#endif
362    row++;
363  }
364  omFree(area);
365  omFree(row_cache);
366}
367
368void simple_gauss2(tgb_matrix* mat)
369{
370  int col, row;
371  col=0;
372  row=0;
373  int i;
374  int pn=mat->get_rows();
375  assume(pn>0);
376  //first clear zeroes
377//   for(i=0;i<pn;i++)
378//   {
379//     if(mat->zero_row(i))
380//     {
381//       mat->perm_rows(i,pn-1);
382//       pn--;
383//       if(i!=pn){i--;}
384//     }
385//   }
386  while((row<pn-1)&&(col<mat->get_columns())){
387    //row is the row where pivot should be
388    // row== pn-1 means we have only to act on one row so no red nec.
389    //we assume further all rows till the pn-1 row are non-zero
390
391    //select column
392
393    //    col=mat->min_col_not_zero_in_row(row);
394    assume(col!=mat->get_columns());
395    int found_in_row=-1;
396
397    //    found_in_row=row;
398    assume(pn<=mat->get_rows());
399    for(i=row;i<pn;i++)
400    {
401      //    int first=mat->min_col_not_zero_in_row(i);
402      //  if(first<col)
403      if(!(mat->is_zero_entry(i,col)))
404      {
405        found_in_row=i;
406        break;
407      }
408    }
409    if(found_in_row!=-1)
410    {
411    //select pivot
412      int act_l=mat->non_zero_entries(found_in_row);
413      for(i=i+1;i<pn;i++)
414      {
415        int vgl;
416        assume(mat->min_col_not_zero_in_row(i)>=col);
417        if((!(mat->is_zero_entry(i,col)))
418        &&((vgl=mat->non_zero_entries(i))<act_l))
419        {
420          found_in_row=i;
421          act_l=vgl;
422        }
423
424      }
425      mat->perm_rows(row,found_in_row);
426
427      //reduction
428      for(i=row+1;i<pn;i++){
429        assume(mat->min_col_not_zero_in_row(i)>=col);
430        if(!(mat->is_zero_entry(i,col)))
431        {
432          number c1=nCopy(mat->get(i,col));
433          c1=nInpNeg(c1);
434          number c2=mat->get(row,col);
435          number n1=c1;
436          number n2=c2;
437
438          ksCheckCoeff(&n1,&n2,currRing->cf);
439          nDelete(&c1);
440          mat->mult_row(i,n2);
441          mat->add_lambda_times_row(i,row,n1);
442          assume(mat->is_zero_entry(i,col));
443        }
444        assume(mat->min_col_not_zero_in_row(i)>col);
445      }
446      row++;
447    }
448    col++;
449    // for(i=row+1;i<pn;i++)
450//     {
451//       if(mat->zero_row(i))
452//       {
453//         mat->perm_rows(i,pn-1);
454//         pn--;
455//         if(i!=pn){i--;}
456//       }
457//     }
458  }
459}
460
461
462tgb_matrix::tgb_matrix(int i, int j)
463{
464  n=(number**) omAlloc(i*sizeof (number*));;
465  int z;
466  int z2;
467  for(z=0;z<i;z++)
468  {
469    n[z]=(number*)omAlloc(j*sizeof(number));
470    for(z2=0;z2<j;z2++)
471    {
472      n[z][z2]=nInit(0);
473    }
474  }
475  columns=j;
476  rows=i;
477  free_numbers=FALSE;
478}
479
480tgb_matrix::~tgb_matrix()
481{
482  int z;
483  for(z=0;z<rows;z++)
484  {
485    if(n[z])
486    {
487      if(free_numbers)
488      {
489        int z2;
490        for(z2=0;z2<columns;z2++)
491        {
492          nDelete(&(n[z][z2]));
493        }
494      }
495      omFree(n[z]);
496    }
497  }
498  omfree(n);
499}
500
501void tgb_matrix::print()
502{
503  int i;
504  int j;
505  PrintLn();
506  for(i=0;i<rows;i++)
507  {
508    PrintS("(");
509    for(j=0;j<columns;j++)
510    {
511      StringSetS("");
512      n_Write(n[i][j],currRing);
513      char *s=StringEndS();
514      PrintS(s);
515      omFree(s);
516      PrintS("\t");
517    }
518    PrintS(")\n");
519  }
520}
521
522//transfers ownership of n to the matrix
523void tgb_matrix::set(int i, int j, number nn)
524{
525  assume(i<rows);
526  assume(j<columns);
527  n[i][j]=nn;
528}
529
530int tgb_matrix::get_rows()
531{
532  return rows;
533}
534
535int tgb_matrix::get_columns()
536{
537  return columns;
538}
539
540number tgb_matrix::get(int i, int j)
541{
542  assume(i<rows);
543  assume(j<columns);
544  return n[i][j];
545}
546
547BOOLEAN tgb_matrix::is_zero_entry(int i, int j)
548{
549  return (nIsZero(n[i][j]));
550}
551
552void tgb_matrix::perm_rows(int i, int j)
553{
554  number* h;
555  h=n[i];
556  n[i]=n[j];
557  n[j]=h;
558}
559
560int tgb_matrix::min_col_not_zero_in_row(int row)
561{
562  int i;
563  for(i=0;i<columns;i++)
564  {
565    if(!(nIsZero(n[row][i])))
566      return i;
567  }
568  return columns;//error code
569}
570
571int tgb_matrix::next_col_not_zero(int row,int pre)
572{
573  int i;
574  for(i=pre+1;i<columns;i++)
575  {
576    if(!(nIsZero(n[row][i])))
577      return i;
578  }
579  return columns;//error code
580}
581
582BOOLEAN tgb_matrix::zero_row(int row)
583{
584  int i;
585  for(i=0;i<columns;i++)
586  {
587    if(!(nIsZero(n[row][i])))
588      return FALSE;
589  }
590  return TRUE;
591}
592
593int tgb_matrix::non_zero_entries(int row)
594{
595  int i;
596  int z=0;
597  for(i=0;i<columns;i++)
598  {
599    if(!(nIsZero(n[row][i])))
600      z++;
601  }
602  return z;
603}
604
605//row add_to=row add_to +row summand*factor
606void tgb_matrix::add_lambda_times_row(int add_to,int summand,number factor)
607{
608  int i;
609  for(i=0;i<columns;i++)
610  {
611    if(!(nIsZero(n[summand][i])))
612    {
613      number n1=n[add_to][i];
614      number n2=nMult(factor,n[summand][i]);
615      n[add_to][i]=nAdd(n1,n2);
616      nDelete(&n1);
617      nDelete(&n2);
618    }
619  }
620}
621
622void tgb_matrix::mult_row(int row,number factor)
623{
624  if (nIsOne(factor))
625    return;
626  int i;
627  for(i=0;i<columns;i++)
628  {
629    if(!(nIsZero(n[row][i])))
630    {
631      number n1=n[row][i];
632      n[row][i]=nMult(n1,factor);
633      nDelete(&n1);
634    }
635  }
636}
637
638void tgb_matrix::free_row(int row, BOOLEAN free_non_zeros)
639{
640  int i;
641  for(i=0;i<columns;i++)
642    if((free_non_zeros)||(!(nIsZero(n[row][i]))))
643      nDelete(&(n[row][i]));
644  omFree(n[row]);
645  n[row]=NULL;
646}
647
648tgb_sparse_matrix::tgb_sparse_matrix(int i, int j, ring rarg)
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;
658  free_numbers=FALSE;
659  r=rarg;
660}
661
662tgb_sparse_matrix::~tgb_sparse_matrix()
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}
685
686static int row_cmp_gen(const void* a, const void* b)
687{
688  const mac_poly ap= *((mac_poly*) a);
689  const mac_poly bp=*((mac_poly*) b);
690  if (ap==NULL) return 1;
691  if (bp==NULL) return -1;
692  if (ap->exp<bp->exp) return -1;
693  return 1;
694}
695
696void tgb_sparse_matrix::sort_rows()
697{
698  qsort(mp,rows,sizeof(mac_poly),row_cmp_gen);
699}
700
701void tgb_sparse_matrix::print()
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);
714      char *s=StringEndS();
715      PrintS(s);
716      omFree(s);
717      PrintS("\t");
718    }
719    PrintS(")\n");
720  }
721}
722
723//transfers ownership of n to the matrix
724void tgb_sparse_matrix::set(int i, int j, number n)
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}
758
759int tgb_sparse_matrix::get_rows()
760{
761  return rows;
762}
763
764int tgb_sparse_matrix::get_columns()
765{
766  return columns;
767}
768
769number tgb_sparse_matrix::get(int i, int j)
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}
784
785BOOLEAN tgb_sparse_matrix::is_zero_entry(int i, int j)
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}
800
801int tgb_sparse_matrix::min_col_not_zero_in_row(int row)
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}
811
812int tgb_sparse_matrix::next_col_not_zero(int row,int pre)
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}
824
825BOOLEAN tgb_sparse_matrix::zero_row(int row)
826{
827  assume((mp[row]==NULL)||(!nIsZero(mp[row]->coef)));
828  if (mp[row]==NULL)
829    return TRUE;
830  else
831    return FALSE;
832}
833
834void tgb_sparse_matrix::row_normalize(int row)
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);
845      m=m->next;
846    }
847  }
848}
849
850void tgb_sparse_matrix::row_content(int row)
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}
906int tgb_sparse_matrix::non_zero_entries(int row)
907{
908  return mac_length(mp[row]);
909}
910
911//row add_to=row add_to +row summand*factor
912void tgb_sparse_matrix::add_lambda_times_row(int add_to,int summand,number factor)
913{
914  mp[add_to]= mac_p_add_ff_qq(mp[add_to], factor,mp[summand]);
915}
916
917void tgb_sparse_matrix::mult_row(int row,number factor)
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}
930
931void tgb_sparse_matrix::free_row(int row, BOOLEAN free_non_zeros)
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}
Note: See TracBrowser for help on using the repository browser.