source: git/kernel/GBEngine/tgbgauss.cc @ 24bc73

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