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

spielwiese
Last change on this file since ba5e9e was 87977c7, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
Merge pull request #342 from YueRen/spielwiese Spielwiese
  • Property mode set to 100644
File size: 5.1 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 <resources/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 * transpose();
29
30    bigintmat(int r, int c, const coeffs n): m_coeffs(n), v(NULL), row(r), col(c)
31    {
32      assume (rows() >= 0);
33      assume (cols() >= 0);
34
35      const int l = r*c;
36
37      if (l>0) /*(r>0) && (c>0) */
38      {
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        }
46      }
47    }
48
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);
57
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)
72    {
73#ifndef NDEBUG
74      if((i<0)||(i>=row*col))
75      {
76        Werror("wrong bigintmat index:%d\n",i);
77      }
78#endif
79      assume ( !((i<0)||(i>=row*col)) );
80
81      return v[i];  // Hier sollte imho kein nlCopy rein...
82    }
83    inline const number& operator[](int i) const
84    {
85#ifndef NDEBUG
86      if((i<0)||(i>=row*col))
87      {
88        Werror("wrong bigintmat index:%d\n",i);
89      }
90#endif
91      assume ( !((i<0)||(i>=row*col)) );
92
93      return v[i];
94    }
95#define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1]
96
97    /// UEberladener *=-Operator (fuer int und bigint)
98    /// Frage hier: *= verwenden oder lieber = und * einzeln?
99    void operator*=(int intop);
100
101    void inpMult(number bintop, const coeffs C = NULL);
102
103    inline int length() { return col*row; }
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()
109    {
110      if (v!=NULL)
111      {
112        for (int i=0; i<row*col; i++) { n_Delete(&(v[i]), basecoeffs()); }
113        omFreeSize((ADDRESS)v, sizeof(number)*row*col);
114        v=NULL;
115      }
116    }
117
118    int index(int r, int c) const
119    {
120      assume (rows() >= 0 && cols() >= 0);
121
122      assume (r > 0 && c > 0);
123      assume (r <= rows() && c <= cols());
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);
140
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;
158      }
159#ifndef NDEBUG
160      else
161      {
162        Werror("wrong bigintmat index:%d\n",i);
163      }
164#endif
165    }
166
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/***
174 * Returns a string as it would have been printed in the interpreter.
175 * Used e.g. in print functions of various blackbox types.
176 **/
177    char * StringAsPrinted();
178    void pprint(int maxwid);
179    int compare(const bigintmat* op) const;
180    int * getwid(int maxwid);
181};
182
183bool operator==(const bigintmat & lhr, const bigintmat & rhr);
184bool operator!=(const bigintmat & lhr, const bigintmat & rhr);
185
186/// Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ?
187/// NOTE: NULL as a result means an error (non-compatible matrices?)
188bigintmat * bimAdd(bigintmat * a, bigintmat * b);
189bigintmat * bimAdd(bigintmat * a, int b);
190bigintmat * bimSub(bigintmat * a, bigintmat * b);
191bigintmat * bimSub(bigintmat * a, int b);
192bigintmat * bimMult(bigintmat * a, bigintmat * b);
193bigintmat * bimMult(bigintmat * a, int b);
194bigintmat * bimMult(bigintmat * a, number b, const coeffs cf);
195bigintmat * bimCopy(const bigintmat * b);
196
197int getShorter (int * a, int l, int j, int cols, int rows);
198int findLongest(int * a, int length);
199int intArrSum(int * a, int length);
200
201class intvec;
202intvec * bim2iv(bigintmat * b);
203bigintmat * iv2bim(intvec * b, const coeffs C);
204bigintmat * bimConcat(bigintmat * a, bigintmat * b, const coeffs C);
205#endif // #ifndef BIGINTMAT_H
Note: See TracBrowser for help on using the repository browser.