source: git/libpolys/coeffs/bigintmat.h @ 75f10d

spielwiese
Last change on this file since 75f10d was 75f10d, checked in by Hans Schoenemann <hannes@…>, 12 years ago
add: bigintmat stuff from master
  • Property mode set to 100644
File size: 4.9 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#define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
94
95    /// UEberladener *=-Operator (fuer int und bigint)
96    /// Frage hier: *= verwenden oder lieber = und * einzeln?
97    void operator*=(int intop);
98
99    void inpMult(number bintop, const coeffs C = NULL);
100
101    inline int  cols() const { return col; }
102    inline int  rows() const { return row; }
103    inline coeffs basecoeffs() const { return m_coeffs; }
104
105    ~bigintmat()
106    {
107      if (v!=NULL)
108      {
109        for (int i=0; i<row*col; i++) { n_Delete(&(v[i]), basecoeffs()); }
110        omFreeSize((ADDRESS)v, sizeof(number)*row*col);
111        v=NULL;
112      }
113    }
114
115    int index(int r, int c) const
116    {
117      assume (rows() >= 0 && cols() >= 0);
118
119      assume (r > 0 && c > 0);
120      assume (r <= rows() && r <= cols());
121
122      const int index = ((r-1)*cols() + (c-1));
123
124      assume (index >= 0 && index < rows() * cols());
125      return index;
126    }
127
128    /// get a copy of an entry. NOTE: starts at [1,1]
129    number get(int i, int j) const;
130
131    /// get a copy of an entry. NOTE: starts at [0]
132    number get(int i) const;
133
134    /// replace an entry with a copy (delete old + copy new!).
135    /// NOTE: starts at [1,1]
136    void set(int i, int j, number n, const coeffs C = NULL);
137
138    /// replace an entry with a copy (delete old + copy new!).
139    /// NOTE: starts at [0]
140    void set(int i, number n, const coeffs C = NULL);
141
142
143    /// replace an entry with the given number n (only delete old).
144    /// NOTE: starts at [0]
145    inline void rawset(int i, number n, const coeffs C = NULL)
146    {
147      assume (C == NULL || C == basecoeffs());
148      assume (i >= 0);
149      const int l = rows() * cols();
150      assume (i<l);
151
152      if (i < l)
153      {
154        n_Delete(&(v[i]), basecoeffs()); v[i] = n;
155      }
156#ifndef NDEBUG
157      else
158      {
159        Werror("wrong bigintmat index:%d\n",i);
160      }
161#endif
162    }
163
164    inline void rawset(int i, int j, number n, const coeffs C = NULL)
165    {
166      rawset( index(i,j), n, C);
167    }
168
169    char * String();
170    void pprint(int maxwid);
171    int compare(const bigintmat* op) const;
172    int getwid(int maxwid);
173};
174
175bool operator==(const bigintmat & lhr, const bigintmat & rhr);
176bool operator!=(const bigintmat & lhr, const bigintmat & rhr);
177
178/// Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ?
179/// NOTE: NULL as a result means an error (non-compatible matrices?)
180bigintmat * bimAdd(bigintmat * a, bigintmat * b);
181bigintmat * bimAdd(bigintmat * a, int b);
182bigintmat * bimSub(bigintmat * a, bigintmat * b);
183bigintmat * bimSub(bigintmat * a, int b);
184bigintmat * bimMult(bigintmat * a, bigintmat * b);
185bigintmat * bimMult(bigintmat * a, int b);
186bigintmat * bimMult(bigintmat * a, number b, const coeffs cf);
187bigintmat * bimCopy(const bigintmat * b);
188
189
190
191// Ungetestet
192static void bimRowContent(bigintmat *bimat, int rowpos, int colpos);
193static void bimReduce(bigintmat *bimat, int rpiv, int colpos,
194                      int ready, int all);
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.