Changeset fe02b1 in git
 Timestamp:
 Apr 25, 2012, 8:38:08 PM (11 years ago)
 Branches:
 (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
 Children:
 0fd1715860b463009cfd80025e81bd671f0a0a2d
 Parents:
 84fc1fddf725ce226a336195603ebcadbb650d4c
 Files:

 4 edited
Legend:
 Unmodified
 Added
 Removed

Singular/grammar.cc
r84fc1f rfe02b1 3177 3177 h=(idhdl)v>data; 3178 3178 delete IDBIMAT(h); 3179 IDBIMAT(h) = new bigintmat(r, c);3179 IDBIMAT(h) = new bigintmat(r, c, coeffs_BIGINT); 3180 3180 if (IDBIMAT(h)==NULL) YYERROR; 3181 3181 } 
Singular/grammar.y
r84fc1f rfe02b1 935 935 h=(idhdl)v>data; 936 936 delete IDBIMAT(h); 937 IDBIMAT(h) = new bigintmat(r, c);937 IDBIMAT(h) = new bigintmat(r, c, coeffs_BIGINT); 938 938 if (IDBIMAT(h)==NULL) YYERROR; 939 939 } 
libpolys/coeffs/bigintmat.cc
r84fc1f rfe02b1 1 1 /***************************************** 2 * Computer Algebra System SINGULAR *3 *****************************************/2 * Computer Algebra System SINGULAR * 3 *****************************************/ 4 4 /* 5 * ABSTRACT: class bigintmat: matrizes of big integers 6 */ 7 #include <kernel/mod2.h> 5 * ABSTRACT: class bigintmat: matrizes of big integers 6 */ 7 #include "bigintmat.h" 8 9 #include <misc/intvec.h> 10 11 //#include <kernel/mod2.h> 8 12 //#include <kernel/options.h> 9 #include "bigintmat.h" 10 #include <omalloc/omalloc.h> 11 #include <coeffs/longrat.h> 12 #include <misc/intvec.h> 13 13 14 #include <math.h> 14 15 #include <string.h> 15 16 16 #define BIGIMATELEM(M,I,J) (M)[(I1)*(M).cols()+J1] 17 #define BIMATELEM(M,I,J) (M)[ (M).index(I,J) ] 18 19 20 // Beginnt bei [0] 21 void bigintmat::set(int i, number n, const coeffs C) 22 { 23 assume (C == NULL  C == basecoeffs()); 24 25 rawset(i, n_Copy(n, basecoeffs()), basecoeffs()); 26 } 17 27 18 28 // Beginnt bei [1,1] 19 void bigintmat::set(int i, int j, number n) 20 { 21 nlDelete(&(v[(i1)*col+j1]), NULL); 22 v[(i1)*col+j1] = nlCopy(n,NULL); 23 } 24 25 // Beginnt bei [0] 26 void bigintmat::set(int i, number n) 27 { 28 if (i<row*col) 29 { 30 nlDelete(&(v[i]), NULL); 31 v[i] = nlCopy(n,NULL); 32 } 33 } 34 35 number bigintmat::get(int i, int j) 36 { 37 return nlCopy(v[(i1)*col+j1],NULL); 38 } 39 40 number bigintmat::get(int i) 41 { 42 return nlCopy(v[i],NULL); 43 } 44 45 bigintmat::bigintmat(int r, int c) 46 { 47 row = r; 48 col = c; 49 int l = r*c; 50 if (l>0) /*(r>0) && (c>0) */ 51 v = (number *)omAlloc(sizeof(number)*l); 52 else 53 v = NULL; 54 for (int i=0; i<l; i++) 55 { 56 v[i] = nlInit(0, NULL); 57 } 29 void bigintmat::set(int i, int j, number n, const coeffs C) 30 { 31 assume (C == NULL  C == basecoeffs()); 32 assume (i > 0 && j > 0); 33 assume (i <= rows() && j <= cols()); 34 35 set(index(i, j), n, C); 36 } 37 38 number bigintmat::get(int i) const 39 { 40 assume (i >= 0); 41 assume (i<rows()*cols()); 42 43 return n_Copy(v[i], basecoeffs()); 44 } 45 46 number bigintmat::get(int i, int j) const 47 { 48 assume (i > 0 && j > 0); 49 assume (i <= rows() && j <= cols()); 50 51 return get(index(i, j)); 58 52 } 59 53 … … 62 56 void bigintmat::operator*=(int intop) 63 57 { 64 for (int i=0; i<row*col; i++) 65 { 66 number iop = nlInit(intop, NULL); 67 number prod = nlMult(v[i], iop,NULL); 68 nlDelete(&(v[i]), NULL); 69 nlDelete(&iop, NULL); 70 v[i] = prod; 71 } 72 } 73 74 void bigintmat::operator*=(number bintop) 75 { 76 for (int i=0; i<row*col; i++) 77 { 78 number prod = nlMult(v[i], bintop,NULL); 79 nlDelete(&(v[i]), NULL); 80 v[i] = prod; 81 } 58 number iop = n_Init(intop, basecoeffs()); 59 60 inpMult(iop, basecoeffs()); 61 62 n_Delete(&iop, basecoeffs()); 63 } 64 65 void bigintmat::inpMult(number bintop, const coeffs C) 66 { 67 assume (C == NULL  C == basecoeffs()); 68 69 const int l = rows() * cols(); 70 71 for (int i=0; i < l; i++) 72 n_InpMult(v[i], bintop, basecoeffs()); 82 73 } 83 74 … … 86 77 // Oder lieber eine compFunktion? 87 78 88 bool operator==( bigintmat & lhr,bigintmat & rhr)79 bool operator==(const bigintmat & lhr, const bigintmat & rhr) 89 80 { 90 81 if (&lhr == &rhr) { return true; } 91 82 if (lhr.cols() != rhr.cols()) { return false; } 92 83 if (lhr.rows() != rhr.rows()) { return false; } 93 for (int i=0; i<(lhr.rows())*(lhr.cols()); i++) 94 { 95 if (!nlEqual(lhr[i], rhr[i],NULL)) { return false; } 96 } 84 if (lhr.basecoeffs() != rhr.basecoeffs()) { return false; } 85 86 const int l = (lhr.rows())*(lhr.cols()); 87 88 for (int i=0; i < l; i++) 89 { 90 if (!n_Equal(lhr[i], rhr[i], lhr.basecoeffs())) { return false; } 91 } 92 97 93 return true; 98 94 } 99 95 100 bool operator!=( bigintmat & lhr,bigintmat & rhr)96 bool operator!=(const bigintmat & lhr, const bigintmat & rhr) 101 97 { 102 98 return !(lhr==rhr); … … 106 102 bigintmat * bimAdd(bigintmat * a, bigintmat * b) 107 103 { 108 bigintmat * bim;109 int mn, ma, i;110 104 if (a>cols() != b>cols()) return NULL; 111 mn = si_min(a>rows(),b>rows()); 112 ma = si_max(a>rows(),b>rows()); 105 if (a>basecoeffs() != b>basecoeffs()) { return NULL; } 106 107 const int mn = si_min(a>rows(),b>rows()); 108 const int ma = si_max(a>rows(),b>rows()); 109 110 const coeffs basecoeffs = a>basecoeffs(); 111 112 int i; 113 113 114 if (a>cols() == 1) 114 115 { 115 bim = new bigintmat(ma, 1); 116 bigintmat * bim = new bigintmat(ma, 1, basecoeffs); 117 116 118 for (i=0; i<mn; i++) 117 { 118 number n = nlAdd((*a)[i], (*b)[i],NULL); 119 bim>set(i, n); 120 nlDelete(&n, NULL); 121 } 119 bim>rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs); 120 122 121 if (ma > mn) 123 122 { 124 123 if (ma == a>rows()) 125 { 124 for(i=mn; i<ma; i++) 125 bim>set(i, (*a)[i], basecoeffs); 126 else 127 for(i=mn; i<ma; i++) 128 bim>set(i, (*b)[i], basecoeffs); 129 } 130 return bim; 131 } 132 133 if (mn != ma) return NULL; 134 135 bigintmat * bim = new bigintmat(mn, a>cols(), basecoeffs); 136 137 for (i=0; i<mn*a>cols(); i++) 138 bim>rawset(i, n_Add((*a)[i], (*b)[i], basecoeffs), basecoeffs); 139 140 return bim; 141 } 142 143 bigintmat * bimSub(bigintmat * a, bigintmat * b) 144 { 145 if (a>cols() != b>cols()) return NULL; 146 if (a>basecoeffs() != b>basecoeffs()) { return NULL; } 147 148 const int mn = si_min(a>rows(),b>rows()); 149 const int ma = si_max(a>rows(),b>rows()); 150 151 const coeffs basecoeffs = a>basecoeffs(); 152 153 int i; 154 155 if (a>cols() == 1) 156 { 157 bigintmat * bim = new bigintmat(ma, 1, basecoeffs); 158 159 for (i=0; i<mn; i++) 160 bim>rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs); 161 162 if (ma > mn) 163 { 164 if (ma == a>rows()) 165 { 166 for(i=mn; i<ma; i++) 167 bim>set(i, (*a)[i], basecoeffs); 168 } 169 else 126 170 for(i=mn; i<ma; i++) 127 171 { 128 bim>set(i, (*a)[i]); 172 number n = b>get(i); 173 n = n_Neg(n, basecoeffs); 174 bim>rawset(i, n, basecoeffs); 129 175 } 130 }131 else132 {133 for(i=mn; i<ma; i++)134 {135 bim>set(i, (*b)[i]);136 }137 }138 176 } 139 177 return bim; 140 178 } 179 141 180 if (mn != ma) return NULL; 142 bim = new bigintmat(mn, a>cols()); 181 182 bigintmat * bim = new bigintmat(mn, a>cols(), basecoeffs); 183 143 184 for (i=0; i<mn*a>cols(); i++) 144 { 145 number n = nlAdd((*a)[i], (*b)[i],NULL); 146 bim>set(i, n); 147 nlDelete(&n, NULL); 148 } 185 bim>rawset(i, n_Sub((*a)[i], (*b)[i], basecoeffs), basecoeffs); 186 149 187 return bim; 150 188 } 151 189 152 bigintmat * bimSub(bigintmat * a, bigintmat * b) 153 { 154 bigintmat * bim; 155 int mn, ma, i; 156 if (a>cols() != b>cols()) return NULL; 157 mn = si_min(a>rows(),b>rows()); 158 ma = si_max(a>rows(),b>rows()); 159 if (a>cols() == 1) 160 { 161 bim = new bigintmat(ma, 1); 162 for (i=0; i<mn; i++) 163 { 164 number n = nlSub((*a)[i], (*b)[i],NULL); 165 bim>set(i, n); 166 nlDelete(&n, NULL); 167 } 168 if (ma > mn) 169 { 170 if (ma == a>rows()) 171 { 172 for(i=mn; i<ma; i++) 173 { 174 bim>set(i, (*a)[i]); 175 } 176 } 177 else 178 { 179 for(i=mn; i<ma; i++) 180 { 181 bim>set(i, (*b)[i]); 182 } 183 } 184 } 185 return bim; 186 } 187 if (mn != ma) return NULL; 188 bim = new bigintmat(mn, a>cols()); 189 for (i=0; i<mn*a>cols(); i++) 190 { 191 number n = nlSub((*a)[i], (*b)[i],NULL); 192 bim>set(i, n); 193 nlDelete(&n, NULL); 194 } 190 bigintmat * bimMult(bigintmat * a, bigintmat * b) 191 { 192 const int ca = a>cols(); 193 const int cb = b>cols(); 194 195 const int ra = a>rows(); 196 const int rb = b>rows(); 197 198 if (ca != rb) 199 { 200 #ifndef NDEBUG 201 Werror("wrong bigintmat sizes at multiplication a * b: acols: %d != brows: %d\n", ca, rb); 202 #endif 203 return NULL; 204 } 205 206 assume (ca == rb); 207 208 if (a>basecoeffs() != b>basecoeffs()) { return NULL; } 209 210 const coeffs basecoeffs = a>basecoeffs(); 211 212 int i, j, k; 213 214 number sum; 215 216 bigintmat * bim = new bigintmat(ra, cb, basecoeffs); 217 218 for (i=0; i<ra; i++) 219 for (j=0; j<cb; j++) 220 { 221 sum = n_Init(0, basecoeffs); 222 223 for (k=0; k<ca; k++) 224 { 225 number prod = n_Mult( BIMATELEM(*a, i, k), BIMATELEM(*b, k, j), basecoeffs); 226 227 number sum2 = n_Add(sum, prod, basecoeffs); // no inplace add :( 228 229 n_Delete(&sum, basecoeffs); n_Delete(&prod, basecoeffs); 230 231 sum = sum2; 232 } 233 bim>rawset(i+1, j+1, sum, basecoeffs); 234 } 195 235 return bim; 196 236 } 197 237 198 bigintmat * bimMult(bigintmat * a, bigintmat * b) 199 { 200 int i, j, k, 201 ra = a>rows(), ca = a>cols(), 202 rb = b>rows(), cb = b>cols(); 203 number sum; 204 bigintmat * bim; 205 if (ca != rb) return NULL; 206 bim = new bigintmat(ra, cb); 207 for (i=0; i<ra; i++) 208 { 209 for (j=0; j<cb; j++) 210 { 211 sum = nlInit(0, NULL); 212 for (k=0; k<ca; k++) 213 { 214 number prod = nlMult((*a)[i*ca+k], (*b)[k*cb+j],NULL); 215 number sum2 = nlAdd(sum, prod,NULL); 216 nlDelete(&sum, NULL); 217 sum = sum2; 218 nlDelete(&prod, NULL); 219 } 220 bim>set(i+1, j+1, sum); 221 nlDelete(&sum, NULL); 222 } 223 } 238 //  // 239 // Korrekt? 240 241 intvec * bim2iv(bigintmat * b) 242 { 243 intvec * iv = new intvec(b>rows(), b>cols(), 0); 244 for (int i=0; i<(b>rows())*(b>cols()); i++) 245 (*iv)[i] = n_Int((*b)[i], b>basecoeffs()); // Geht das so? 246 return iv; 247 } 248 249 bigintmat * iv2bim(intvec * b, const coeffs C) 250 { 251 const int l = (b>rows())*(b>cols()); 252 bigintmat * bim = new bigintmat(b>rows(), b>cols(), C); 253 254 for (int i=0; i < l; i++) 255 bim>rawset(i, n_Init((*b)[i], C), C); 256 224 257 return bim; 225 258 } 226 259 227 // Korrekt? 228 229 intvec * bim2iv(bigintmat * b) 230 { 231 intvec * iv; 232 iv = new intvec(b>rows(), b>cols(), 0); 233 for (int i=0; i<(b>rows())*(b>cols()); i++) { (*iv)[i] = nlInt((*b)[i], NULL); } // Geht das so? 234 return iv; 235 } 236 237 bigintmat * iv2bim(intvec * b) 238 { 239 bigintmat * bim; 240 bim = new bigintmat(b>rows(), b>cols()); 241 for (int i=0; i<(b>rows())*(b>cols()); i++) 242 { 243 number n = nlInit((*b)[i], NULL); 244 bim>set(i, n); 245 nlDelete(&n, NULL); 246 } 247 return bim; 248 } 260 //  // 249 261 250 262 int bigintmat::compare(const bigintmat* op) const 251 263 { 264 assume (basecoeffs() == op>basecoeffs() ); 265 266 #ifndef NDEBUG 267 if (basecoeffs() != op>basecoeffs() ) 268 WerrorS("wrong bigintmat comparison: different basecoeffs!\n"); 269 #endif 270 252 271 if ((col!=1) (op>cols()!=1)) 253 272 { 254 273 if((col!=op>cols()) 255  (row!=op>rows()))274  (row!=op>rows())) 256 275 return 2; 257 276 } 277 258 278 int i; 259 279 for (i=0; i<si_min(row*col,op>rows()*op>cols()); i++) 260 280 { 261 if ( nlGreater(v[i], (*op)[i],NULL))281 if ( n_Greater(v[i], (*op)[i], basecoeffs()) ) 262 282 return 1; 263 else if (! nlEqual(v[i], (*op)[i],NULL))283 else if (! n_Equal(v[i], (*op)[i], basecoeffs())) 264 284 return 1; 265 285 } … … 267 287 for (; i<row; i++) 268 288 { 269 if ( nlGreaterZero(v[i],NULL))289 if ( n_GreaterZero(v[i], basecoeffs()) ) 270 290 return 1; 271 else if (! nlIsZero(v[i],NULL))291 else if (! n_IsZero(v[i], basecoeffs()) ) 272 292 return 1; 273 293 } 274 294 for (; i<op>rows(); i++) 275 295 { 276 if ( nlGreaterZero((*op)[i],NULL))296 if ( n_GreaterZero((*op)[i], basecoeffs()) ) 277 297 return 1; 278 else if (! nlIsZero((*op)[i],NULL))298 else if (! n_IsZero((*op)[i], basecoeffs()) ) 279 299 return 1; 280 300 } … … 285 305 bigintmat * bimCopy(const bigintmat * b) 286 306 { 287 bigintmat * a=NULL; 288 if (b!=NULL) 289 { 290 a = new bigintmat(b>rows(), b>cols()); 291 for (int i=0; i<(b>rows())*(b>cols()); i++) 292 { 293 a>set(i, (*b)[i]); 294 } 295 } 296 return a; 307 if (b == NULL) 308 return NULL; 309 310 return new bigintmat(b); 297 311 } 298 312 299 313 char* bigintmat::String() 300 314 { 315 assume (rows() > 0); 316 assume (cols() > 0); 317 301 318 StringSetS(""); 302 int i;303 for (i=0; i<col*row1; i++) 304 {305 nlWrite(v[i], NULL);306 StringAppendS(",");307 }308 nlWrite(v[i], NULL);309 310 311 312 313 314 319 const int l = cols()*rows(); 320 321 n_Write(v[0], basecoeffs()); 322 for (int i = 1; i < l; i++) 323 { 324 StringAppendS(","); n_Write(v[i], basecoeffs()); 325 } 326 /* if (i != col*row1) 327 { 328 StringAppendS(","); 329 if ((i+1)%col == 0) 330 StringAppendS("\n"); 331 } */ 315 332 return StringAppendS(""); 316 333 } … … 323 340 { 324 341 StringSetS(""); 325 n lWrite(v[i], NULL);342 n_Write(v[i], basecoeffs()); 326 343 char * tmp = StringAppendS(""); 327 char * ts = omStrDup(tmp);328 int nl = strlen(ts);329 if ( nl > wid)330 { 331 if ( nl > colwid)344 // char * ts = omStrDup(tmp); 345 const int _nl = strlen(tmp); // ts? 346 if (_nl > wid) 347 { 348 if (_nl > colwid) 332 349 { 333 350 int phwid = floor(log10(row))+floor(log10(col))+5; … … 336 353 } 337 354 else 338 wid = nl;355 wid = _nl; 339 356 } 340 357 } … … 357 374 { 358 375 StringSetS(""); 359 n lWrite(v[i], NULL);376 n_Write(v[i], basecoeffs()); 360 377 char * temp = StringAppendS(""); 361 378 char * ts = omStrDup(temp); 362 intnl = strlen(ts);363 if ( nl > colwid)379 const int _nl = strlen(ts); 380 if (_nl > colwid) 364 381 { 365 382 StringSetS(""); … … 386 403 else // Mit Leerzeichen auffÃŒllen und zahl reinschreiben 387 404 { 388 for (int j=0; j<colwid nl; j++)405 for (int j=0; j<colwid_nl; j++) 389 406 ps[pos+j] = ' '; 390 for (int j=0; j< nl; j++)391 ps[pos+colwid nl+j] = ts[j];407 for (int j=0; j<_nl; j++) 408 ps[pos+colwid_nl+j] = ts[j]; 392 409 } 393 410 // ", " oder "\n" einfÃŒgen … … 406 423 pos += colwid+2; 407 424 } 408 // Hier ts zerstÃ¶ren425 // Hier ts zerstÃ¶ren 409 426 } 410 427 PrintS(ps); … … 416 433 static void bimRowContent(bigintmat *bimat, int rowpos, int colpos) 417 434 { 435 const coeffs basecoeffs = bimat>basecoeffs(); 436 418 437 number tgcd, m; 419 438 int i=bimat>cols(); … … 421 440 loop 422 441 { 423 tgcd = n lCopy(BIMATELEM(*bimat,rowpos,i),NULL);424 if (! nlIsZero(tgcd,NULL)) break;442 tgcd = n_Copy(BIMATELEM(*bimat,rowpos,i), basecoeffs); 443 if (! n_IsZero(tgcd, basecoeffs)) break; 425 444 if (i<colpos) return; 426 445 } 427 if ((! nlGreaterZero(tgcd,NULL)) && (!nlIsZero(tgcd,NULL))) tgcd = nlNeg(tgcd,NULL);428 if ( nlIsOne(tgcd,NULL)) return;446 if ((! n_GreaterZero(tgcd, basecoeffs)) && (! n_IsZero(tgcd, basecoeffs))) tgcd = n_Neg(tgcd, basecoeffs); 447 if ( n_IsOne(tgcd,basecoeffs)) return; 429 448 loop 430 449 { 431 m = n lCopy(BIMATELEM(*bimat,rowpos,i),NULL);432 if (! nlIsZero(m,NULL))433 { 434 number tp1 = n lGcd(tgcd, m, NULL);435 n lDelete(&tgcd, NULL);450 m = n_Copy(BIMATELEM(*bimat,rowpos,i), basecoeffs); 451 if (! n_IsZero(m,basecoeffs)) 452 { 453 number tp1 = n_Gcd(tgcd, m, basecoeffs); 454 n_Delete(&tgcd, basecoeffs); 436 455 tgcd = tp1; 437 456 } 438 if ( nlIsOne(tgcd,NULL)) return;457 if ( n_IsOne(tgcd,basecoeffs)) return; 439 458 if (i<colpos) break; 440 459 } 441 460 for (i=bimat>cols();i>=colpos;i) 442 461 { 443 number tp2 = n lDiv(BIMATELEM(*bimat,rowpos,i), tgcd,NULL);444 n lDelete(&BIMATELEM(*bimat,rowpos,i), NULL);462 number tp2 = n_Div(BIMATELEM(*bimat,rowpos,i), tgcd,basecoeffs); 463 n_Delete(&BIMATELEM(*bimat,rowpos,i), basecoeffs); 445 464 BIMATELEM(*bimat,rowpos,i) = tp2; 446 465 } 447 n lDelete(&tgcd, NULL);448 n lDelete(&m, NULL);466 n_Delete(&tgcd, basecoeffs); 467 n_Delete(&m, basecoeffs); 449 468 } 450 469 451 470 static void bimReduce(bigintmat *bimat, int rpiv, int colpos, 452 int ready, int all) 453 { 471 int ready, int all) 472 { 473 const coeffs basecoeffs = bimat>basecoeffs(); 474 454 475 number tgcd, ce, m1, m2; 455 476 int j, i; … … 458 479 for (j=all;j>ready;j) 459 480 { 460 ce = n lCopy(BIMATELEM(*bimat,j,colpos),NULL);461 if (! nlIsZero(ce,NULL))462 { 463 n lDelete(&BIMATELEM(*bimat,j,colpos), NULL);464 BIMATELEM(*bimat,j,colpos) = n lInit(0, NULL);465 m1 = n lCopy(piv,NULL);466 m2 = n lCopy(ce,NULL);467 tgcd = n lGcd(m1, m2, NULL);468 if (! nlIsOne(tgcd,NULL))469 { 470 number tp1 = n lDiv(m1, tgcd,NULL);471 number tp2 = n lDiv(m2, tgcd,NULL);472 n lDelete(&m1, NULL);473 n lDelete(&m2, NULL);481 ce = n_Copy(BIMATELEM(*bimat,j,colpos),basecoeffs); 482 if (! n_IsZero(ce, basecoeffs)) 483 { 484 n_Delete(&BIMATELEM(*bimat,j,colpos), basecoeffs); 485 BIMATELEM(*bimat,j,colpos) = n_Init(0, basecoeffs); 486 m1 = n_Copy(piv,basecoeffs); 487 m2 = n_Copy(ce,basecoeffs); 488 tgcd = n_Gcd(m1, m2, basecoeffs); 489 if (! n_IsOne(tgcd,basecoeffs)) 490 { 491 number tp1 = n_Div(m1, tgcd,basecoeffs); 492 number tp2 = n_Div(m2, tgcd,basecoeffs); 493 n_Delete(&m1, basecoeffs); 494 n_Delete(&m2, basecoeffs); 474 495 m1 = tp1; 475 496 m2 = tp2; … … 477 498 for (i=bimat>cols();i>colpos;i) 478 499 { 479 n lDelete(&BIMATELEM(*bimat,j,i), NULL);480 number tp1 = n lMult(BIMATELEM(*bimat,j,i), m1,NULL);481 number tp2 = n lMult(BIMATELEM(*bimat,rpiv,i), m2,NULL);482 BIMATELEM(*bimat,j,i) = n lSub(tp1, tp2,NULL);483 n lDelete(&tp1, NULL);484 n lDelete(&tp2, NULL);500 n_Delete(&BIMATELEM(*bimat,j,i), basecoeffs); 501 number tp1 = n_Mult(BIMATELEM(*bimat,j,i), m1,basecoeffs); 502 number tp2 = n_Mult(BIMATELEM(*bimat,rpiv,i), m2,basecoeffs); 503 BIMATELEM(*bimat,j,i) = n_Sub(tp1, tp2,basecoeffs); 504 n_Delete(&tp1, basecoeffs); 505 n_Delete(&tp2, basecoeffs); 485 506 } 486 507 bimRowContent(bimat, j, colpos+1); 487 n lDelete(&m1, NULL);488 n lDelete(&m2, NULL);489 } 490 n lDelete(&ce, NULL);491 } 492 } 493 494 495 496 497 508 n_Delete(&m1, basecoeffs); 509 n_Delete(&m2, basecoeffs); 510 } 511 n_Delete(&ce, basecoeffs); 512 } 513 } 514 515 516 517 518 
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*col1; 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 = l1; 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)[(I1)*(M).cols()+J1] 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 = ((r1)*cols() + (c1)); 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 /// MatrixAdd/Sub/Mult so oder mit operator+//* ? 177 /// NOTE: NULL as a result means an error (noncompatible 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.