source: git/libpolys/coeffs/bigintmat.h @ fe02b1

spielwiese
Last change on this file since fe02b1 was fe02b1, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
my rewrite of bigintmat as a matrix of numbers from any coeff. domain fix: several bugs and mem. leaks add: improved interface (mostly backward compatible) chg: many minor improvements add: started documenting with doxygen comments add: lots of assumes NOTE: NULL should NOT be used as a coeff. domain (use coeffs_BIGINT for Q!)
  • Property mode set to 100644
File size: 4.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: class bigintmat: matrizes of big integers
6*/
7
8#ifndef BIGINTMAT_H
9#define BIGINTMAT_H
10
11#include <omalloc/omalloc.h>
12#include <findexec/feFopen.h>
13#include <coeffs/coeffs.h>
14
15/// matrix of numbers
16/// NOTE: no reference counting!!!
17class bigintmat
18{
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
28    bigintmat(int r, int c, const coeffs n): m_coeffs(n), v(NULL), row(r), col(c)
29    {
30      assume (rows() > 0);
31      assume (cols() > 0);
32
33      const int l = r*c;
34
35      if (l>0) /*(r>0) && (c>0) */
36      {
37        v = (number *)omAlloc(sizeof(number)*l);
38
39        assume (basecoeffs() != NULL);
40        for (int i = l - 1; i>=0; i--)
41        {
42          v[i] = n_Init(0, basecoeffs());
43        }
44      }
45    }
46
47    bigintmat(const bigintmat *m): m_coeffs(m->basecoeffs()), v(NULL), row(m->rows()), col(m->cols())
48    {
49      const int l = row*col;
50
51      if (l > 0)
52      {
53        assume (rows() > 0);
54        assume (cols() > 0);
55
56        assume (m->v != NULL);
57
58        v = (number *)omAlloc(sizeof(number)*row*col);
59
60        assume (basecoeffs() != NULL);
61
62        for (int i = l-1; i>=0; i--)
63        {
64          v[i] = n_Copy((*m)[i], basecoeffs());
65        }
66      }
67    }
68
69    inline number& operator[](int i)
70    {
71#ifndef NDEBUG
72      if((i<0)||(i>=row*col))
73      {
74        Werror("wrong bigintmat index:%d\n",i);
75      }
76#endif
77      assume ( !((i<0)||(i>=row*col)) );
78
79      return v[i];  // Hier sollte imho kein nlCopy rein...
80    }
81    inline const number& operator[](int i) const
82    {
83#ifndef NDEBUG
84      if((i<0)||(i>=row*col))
85      {
86        Werror("wrong bigintmat index:%d\n",i);
87      }
88#endif
89      assume ( !((i<0)||(i>=row*col)) );
90
91      return v[i];
92    }
93
94    /// UEberladener *=-Operator (fuer int und bigint)
95    /// Frage hier: *= verwenden oder lieber = und * einzeln?
96    void operator*=(int intop);
97   
98    void inpMult(number bintop, const coeffs C = NULL);
99
100    inline int  cols() const { return col; }
101    inline int  rows() const { return row; }
102    inline coeffs basecoeffs() const { return m_coeffs; }
103
104    ~bigintmat()
105    {
106      if (v!=NULL)
107      {
108        for (int i=0; i<row*col; i++) { n_Delete(&(v[i]), basecoeffs()); }
109        omFreeSize((ADDRESS)v, sizeof(number)*row*col);
110        v=NULL;
111      }
112    }
113
114    int index(int r, int c) const
115    {
116      assume (rows() >= 0 && cols() >= 0);
117     
118      assume (r > 0 && c > 0);
119      assume (r <= rows() && r <= cols());
120
121      const int index = ((r-1)*cols() + (c-1));
122
123      assume (index >= 0 && index < rows() * cols());
124      return index;
125    }
126
127    /// get a copy of an entry. NOTE: starts at [1,1]
128    number get(int i, int j) const;
129
130    /// get a copy of an entry. NOTE: starts at [0]
131    number get(int i) const;
132
133    /// replace an entry with a copy (delete old + copy new!).
134    /// NOTE: starts at [1,1]
135    void set(int i, int j, number n, const coeffs C = NULL);
136   
137    /// replace an entry with a copy (delete old + copy new!).
138    /// NOTE: starts at [0]
139    void set(int i, number n, const coeffs C = NULL);
140
141
142    /// replace an entry with the given number n (only delete old).
143    /// NOTE: starts at [0]
144    inline void rawset(int i, number n, const coeffs C = NULL)
145    {
146      assume (C == NULL || C == basecoeffs());
147      assume (i >= 0);
148      const int l = rows() * cols();
149      assume (i<l);
150
151      if (i < l)
152      {
153        n_Delete(&(v[i]), basecoeffs()); v[i] = n;
154      } else
155      {
156#ifndef NDEBUG
157        Werror("wrong bigintmat index:%d\n",i);
158#endif
159      }
160    }
161   
162    inline void rawset(int i, int j, number n, const coeffs C = NULL)
163    {
164      rawset( index(i,j), n, C);
165    }
166
167    char * String();
168    void pprint(int maxwid);
169    int compare(const bigintmat* op) const;
170    int getwid(int maxwid);
171};
172
173bool operator==(const bigintmat & lhr, const bigintmat & rhr);
174bool operator!=(const bigintmat & lhr, const bigintmat & rhr);
175
176/// Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ?
177/// NOTE: NULL as a result means an error (non-compatible matrices?)
178bigintmat * bimAdd(bigintmat * a, bigintmat * b);
179bigintmat * bimSub(bigintmat * a, bigintmat * b);
180bigintmat * bimMult(bigintmat * a, bigintmat * b);
181bigintmat * bimCopy(const bigintmat * b);
182
183
184
185// Ungetestet
186static void bimRowContent(bigintmat *bimat, int rowpos, int colpos);
187static void bimReduce(bigintmat *bimat, int rpiv, int colpos,
188                      int ready, int all);
189
190class intvec;
191intvec * bim2iv(bigintmat * b);
192bigintmat * iv2bim(intvec * b, const coeffs C);
193
194
195#endif // #ifndef BIGINTMAT_H
Note: See TracBrowser for help on using the repository browser.