source: git/kernel/tgbgauss.cc @ 4da485

spielwiese
Last change on this file since 4da485 was 44fac1, checked in by Hans Schoenemann <hannes@…>, 11 years ago
fix: omalloc -> omAlloc from master
  • 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#include "config.h"
8#include <kernel/mod2.h>
9#include <misc/options.h>
10#include <kernel/tgbgauss.h>
11#include <omalloc/omalloc.h>
12#include <stdlib.h>
13#include <kernel/kutil.h>
14#include <kernel/febase.h>
15#include <kernel/polys.h>
16static const int bundle_size=100;
17
18mac_poly mac_p_add_ff_qq(mac_poly a, number f,mac_poly b)
19{
20  mac_poly erg;
21  mac_poly* set_this;
22  set_this=&erg;
23  while((a!=NULL) &&(b!=NULL))
24  {
25    if (a->exp<b->exp)
26    {
27      (*set_this)=a;
28      a=a->next;
29      set_this= &((*set_this)->next);
30    }
31    else
32    {
33      if (a->exp>b->exp)
34      {
35        mac_poly in =new mac_poly_r();
36        in->exp=b->exp;
37        in->coef=nMult(b->coef,f);
38        (*set_this)=in;
39        b=b->next;
40        set_this= &((*set_this)->next);
41      }
42      else
43      {
44        //a->exp==b->ecp
45        number n=nMult(b->coef,f);
46        number n2=nAdd(a->coef,n);
47        nDelete(&n);
48        nDelete(&(a->coef));
49        if (nIsZero(n2))
50        {
51          nDelete(&n2);
52          mac_poly ao=a;
53          a=a->next;
54          delete ao;
55          b=b->next;
56        }
57        else
58        {
59          a->coef=n2;
60          b=b->next;
61          (*set_this)=a;
62          a=a->next;
63          set_this= &((*set_this)->next);
64        }
65      }
66    }
67  }
68  if((a==NULL)&&(b==NULL))
69  {
70    (*set_this)=NULL;
71    return erg;
72  }
73  if (b==NULL)
74  {
75    (*set_this=a);
76    return erg;
77  }
78
79  //a==NULL
80  while(b!=NULL)
81  {
82    mac_poly mp= new mac_poly_r();
83    mp->exp=b->exp;
84    mp->coef=nMult(f,b->coef);
85    (*set_this)=mp;
86    set_this=&(mp->next);
87    b=b->next;
88  }
89  (*set_this)=NULL;
90  return erg;
91}
92
93void mac_mult_cons(mac_poly p,number c)
94{
95  while(p)
96  {
97    number m=nMult(p->coef,c);
98    nDelete(&(p->coef));
99    p->coef=m;
100    p=p->next;
101  }
102}
103
104int mac_length(mac_poly p)
105{
106  int l=0;
107  while(p){
108    l++;
109    p=p->next;
110  }
111  return l;
112}
113
114//contrary to delete on the mac_poly_r, the coefficients are also destroyed here
115void mac_destroy(mac_poly p)
116{
117  mac_poly iter=p;
118  while(iter)
119  {
120    mac_poly next=iter->next;
121    nDelete(&iter->coef);
122    delete iter;
123    iter=next;
124  }
125}
126
127void simple_gauss(tgb_sparse_matrix* mat, slimgb_alg* c)
128{
129  int col, row;
130  int* row_cache=(int*) omAlloc(mat->get_rows()*sizeof(int));
131  col=0;
132  row=0;
133  int i;
134  int pn=mat->get_rows();
135  int matcol=mat->get_columns();
136  int* area=(int*) omAlloc(sizeof(int)*((matcol-1)/bundle_size+1));
137  const int max_area_index=(matcol-1)/bundle_size;
138    //rows are divided in areas
139  //if row begins with columns col, it is located in [area[col/bundle_size],area[col/bundle_size+1]-1]
140  assume(pn>0);
141  //first clear zeroes
142  for(i=0;i<pn;i++)
143  {
144    if(mat->zero_row(i))
145    {
146      mat->perm_rows(i,pn-1);
147      pn--;
148      if(i!=pn){i--;}
149    }
150
151  }
152  mat->sort_rows();
153  for(i=0;i<pn;i++)
154  {
155      row_cache[i]=mat->min_col_not_zero_in_row(i);
156      // Print("row_cache:%d\n",row_cache[i]);
157  }
158  int last_area=-1;
159  for(i=0;i<pn;i++)
160  {
161    int this_area=row_cache[i]/bundle_size;
162    assume(this_area>=last_area);
163    if(this_area>last_area)
164    {
165      int j;
166      for(j=last_area+1;j<=this_area;j++)
167        area[j]=i;
168      last_area=this_area;
169    }
170  }
171  for(i=last_area+1;i<=max_area_index;i++)
172  {
173    area[i]=pn;
174  }
175  while(row<pn-1)
176  {
177    //row is the row where pivot should be
178    // row== pn-1 means we have only to act on one row so no red nec.
179    //we assume further all rows till the pn-1 row are non-zero
180
181    //select column
182
183    //col=mat->min_col_not_zero_in_row(row);
184    int max_in_area;
185    {
186      int tai=row_cache[row]/bundle_size;
187      assume(tai<=max_area_index);
188      if(tai==max_area_index)
189        max_in_area=pn-1;
190      else
191        max_in_area=area[tai+1]-1;
192    }
193    assume(row_cache[row]==mat->min_col_not_zero_in_row(row));
194    col=row_cache[row];
195
196    assume(col!=matcol);
197    int found_in_row;
198
199    found_in_row=row;
200    BOOLEAN must_reduce=FALSE;
201    assume(pn<=mat->get_rows());
202    for(i=row+1;i<=max_in_area;i++)
203    {
204      int first;//=mat->min_col_not_zero_in_row(i);
205      assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
206      first=row_cache[i];
207      assume(first!=matcol);
208      if(first<col)
209      {
210        col=first;
211        found_in_row=i;
212        must_reduce=FALSE;
213      }
214      else
215      {
216        if(first==col)
217          must_reduce=TRUE;
218      }
219    }
220    //select pivot
221    int act_l=nSize(mat->get(found_in_row,col))*mat->non_zero_entries(found_in_row);
222    if(must_reduce)
223    {
224      for(i=found_in_row+1;i<=max_in_area;i++)
225      {
226        assume(mat->min_col_not_zero_in_row(i)>=col);
227        int first;
228        assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
229        first=row_cache[i];
230        assume(first!=matcol);
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      int first;
263      assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
264      first=row_cache[i];
265      assume(first!=matcol);
266      if(row_cache[i]==col)
267      {
268
269        number c1=mat->get(i,col);
270        number c2=mat->get(row,col);
271        number n1=c1;
272        number n2=c2;
273
274        ksCheckCoeff(&n1,&n2,currRing->cf);
275        //nDelete(&c1);
276        n1=nNeg(n1);
277        mat->mult_row(i,n2);
278        mat->add_lambda_times_row(i,row,n1);
279        nDelete(&n1);
280        nDelete(&n2);
281        assume(mat->is_zero_entry(i,col));
282        row_cache[i]=mat->min_col_not_zero_in_row(i);
283        assume(mat->min_col_not_zero_in_row(i)>col);
284        if(row_cache[i]==matcol)
285        {
286          int index;
287          index=i;
288          int last_in_area;
289          int this_cai=col_area_index;
290          while(this_cai<max_area_index)
291          {
292            last_in_area=area[this_cai+1]-1;
293            int h_c=row_cache[last_in_area];
294            row_cache[last_in_area]=row_cache[index];
295            row_cache[index]=h_c;
296            mat->perm_rows(index,last_in_area);
297            index=last_in_area;
298            this_cai++;
299            area[this_cai]--;
300          }
301          mat->perm_rows(index,pn-1);
302          row_cache[index]=row_cache[pn-1];
303          row_cache[pn-1]=matcol;
304          pn--;
305        }
306        else
307        {
308          int index;
309          index=i;
310          int last_in_area;
311          int this_cai=col_area_index;
312          int final_cai=row_cache[index]/bundle_size;
313          assume(final_cai<=max_area_index);
314          while(this_cai<final_cai)
315          {
316            last_in_area=area[this_cai+1]-1;
317            int h_c=row_cache[last_in_area];
318            row_cache[last_in_area]=row_cache[index];
319            row_cache[index]=h_c;
320            mat->perm_rows(index,last_in_area);
321            index=last_in_area;
322            this_cai++;
323            area[this_cai]--;
324          }
325        }
326      }
327      else
328        assume(mat->min_col_not_zero_in_row(i)>col);
329    }
330//     for(i=row+1;i<pn;i++)
331//     {
332//       assume(mat->min_col_not_zero_in_row(i)==row_cache[i]);
333//       // if(mat->zero_row(i))
334//       assume(matcol==mat->get_columns());
335//       if(row_cache[i]==matcol)
336//       {
337//         assume(mat->zero_row(i));
338//         mat->perm_rows(i,pn-1);
339//         row_cache[i]=row_cache[pn-1];
340//         row_cache[pn-1]=matcol;
341//         pn--;
342//         if(i!=pn){i--;}
343//       }
344//     }
345#ifdef TGB_DEBUG
346  {
347    int last=-1;
348    for(i=0;i<pn;i++)
349    {
350      int act=mat->min_col_not_zero_in_row(i);
351      assume(act>last);
352    }
353    for(i=pn;i<mat->get_rows();i++)
354    {
355      assume(mat->zero_row(i));
356    }
357  }
358#endif
359    row++;
360  }
361  omFree(area);
362  omFree(row_cache);
363}
364
365void simple_gauss2(tgb_matrix* mat)
366{
367  int col, row;
368  col=0;
369  row=0;
370  int i;
371  int pn=mat->get_rows();
372  assume(pn>0);
373  //first clear zeroes
374//   for(i=0;i<pn;i++)
375//   {
376//     if(mat->zero_row(i))
377//     {
378//       mat->perm_rows(i,pn-1);
379//       pn--;
380//       if(i!=pn){i--;}
381//     }
382//   }
383  while((row<pn-1)&&(col<mat->get_columns())){
384    //row is the row where pivot should be
385    // row== pn-1 means we have only to act on one row so no red nec.
386    //we assume further all rows till the pn-1 row are non-zero
387
388    //select column
389
390    //    col=mat->min_col_not_zero_in_row(row);
391    assume(col!=mat->get_columns());
392    int found_in_row=-1;
393
394    //    found_in_row=row;
395    assume(pn<=mat->get_rows());
396    for(i=row;i<pn;i++)
397    {
398      //    int first=mat->min_col_not_zero_in_row(i);
399      //  if(first<col)
400      if(!(mat->is_zero_entry(i,col)))
401      {
402        found_in_row=i;
403        break;
404      }
405    }
406    if(found_in_row!=-1)
407    {
408    //select pivot
409      int act_l=mat->non_zero_entries(found_in_row);
410      for(i=i+1;i<pn;i++)
411      {
412        int vgl;
413        assume(mat->min_col_not_zero_in_row(i)>=col);
414        if((!(mat->is_zero_entry(i,col)))
415        &&((vgl=mat->non_zero_entries(i))<act_l))
416        {
417          found_in_row=i;
418          act_l=vgl;
419        }
420
421      }
422      mat->perm_rows(row,found_in_row);
423
424      //reduction
425      for(i=row+1;i<pn;i++){
426        assume(mat->min_col_not_zero_in_row(i)>=col);
427        if(!(mat->is_zero_entry(i,col)))
428        {
429          number c1=nNeg(nCopy(mat->get(i,col)));
430          number c2=mat->get(row,col);
431          number n1=c1;
432          number n2=c2;
433
434          ksCheckCoeff(&n1,&n2,currRing->cf);
435          nDelete(&c1);
436          mat->mult_row(i,n2);
437          mat->add_lambda_times_row(i,row,n1);
438          assume(mat->is_zero_entry(i,col));
439        }
440        assume(mat->min_col_not_zero_in_row(i)>col);
441      }
442      row++;
443    }
444    col++;
445    // for(i=row+1;i<pn;i++)
446//     {
447//       if(mat->zero_row(i))
448//       {
449//         mat->perm_rows(i,pn-1);
450//         pn--;
451//         if(i!=pn){i--;}
452//       }
453//     }
454  }
455}
456
457
458tgb_matrix::tgb_matrix(int i, int j)
459{
460  n=(number**) omAlloc(i*sizeof (number*));;
461  int z;
462  int z2;
463  for(z=0;z<i;z++)
464  {
465    n[z]=(number*)omAlloc(j*sizeof(number));
466    for(z2=0;z2<j;z2++)
467    {
468      n[z][z2]=nInit(0);
469    }
470  }
471  columns=j;
472  rows=i;
473  free_numbers=FALSE;
474}
475
476tgb_matrix::~tgb_matrix()
477{
478  int z;
479  for(z=0;z<rows;z++)
480  {
481    if(n[z])
482    {
483      if(free_numbers)
484      {
485        int z2;
486        for(z2=0;z2<columns;z2++)
487        {
488          nDelete(&(n[z][z2]));
489        }
490      }
491      omFree(n[z]);
492    }
493  }
494  omfree(n);
495}
496
497void tgb_matrix::print()
498{
499  int i;
500  int j;
501  PrintLn();
502  for(i=0;i<rows;i++)
503  {
504    PrintS("(");
505    for(j=0;j<columns;j++)
506    {
507      StringSetS("");
508      n_Write(n[i][j],currRing);
509      char *s=StringEndS();
510      PrintS(s);
511      omFree(s);
512      PrintS("\t");
513    }
514    PrintS(")\n");
515  }
516}
517
518//transfers ownership of n to the matrix
519void tgb_matrix::set(int i, int j, number nn)
520{
521  assume(i<rows);
522  assume(j<columns);
523  n[i][j]=nn;
524}
525
526int tgb_matrix::get_rows()
527{
528  return rows;
529}
530
531int tgb_matrix::get_columns()
532{
533  return columns;
534}
535
536number tgb_matrix::get(int i, int j)
537{
538  assume(i<rows);
539  assume(j<columns);
540  return n[i][j];
541}
542
543BOOLEAN tgb_matrix::is_zero_entry(int i, int j)
544{
545  return (nIsZero(n[i][j]));
546}
547
548void tgb_matrix::perm_rows(int i, int j)
549{
550  number* h;
551  h=n[i];
552  n[i]=n[j];
553  n[j]=h;
554}
555
556int tgb_matrix::min_col_not_zero_in_row(int row)
557{
558  int i;
559  for(i=0;i<columns;i++)
560  {
561    if(!(nIsZero(n[row][i])))
562      return i;
563  }
564  return columns;//error code
565}
566
567int tgb_matrix::next_col_not_zero(int row,int pre)
568{
569  int i;
570  for(i=pre+1;i<columns;i++)
571  {
572    if(!(nIsZero(n[row][i])))
573      return i;
574  }
575  return columns;//error code
576}
577
578BOOLEAN tgb_matrix::zero_row(int row)
579{
580  int i;
581  for(i=0;i<columns;i++)
582  {
583    if(!(nIsZero(n[row][i])))
584      return FALSE;
585  }
586  return TRUE;
587}
588
589int tgb_matrix::non_zero_entries(int row)
590{
591  int i;
592  int z=0;
593  for(i=0;i<columns;i++)
594  {
595    if(!(nIsZero(n[row][i])))
596      z++;
597  }
598  return z;
599}
600
601//row add_to=row add_to +row summand*factor
602void tgb_matrix::add_lambda_times_row(int add_to,int summand,number factor)
603{
604  int i;
605  for(i=0;i<columns;i++)
606  {
607    if(!(nIsZero(n[summand][i])))
608    {
609      number n1=n[add_to][i];
610      number n2=nMult(factor,n[summand][i]);
611      n[add_to][i]=nAdd(n1,n2);
612      nDelete(&n1);
613      nDelete(&n2);
614    }
615  }
616}
617
618void tgb_matrix::mult_row(int row,number factor)
619{
620  if (nIsOne(factor))
621    return;
622  int i;
623  for(i=0;i<columns;i++)
624  {
625    if(!(nIsZero(n[row][i])))
626    {
627      number n1=n[row][i];
628      n[row][i]=nMult(n1,factor);
629      nDelete(&n1);
630    }
631  }
632}
633
634void tgb_matrix::free_row(int row, BOOLEAN free_non_zeros)
635{
636  int i;
637  for(i=0;i<columns;i++)
638    if((free_non_zeros)||(!(nIsZero(n[row][i]))))
639      nDelete(&(n[row][i]));
640  omFree(n[row]);
641  n[row]=NULL;
642}
643
644tgb_sparse_matrix::tgb_sparse_matrix(int i, int j, ring rarg)
645{
646  mp=(mac_poly*) omAlloc(i*sizeof (mac_poly));;
647  int z;
648  for(z=0;z<i;z++)
649  {
650    mp[z]=NULL;
651  }
652  columns=j;
653  rows=i;
654  free_numbers=FALSE;
655  r=rarg;
656}
657
658tgb_sparse_matrix::~tgb_sparse_matrix()
659{
660  int z;
661  for(z=0;z<rows;z++)
662  {
663    if(mp[z]!=NULL)
664    {
665      if(free_numbers)
666      {
667        mac_destroy(mp[z]);
668      }
669      else {
670        while(mp[z]!=NULL)
671        {
672          mac_poly next=mp[z]->next;
673          delete mp[z];
674          mp[z]=next;
675        }
676      }
677    }
678  }
679  omfree(mp);
680}
681
682static int row_cmp_gen(const void* a, const void* b)
683{
684  const mac_poly ap= *((mac_poly*) a);
685  const mac_poly bp=*((mac_poly*) b);
686  if (ap==NULL) return 1;
687  if (bp==NULL) return -1;
688  if (ap->exp<bp->exp) return -1;
689  return 1;
690}
691
692void tgb_sparse_matrix::sort_rows()
693{
694  qsort(mp,rows,sizeof(mac_poly),row_cmp_gen);
695}
696
697void tgb_sparse_matrix::print()
698{
699  int i;
700  int j;
701  PrintLn();
702  for(i=0;i<rows;i++)
703  {
704    PrintS("(");
705    for(j=0;j<columns;j++)
706    {
707      StringSetS("");
708      number n=get(i,j);
709      n_Write(n,currRing);
710      char *s=StringEndS();
711      PrintS(s);
712      omFree(s);
713      PrintS("\t");
714    }
715    PrintS(")\n");
716  }
717}
718
719//transfers ownership of n to the matrix
720void tgb_sparse_matrix::set(int i, int j, number n)
721{
722  assume(i<rows);
723  assume(j<columns);
724  mac_poly* set_this=&mp[i];
725  //  while(((*set_this)!=NULL)&&((*set_this)­>exp<j))
726  while(((*set_this)!=NULL) && ((*set_this)->exp<j))
727    set_this=&((*set_this)->next);
728
729  if (((*set_this)==NULL)||((*set_this)->exp>j))
730  {
731    if (nIsZero(n)) return;
732    mac_poly old=(*set_this);
733    (*set_this)=new mac_poly_r();
734    (*set_this)->exp=j;
735    (*set_this)->coef=n;
736    (*set_this)->next=old;
737    return;
738  }
739  assume((*set_this)->exp==j);
740  if(!nIsZero(n))
741  {
742    nDelete(&(*set_this)->coef);
743    (*set_this)->coef=n;
744  }
745  else
746  {
747    nDelete(&(*set_this)->coef);
748    mac_poly dt=(*set_this);
749    (*set_this)=dt->next;
750    delete dt;
751  }
752  return;
753}
754
755int tgb_sparse_matrix::get_rows()
756{
757  return rows;
758}
759
760int tgb_sparse_matrix::get_columns()
761{
762  return columns;
763}
764
765number tgb_sparse_matrix::get(int i, int j)
766{
767  assume(i<rows);
768  assume(j<columns);
769  mac_poly rr=mp[i];
770  while((rr!=NULL)&&(rr->exp<j))
771    rr=rr->next;
772  if ((rr==NULL)||(rr->exp>j))
773  {
774    number n=nInit(0);
775    return n;
776  }
777  assume(rr->exp==j);
778  return rr->coef;
779}
780
781BOOLEAN tgb_sparse_matrix::is_zero_entry(int i, int j)
782{
783  assume(i<rows);
784  assume(j<columns);
785  mac_poly rr=mp[i];
786  while((rr!=NULL)&&(rr->exp<j))
787    rr=rr->next;
788  if ((rr==NULL)||(rr->exp>j))
789  {
790    return TRUE;
791  }
792  assume(!nIsZero(rr->coef));
793  assume(rr->exp==j);
794  return FALSE;
795}
796
797int tgb_sparse_matrix::min_col_not_zero_in_row(int row)
798{
799  if(mp[row]!=NULL)
800  {
801    assume(!nIsZero(mp[row]->coef));
802    return mp[row]->exp;
803  }
804  else
805    return columns;//error code
806}
807
808int tgb_sparse_matrix::next_col_not_zero(int row,int pre)
809{
810  mac_poly rr=mp[row];
811  while((rr!=NULL)&&(rr->exp<=pre))
812    rr=rr->next;
813  if(rr!=NULL)
814  {
815    assume(!nIsZero(rr->coef));
816    return rr->exp;
817  }
818  return columns;//error code
819}
820
821BOOLEAN tgb_sparse_matrix::zero_row(int row)
822{
823  assume((mp[row]==NULL)||(!nIsZero(mp[row]->coef)));
824  if (mp[row]==NULL)
825    return TRUE;
826  else
827    return FALSE;
828}
829
830void tgb_sparse_matrix::row_normalize(int row)
831{
832  if (!rField_has_simple_inverse(r))  /* Z/p, GF(p,n), R, long R/C */
833  {
834    mac_poly m=mp[row];
835    while (m!=NULL)
836    {
837      #ifndef NDEBUG
838      if (currRing==r) {nTest(m->coef);}
839      #endif
840      n_Normalize(m->coef,r);
841      m=m->next;
842    }
843  }
844}
845
846void tgb_sparse_matrix::row_content(int row)
847{
848  mac_poly ph=mp[row];
849  number h,d;
850  mac_poly p;
851
852  if(TEST_OPT_CONTENTSB) return;
853  if(ph->next==NULL)
854  {
855    nDelete(&ph->coef);
856    ph->coef=nInit(1);
857  }
858  else
859  {
860    nNormalize(ph->coef);
861    if(!nGreaterZero(ph->coef))
862    {
863      //ph = pNeg(ph);
864      p=ph;
865      while(p!=NULL)
866      {
867        p->coef=nNeg(p->coef);
868        p=p->next;
869      }
870    }
871
872    h=nCopy(ph->coef);
873    p = ph->next;
874
875    while (p!=NULL)
876    {
877      nNormalize(p->coef);
878      d=nGcd(h,p->coef,currRing);
879      nDelete(&h);
880      h = d;
881      if(nIsOne(h))
882      {
883        break;
884      }
885      p=p->next;
886    }
887    p = ph;
888    //number tmp;
889    if(!nIsOne(h))
890    {
891      while (p!=NULL)
892      {
893        d = nIntDiv(p->coef,h);
894        nDelete(&p->coef);
895        p->coef=d;
896        p=p->next;
897      }
898    }
899    nDelete(&h);
900  }
901}
902int tgb_sparse_matrix::non_zero_entries(int row)
903{
904  return mac_length(mp[row]);
905}
906
907//row add_to=row add_to +row summand*factor
908void tgb_sparse_matrix::add_lambda_times_row(int add_to,int summand,number factor)
909{
910  mp[add_to]= mac_p_add_ff_qq(mp[add_to], factor,mp[summand]);
911}
912
913void tgb_sparse_matrix::mult_row(int row,number factor)
914{
915  if (nIsZero(factor))
916  {
917    mac_destroy(mp[row]);
918    mp[row]=NULL;
919
920    return;
921  }
922  if(nIsOne(factor))
923    return;
924  mac_mult_cons(mp[row],factor);
925}
926
927void tgb_sparse_matrix::free_row(int row, BOOLEAN free_non_zeros)
928{
929  if(free_non_zeros)
930    mac_destroy(mp[row]);
931  else
932  {
933    while(mp[row]!=NULL)
934    {
935      mac_poly next=mp[row]->next;
936      delete mp[row];
937      mp[row]=next;
938    }
939  }
940  mp[row]=NULL;
941}
Note: See TracBrowser for help on using the repository browser.