Changeset 510dbc in git


Ignore:
Timestamp:
Jun 1, 2012, 12:46:23 PM (11 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
6284186fbb128f1c5a0c99ff170cec4bb5afd5a3
Parents:
98d6c34c2a74edb284caaeaec97a1295a4c2a402
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-06-01 12:46:23+02:00
git-committer:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-06-01 12:46:50+02:00
Message:
add: transpose for bigintmat
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Singular/iparith.cc

    r98d6c3 r510dbc  
    48634863{
    48644864  res->data = (char *)(long)ivTrace((intvec*)(v->Data()));
     4865  return FALSE;
     4866}
     4867static BOOLEAN jjTRANSP_BIM(leftv res, leftv v)
     4868{
     4869  res->data = (char *)(((bigintmat*)(v->Data()))->transpose());
    48654870  return FALSE;
    48664871}
  • Singular/table.h

    r98d6c3 r510dbc  
    264264,{D(jjTRANSP_IV),  TRANSPOSE_CMD,   INTMAT_CMD,     INTVEC_CMD    , ALLOW_PLURAL |ALLOW_RING}
    265265,{D(jjTRANSP_IV),  TRANSPOSE_CMD,   INTMAT_CMD,     INTMAT_CMD    , ALLOW_PLURAL |ALLOW_RING}
     266,{D(jjTRANSP_BIM), TRANSPOSE_CMD,   BIGINTMAT_CMD,  BIGINTMAT_CMD , ALLOW_PLURAL |ALLOW_RING}
    266267,{D(jjmpTransp),   TRANSPOSE_CMD,   XS(MATRIX_CMD), MATRIX_CMD    , ALLOW_PLURAL |ALLOW_RING}
    267268,{D(jjidTransp),   TRANSPOSE_CMD,   XS(MODUL_CMD),  MODUL_CMD     , ALLOW_PLURAL |ALLOW_RING}
  • libpolys/coeffs/bigintmat.cc

    r98d6c3 r510dbc  
    1717#define BIMATELEM(M,I,J) (M)[ (M).index(I,J) ]
    1818
     19bigintmat * bigintmat::transpose()
     20{
     21  bigintmat * t = new bigintmat(col, row, basecoeffs());
     22  for (int i=1; i<=row; i++)
     23  {
     24    for (int j=1; j<=col; j++)
     25    {
     26      t->set(j, i, v[(i-1)*col+(j-1)]);
     27    }
     28  }
     29  return t;
     30}
    1931
    2032// Beginnt bei [0]
     
    253265  bigintmat * bim = new bigintmat(ra, cb, basecoeffs);
    254266
    255   for (i=0; i<ra; i++)
    256     for (j=0; j<cb; j++)
     267  for (i=1; i<=ra; i++)
     268    for (j=1; j<=cb; j++)
    257269    {
    258270      sum = n_Init(0, basecoeffs);
    259271
    260       for (k=0; k<ca; k++)
     272      for (k=1; k<=ca; k++)
    261273      {
    262274        number prod = n_Mult( BIMATELEM(*a, i, k), BIMATELEM(*b, k, j), basecoeffs);
     
    268280        sum = sum2;
    269281      }
    270       bim->rawset(i+1, j+1, sum, basecoeffs);
     282      bim->rawset(i, j, sum, basecoeffs);
    271283    }
    272284  return bim;
     
    407419}
    408420
    409 int bigintmat::getwid(int maxwid)
    410 {
    411   int wid=0;
    412   int colwid = floor((maxwid-2*(col-1))/col);
    413   for (int i=0; i<col*row; i++)
    414   {
    415     StringSetS("");
    416     n_Write(v[i], basecoeffs());
    417     char * tmp = StringAppendS("");
    418 //    char * ts = omStrDup(tmp);
    419     const int _nl = strlen(tmp); // ts?
    420     if (_nl > wid)
    421     {
    422       if (_nl > colwid)
    423       {
    424         int phwid = floor(log10(row))+floor(log10(col))+5;
    425         if ((colwid > phwid) && (wid < phwid))
    426           wid = phwid;
    427       }
     421int intArrSum(int * a, int length)
     422{
     423  int sum = 0;
     424  for (int i=0; i<length; i++)
     425    sum += a[i];
     426  return sum;
     427}
     428
     429int findLongest(int * a, int length)
     430{
     431  int l = 0;
     432  int index;
     433  for (int i=0; i<length; i++)
     434  {
     435    if (a[i] > l)
     436    {
     437      l = a[i];
     438      index = i;
     439    }
     440  }
     441  return index;
     442}
     443
     444int getShorter (int * a, int l, int j, int cols, int rows)
     445{
     446  int sndlong = 0;
     447  int min;
     448  for (int i=0; i<rows; i++)
     449  {
     450    int index = cols*i+j;
     451    if ((a[index] > sndlong) && (a[index] < l))
     452    {
     453      min = floor(log10(cols))+floor(log10(rows))+5;
     454      if ((a[index] < min) && (min < l))
     455        sndlong = min;
    428456      else
    429         wid = _nl;
    430     }
    431   }
    432   return wid;
     457        sndlong = a[index];
     458    }
     459  }
     460  if (sndlong == 0)
     461  {
     462    min = floor(log10(cols))+floor(log10(rows))+5;
     463    if (min < l)
     464      sndlong = min;
     465    else
     466      sndlong = 1;
     467  }
     468  return sndlong;
     469}
     470
     471
     472int * bigintmat::getwid(int maxwid)
     473{
     474  int const c = /*2**/(col-1)+1;
     475  if (col + c > maxwid-1) return NULL;
     476  int * wv = (int*)omAlloc(sizeof(int)*col*row);
     477  int * cwv = (int*)omAlloc(sizeof(int)*col);
     478  for (int j=0; j<col; j++)
     479  {
     480    cwv[j] = 0;
     481    for (int i=0; i<row; i++)
     482    {
     483      StringSetS("");
     484      n_Write(v[col*i+j], basecoeffs());
     485      char * tmp = StringAppendS("");
     486      const int _nl = strlen(tmp);
     487      wv[col*i+j] = _nl;
     488      if (_nl > cwv[j])
     489        cwv[j]=_nl;
     490    }
     491  }
     492
     493  // Groesse verkleinern, bis < maxwid
     494  while (intArrSum(cwv, col)+c > maxwid)
     495  {
     496    int j = findLongest(cwv, col);
     497    cwv[j] = getShorter(wv, cwv[j], j, col, row);
     498  }
     499  omFree(wv);
     500  return cwv;
    433501}
    434502
     
    439507  else
    440508  {
    441     int colwid = getwid(maxwid);
    442     if (colwid*col+2*(col-1) > maxwid)
    443       colwid = floor((maxwid-2*(col-1))/col);
     509    int * colwid = getwid(maxwid);
     510    if (colwid == NULL)
     511    {
     512      WerrorS("not enough space to print bigintmat");
     513      return;
     514    }
    444515    char * ps;
    445     ps = (char*) omAlloc0(sizeof(char)*(colwid*col*row+2*(col-1)*row+row));
     516    int slength = 0;
     517    for (int j=0; j<col; j++)
     518      slength += colwid[j]*row;
     519    slength += col*row+row;
     520    ps = (char*) omAlloc0(sizeof(char)*(slength));
    446521    int pos = 0;
    447522    for (int i=0; i<col*row; i++)
     
    452527      char * ts = omStrDup(temp);
    453528      const int _nl = strlen(ts);
    454       if (_nl > colwid)
     529      int cj = i%col;
     530      if (_nl > colwid[cj])
    455531      {
    456532        StringSetS("");
    457         int cj = i%col;
    458533        int ci = floor(i/col);
    459534        StringAppend("[%d,%d]", ci+1, cj+1);
     
    461536        char * ph = omStrDup(tmp);
    462537        int phl = strlen(ph);
    463         if (phl > colwid)
     538        if (phl > colwid[cj])
    464539        {
    465           for (int j=0; j<colwid; j++)
    466             ps[pos+j] = '*';
     540          for (int j=0; j<colwid[cj]-1; j++)
     541            ps[pos+j] = ' ';
     542          ps[pos+colwid[cj]-1] = '*';
    467543        }
    468544        else
    469545        {
    470           for (int j=0; j<colwid-phl; j++)
     546          for (int j=0; j<colwid[cj]-phl; j++)
    471547            ps[pos+j] = ' ';
    472548          for (int j=0; j<phl; j++)
    473             ps[pos+colwid-phl+j] = ph[j];
     549            ps[pos+colwid[cj]-phl+j] = ph[j];
    474550        }
    475551        omFree(ph);
     
    477553      else  // Mit Leerzeichen auffÃŒllen und zahl reinschreiben
    478554      {
    479         for (int j=0; j<colwid-_nl; j++)
     555        for (int j=0; j<colwid[cj]-_nl; j++)
    480556          ps[pos+j] = ' ';
    481557        for (int j=0; j<_nl; j++)
    482           ps[pos+colwid-_nl+j] = ts[j];
    483       }
    484       // ", " oder "\n" einfÃŒgen
     558          ps[pos+colwid[cj]-_nl+j] = ts[j];
     559      }
     560      // ", " und (evtl) "\n" einfÃŒgen
    485561      if ((i+1)%col == 0)
    486562      {
    487563        if (i != col*row-1)
    488564        {
    489           ps[pos+colwid] = '\n';
    490           pos += colwid+1;
     565          ps[pos+colwid[cj]] = ',';
     566          ps[pos+colwid[cj]+1] = '\n';
     567          pos += colwid[cj]+2;
    491568        }
    492569      }
    493570      else
    494571      {
    495         ps[pos+colwid] = ',';
    496         ps[pos+colwid+1] = ' ';
    497         pos += colwid+2;
    498       }
    499       // Hier ts zerstören
     572        ps[pos+colwid[cj]] = ',';
     573        pos += colwid[cj]+1;
     574      }
     575
     576      omFree(ts);  // Hier ts zerstören
    500577    }
    501578    PrintS(ps);
    502     omFree(ps);
     579   // omFree(ps);
    503580  }
    504581}
  • libpolys/coeffs/bigintmat.h

    r98d6c3 r510dbc  
    2626    bigintmat(): m_coeffs(NULL), v(NULL), row(1), col(0){}
    2727
     28    bigintmat * transpose();
     29
    2830    bigintmat(int r, int c, const coeffs n): m_coeffs(n), v(NULL), row(r), col(c)
    2931    {
     
    171173    void pprint(int maxwid);
    172174    int compare(const bigintmat* op) const;
    173     int getwid(int maxwid);
     175    int * getwid(int maxwid);
    174176};
    175177
     
    188190bigintmat * bimCopy(const bigintmat * b);
    189191
     192int getShorter (int * a, int l, int j, int cols, int rows);
     193int findLongest(int * a, int length);
     194int intArrSum(int * a, int length);
    190195
    191196
Note: See TracChangeset for help on using the changeset viewer.