- Timestamp:
- May 10, 2012, 1:59:15 PM (12 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 6f0279ecd605db3872247f2211d8efd1ac65d42a
- Parents:
- c8302bb70ef743b5705287005391184566e69b06
- git-author:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-05-10 13:59:15+02:00
- git-committer:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-05-10 13:59:37+02:00
- Location:
- libpolys/coeffs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/bigintmat.cc
rc8302b r75f10d 32 32 assume (i > 0 && j > 0); 33 33 assume (i <= rows() && j <= cols()); 34 34 35 35 set(index(i, j), n, C); 36 36 } … … 40 40 assume (i >= 0); 41 41 assume (i<rows()*cols()); 42 42 43 43 return n_Copy(v[i], basecoeffs()); 44 44 } … … 48 48 assume (i > 0 && j > 0); 49 49 assume (i <= rows() && j <= cols()); 50 50 51 51 return get(index(i, j)); 52 52 } … … 57 57 { 58 58 number iop = n_Init(intop, basecoeffs()); 59 59 60 60 inpMult(iop, basecoeffs()); 61 61 62 62 n_Delete(&iop, basecoeffs()); 63 63 } … … 66 66 { 67 67 assume (C == NULL || C == basecoeffs()); 68 68 69 69 const int l = rows() * cols(); 70 70 … … 85 85 86 86 const int l = (lhr.rows())*(lhr.cols()); 87 87 88 88 for (int i=0; i < l; i++) 89 89 { 90 90 if (!n_Equal(lhr[i], rhr[i], lhr.basecoeffs())) { return false; } 91 91 } 92 92 93 93 return true; 94 94 } … … 104 104 if (a->cols() != b->cols()) return NULL; 105 105 if (a->basecoeffs() != b->basecoeffs()) { return NULL; } 106 106 107 107 const int mn = si_min(a->rows(),b->rows()); 108 108 const int ma = si_max(a->rows(),b->rows()); 109 109 110 110 const coeffs basecoeffs = a->basecoeffs(); 111 111 112 112 int i; 113 113 … … 115 115 { 116 116 bigintmat * bim = new bigintmat(ma, 1, basecoeffs); 117 117 118 118 for (i=0; i<mn; i++) 119 119 bim->rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs); 120 120 121 121 if (ma > mn) 122 122 { … … 130 130 return bim; 131 131 } 132 132 133 133 if (mn != ma) return NULL; 134 134 135 135 bigintmat * bim = new bigintmat(mn, a->cols(), basecoeffs); 136 136 137 137 for (i=0; i<mn*a->cols(); i++) 138 138 bim->rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs); 139 139 140 return bim; 141 } 142 bigintmat * bimAdd(bigintmat * a, int b) 143 { 144 145 const int mn = a->rows()*a->cols(); 146 147 const coeffs basecoeffs = a->basecoeffs(); 148 number bb=n_Init(b,basecoeffs); 149 150 int i; 151 152 bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs); 153 154 for (i=0; i<mn; i++) 155 bim->rawset(i, n_Add((*a)[i], bb, basecoeffs), basecoeffs); 156 157 n_Delete(&bb,basecoeffs); 140 158 return bim; 141 159 } … … 156 174 { 157 175 bigintmat * bim = new bigintmat(ma, 1, basecoeffs); 158 176 159 177 for (i=0; i<mn; i++) 160 178 bim->rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs); … … 177 195 return bim; 178 196 } 179 197 180 198 if (mn != ma) return NULL; 181 199 182 200 bigintmat * bim = new bigintmat(mn, a->cols(), basecoeffs); 183 201 184 202 for (i=0; i<mn*a->cols(); i++) 185 203 bim->rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs); 186 204 205 return bim; 206 } 207 208 bigintmat * bimSub(bigintmat * a, int b) 209 { 210 211 const int mn = a->rows()*a->cols(); 212 213 const coeffs basecoeffs = a->basecoeffs(); 214 number bb=n_Init(b,basecoeffs); 215 216 int i; 217 218 bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs); 219 220 for (i=0; i<mn; i++) 221 bim->rawset(i, n_Sub((*a)[i], bb, basecoeffs), basecoeffs); 222 223 n_Delete(&bb,basecoeffs); 187 224 return bim; 188 225 } … … 195 232 const int ra = a->rows(); 196 233 const int rb = b->rows(); 197 234 198 235 if (ca != rb) 199 236 { … … 203 240 return NULL; 204 241 } 205 242 206 243 assume (ca == rb); 207 244 208 245 if (a->basecoeffs() != b->basecoeffs()) { return NULL; } 209 246 210 247 const coeffs basecoeffs = a->basecoeffs(); 211 248 212 249 int i, j, k; 213 250 214 251 number sum; 215 252 216 253 bigintmat * bim = new bigintmat(ra, cb, basecoeffs); 217 254 218 255 for (i=0; i<ra; i++) 219 256 for (j=0; j<cb; j++) 220 257 { 221 258 sum = n_Init(0, basecoeffs); 222 259 223 260 for (k=0; k<ca; k++) 224 261 { 225 262 number prod = n_Mult( BIMATELEM(*a, i, k), BIMATELEM(*b, k, j), basecoeffs); 226 263 227 264 number sum2 = n_Add(sum, prod, basecoeffs); // no inplace add :( 228 265 229 266 n_Delete(&sum, basecoeffs); n_Delete(&prod, basecoeffs); 230 267 231 268 sum = sum2; 232 269 } 233 270 bim->rawset(i+1, j+1, sum, basecoeffs); 234 271 } 272 return bim; 273 } 274 275 bigintmat * bimMult(bigintmat * a, int b) 276 { 277 278 const int mn = a->rows()*a->cols(); 279 280 const coeffs basecoeffs = a->basecoeffs(); 281 number bb=n_Init(b,basecoeffs); 282 283 int i; 284 285 bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs); 286 287 for (i=0; i<mn; i++) 288 bim->rawset(i, n_Mult((*a)[i], bb, basecoeffs), basecoeffs); 289 290 n_Delete(&bb,basecoeffs); 291 return bim; 292 } 293 294 bigintmat * bimMult(bigintmat * a, number b, const coeffs cf) 295 { 296 if (cf!=a->basecoeffs()) return NULL; 297 298 const int mn = a->rows()*a->cols(); 299 300 const coeffs basecoeffs = a->basecoeffs(); 301 302 int i; 303 304 bigintmat * bim = new bigintmat(a->rows(),a->cols() , basecoeffs); 305 306 for (i=0; i<mn; i++) 307 bim->rawset(i, n_Mult((*a)[i], b, basecoeffs), basecoeffs); 308 235 309 return bim; 236 310 } … … 251 325 const int l = (b->rows())*(b->cols()); 252 326 bigintmat * bim = new bigintmat(b->rows(), b->cols(), C); 253 327 254 328 for (int i=0; i < l; i++) 255 329 bim->rawset(i, n_Init((*b)[i], C), C); 256 330 257 331 return bim; 258 332 } … … 307 381 if (b == NULL) 308 382 return NULL; 309 383 310 384 return new bigintmat(b); 311 385 } … … 434 508 { 435 509 const coeffs basecoeffs = bimat->basecoeffs(); 436 510 437 511 number tgcd, m; 438 512 int i=bimat->cols(); -
libpolys/coeffs/bigintmat.h
rc8302b r75f10d 91 91 return v[i]; 92 92 } 93 #define BIMATELEM(M,I,J) (M)[(I-1)*(M).cols()+J-1] 93 94 94 95 /// UEberladener *=-Operator (fuer int und bigint) 95 96 /// Frage hier: *= verwenden oder lieber = und * einzeln? 96 97 void operator*=(int intop); 97 98 98 99 void inpMult(number bintop, const coeffs C = NULL); 99 100 … … 115 116 { 116 117 assume (rows() >= 0 && cols() >= 0); 117 118 118 119 assume (r > 0 && c > 0); 119 120 assume (r <= rows() && r <= cols()); … … 134 135 /// NOTE: starts at [1,1] 135 136 void set(int i, int j, number n, const coeffs C = NULL); 136 137 137 138 /// replace an entry with a copy (delete old + copy new!). 138 139 /// NOTE: starts at [0] … … 152 153 { 153 154 n_Delete(&(v[i]), basecoeffs()); v[i] = n; 154 } else 155 { 155 } 156 156 #ifndef NDEBUG 157 else 158 { 157 159 Werror("wrong bigintmat index:%d\n",i); 160 } 158 161 #endif 159 } 160 } 161 162 } 163 162 164 inline void rawset(int i, int j, number n, const coeffs C = NULL) 163 165 { … … 177 179 /// NOTE: NULL as a result means an error (non-compatible matrices?) 178 180 bigintmat * bimAdd(bigintmat * a, bigintmat * b); 181 bigintmat * bimAdd(bigintmat * a, int b); 179 182 bigintmat * bimSub(bigintmat * a, bigintmat * b); 183 bigintmat * bimSub(bigintmat * a, int b); 180 184 bigintmat * bimMult(bigintmat * a, bigintmat * b); 185 bigintmat * bimMult(bigintmat * a, int b); 186 bigintmat * bimMult(bigintmat * a, number b, const coeffs cf); 181 187 bigintmat * bimCopy(const bigintmat * b); 182 188
Note: See TracChangeset
for help on using the changeset viewer.