Changeset 75f10d in git for libpolys


Ignore:
Timestamp:
May 10, 2012, 1:59:15 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6f0279ecd605db3872247f2211d8efd1ac65d42a
Parents:
c8302bb70ef743b5705287005391184566e69b06
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-05-10 13:59:15+02:00
git-committer:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-05-10 13:59:37+02:00
Message:
add: bigintmat stuff from master
Location:
libpolys/coeffs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/bigintmat.cc

    rc8302b r75f10d  
    3232  assume (i > 0 && j > 0);
    3333  assume (i <= rows() && j <= cols());
    34  
     34
    3535  set(index(i, j), n, C);
    3636}
     
    4040  assume (i >= 0);
    4141  assume (i<rows()*cols());
    42  
     42
    4343  return n_Copy(v[i], basecoeffs());
    4444}
     
    4848  assume (i > 0 && j > 0);
    4949  assume (i <= rows() && j <= cols());
    50  
     50
    5151  return get(index(i, j));
    5252}
     
    5757{
    5858  number iop = n_Init(intop, basecoeffs());
    59  
     59
    6060  inpMult(iop, basecoeffs());
    61  
     61
    6262  n_Delete(&iop, basecoeffs());
    6363}
     
    6666{
    6767  assume (C == NULL || C == basecoeffs());
    68  
     68
    6969  const int l = rows() * cols();
    7070
     
    8585
    8686  const int l = (lhr.rows())*(lhr.cols());
    87  
     87
    8888  for (int i=0; i < l; i++)
    8989  {
    9090    if (!n_Equal(lhr[i], rhr[i], lhr.basecoeffs())) { return false; }
    9191  }
    92  
     92
    9393  return true;
    9494}
     
    104104  if (a->cols() != b->cols()) return NULL;
    105105  if (a->basecoeffs() != b->basecoeffs()) { return NULL; }
    106  
     106
    107107  const int mn = si_min(a->rows(),b->rows());
    108108  const int ma = si_max(a->rows(),b->rows());
    109109
    110110  const coeffs basecoeffs = a->basecoeffs();
    111  
     111
    112112  int i;
    113113
     
    115115  {
    116116    bigintmat * bim = new bigintmat(ma, 1, basecoeffs);
    117    
     117
    118118    for (i=0; i<mn; i++)
    119119      bim->rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs);
    120    
     120
    121121    if (ma > mn)
    122122    {
     
    130130    return bim;
    131131  }
    132  
     132
    133133  if (mn != ma) return NULL;
    134134
    135135  bigintmat * bim = new bigintmat(mn, a->cols(), basecoeffs);
    136  
     136
    137137  for (i=0; i<mn*a->cols(); i++)
    138138    bim->rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs);
    139  
     139
     140  return bim;
     141}
     142bigintmat * bimAdd(bigintmat * a, int b)
     143{
     144
     145  const int mn = a->rows()*a->cols();
     146
     147  const coeffs basecoeffs = a->basecoeffs();
     148  number bb=n_Init(b,basecoeffs);
     149
     150  int i;
     151
     152  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
     153
     154  for (i=0; i<mn; i++)
     155    bim->rawset(i, n_Add((*a)[i], bb, basecoeffs), basecoeffs);
     156
     157  n_Delete(&bb,basecoeffs);
    140158  return bim;
    141159}
     
    156174  {
    157175    bigintmat * bim = new bigintmat(ma, 1, basecoeffs);
    158    
     176
    159177    for (i=0; i<mn; i++)
    160178      bim->rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs);
     
    177195    return bim;
    178196  }
    179  
     197
    180198  if (mn != ma) return NULL;
    181  
     199
    182200  bigintmat * bim = new bigintmat(mn, a->cols(), basecoeffs);
    183  
     201
    184202  for (i=0; i<mn*a->cols(); i++)
    185203    bim->rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs);
    186  
     204
     205  return bim;
     206}
     207
     208bigintmat * bimSub(bigintmat * a, int b)
     209{
     210
     211  const int mn = a->rows()*a->cols();
     212
     213  const coeffs basecoeffs = a->basecoeffs();
     214  number bb=n_Init(b,basecoeffs);
     215
     216  int i;
     217
     218  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
     219
     220  for (i=0; i<mn; i++)
     221    bim->rawset(i, n_Sub((*a)[i], bb, basecoeffs), basecoeffs);
     222
     223  n_Delete(&bb,basecoeffs);
    187224  return bim;
    188225}
     
    195232  const int ra = a->rows();
    196233  const int rb = b->rows();
    197  
     234
    198235  if (ca != rb)
    199236  {
     
    203240    return NULL;
    204241  }
    205  
     242
    206243  assume (ca == rb);
    207  
     244
    208245  if (a->basecoeffs() != b->basecoeffs()) { return NULL; }
    209  
     246
    210247  const coeffs basecoeffs = a->basecoeffs();
    211248
    212249  int i, j, k;
    213  
     250
    214251  number sum;
    215  
     252
    216253  bigintmat * bim = new bigintmat(ra, cb, basecoeffs);
    217  
     254
    218255  for (i=0; i<ra; i++)
    219256    for (j=0; j<cb; j++)
    220257    {
    221258      sum = n_Init(0, basecoeffs);
    222      
     259
    223260      for (k=0; k<ca; k++)
    224261      {
    225262        number prod = n_Mult( BIMATELEM(*a, i, k), BIMATELEM(*b, k, j), basecoeffs);
    226        
     263
    227264        number sum2 = n_Add(sum, prod, basecoeffs); // no inplace add :(
    228        
     265
    229266        n_Delete(&sum, basecoeffs); n_Delete(&prod, basecoeffs);
    230        
     267
    231268        sum = sum2;
    232269      }
    233270      bim->rawset(i+1, j+1, sum, basecoeffs);
    234271    }
     272  return bim;
     273}
     274
     275bigintmat * bimMult(bigintmat * a, int b)
     276{
     277
     278  const int mn = a->rows()*a->cols();
     279
     280  const coeffs basecoeffs = a->basecoeffs();
     281  number bb=n_Init(b,basecoeffs);
     282
     283  int i;
     284
     285  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
     286
     287  for (i=0; i<mn; i++)
     288    bim->rawset(i, n_Mult((*a)[i], bb, basecoeffs), basecoeffs);
     289
     290  n_Delete(&bb,basecoeffs);
     291  return bim;
     292}
     293
     294bigintmat * bimMult(bigintmat * a, number b, const coeffs cf)
     295{
     296  if (cf!=a->basecoeffs()) return NULL;
     297
     298  const int mn = a->rows()*a->cols();
     299
     300  const coeffs basecoeffs = a->basecoeffs();
     301
     302  int i;
     303
     304  bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs);
     305
     306  for (i=0; i<mn; i++)
     307    bim->rawset(i, n_Mult((*a)[i], b, basecoeffs), basecoeffs);
     308
    235309  return bim;
    236310}
     
    251325  const int l = (b->rows())*(b->cols());
    252326  bigintmat * bim = new bigintmat(b->rows(), b->cols(), C);
    253  
     327
    254328  for (int i=0; i < l; i++)
    255329    bim->rawset(i, n_Init((*b)[i], C), C);
    256  
     330
    257331  return bim;
    258332}
     
    307381  if (b == NULL)
    308382    return NULL;
    309    
     383
    310384  return new bigintmat(b);
    311385}
     
    434508{
    435509  const coeffs basecoeffs = bimat->basecoeffs();
    436  
     510
    437511  number tgcd, m;
    438512  int i=bimat->cols();
  • libpolys/coeffs/bigintmat.h

    rc8302b r75f10d  
    9191      return v[i];
    9292    }
     93#define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
    9394
    9495    /// UEberladener *=-Operator (fuer int und bigint)
    9596    /// Frage hier: *= verwenden oder lieber = und * einzeln?
    9697    void operator*=(int intop);
    97    
     98
    9899    void inpMult(number bintop, const coeffs C = NULL);
    99100
     
    115116    {
    116117      assume (rows() >= 0 && cols() >= 0);
    117      
     118
    118119      assume (r > 0 && c > 0);
    119120      assume (r <= rows() && r <= cols());
     
    134135    /// NOTE: starts at [1,1]
    135136    void set(int i, int j, number n, const coeffs C = NULL);
    136    
     137
    137138    /// replace an entry with a copy (delete old + copy new!).
    138139    /// NOTE: starts at [0]
     
    152153      {
    153154        n_Delete(&(v[i]), basecoeffs()); v[i] = n;
    154       } else
    155       {
     155      }
    156156#ifndef NDEBUG
     157      else
     158      {
    157159        Werror("wrong bigintmat index:%d\n",i);
     160      }
    158161#endif
    159       }
    160     }
    161    
     162    }
     163
    162164    inline void rawset(int i, int j, number n, const coeffs C = NULL)
    163165    {
     
    177179/// NOTE: NULL as a result means an error (non-compatible matrices?)
    178180bigintmat * bimAdd(bigintmat * a, bigintmat * b);
     181bigintmat * bimAdd(bigintmat * a, int b);
    179182bigintmat * bimSub(bigintmat * a, bigintmat * b);
     183bigintmat * bimSub(bigintmat * a, int b);
    180184bigintmat * bimMult(bigintmat * a, bigintmat * b);
     185bigintmat * bimMult(bigintmat * a, int b);
     186bigintmat * bimMult(bigintmat * a, number b, const coeffs cf);
    181187bigintmat * bimCopy(const bigintmat * b);
    182188
Note: See TracChangeset for help on using the changeset viewer.