Changeset a5bf88 in git
 Timestamp:
 Jun 22, 1999, 1:24:02 PM (24 years ago)
 Branches:
 (u'jengelhdatetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
 Children:
 1eb7af12ba2eda02be4f55b12705297ff94d3b13
 Parents:
 a36a1a32a3460ef9a46e7836e70238b00c8c5618
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Singular/sparsmat.cc
ra36a1a ra5bf88 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: sparsmat.cc,v 1. 8 19990610 09:01:17pohl Exp $ */4 /* $Id: sparsmat.cc,v 1.9 19990622 11:24:02 pohl Exp $ */ 5 5 6 6 /* … … 19 19 #include "ideals.h" 20 20 #include "numbers.h" 21 #include "longrat.h" 21 22 #include "sparsmat.h" 22 23 … … 58 59 static smpoly smElemCopy(smpoly); 59 60 static float smPolyWeight(smpoly); 60 static smpoly smPoly2Smpoly(poly p); 61 static poly smSmpoly2Poly(smpoly a); 61 static smpoly smPoly2Smpoly(poly); 62 static poly smSmpoly2Poly(smpoly); 63 static BOOLEAN smHaveDenom(poly); 64 static number smCleardenom(ideal); 62 65 63 66 /* class for sparse matrix: … … 89 92 int inred; // unreducable part 90 93 int rpiv, cpiv; // position of the pivot 91 unsigned short *perm;// permutation of rows 94 int normalize; // Normalization flag 95 EXPONENT_TYPE *perm; // permutation of rows 92 96 float wpoints; // weight of all points 93 97 float *wrw, *wcl; // weights of rows and columns … … 120 124 void smSign(); 121 125 void smInitPerm(); 126 int smCheckNormalize(); 127 void smNormalize(); 122 128 public: 123 129 sparse_mat(ideal); … … 189 195 return NULL; 190 196 } 197 number diag,h=nInit(1); 191 198 poly res,save; 192 199 ring origR; 193 200 sip_sring tmpR; 201 sparse_mat *det; 194 202 ideal II=smRingCopy(I,&origR,tmpR); 195 sparse_mat *det = new sparse_mat(II); 196 203 204 diag = smCleardenom(II); 205 det = new sparse_mat(II); 197 206 idDelete(&II); 198 207 if (det>smGetAct() == NULL) … … 214 223 smRingClean(origR,tmpR); 215 224 } 225 if (nEqual(diag,h) == FALSE) 226 { 227 pMultN(res,diag); 228 pNormalize(res); 229 } 230 nDelete(&diag); 231 nDelete(&h); 216 232 return res; 217 233 } … … 312 328 tored = nrows; // without border 313 329 i = tored+1; 314 perm = ( unsigned short *)Alloc(sizeof(unsigned short)*(i+1));330 perm = (EXPONENT_TYPE *)Alloc(sizeof(EXPONENT_TYPE)*(i+1)); 315 331 perm[i] = 0; 316 332 m_row = (smpoly *)Alloc0(sizeof(smpoly)*i); … … 349 365 Free((ADDRESS)wrw, sizeof(float)*i); 350 366 Free((ADDRESS)m_row, sizeof(smpoly)*i); 351 Free((ADDRESS)perm, sizeof( unsigned short)*(i+1));367 Free((ADDRESS)perm, sizeof(EXPONENT_TYPE)*(i+1)); 352 368 } 353 369 … … 396 412 return res; 397 413 } 414 normalize = 0; 398 415 this>smInitPerm(); 399 416 this>smPivot(); … … 520 537 return; 521 538 } 539 normalize = this>smCheckNormalize(); 540 if (normalize) this>smNormalize(); 522 541 this>smPivot(); 523 542 this>smSelectPR(); … … 538 557 loop 539 558 { 559 if (normalize) this>smNormalize(); 540 560 this>smNewPivot(); 541 561 this>smSelectPR(); … … 1416 1436 if (f) SM_DIV(ha, m_res[f]>m); 1417 1437 a>m = ha; 1438 if (normalize) pNormalize(a>m); 1418 1439 } 1419 1440 a = a>n; … … 1444 1465 a>m = ha; 1445 1466 } 1467 if (normalize) pNormalize(a>m); 1468 a = a>n; 1469 } while (a != NULL); 1470 } 1471 } 1472 1473 /* 1474 * check for denominators 1475 */ 1476 int sparse_mat::smCheckNormalize() 1477 { 1478 int i; 1479 smpoly a; 1480 1481 for (i=act; i; i) 1482 { 1483 a = m_act[i]; 1484 do 1485 { 1486 if(smHaveDenom(a>m)) return 1; 1487 a = a>n; 1488 } while (a != NULL); 1489 } 1490 return 0; 1491 } 1492 1493 /* 1494 * normalize 1495 */ 1496 void sparse_mat::smNormalize() 1497 { 1498 smpoly a; 1499 int i; 1500 int e = crd; 1501 1502 for (i=act; i; i) 1503 { 1504 a = m_act[i]; 1505 do 1506 { 1507 if (e == a>e) pNormalize(a>m); 1446 1508 a = a>n; 1447 1509 } while (a != NULL); … … 1463 1525 if (f) SM_DIV(h, m_res[f]>m); 1464 1526 a>m = h; 1527 if (normalize) pNormalize(a>m); 1465 1528 a>f = smPolyWeight(a); 1466 1529 return r; … … 2137 2200 } 2138 2201 2202 static BOOLEAN smHaveDenom(poly a) 2203 { 2204 BOOLEAN sw; 2205 number x,o=nInit(1); 2206 2207 while (a != NULL) 2208 { 2209 x = nGetDenom(pGetCoeff(a)); 2210 sw = nEqual(x,o); 2211 nDelete(&x); 2212 if (!sw) 2213 { 2214 nDelete(&o); 2215 return TRUE; 2216 } 2217 pIter(a); 2218 } 2219 nDelete(&o); 2220 return FALSE; 2221 } 2222 2223 static number smCleardenom(ideal id) 2224 { 2225 poly a; 2226 number x,y,res=nInit(1); 2227 BOOLEAN sw=FALSE; 2228 2229 for (int i=0; i<IDELEMS(id); i++) 2230 { 2231 a = id>m[i]; 2232 sw = smHaveDenom(a); 2233 if (sw) break; 2234 } 2235 if (!sw) return res; 2236 for (int i=0; i<IDELEMS(id); i++) 2237 { 2238 a = id>m[i]; 2239 x = nCopy(pGetCoeff(a)); 2240 pCleardenom(a); 2241 y = nDiv(x,pGetCoeff(a)); 2242 nDelete(&x); 2243 x = nMult(res,y); 2244 nNormalize(x); 2245 nDelete(&res); 2246 res = x; 2247 } 2248 return res; 2249 } 2250
Note: See TracChangeset
for help on using the changeset viewer.