source: git/libpolys/coeffs/bigintmat.h @ 6caad65

spielwiese
Last change on this file since 6caad65 was 6caad65, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
warnings elimination chg: uninitialized fake variables chg: "'const' type qualifier on return type has no effect" for numeric/ chg: more minor warnings elimination
  • Property mode set to 100644
File size: 4.9 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]
148    inline void rawset(int i, number n, const coeffs C = NULL)
149    {
150      assume (C == NULL || C == basecoeffs());
151      assume (i >= 0);
152      const int l = rows() * cols();
153      assume (i<l);
154
155      if (i < l)
156      {
157        n_Delete(&(v[i]), basecoeffs()); v[i] = n;
[75f10d]158      }
[fe02b1]159#ifndef NDEBUG
[75f10d]160      else
161      {
[fe02b1]162        Werror("wrong bigintmat index:%d\n",i);
163      }
[75f10d]164#endif
[fe02b1]165    }
[75f10d]166
[fe02b1]167    inline void rawset(int i, int j, number n, const coeffs C = NULL)
168    {
169      rawset( index(i,j), n, C);
170    }
171
172    char * String();
173    void pprint(int maxwid);
174    int compare(const bigintmat* op) const;
[510dbc]175    int * getwid(int maxwid);
[9127cc]176};
[fe02b1]177
178bool operator==(const bigintmat & lhr, const bigintmat & rhr);
179bool operator!=(const bigintmat & lhr, const bigintmat & rhr);
180
181/// Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ?
182/// NOTE: NULL as a result means an error (non-compatible matrices?)
[9127cc]183bigintmat * bimAdd(bigintmat * a, bigintmat * b);
[75f10d]184bigintmat * bimAdd(bigintmat * a, int b);
[9127cc]185bigintmat * bimSub(bigintmat * a, bigintmat * b);
[75f10d]186bigintmat * bimSub(bigintmat * a, int b);
[9127cc]187bigintmat * bimMult(bigintmat * a, bigintmat * b);
[75f10d]188bigintmat * bimMult(bigintmat * a, int b);
189bigintmat * bimMult(bigintmat * a, number b, const coeffs cf);
[9127cc]190bigintmat * bimCopy(const bigintmat * b);
[fe02b1]191
[510dbc]192int getShorter (int * a, int l, int j, int cols, int rows);
193int findLongest(int * a, int length);
194int intArrSum(int * a, int length);
[fe02b1]195
196class intvec;
197intvec * bim2iv(bigintmat * b);
198bigintmat * iv2bim(intvec * b, const coeffs C);
199
200
201#endif // #ifndef BIGINTMAT_H
Note: See TracBrowser for help on using the repository browser.