Changeset f930d8 in git


Ignore:
Timestamp:
Aug 21, 2006, 7:08:47 PM (17 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
1b12fcd48b5731ac61772169e5ec7e9fd745bda5
Parents:
e9657f200f11e748fef7f426e99de6046f10f1db
Message:
*hannes: format


git-svn-id: file:///usr/local/Singular/svn/trunk@9409 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/tgbgauss.cc

    re9657f rf930d8  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: tgbgauss.cc,v 1.7 2005-05-17 15:26:27 bricken Exp $ */
     4/* $Id: tgbgauss.cc,v 1.8 2006-08-21 17:08:47 Singular Exp $ */
    55/*
    66* ABSTRACT: gauss implementation for F4
     
    1515static const int bundle_size=100;
    1616
    17 mac_poly mac_p_add_ff_qq(mac_poly a, number f,mac_poly b){
     17mac_poly mac_p_add_ff_qq(mac_poly a, number f,mac_poly b)
     18{
    1819  mac_poly erg;
    1920  mac_poly* set_this;
    2021  set_this=&erg;
    21   while((a!=NULL) &&(b!=NULL)){
    22     if (a->exp<b->exp){
     22  while((a!=NULL) &&(b!=NULL))
     23  {
     24    if (a->exp<b->exp)
     25    {
    2326      (*set_this)=a;
    2427      a=a->next;
    2528      set_this= &((*set_this)->next);
    26     }
    27     else{
    28       if (a->exp>b->exp){
    29         mac_poly in =new mac_poly_r();
    30         in->exp=b->exp;
    31         in->coef=nMult(b->coef,f);
    32         (*set_this)=in;
    33         b=b->next;
    34         set_this= &((*set_this)->next);
    35       }
    36       else {
    37         //a->exp==b->ecp
    38         number n=nMult(b->coef,f);
    39         number n2=nAdd(a->coef,n);
    40         nDelete(&n);
    41         nDelete(&(a->coef));
    42         if (nIsZero(n2)){
    43           nDelete(&n2);
    44           mac_poly ao=a;
    45           a=a->next;
    46           delete ao;
    47           b=b->next;
    48          
    49         } else {
    50           a->coef=n2;
    51           b=b->next;
    52           (*set_this)=a;
    53           a=a->next;
    54           set_this= &((*set_this)->next);
    55         }
    56  
    57       }
    58    
    59     }
    60   }
    61   if((a==NULL)&&(b==NULL)){
     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  {
    6269    (*set_this)=NULL;
    6370    return erg;
    6471  }
    65   if (b==NULL) {
     72  if (b==NULL)
     73  {
    6674    (*set_this=a);
    6775    return erg;
    6876  }
    69  
     77
    7078  //a==NULL
    71   while(b!=NULL){
     79  while(b!=NULL)
     80  {
    7281    mac_poly mp= new mac_poly_r();
    7382    mp->exp=b->exp;
     
    7988  (*set_this)=NULL;
    8089  return erg;
    81  
    82 }
    83 void mac_mult_cons(mac_poly p,number c){
    84   while(p){
     90}
     91
     92void mac_mult_cons(mac_poly p,number c)
     93{
     94  while(p)
     95  {
    8596    number m=nMult(p->coef,c);
    8697    nDelete(&(p->coef));
     
    8899    p=p->next;
    89100  }
    90  
    91 }
    92 int mac_length(mac_poly p){
     101}
     102
     103int mac_length(mac_poly p)
     104{
    93105  int l=0;
    94106  while(p){
     
    98110  return l;
    99111}
     112
    100113//contrary to delete on the mac_poly_r, the coefficients are also destroyed here
    101 void mac_destroy(mac_poly p){
     114void mac_destroy(mac_poly p)
     115{
    102116  mac_poly iter=p;
    103117  while(iter)
     
    110124}
    111125
    112 void simple_gauss(tgb_sparse_matrix* mat, slimgb_alg* c){
     126void simple_gauss(tgb_sparse_matrix* mat, slimgb_alg* c)
     127{
    113128  int col, row;
    114129  int* row_cache=(int*) omalloc(mat->get_rows()*sizeof(int));
     
    120135  int* area=(int*) omalloc(sizeof(int)*((matcol-1)/bundle_size+1));
    121136  const int max_area_index=(matcol-1)/bundle_size;
    122     //rows are divided in areas 
     137    //rows are divided in areas
    123138  //if row begins with columns col, it is located in [area[col/bundle_size],area[col/bundle_size+1]-1]
    124139  assume(pn>0);
     
    132147      if(i!=pn){i--;}
    133148    }
    134  
     149
    135150  }
    136151  mat->sort_rows();
     
    149164      int j;
    150165      for(j=last_area+1;j<=this_area;j++)
    151         area[j]=i;
     166        area[j]=i;
    152167      last_area=this_area;
    153168    }
     
    157172    area[i]=pn;
    158173  }
    159   while(row<pn-1){
     174  while(row<pn-1)
     175  {
    160176    //row is the row where pivot should be
    161177    // row== pn-1 means we have only to act on one row so no red nec.
    162178    //we assume further all rows till the pn-1 row are non-zero
    163    
     179
    164180    //select column
    165    
     181
    166182    //col=mat->min_col_not_zero_in_row(row);
    167183    int max_in_area;
     
    170186      assume(tai<=max_area_index);
    171187      if(tai==max_area_index)
    172         max_in_area=pn-1;
     188        max_in_area=pn-1;
    173189      else
    174         max_in_area=area[tai+1]-1;
     190        max_in_area=area[tai+1]-1;
    175191    }
    176192    assume(row_cache[row]==mat->min_col_not_zero_in_row(row));
    177193    col=row_cache[row];
    178194
    179    
    180195    assume(col!=matcol);
    181196    int found_in_row;
    182    
     197
    183198    found_in_row=row;
    184199    BOOLEAN must_reduce=FALSE;
    185200    assume(pn<=mat->get_rows());
    186     for(i=row+1;i<=max_in_area;i++){
     201    for(i=row+1;i<=max_in_area;i++)
     202    {
    187203      int first;//=mat->min_col_not_zero_in_row(i);
    188204      assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
     
    191207      if(first<col)
    192208      {
    193         col=first;
    194         found_in_row=i;
    195         must_reduce=FALSE;
    196       }
    197       else {
    198         if(first==col)
    199           must_reduce=TRUE;
     209        col=first;
     210        found_in_row=i;
     211        must_reduce=FALSE;
     212      }
     213      else
     214      {
     215        if(first==col)
     216          must_reduce=TRUE;
    200217      }
    201218    }
     
    204221    if(must_reduce)
    205222    {
    206       for(i=found_in_row+1;i<=max_in_area;i++){
    207         assume(mat->min_col_not_zero_in_row(i)>=col);
    208         int first;
    209         assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
    210         first=row_cache[i];
    211         assume(first!=matcol);
    212         //      if((!(mat->is_zero_entry(i,col)))&&(mat->non_zero_entries(i)<act_l))
    213         int nz;
    214         if((row_cache[i]==col)&&((nz=nSize(mat->get(i,col))*mat->non_zero_entries(i))<act_l))
    215         {
    216           found_in_row=i;
    217         act_l=nz;
    218         }
    219        
     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        int first;
     227        assume(row_cache[i]==mat->min_col_not_zero_in_row(i));
     228        first=row_cache[i];
     229        assume(first!=matcol);
     230        //      if((!(mat->is_zero_entry(i,col)))&&(mat->non_zero_entries(i)<act_l))
     231        int nz;
     232        if((row_cache[i]==col)&&((nz=nSize(mat->get(i,col))*mat->non_zero_entries(i))<act_l))
     233        {
     234          found_in_row=i;
     235          act_l=nz;
     236        }
     237
    220238      }
    221239    }
     
    225243    row_cache[found_in_row]=h;
    226244
    227 
    228 
    229     if(!must_reduce){
     245    if(!must_reduce)
     246    {
    230247      row++;
    231248      continue;
     
    248265      if(row_cache[i]==col)
    249266      {
    250        
    251         number c1=mat->get(i,col);
    252         number c2=mat->get(row,col);
    253         number n1=c1;
    254         number n2=c2;
    255 
    256         ksCheckCoeff(&n1,&n2);
    257         //nDelete(&c1);
    258         n1=nNeg(n1);
    259         mat->mult_row(i,n2);
    260         mat->add_lambda_times_row(i,row,n1);
    261         nDelete(&n1);
    262         nDelete(&n2);
    263         assume(mat->is_zero_entry(i,col));
    264         row_cache[i]=mat->min_col_not_zero_in_row(i);
    265         assume(mat->min_col_not_zero_in_row(i)>col);
    266         if(row_cache[i]==matcol)
    267         {
    268           int index;
    269           index=i;
    270           int last_in_area;
    271           int this_cai=col_area_index;
    272           while(this_cai<max_area_index)
    273           {
    274             last_in_area=area[this_cai+1]-1;
    275             int h_c=row_cache[last_in_area];
    276             row_cache[last_in_area]=row_cache[index];
    277             row_cache[index]=h_c;
    278             mat->perm_rows(index,last_in_area);
    279             index=last_in_area;
    280             this_cai++;
    281             area[this_cai]--;
    282           }
    283           mat->perm_rows(index,pn-1);
    284           row_cache[index]=row_cache[pn-1];
    285           row_cache[pn-1]=matcol;
    286           pn--;
    287         }
    288         else
    289         {
    290           int index;
    291           index=i;
    292           int last_in_area;
    293           int this_cai=col_area_index;
    294           int final_cai=row_cache[index]/bundle_size;
    295           assume(final_cai<=max_area_index);
    296           while(this_cai<final_cai)
    297           {
    298             last_in_area=area[this_cai+1]-1;
    299             int h_c=row_cache[last_in_area];
    300             row_cache[last_in_area]=row_cache[index];
    301             row_cache[index]=h_c;
    302             mat->perm_rows(index,last_in_area);
    303             index=last_in_area;
    304             this_cai++;
    305             area[this_cai]--;
    306           }
    307         }
     267
     268        number c1=mat->get(i,col);
     269        number c2=mat->get(row,col);
     270        number n1=c1;
     271        number n2=c2;
     272
     273        ksCheckCoeff(&n1,&n2);
     274        //nDelete(&c1);
     275        n1=nNeg(n1);
     276        mat->mult_row(i,n2);
     277        mat->add_lambda_times_row(i,row,n1);
     278        nDelete(&n1);
     279        nDelete(&n2);
     280        assume(mat->is_zero_entry(i,col));
     281        row_cache[i]=mat->min_col_not_zero_in_row(i);
     282        assume(mat->min_col_not_zero_in_row(i)>col);
     283        if(row_cache[i]==matcol)
     284        {
     285          int index;
     286          index=i;
     287          int last_in_area;
     288          int this_cai=col_area_index;
     289          while(this_cai<max_area_index)
     290          {
     291            last_in_area=area[this_cai+1]-1;
     292            int h_c=row_cache[last_in_area];
     293            row_cache[last_in_area]=row_cache[index];
     294            row_cache[index]=h_c;
     295            mat->perm_rows(index,last_in_area);
     296            index=last_in_area;
     297            this_cai++;
     298            area[this_cai]--;
     299          }
     300          mat->perm_rows(index,pn-1);
     301          row_cache[index]=row_cache[pn-1];
     302          row_cache[pn-1]=matcol;
     303          pn--;
     304        }
     305        else
     306        {
     307          int index;
     308          index=i;
     309          int last_in_area;
     310          int this_cai=col_area_index;
     311          int final_cai=row_cache[index]/bundle_size;
     312          assume(final_cai<=max_area_index);
     313          while(this_cai<final_cai)
     314          {
     315            last_in_area=area[this_cai+1]-1;
     316            int h_c=row_cache[last_in_area];
     317            row_cache[last_in_area]=row_cache[index];
     318            row_cache[index]=h_c;
     319            mat->perm_rows(index,last_in_area);
     320            index=last_in_area;
     321            this_cai++;
     322            area[this_cai]--;
     323          }
     324        }
    308325      }
    309326      else
    310         assume(mat->min_col_not_zero_in_row(i)>col);
    311     }
    312 
     327        assume(mat->min_col_not_zero_in_row(i)>col);
     328    }
    313329//     for(i=row+1;i<pn;i++)
    314330//     {
     
    318334//       if(row_cache[i]==matcol)
    319335//       {
    320 //      assume(mat->zero_row(i));
    321 //      mat->perm_rows(i,pn-1);
    322 //      row_cache[i]=row_cache[pn-1];
    323 //      row_cache[pn-1]=matcol;
    324 //      pn--;
    325 //      if(i!=pn){i--;}
     336//         assume(mat->zero_row(i));
     337//         mat->perm_rows(i,pn-1);
     338//         row_cache[i]=row_cache[pn-1];
     339//         row_cache[pn-1]=matcol;
     340//         pn--;
     341//         if(i!=pn){i--;}
    326342//       }
    327343//     }
    328344#ifdef TGB_DEBUG
    329345  {
    330   int last=-1;
    331   for(i=0;i<pn;i++)
    332   {
    333     int act=mat->min_col_not_zero_in_row(i);
    334     assume(act>last);
    335    
    336   }
    337   for(i=pn;i<mat->get_rows();i++)
    338   {
    339     assume(mat->zero_row(i));
    340    
    341   }
    342  
    343 
     346    int last=-1;
     347    for(i=0;i<pn;i++)
     348    {
     349      int act=mat->min_col_not_zero_in_row(i);
     350      assume(act>last);
     351    }
     352    for(i=pn;i<mat->get_rows();i++)
     353    {
     354      assume(mat->zero_row(i));
     355    }
    344356  }
    345357#endif
     
    349361  omfree(row_cache);
    350362}
    351 void simple_gauss2(tgb_matrix* mat){
     363
     364void simple_gauss2(tgb_matrix* mat)
     365{
    352366  int col, row;
    353367  col=0;
     
    370384    // row== pn-1 means we have only to act on one row so no red nec.
    371385    //we assume further all rows till the pn-1 row are non-zero
    372    
     386
    373387    //select column
    374    
     388
    375389    //    col=mat->min_col_not_zero_in_row(row);
    376390    assume(col!=mat->get_columns());
    377391    int found_in_row=-1;
    378    
     392
    379393    //    found_in_row=row;
    380394    assume(pn<=mat->get_rows());
     
    383397      //    int first=mat->min_col_not_zero_in_row(i);
    384398      //  if(first<col)
    385       if(!(mat->is_zero_entry(i,col))){
    386        
    387         found_in_row=i;
    388         break;
     399      if(!(mat->is_zero_entry(i,col)))
     400      {
     401        found_in_row=i;
     402        break;
    389403      }
    390404    }
     
    395409      for(i=i+1;i<pn;i++)
    396410      {
    397         int vgl;
    398         assume(mat->min_col_not_zero_in_row(i)>=col);
    399         if((!(mat->is_zero_entry(i,col)))&&((vgl=mat->non_zero_entries(i))<act_l))
    400         {
    401           found_in_row=i;
    402           act_l=vgl;
    403         }
    404        
     411        int vgl;
     412        assume(mat->min_col_not_zero_in_row(i)>=col);
     413        if((!(mat->is_zero_entry(i,col)))
     414        &&((vgl=mat->non_zero_entries(i))<act_l))
     415        {
     416          found_in_row=i;
     417          act_l=vgl;
     418        }
     419
    405420      }
    406421      mat->perm_rows(row,found_in_row);
    407      
    408      
     422
    409423      //reduction
    410424      for(i=row+1;i<pn;i++){
    411         assume(mat->min_col_not_zero_in_row(i)>=col);
    412         if(!(mat->is_zero_entry(i,col)))
    413         {
    414          
    415           number c1=nNeg(nCopy(mat->get(i,col)));
    416           number c2=mat->get(row,col);
    417           number n1=c1;
    418           number n2=c2;
    419          
    420           ksCheckCoeff(&n1,&n2);
    421           nDelete(&c1);
    422           mat->mult_row(i,n2);
    423           mat->add_lambda_times_row(i,row,n1);
    424           assume(mat->is_zero_entry(i,col));
    425          
    426         }
    427         assume(mat->min_col_not_zero_in_row(i)>col);
     425        assume(mat->min_col_not_zero_in_row(i)>=col);
     426        if(!(mat->is_zero_entry(i,col)))
     427        {
     428          number c1=nNeg(nCopy(mat->get(i,col)));
     429          number c2=mat->get(row,col);
     430          number n1=c1;
     431          number n2=c2;
     432
     433          ksCheckCoeff(&n1,&n2);
     434          nDelete(&c1);
     435          mat->mult_row(i,n2);
     436          mat->add_lambda_times_row(i,row,n1);
     437          assume(mat->is_zero_entry(i,col));
     438        }
     439        assume(mat->min_col_not_zero_in_row(i)>col);
    428440      }
    429441      row++;
     
    434446//       if(mat->zero_row(i))
    435447//       {
    436 //      mat->perm_rows(i,pn-1);
    437 //      pn--;
    438 //      if(i!=pn){i--;}
     448//         mat->perm_rows(i,pn-1);
     449//         pn--;
     450//         if(i!=pn){i--;}
    439451//       }
    440452//     }
    441 
    442   }
    443 }
    444 
    445 tgb_matrix::tgb_matrix(int i, int j){
     453  }
     454}
     455
     456
     457tgb_matrix::tgb_matrix(int i, int j)
     458{
    446459  n=(number**) omalloc(i*sizeof (number*));;
    447460  int z;
     
    459472  free_numbers=FALSE;
    460473}
    461 tgb_matrix::~tgb_matrix(){
     474
     475tgb_matrix::~tgb_matrix()
     476{
    462477  int z;
    463478  for(z=0;z<rows;z++)
     
    467482      if(free_numbers)
    468483      {
    469         int z2;
    470         for(z2=0;z2<columns;z2++)
    471         {
    472           nDelete(&(n[z][z2]));
    473         }
     484        int z2;
     485        for(z2=0;z2<columns;z2++)
     486        {
     487          nDelete(&(n[z][z2]));
     488        }
    474489      }
    475490      omfree(n[z]);
     
    478493  omfree(n);
    479494}
    480 void tgb_matrix::print(){
     495
     496void tgb_matrix::print()
     497{
    481498  int i;
    482499  int j;
    483   Print("\n");
     500  PrintLn();
    484501  for(i=0;i<rows;i++)
    485502  {
     
    495512  }
    496513}
     514
    497515//transfers ownership of n to the matrix
    498 void tgb_matrix::set(int i, int j, number n){
     516void tgb_matrix::set(int i, int j, number n)
     517{
    499518  assume(i<rows);
    500519  assume(j<columns);
    501520  this->n[i][j]=n;
    502521}
    503 int tgb_matrix::get_rows(){
     522
     523int tgb_matrix::get_rows()
     524{
    504525  return rows;
    505526}
    506 int tgb_matrix::get_columns(){
     527
     528int tgb_matrix::get_columns()
     529{
    507530  return columns;
    508531}
    509 number tgb_matrix::get(int i, int j){
     532
     533number tgb_matrix::get(int i, int j)
     534{
    510535  assume(i<rows);
    511536  assume(j<columns);
    512537  return n[i][j];
    513538}
    514 BOOLEAN tgb_matrix::is_zero_entry(int i, int j){
     539
     540BOOLEAN tgb_matrix::is_zero_entry(int i, int j)
     541{
    515542  return (nIsZero(n[i][j]));
    516543}
    517 void tgb_matrix::perm_rows(int i, int j){
     544
     545void tgb_matrix::perm_rows(int i, int j)
     546{
    518547  number* h;
    519548  h=n[i];
     
    521550  n[j]=h;
    522551}
    523 int tgb_matrix::min_col_not_zero_in_row(int row){
     552
     553int tgb_matrix::min_col_not_zero_in_row(int row)
     554{
    524555  int i;
    525556  for(i=0;i<columns;i++)
     
    530561  return columns;//error code
    531562}
    532 int tgb_matrix::next_col_not_zero(int row,int pre){
     563
     564int tgb_matrix::next_col_not_zero(int row,int pre)
     565{
    533566  int i;
    534567  for(i=pre+1;i<columns;i++)
     
    539572  return columns;//error code
    540573}
    541 BOOLEAN tgb_matrix::zero_row(int row){
     574
     575BOOLEAN tgb_matrix::zero_row(int row)
     576{
    542577  int i;
    543578  for(i=0;i<columns;i++)
     
    548583  return TRUE;
    549584}
    550 int tgb_matrix::non_zero_entries(int row){
     585
     586int tgb_matrix::non_zero_entries(int row)
     587{
    551588  int i;
    552589  int z=0;
     
    558595  return z;
    559596}
     597
    560598//row add_to=row add_to +row summand*factor
    561 void tgb_matrix::add_lambda_times_row(int add_to,int summand,number factor){
    562   int i;
    563   for(i=0;i<columns;i++){
     599void tgb_matrix::add_lambda_times_row(int add_to,int summand,number factor)
     600{
     601  int i;
     602  for(i=0;i<columns;i++)
     603  {
    564604    if(!(nIsZero(n[summand][i])))
    565605    {
     
    572612  }
    573613}
    574 void tgb_matrix::mult_row(int row,number factor){
     614
     615void tgb_matrix::mult_row(int row,number factor)
     616{
    575617  if (nIsOne(factor))
    576618    return;
    577619  int i;
    578   for(i=0;i<columns;i++){
     620  for(i=0;i<columns;i++)
     621  {
    579622    if(!(nIsZero(n[row][i])))
    580623    {
     
    585628  }
    586629}
    587 void tgb_matrix::free_row(int row, BOOLEAN free_non_zeros){
     630
     631void tgb_matrix::free_row(int row, BOOLEAN free_non_zeros)
     632{
    588633  int i;
    589634  for(i=0;i<columns;i++)
     
    594639}
    595640
    596 
    597 tgb_sparse_matrix::tgb_sparse_matrix(int i, int j, ring rarg){
     641tgb_sparse_matrix::tgb_sparse_matrix(int i, int j, ring rarg)
     642{
    598643  mp=(mac_poly*) omalloc(i*sizeof (mac_poly));;
    599644  int z;
     
    608653  r=rarg;
    609654}
    610 tgb_sparse_matrix::~tgb_sparse_matrix(){
     655
     656tgb_sparse_matrix::~tgb_sparse_matrix()
     657{
    611658  int z;
    612659  for(z=0;z<rows;z++)
    613660  {
    614     if(mp[z])
     661    if(mp[z]!=NULL)
    615662    {
    616663      if(free_numbers)
    617664      {
    618         mac_destroy(mp[z]);
     665        mac_destroy(mp[z]);
    619666      }
    620667      else {
    621         while(mp[z])
    622         {
    623          
    624           mac_poly next=mp[z]->next;
    625           delete mp[z];
    626           mp[z]=next;
    627         }
     668        while(mp[z]!=NULL)
     669        {
     670          mac_poly next=mp[z]->next;
     671          delete mp[z];
     672          mp[z]=next;
     673        }
    628674      }
    629675    }
     
    631677  omfree(mp);
    632678}
    633 static int row_cmp_gen(const void* a, const void* b){
     679
     680static int row_cmp_gen(const void* a, const void* b)
     681{
    634682  const mac_poly ap= *((mac_poly*) a);
    635683  const mac_poly bp=*((mac_poly*) b);
     
    639687  return 1;
    640688}
    641 void tgb_sparse_matrix::sort_rows(){
     689
     690void tgb_sparse_matrix::sort_rows()
     691{
    642692  qsort(mp,rows,sizeof(mac_poly),row_cmp_gen);
    643693}
    644 void tgb_sparse_matrix::print(){
     694
     695void tgb_sparse_matrix::print()
     696{
    645697  int i;
    646698  int j;
     
    660712  }
    661713}
     714
    662715//transfers ownership of n to the matrix
    663 void tgb_sparse_matrix::set(int i, int j, number n){
     716void tgb_sparse_matrix::set(int i, int j, number n)
     717{
    664718  assume(i<rows);
    665719  assume(j<columns);
     
    691745    (*set_this)=dt->next;
    692746    delete dt;
    693    
    694    
    695747  }
    696748  return;
    697749}
    698750
    699 
    700 
    701 int tgb_sparse_matrix::get_rows(){
     751int tgb_sparse_matrix::get_rows()
     752{
    702753  return rows;
    703754}
    704 int tgb_sparse_matrix::get_columns(){
     755
     756int tgb_sparse_matrix::get_columns()
     757{
    705758  return columns;
    706759}
    707 number tgb_sparse_matrix::get(int i, int j){
     760
     761number tgb_sparse_matrix::get(int i, int j)
     762{
    708763  assume(i<rows);
    709764  assume(j<columns);
     
    719774  return r->coef;
    720775}
    721 BOOLEAN tgb_sparse_matrix::is_zero_entry(int i, int j){
     776
     777BOOLEAN tgb_sparse_matrix::is_zero_entry(int i, int j)
     778{
    722779  assume(i<rows);
    723780  assume(j<columns);
     
    732789  assume(r->exp==j);
    733790  return FALSE;
    734  
    735 }
    736 
    737 int tgb_sparse_matrix::min_col_not_zero_in_row(int row){
     791}
     792
     793int tgb_sparse_matrix::min_col_not_zero_in_row(int row)
     794{
    738795  if(mp[row]!=NULL)
    739796  {
     
    742799  }
    743800  else
    744 
    745  
    746   return columns;//error code
    747 }
    748 int tgb_sparse_matrix::next_col_not_zero(int row,int pre){ 
     801    return columns;//error code
     802}
     803
     804int tgb_sparse_matrix::next_col_not_zero(int row,int pre)
     805{
    749806  mac_poly r=mp[row];
    750807  while((r!=NULL)&&(r->exp<=pre))
     
    757814  return columns;//error code
    758815}
    759 BOOLEAN tgb_sparse_matrix::zero_row(int row){
     816
     817BOOLEAN tgb_sparse_matrix::zero_row(int row)
     818{
    760819  assume((mp[row]==NULL)||(!nIsZero(mp[row]->coef)));
    761820  if (mp[row]==NULL)
     
    764823    return FALSE;
    765824}
    766 void tgb_sparse_matrix::row_normalize(int row){
     825
     826void tgb_sparse_matrix::row_normalize(int row)
     827{
    767828  if (!rField_has_simple_inverse(r))  /* Z/p, GF(p,n), R, long R/C */
    768829  {
    769830    mac_poly m=mp[row];
    770         while (m!=NULL)
    771         {
    772           if (currRing==r) {nTest(m->coef);}
    773           n_Normalize(m->coef,r);
    774           m=m->next;
    775         }
    776   }
    777 }
    778 void tgb_sparse_matrix::row_content(int row){
    779  
     831    while (m!=NULL)
     832    {
     833      if (currRing==r) {nTest(m->coef);}
     834      n_Normalize(m->coef,r);
     835      m=m->next;
     836    }
     837  }
     838}
     839
     840void tgb_sparse_matrix::row_content(int row)
     841{
    780842  mac_poly ph=mp[row];
    781843  number h,d;
     
    791853  {
    792854    nNormalize(ph->coef);
    793     if(!nGreaterZero(ph->coef)) {
     855    if(!nGreaterZero(ph->coef))
     856    {
    794857      //ph = pNeg(ph);
    795858      p=ph;
    796       while(p)
    797       {
    798         p->coef=nNeg(p->coef);
    799         p=p->next;
    800       }
    801     }
    802    
     859      while(p!=NULL)
     860      {
     861        p->coef=nNeg(p->coef);
     862        p=p->next;
     863      }
     864    }
     865
    803866    h=nCopy(ph->coef);
    804867    p = ph->next;
    805    
     868
    806869    while (p!=NULL)
    807870    {
     
    822885      while (p!=NULL)
    823886      {
    824    
    825887        d = nIntDiv(pGetCoeff(p),h);
    826         nDelete(&p->coef);
     888        nDelete(&p->coef);
    827889        p->coef=d;
    828890        p=p->next;
     
    830892    }
    831893    nDelete(&h);
    832 
    833   }
    834 }
    835 int tgb_sparse_matrix::non_zero_entries(int row){
    836 
     894  }
     895}
     896int tgb_sparse_matrix::non_zero_entries(int row)
     897{
    837898  return mac_length(mp[row]);
    838899}
     900
    839901//row add_to=row add_to +row summand*factor
    840 void tgb_sparse_matrix::add_lambda_times_row(int add_to,int summand,number factor){
     902void tgb_sparse_matrix::add_lambda_times_row(int add_to,int summand,number factor)
     903{
    841904  mp[add_to]= mac_p_add_ff_qq(mp[add_to], factor,mp[summand]);
    842 
    843 }
    844 void tgb_sparse_matrix::mult_row(int row,number factor){
     905}
     906
     907void tgb_sparse_matrix::mult_row(int row,number factor)
     908{
    845909  if (nIsZero(factor))
    846910  {
    847911    mac_destroy(mp[row]);
    848912    mp[row]=NULL;
    849    
     913
    850914    return;
    851915  }
     
    854918  mac_mult_cons(mp[row],factor);
    855919}
    856 void tgb_sparse_matrix::free_row(int row, BOOLEAN free_non_zeros){
     920
     921void tgb_sparse_matrix::free_row(int row, BOOLEAN free_non_zeros)
     922{
    857923  if(free_non_zeros)
    858924    mac_destroy(mp[row]);
    859925  else
    860926  {
    861     while(mp[row])
    862     {
    863      
     927    while(mp[row]!=NULL)
     928    {
    864929      mac_poly next=mp[row]->next;
    865930      delete mp[row];
Note: See TracChangeset for help on using the changeset viewer.