Changeset a5ceaf in git
- Timestamp:
- Jun 2, 1999, 4:09:36 PM (24 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- c801beb15dbf5f6a7997a33c6be813e2a7b471c1
- Parents:
- 1e7da0633882bafa6663fdd72dc3ddf832a44096
- Location:
- Singular
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/sparsmat.cc
r1e7da06 ra5ceaf 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: sparsmat.cc,v 1. 5 1999-03-15 16:55:42 SingularExp $ */4 /* $Id: sparsmat.cc,v 1.6 1999-06-02 14:09:34 pohl Exp $ */ 5 5 6 6 /* … … 115 115 void smMultCol(); 116 116 poly smMultPoly(smpoly); 117 void smActDel(); 118 void smColDel(); 119 void smPivDel(); 120 void smSign(); 117 121 public: 118 122 sparse_mat(ideal); 119 123 ~sparse_mat(); 124 int smGetSign() { return sign; } 120 125 smpoly * smGetAct() { return m_act; } 121 126 int smGetRed() { return tored; } 122 127 ideal smRes2Mod(); 128 poly smDet(); 123 129 void smBareiss(int, int); 124 130 void smNewBareiss(int, int); … … 126 132 }; 127 133 128 /* ----------------- basics (used from 'C') ------------------ */ 129 130 lists smCallBareiss(ideal I, int x, int y) 131 { 132 lists res=(lists)Alloc(sizeof(slists)); 133 ideal II = idCopy(I); 134 sparse_mat *bareiss = new sparse_mat(II); 135 intvec *v; 136 ideal m; 137 138 idDelete(&II); 139 if (bareiss->smGetAct() == NULL) 140 { 141 Free((ADDRESS)res, sizeof(slists)); 142 return NULL; 143 } 144 bareiss->smBareiss(x, y); 145 m = bareiss->smRes2Mod(); 146 v = new intvec(bareiss->smGetRed()); 147 bareiss->smToIntvec(v); 148 delete bareiss; 149 res->Init(2); 150 res->m[0].rtyp=MODUL_CMD; 151 res->m[0].data=(void *)m; 152 res->m[1].rtyp=INTVEC_CMD; 153 res->m[1].data=(void *)v; 154 return res; 155 } 156 157 lists smCallNewBareiss(ideal I, int x, int y) 158 { 159 lists res=(lists)Alloc(sizeof(slists)); 134 /* ----------------- ops with rings ------------------ */ 135 ideal smRingCopy(ideal I, ring *ri, sip_sring &tmpR) 136 { 160 137 ring origR =NULL; 161 sip_sring tmpR;162 138 ideal II; 163 139 if (currRing->order[0]!=ringorder_c) … … 186 162 II=idCopy(I); 187 163 } 164 *ri = origR; 165 return II; 166 } 167 168 void smRingClean(ring origR, ip_sring &tmpR) 169 { 170 rChangeCurrRing(origR,TRUE); 171 rUnComplete(&tmpR); 172 Free((ADDRESS)tmpR.order,3*sizeof(int)); 173 Free((ADDRESS)tmpR.block0,3*sizeof(int)); 174 Free((ADDRESS)tmpR.block1,3*sizeof(int)); 175 } 176 177 /* ----------------- basics (used from 'C') ------------------ */ 178 /*2 179 *returns the determinant of the module I; 180 *uses Bareiss algorithm 181 */ 182 poly smCallDet(ideal I) 183 { 184 int r=idRankFreeModule(I); 185 if (I->ncols != r) 186 { 187 Werror("det of %d x %d module (matrix)",r,I->ncols); 188 return NULL; 189 } 190 poly res,save; 191 ring origR; 192 sip_sring tmpR; 193 ideal II=smRingCopy(I,&origR,tmpR); 194 sparse_mat *det = new sparse_mat(II); 195 196 idDelete(&II); 197 if (det->smGetAct() == NULL) 198 { 199 delete det; 200 if (origR!=NULL) smRingClean(origR,tmpR); 201 return NULL; 202 } 203 res=det->smDet(); 204 if(det->smGetSign()<0) res=pNeg(res); 205 delete det; 206 if (origR!=NULL) 207 { 208 rChangeCurrRing(origR,TRUE); 209 save = res; 210 res = pFetchCopy(&tmpR, save); 211 rChangeCurrRing(&tmpR,FALSE); 212 pDelete(&save); 213 smRingClean(origR,tmpR); 214 } 215 return res; 216 } 217 218 lists smCallBareiss(ideal I, int x, int y) 219 { 220 lists res=(lists)Alloc(sizeof(slists)); 221 ideal II = idCopy(I); 222 sparse_mat *bareiss = new sparse_mat(II); 223 intvec *v; 224 ideal m; 225 226 idDelete(&II); 227 if (bareiss->smGetAct() == NULL) 228 { 229 Free((ADDRESS)res, sizeof(slists)); 230 return NULL; 231 } 232 bareiss->smBareiss(x, y); 233 m = bareiss->smRes2Mod(); 234 v = new intvec(bareiss->smGetRed()); 235 bareiss->smToIntvec(v); 236 delete bareiss; 237 res->Init(2); 238 res->m[0].rtyp=MODUL_CMD; 239 res->m[0].data=(void *)m; 240 res->m[1].rtyp=INTVEC_CMD; 241 res->m[1].data=(void *)v; 242 return res; 243 } 244 245 lists smCallNewBareiss(ideal I, int x, int y) 246 { 247 ring origR; 248 sip_sring tmpR; 249 lists res=(lists)Alloc(sizeof(slists)); 250 ideal II=smRingCopy(I,&origR,tmpR); 188 251 sparse_mat *bareiss = new sparse_mat(II); 189 252 ideal mm=II; … … 194 257 { 195 258 delete bareiss; 196 if (origR!=NULL) 197 { 198 rChangeCurrRing(origR,TRUE); 199 rUnComplete(&tmpR); 200 Free((ADDRESS)tmpR.order,3*sizeof(int)); 201 Free((ADDRESS)tmpR.block0,3*sizeof(int)); 202 Free((ADDRESS)tmpR.block1,3*sizeof(int)); 203 } 259 if (origR!=NULL) smRingClean(origR,tmpR); 204 260 v=new intvec(1,pVariables); 205 261 } … … 217 273 mm=idInit(IDELEMS(m),m->rank); 218 274 int k; 219 for (k=0;k<IDELEMS(m);k++) mm->m[k] = pFetchCopy( origR, m->m[k]);275 for (k=0;k<IDELEMS(m);k++) mm->m[k] = pFetchCopy(&tmpR, m->m[k]); 220 276 rChangeCurrRing(&tmpR,FALSE); 221 277 idDelete(&m); 222 rChangeCurrRing(origR,TRUE); 223 rUnComplete(&tmpR); 224 Free((ADDRESS)tmpR.order,3*sizeof(int)); 225 Free((ADDRESS)tmpR.block0,3*sizeof(int)); 226 Free((ADDRESS)tmpR.block1,3*sizeof(int)); 278 smRingClean(origR,tmpR); 227 279 } 228 280 else … … 259 311 tored = nrows; // without border 260 312 i = tored+1; 261 perm = (unsigned short *)Alloc(sizeof(unsigned short)*i); 313 perm = (unsigned short *)Alloc(sizeof(unsigned short)*(i+1)); 314 perm[i] = 0; 262 315 m_row = (smpoly *)Alloc0(sizeof(smpoly)*i); 263 316 wrw = (float *)Alloc(sizeof(float)*i); … … 295 348 Free((ADDRESS)wrw, sizeof(float)*i); 296 349 Free((ADDRESS)m_row, sizeof(smpoly)*i); 297 Free((ADDRESS)perm, sizeof(unsigned short)* i);350 Free((ADDRESS)perm, sizeof(unsigned short)*(i+1)); 298 351 } 299 352 … … 322 375 } 323 376 377 /* ---------------- the algorithm's ------------------ */ 378 /* 379 * the determinant (up to sign), uses new Bareiss elimination 380 */ 381 poly sparse_mat::smDet() 382 { 383 int y; 384 poly res = NULL; 385 386 if (sign == 0) 387 { 388 this->smActDel(); 389 return NULL; 390 } 391 if (act < 2) 392 { 393 if (act != 0) res = m_act[1]->m; 394 Free((void *)m_act[1], sizeof(smprec)); 395 return res; 396 } 397 this->smPivot(); 398 this->smSign(); 399 this->smSelectPR(); 400 this->sm1Elim(); 401 crd++; 402 this->smColDel(); 403 act--; 404 this->smZeroElim(); 405 if (sign == 0) 406 { 407 this->smActDel(); 408 return NULL; 409 } 410 if (act < 2) 411 { 412 if (act != 0) res = m_act[1]->m; 413 Free((void *)m_act[1], sizeof(smprec)); 414 return res; 415 } 416 loop 417 { 418 m_res[crd] = piv; 419 this->smNewPivot(); 420 this->smSign(); 421 this->smSelectPR(); 422 this->smMultCol(); 423 this->smHElim(); 424 crd++; 425 this->smColDel(); 426 act--; 427 this->smZeroElim(); 428 if (sign == 0) 429 { 430 this->smPivDel(); 431 this->smActDel(); 432 return NULL; 433 } 434 if (act < 2) 435 { 436 this->smPivDel(); 437 if (act != 0) res = m_act[1]->m; 438 Free((void *)m_act[1], sizeof(smprec)); 439 return res; 440 } 441 } 442 } 443 324 444 /* 325 445 * the Bareiss elimination: … … 339 459 if (act != 0) 340 460 { 341 oldpiv = NULL;342 461 this->smCopToRes(); 343 462 } … … 402 521 if (act != 0) 403 522 { 404 oldpiv = NULL;405 523 this->smCopToRes(); 406 524 } … … 1302 1420 } 1303 1421 1422 /* 1423 * delete the m_act finaly 1424 */ 1425 void sparse_mat::smActDel() 1426 { 1427 smpoly a; 1428 int i; 1429 1430 for (i=act; i; i--) 1431 { 1432 a = m_act[i]; 1433 do 1434 { 1435 smElemDelete(&a); 1436 } while (a != NULL); 1437 } 1438 } 1439 1440 /* 1441 * delete the pivotcol 1442 */ 1443 void sparse_mat::smColDel() 1444 { 1445 smpoly a = m_act[act]; 1446 1447 while (a != NULL) 1448 { 1449 smElemDelete(&a); 1450 } 1451 } 1452 1453 /* 1454 * delete pivot elements 1455 */ 1456 void sparse_mat::smPivDel() 1457 { 1458 int i=crd-1; 1459 1460 while (i != 0) 1461 { 1462 smElemDelete(&m_res[i]); 1463 i--; 1464 } 1465 } 1466 1467 /* 1468 * the sign of the determinant 1469 */ 1470 void sparse_mat::smSign() 1471 { 1472 int j,i=1; 1473 if (cpiv!=act) sign=-sign; 1474 if ((act%2)==0) sign=-sign; 1475 j=perm[1]; 1476 while(j<rpiv) 1477 { 1478 sign=-sign; 1479 i++; 1480 j=perm[i]; 1481 } 1482 while(perm[i]!=0) 1483 { 1484 perm[i]=perm[i+1]; 1485 i++; 1486 } 1487 } 1488 1304 1489 /* ----------------- arithmetic ------------------ */ 1305 1490 … … 1486 1671 } 1487 1672 1488 /* 21673 /*n 1489 1674 * exact division a/b 1490 1675 * a is a result of smMultDiv -
Singular/sparsmat.h
r1e7da06 ra5ceaf 8 8 * 9 9 *******************************************************************/ 10 /* $Id: sparsmat.h,v 1. 1 1999-02-10 16:00:06 SingularExp $ */10 /* $Id: sparsmat.h,v 1.2 1999-06-02 14:09:36 pohl Exp $ */ 11 11 12 12 … … 16 16 void smSpecialPolyDiv(poly, poly); 17 17 18 poly smCallDet(ideal I); 18 19 lists smCallBareiss(ideal smat, int x, int y); 19 20 lists smCallNewBareiss(ideal smat, int x, int y);
Note: See TracChangeset
for help on using the changeset viewer.