Changeset fe02b1 in git for libpolys/coeffs/bigintmat.h
- Timestamp:
- Apr 25, 2012, 8:38:08 PM (11 years ago)
- Branches:
- (u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
- Children:
- 0fd1715860b463009cfd80025e81bd671f0a0a2d
- Parents:
- 84fc1fddf725ce226a336195603ebcadbb650d4c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/bigintmat.h
r84fc1f rfe02b1 1 #ifndef BIGINTMAT_H2 #define BIGINTMAT_H3 1 /**************************************** 4 2 * Computer Algebra System SINGULAR * … … 7 5 * ABSTRACT: class bigintmat: matrizes of big integers 8 6 */ 9 #include <string.h> 7 8 #ifndef BIGINTMAT_H 9 #define BIGINTMAT_H 10 10 11 #include <omalloc/omalloc.h> 12 #include <findexec/feFopen.h> 11 13 #include <coeffs/coeffs.h> 12 #include <coeffs/longrat.h>13 #include <misc/intvec.h>14 14 15 15 /// matrix of numbers 16 /// NOTE: no reference counting!!! 16 17 class bigintmat 17 18 { 18 private: 19 number *v; 20 int row; 21 int col; 22 public: 19 private: 20 coeffs m_coeffs; 21 number *v; 22 int row; 23 int col; 24 public: 23 25 24 bigintmat() 25 { 26 row = 1; 27 col = 0; 28 v = NULL; 29 } 30 bigintmat(int r, int c); 26 bigintmat(): m_coeffs(NULL), v(NULL), row(1), col(0){} 31 27 32 bigintmat(const bigintmat *m) 33 { 34 row = m->rows(); 35 col = m->cols(); 36 if (row*col>0) 28 bigintmat(int r, int c, const coeffs n): m_coeffs(n), v(NULL), row(r), col(c) 37 29 { 38 v = (number *)omAlloc(sizeof(number)*row*col); 39 for (int i=row*col-1; i>=0; i--) 30 assume (rows() > 0); 31 assume (cols() > 0); 32 33 const int l = r*c; 34 35 if (l>0) /*(r>0) && (c>0) */ 40 36 { 41 v[i] = nlCopy((*m)[i],NULL); 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 } 42 44 } 43 45 } 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; 46 50 47 inline number& operator[](int i) 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) 48 70 { 49 71 #ifndef NDEBUG … … 53 75 } 54 76 #endif 77 assume ( !((i<0)||(i>=row*col)) ); 78 55 79 return v[i]; // Hier sollte imho kein nlCopy rein... 56 80 } 57 inline const number& operator[](int i) const81 inline const number& operator[](int i) const 58 82 { 59 83 #ifndef NDEBUG … … 63 87 } 64 88 #endif 89 assume ( !((i<0)||(i>=row*col)) ); 90 65 91 return v[i]; 66 92 } 67 93 68 #define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1] 69 void operator*=(int intop); 70 void operator*=(number bintop); 71 inline int cols() const { return col; } 72 inline int rows() const { return row; } 73 inline ~bigintmat() 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() 74 105 { 75 106 if (v!=NULL) 76 107 { 77 for (int i=0; i<row*col; i++) { n lDelete(&(v[i]), NULL); }78 omFreeSize((ADDRESS)v, sizeof(number)*row*col);108 for (int i=0; i<row*col; i++) { n_Delete(&(v[i]), basecoeffs()); } 109 omFreeSize((ADDRESS)v, sizeof(number)*row*col); 79 110 v=NULL; 80 111 } 81 112 } 82 number get(int i, int j); 83 number get(int i); 84 void set(int i, int j, number n); 85 void set(int i, number n); 86 char * String(); 87 void pprint(int maxwid); 88 int compare(const bigintmat* op) const; 89 int getwid(int maxwid); 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); 90 171 }; 91 bool operator==(bigintmat & lhr, bigintmat & rhr); 92 bool operator!=(bigintmat & lhr, bigintmat & rhr); 172 173 bool operator==(const bigintmat & lhr, const bigintmat & rhr); 174 bool 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?) 93 178 bigintmat * bimAdd(bigintmat * a, bigintmat * b); 94 179 bigintmat * bimSub(bigintmat * a, bigintmat * b); 95 180 bigintmat * bimMult(bigintmat * a, bigintmat * b); 96 intvec * bim2iv(bigintmat * b);97 181 bigintmat * bimCopy(const bigintmat * b); 182 183 184 185 // Ungetestet 98 186 static void bimRowContent(bigintmat *bimat, int rowpos, int colpos); 99 187 static void bimReduce(bigintmat *bimat, int rpiv, int colpos, 100 int ready, int all);188 int ready, int all); 101 189 102 bigintmat * iv2bim(intvec * b); 103 #endif 190 class intvec; 191 intvec * bim2iv(bigintmat * b); 192 bigintmat * iv2bim(intvec * b, const coeffs C); 193 194 195 #endif // #ifndef BIGINTMAT_H
Note: See TracChangeset
for help on using the changeset viewer.