source: git/libpolys/coeffs/bigintmat.h @ 26b713

spielwiese
Last change on this file since 26b713 was 2e4ec14, checked in by Yue Ren <ren@…>, 11 years ago
fix: -Wunused-parameter warnings
  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[9127cc]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: class bigintmat: matrizes of big integers
6*/
[fe02b1]7
8#ifndef BIGINTMAT_H
9#define BIGINTMAT_H
10
[9127cc]11#include <omalloc/omalloc.h>
[fe02b1]12#include <findexec/feFopen.h>
[9127cc]13#include <coeffs/coeffs.h>
14
[fe02b1]15/// matrix of numbers
16/// NOTE: no reference counting!!!
[9127cc]17class bigintmat
18{
[fe02b1]19  private:
20    coeffs m_coeffs;
21    number *v;
22    int row;
23    int col;
24  public:
25
26    bigintmat(): m_coeffs(NULL), v(NULL), row(1), col(0){}
27
[510dbc]28    bigintmat * transpose();
29
[fe02b1]30    bigintmat(int r, int c, const coeffs n): m_coeffs(n), v(NULL), row(r), col(c)
[9127cc]31    {
[fe02b1]32      assume (rows() > 0);
33      assume (cols() > 0);
34
35      const int l = r*c;
36
37      if (l>0) /*(r>0) && (c>0) */
[9127cc]38      {
[fe02b1]39        v = (number *)omAlloc(sizeof(number)*l);
40
41        assume (basecoeffs() != NULL);
42        for (int i = l - 1; i>=0; i--)
43        {
44          v[i] = n_Init(0, basecoeffs());
45        }
[9127cc]46      }
47    }
48
[fe02b1]49    bigintmat(const bigintmat *m): m_coeffs(m->basecoeffs()), v(NULL), row(m->rows()), col(m->cols())
50    {
51      const int l = row*col;
52
53      if (l > 0)
54      {
55        assume (rows() > 0);
56        assume (cols() > 0);
[9127cc]57
[fe02b1]58        assume (m->v != NULL);
59
60        v = (number *)omAlloc(sizeof(number)*row*col);
61
62        assume (basecoeffs() != NULL);
63
64        for (int i = l-1; i>=0; i--)
65        {
66          v[i] = n_Copy((*m)[i], basecoeffs());
67        }
68      }
69    }
70
71    inline number& operator[](int i)
[9127cc]72    {
73#ifndef NDEBUG
74      if((i<0)||(i>=row*col))
75      {
76        Werror("wrong bigintmat index:%d\n",i);
77      }
78#endif
[fe02b1]79      assume ( !((i<0)||(i>=row*col)) );
80
[9127cc]81      return v[i];  // Hier sollte imho kein nlCopy rein...
82    }
[fe02b1]83    inline const number& operator[](int i) const
[9127cc]84    {
85#ifndef NDEBUG
86      if((i<0)||(i>=row*col))
87      {
88        Werror("wrong bigintmat index:%d\n",i);
89      }
90#endif
[fe02b1]91      assume ( !((i<0)||(i>=row*col)) );
92
[9127cc]93      return v[i];
94    }
[75f10d]95#define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
[9127cc]96
[fe02b1]97    /// UEberladener *=-Operator (fuer int und bigint)
98    /// Frage hier: *= verwenden oder lieber = und * einzeln?
99    void operator*=(int intop);
[75f10d]100
[fe02b1]101    void inpMult(number bintop, const coeffs C = NULL);
102
[ebbb9c]103    inline int length() { return col*row; }
[fe02b1]104    inline int  cols() const { return col; }
105    inline int  rows() const { return row; }
106    inline coeffs basecoeffs() const { return m_coeffs; }
107
108    ~bigintmat()
[9127cc]109    {
110      if (v!=NULL)
111      {
[fe02b1]112        for (int i=0; i<row*col; i++) { n_Delete(&(v[i]), basecoeffs()); }
113        omFreeSize((ADDRESS)v, sizeof(number)*row*col);
[9127cc]114        v=NULL;
115      }
116    }
[fe02b1]117
118    int index(int r, int c) const
119    {
120      assume (rows() >= 0 && cols() >= 0);
[75f10d]121
[fe02b1]122      assume (r > 0 && c > 0);
[aaf761]123      assume (r <= rows() && c <= cols());
[fe02b1]124
125      const int index = ((r-1)*cols() + (c-1));
126
127      assume (index >= 0 && index < rows() * cols());
128      return index;
129    }
130
131    /// get a copy of an entry. NOTE: starts at [1,1]
132    number get(int i, int j) const;
133
134    /// get a copy of an entry. NOTE: starts at [0]
135    number get(int i) const;
136
137    /// replace an entry with a copy (delete old + copy new!).
138    /// NOTE: starts at [1,1]
139    void set(int i, int j, number n, const coeffs C = NULL);
[75f10d]140
[fe02b1]141    /// replace an entry with a copy (delete old + copy new!).
142    /// NOTE: starts at [0]
143    void set(int i, number n, const coeffs C = NULL);
144
145
146    /// replace an entry with the given number n (only delete old).
147    /// NOTE: starts at [0]
[2e4ec14]148#ifdef NDEBUG
149    inline void rawset(int i, number n, const coeffs /*C = NULL*/)
150#else
[fe02b1]151    inline void rawset(int i, number n, const coeffs C = NULL)
[2e4ec14]152#endif
[fe02b1]153    {
154      assume (C == NULL || C == basecoeffs());
155      assume (i >= 0);
156      const int l = rows() * cols();
157      assume (i<l);
158
159      if (i < l)
160      {
161        n_Delete(&(v[i]), basecoeffs()); v[i] = n;
[75f10d]162      }
[fe02b1]163#ifndef NDEBUG
[75f10d]164      else
165      {
[fe02b1]166        Werror("wrong bigintmat index:%d\n",i);
167      }
[75f10d]168#endif
[fe02b1]169    }
[75f10d]170
[fe02b1]171    inline void rawset(int i, int j, number n, const coeffs C = NULL)
172    {
173      rawset( index(i,j), n, C);
174    }
175
176    char * String();
177    void pprint(int maxwid);
178    int compare(const bigintmat* op) const;
[510dbc]179    int * getwid(int maxwid);
[9127cc]180};
[fe02b1]181
182bool operator==(const bigintmat & lhr, const bigintmat & rhr);
183bool operator!=(const bigintmat & lhr, const bigintmat & rhr);
184
185/// Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ?
186/// NOTE: NULL as a result means an error (non-compatible matrices?)
[9127cc]187bigintmat * bimAdd(bigintmat * a, bigintmat * b);
[75f10d]188bigintmat * bimAdd(bigintmat * a, int b);
[9127cc]189bigintmat * bimSub(bigintmat * a, bigintmat * b);
[75f10d]190bigintmat * bimSub(bigintmat * a, int b);
[9127cc]191bigintmat * bimMult(bigintmat * a, bigintmat * b);
[75f10d]192bigintmat * bimMult(bigintmat * a, int b);
193bigintmat * bimMult(bigintmat * a, number b, const coeffs cf);
[9127cc]194bigintmat * bimCopy(const bigintmat * b);
[fe02b1]195
[510dbc]196int getShorter (int * a, int l, int j, int cols, int rows);
197int findLongest(int * a, int length);
198int intArrSum(int * a, int length);
[fe02b1]199
200class intvec;
201intvec * bim2iv(bigintmat * b);
202bigintmat * iv2bim(intvec * b, const coeffs C);
203
204
205#endif // #ifndef BIGINTMAT_H
Note: See TracBrowser for help on using the repository browser.