Changeset 510dbc in git
- Timestamp:
- Jun 1, 2012, 12:46:23 PM (11 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- 6284186fbb128f1c5a0c99ff170cec4bb5afd5a3
- Parents:
- 98d6c34c2a74edb284caaeaec97a1295a4c2a402
- git-author:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-06-01 12:46:23+02:00
- git-committer:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2012-06-01 12:46:50+02:00
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/iparith.cc
r98d6c3 r510dbc 4863 4863 { 4864 4864 res->data = (char *)(long)ivTrace((intvec*)(v->Data())); 4865 return FALSE; 4866 } 4867 static BOOLEAN jjTRANSP_BIM(leftv res, leftv v) 4868 { 4869 res->data = (char *)(((bigintmat*)(v->Data()))->transpose()); 4865 4870 return FALSE; 4866 4871 } -
Singular/table.h
r98d6c3 r510dbc 264 264 ,{D(jjTRANSP_IV), TRANSPOSE_CMD, INTMAT_CMD, INTVEC_CMD , ALLOW_PLURAL |ALLOW_RING} 265 265 ,{D(jjTRANSP_IV), TRANSPOSE_CMD, INTMAT_CMD, INTMAT_CMD , ALLOW_PLURAL |ALLOW_RING} 266 ,{D(jjTRANSP_BIM), TRANSPOSE_CMD, BIGINTMAT_CMD, BIGINTMAT_CMD , ALLOW_PLURAL |ALLOW_RING} 266 267 ,{D(jjmpTransp), TRANSPOSE_CMD, XS(MATRIX_CMD), MATRIX_CMD , ALLOW_PLURAL |ALLOW_RING} 267 268 ,{D(jjidTransp), TRANSPOSE_CMD, XS(MODUL_CMD), MODUL_CMD , ALLOW_PLURAL |ALLOW_RING} -
libpolys/coeffs/bigintmat.cc
r98d6c3 r510dbc 17 17 #define BIMATELEM(M,I,J) (M)[ (M).index(I,J) ] 18 18 19 bigintmat * bigintmat::transpose() 20 { 21 bigintmat * t = new bigintmat(col, row, basecoeffs()); 22 for (int i=1; i<=row; i++) 23 { 24 for (int j=1; j<=col; j++) 25 { 26 t->set(j, i, v[(i-1)*col+(j-1)]); 27 } 28 } 29 return t; 30 } 19 31 20 32 // Beginnt bei [0] … … 253 265 bigintmat * bim = new bigintmat(ra, cb, basecoeffs); 254 266 255 for (i= 0; i<ra; i++)256 for (j= 0; j<cb; j++)267 for (i=1; i<=ra; i++) 268 for (j=1; j<=cb; j++) 257 269 { 258 270 sum = n_Init(0, basecoeffs); 259 271 260 for (k= 0; k<ca; k++)272 for (k=1; k<=ca; k++) 261 273 { 262 274 number prod = n_Mult( BIMATELEM(*a, i, k), BIMATELEM(*b, k, j), basecoeffs); … … 268 280 sum = sum2; 269 281 } 270 bim->rawset(i +1, j+1, sum, basecoeffs);282 bim->rawset(i, j, sum, basecoeffs); 271 283 } 272 284 return bim; … … 407 419 } 408 420 409 int bigintmat::getwid(int maxwid) 410 { 411 int wid=0; 412 int colwid = floor((maxwid-2*(col-1))/col); 413 for (int i=0; i<col*row; i++) 414 { 415 StringSetS(""); 416 n_Write(v[i], basecoeffs()); 417 char * tmp = StringAppendS(""); 418 // char * ts = omStrDup(tmp); 419 const int _nl = strlen(tmp); // ts? 420 if (_nl > wid) 421 { 422 if (_nl > colwid) 423 { 424 int phwid = floor(log10(row))+floor(log10(col))+5; 425 if ((colwid > phwid) && (wid < phwid)) 426 wid = phwid; 427 } 421 int intArrSum(int * a, int length) 422 { 423 int sum = 0; 424 for (int i=0; i<length; i++) 425 sum += a[i]; 426 return sum; 427 } 428 429 int findLongest(int * a, int length) 430 { 431 int l = 0; 432 int index; 433 for (int i=0; i<length; i++) 434 { 435 if (a[i] > l) 436 { 437 l = a[i]; 438 index = i; 439 } 440 } 441 return index; 442 } 443 444 int getShorter (int * a, int l, int j, int cols, int rows) 445 { 446 int sndlong = 0; 447 int min; 448 for (int i=0; i<rows; i++) 449 { 450 int index = cols*i+j; 451 if ((a[index] > sndlong) && (a[index] < l)) 452 { 453 min = floor(log10(cols))+floor(log10(rows))+5; 454 if ((a[index] < min) && (min < l)) 455 sndlong = min; 428 456 else 429 wid = _nl; 430 } 431 } 432 return wid; 457 sndlong = a[index]; 458 } 459 } 460 if (sndlong == 0) 461 { 462 min = floor(log10(cols))+floor(log10(rows))+5; 463 if (min < l) 464 sndlong = min; 465 else 466 sndlong = 1; 467 } 468 return sndlong; 469 } 470 471 472 int * bigintmat::getwid(int maxwid) 473 { 474 int const c = /*2**/(col-1)+1; 475 if (col + c > maxwid-1) return NULL; 476 int * wv = (int*)omAlloc(sizeof(int)*col*row); 477 int * cwv = (int*)omAlloc(sizeof(int)*col); 478 for (int j=0; j<col; j++) 479 { 480 cwv[j] = 0; 481 for (int i=0; i<row; i++) 482 { 483 StringSetS(""); 484 n_Write(v[col*i+j], basecoeffs()); 485 char * tmp = StringAppendS(""); 486 const int _nl = strlen(tmp); 487 wv[col*i+j] = _nl; 488 if (_nl > cwv[j]) 489 cwv[j]=_nl; 490 } 491 } 492 493 // Groesse verkleinern, bis < maxwid 494 while (intArrSum(cwv, col)+c > maxwid) 495 { 496 int j = findLongest(cwv, col); 497 cwv[j] = getShorter(wv, cwv[j], j, col, row); 498 } 499 omFree(wv); 500 return cwv; 433 501 } 434 502 … … 439 507 else 440 508 { 441 int colwid = getwid(maxwid); 442 if (colwid*col+2*(col-1) > maxwid) 443 colwid = floor((maxwid-2*(col-1))/col); 509 int * colwid = getwid(maxwid); 510 if (colwid == NULL) 511 { 512 WerrorS("not enough space to print bigintmat"); 513 return; 514 } 444 515 char * ps; 445 ps = (char*) omAlloc0(sizeof(char)*(colwid*col*row+2*(col-1)*row+row)); 516 int slength = 0; 517 for (int j=0; j<col; j++) 518 slength += colwid[j]*row; 519 slength += col*row+row; 520 ps = (char*) omAlloc0(sizeof(char)*(slength)); 446 521 int pos = 0; 447 522 for (int i=0; i<col*row; i++) … … 452 527 char * ts = omStrDup(temp); 453 528 const int _nl = strlen(ts); 454 if (_nl > colwid) 529 int cj = i%col; 530 if (_nl > colwid[cj]) 455 531 { 456 532 StringSetS(""); 457 int cj = i%col;458 533 int ci = floor(i/col); 459 534 StringAppend("[%d,%d]", ci+1, cj+1); … … 461 536 char * ph = omStrDup(tmp); 462 537 int phl = strlen(ph); 463 if (phl > colwid )538 if (phl > colwid[cj]) 464 539 { 465 for (int j=0; j<colwid; j++) 466 ps[pos+j] = '*'; 540 for (int j=0; j<colwid[cj]-1; j++) 541 ps[pos+j] = ' '; 542 ps[pos+colwid[cj]-1] = '*'; 467 543 } 468 544 else 469 545 { 470 for (int j=0; j<colwid -phl; j++)546 for (int j=0; j<colwid[cj]-phl; j++) 471 547 ps[pos+j] = ' '; 472 548 for (int j=0; j<phl; j++) 473 ps[pos+colwid -phl+j] = ph[j];549 ps[pos+colwid[cj]-phl+j] = ph[j]; 474 550 } 475 551 omFree(ph); … … 477 553 else // Mit Leerzeichen auffÃŒllen und zahl reinschreiben 478 554 { 479 for (int j=0; j<colwid -_nl; j++)555 for (int j=0; j<colwid[cj]-_nl; j++) 480 556 ps[pos+j] = ' '; 481 557 for (int j=0; j<_nl; j++) 482 ps[pos+colwid -_nl+j] = ts[j];483 } 484 // ", " oder"\n" einfÃŒgen558 ps[pos+colwid[cj]-_nl+j] = ts[j]; 559 } 560 // ", " und (evtl) "\n" einfÃŒgen 485 561 if ((i+1)%col == 0) 486 562 { 487 563 if (i != col*row-1) 488 564 { 489 ps[pos+colwid] = '\n'; 490 pos += colwid+1; 565 ps[pos+colwid[cj]] = ','; 566 ps[pos+colwid[cj]+1] = '\n'; 567 pos += colwid[cj]+2; 491 568 } 492 569 } 493 570 else 494 571 { 495 ps[pos+colwid ] = ',';496 p s[pos+colwid+1] = ' ';497 pos += colwid+2;498 } 499 // Hier ts zerstören572 ps[pos+colwid[cj]] = ','; 573 pos += colwid[cj]+1; 574 } 575 576 omFree(ts); // Hier ts zerstören 500 577 } 501 578 PrintS(ps); 502 omFree(ps);579 // omFree(ps); 503 580 } 504 581 } -
libpolys/coeffs/bigintmat.h
r98d6c3 r510dbc 26 26 bigintmat(): m_coeffs(NULL), v(NULL), row(1), col(0){} 27 27 28 bigintmat * transpose(); 29 28 30 bigintmat(int r, int c, const coeffs n): m_coeffs(n), v(NULL), row(r), col(c) 29 31 { … … 171 173 void pprint(int maxwid); 172 174 int compare(const bigintmat* op) const; 173 int getwid(int maxwid);175 int * getwid(int maxwid); 174 176 }; 175 177 … … 188 190 bigintmat * bimCopy(const bigintmat * b); 189 191 192 int getShorter (int * a, int l, int j, int cols, int rows); 193 int findLongest(int * a, int length); 194 int intArrSum(int * a, int length); 190 195 191 196
Note: See TracChangeset
for help on using the changeset viewer.