Changeset 95a6f3 in git
- Timestamp:
- Oct 9, 2009, 3:46:30 PM (14 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- 60e4be265398f8004f3b093179a74b59f4fdcb74
- Parents:
- 70f63ab39d1a6a435e42e041336a21e13c1269d9
- Location:
- Singular
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/MinorProcessor.cc
r70f63a r95a6f3 270 270 271 271 IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices, 272 Cache<MinorKey, IntMinorValue>& c ) {272 Cache<MinorKey, IntMinorValue>& c, const int characteristic) { 273 273 defineSubMatrix(dimension, rowIndices, dimension, columnIndices); 274 274 _minorSize = dimension; 275 275 // call a helper method which recursively computes the minor using the cache c: 276 return getMinorPrivate(dimension, _container, false, c );277 } 278 279 IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices ) {276 return getMinorPrivate(dimension, _container, false, c, characteristic); 277 } 278 279 IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices, const int characteristic) { 280 280 defineSubMatrix(dimension, rowIndices, dimension, columnIndices); 281 281 _minorSize = dimension; 282 282 // call a helper method which recursively computes the minor (without using a cache): 283 return getMinorPrivate(_minorSize, _container );284 } 285 286 IntMinorValue IntMinorProcessor::getNextMinor( ) {283 return getMinorPrivate(_minorSize, _container, characteristic); 284 } 285 286 IntMinorValue IntMinorProcessor::getNextMinor(const int characteristic) { 287 287 // computation without cache 288 return getMinorPrivate(_minorSize, _minor );289 } 290 291 IntMinorValue IntMinorProcessor::getNextMinor(Cache<MinorKey, IntMinorValue>& c ) {288 return getMinorPrivate(_minorSize, _minor, characteristic); 289 } 290 291 IntMinorValue IntMinorProcessor::getNextMinor(Cache<MinorKey, IntMinorValue>& c, const int characteristic) { 292 292 // computation with cache 293 return getMinorPrivate(_minorSize, _minor, true, c );294 } 295 296 IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk ) {293 return getMinorPrivate(_minorSize, _minor, true, c, characteristic); 294 } 295 296 IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk, const int characteristic) { 297 297 assert(k > 0); // k is the minor's dimension; the minor must be at least 1x1 298 298 // The method works by recursion, and using Lapace's Theorem along the row/column with the most zeros. … … 317 317 MinorKey subMk = mk.getSubMinorKey(b, absoluteC); // This is MinorKey when we omit row b and column absoluteC. 318 318 if (_matrix[b][absoluteC] != 0) { // Only then do we have to consider this sub-determinante. 319 IntMinorValue mv = getMinorPrivate(k - 1, subMk ); // recursive call319 IntMinorValue mv = getMinorPrivate(k - 1, subMk, characteristic); // recursive call 320 320 m += mv.getMultiplications(); 321 321 s += mv.getAdditions(); … … 324 324 result += sign * mv.getResult() * _matrix[b][absoluteC]; // adding sub-determinante times matrix entry 325 325 // times appropriate sign 326 if (characteristic != 0) result = result % characteristic; 326 327 s++; m++; as++, am++; // This is for the addition and multiplication in the previous line of code. 327 328 } … … 339 340 MinorKey subMk = mk.getSubMinorKey(absoluteR, b); // This is MinorKey when we omit row absoluteR and column b. 340 341 if (_matrix[absoluteR][b] != 0) { // Only then do we have to consider this sub-determinante. 341 IntMinorValue mv = getMinorPrivate(k - 1, subMk ); // recursive call342 IntMinorValue mv = getMinorPrivate(k - 1, subMk, characteristic); // recursive call 342 343 m += mv.getMultiplications(); 343 344 s += mv.getAdditions(); … … 346 347 result += sign * mv.getResult() * _matrix[absoluteR][b]; // adding sub-determinante times matrix entry 347 348 // times appropriate sign 349 if (characteristic != 0) result = result % characteristic; 348 350 s++; m++; as++, am++; // This is for the addition and multiplication in the previous line of code. 349 351 } … … 362 364 363 365 IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk, 364 const bool multipleMinors, 365 Cache<MinorKey, IntMinorValue>& cch) { 366 const bool multipleMinors, 367 Cache<MinorKey, IntMinorValue>& cch, 368 const int characteristic) { 366 369 assert(k > 0); // k is the minor's dimension; the minor must be at least 1x1 367 370 // The method works by recursion, and using Lapace's Theorem along the row/column with the most zeros. … … 392 395 } 393 396 else { 394 mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch ); // recursive call397 mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch, characteristic); // recursive call 395 398 // As this minor was not in the cache, we count the additions and 396 399 // multiplications that we needed to do in the recursive call: … … 403 406 result += sign * mv.getResult() * _matrix[b][absoluteC]; // adding sub-determinante times matrix entry 404 407 // times appropriate sign 408 if (characteristic != 0) result = result % characteristic; 405 409 s++; m++; as++; am++; // This is for the addition and multiplication in the previous line of code. 406 410 } … … 425 429 } 426 430 else { 427 mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch ); // recursive call431 mv = getMinorPrivate(k - 1, subMk, multipleMinors, cch, characteristic); // recursive call 428 432 // As this minor was not in the cache, we count the additions and 429 433 // multiplications that we needed to do in the recursive call: … … 436 440 result += sign * mv.getResult() * _matrix[absoluteR][b]; // adding sub-determinante times matrix entry 437 441 // times appropriate sign 442 if (characteristic != 0) result = result % characteristic; 438 443 s++; m++; as++; am++; // This is for the addition and multiplication in the previous line of code. 439 444 } -
Singular/MinorProcessor.h
r70f63a r95a6f3 237 237 */ 238 238 IntMinorValue getMinorPrivate (const int k, const MinorKey& mk, 239 const bool multipleMinors, 240 Cache<MinorKey, IntMinorValue>& c); 239 const bool multipleMinors, 240 Cache<MinorKey, IntMinorValue>& c, 241 int characteristic); 241 242 242 243 /** … … 250 251 * @see MinorProcessor::getMinorPrivate (const int, const MinorKey&, const bool, Cache<MinorKey, MinorValue>&) 251 252 */ 252 IntMinorValue getMinorPrivate (const int k, const MinorKey& mk );253 IntMinorValue getMinorPrivate (const int k, const MinorKey& mk, int characteristic); 253 254 protected: 254 255 bool isEntryZero (const int absoluteRowIndex, const int absoluteColumnIndex) const; … … 284 285 * @see MinorProcessor::getMinor (const int, const int*, const int*, Cache<MinorKey, MinorValue>&) 285 286 */ 286 IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices );287 IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices, const int characteristic); 287 288 288 289 /** … … 299 300 */ 300 301 IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices, 301 Cache<MinorKey, IntMinorValue>& c );302 Cache<MinorKey, IntMinorValue>& c, const int characteristic); 302 303 303 304 /** … … 311 312 * @see MinorProcessor::hasNextMinor () 312 313 */ 313 IntMinorValue getNextMinor ( );314 IntMinorValue getNextMinor (const int characteristic); 314 315 315 316 /** … … 324 325 * @see MinorProcessor::hasNextMinor () 325 326 */ 326 IntMinorValue getNextMinor (Cache<MinorKey, IntMinorValue>& c );327 IntMinorValue getNextMinor (Cache<MinorKey, IntMinorValue>& c, const int characteristic); 327 328 328 329 /** -
Singular/TestMinors.cc
r70f63a r95a6f3 69 69 PrintS("\nweight of the cache equals the total number of monomials counted over"); 70 70 PrintS("\nall cached polynomials.)"); 71 PrintS("\nFor this command, there will be no file or console outputs.\n\n"); 71 PrintS("\nFor this command, there will be no file or console outputs."); 72 PrintS("\n\nType 'ideal i = system(\"minors\", m, k, strategy, nCache, wCache, ch);'"); 73 PrintS("\nto obtain the ideal generated by all k x k non-zero minors of the"); 74 PrintS("\ninteger matrix m modulo ch. (For the remaining parameters, see the"); 75 PrintS("\nprevious call.)\n\n"); 72 76 } 73 77 … … 409 413 } 410 414 415 ideal testAllIntMinorsAsIdeal(matrix mat, int minorSize, int strategy, int cacheEntries, int cacheWeight, int characteristic) 416 { 417 // counters + auxiliary stuff 418 int totalMultiplications = 0; 419 int totalAdditions = 0; 420 int totalMultiplicationsAccumulated = 0; 421 int totalAdditionsAccumulated = 0; 422 char h[30]; 423 424 int rowCount = mat->nrows; 425 int columnCount = mat->ncols; 426 427 int* myPolyMatrix = (int*)(mat->m); 428 IntMinorProcessor mp; 429 mp.defineMatrix(rowCount, columnCount, myPolyMatrix); 430 431 /* The next lines are for defining the sub-matrix of myPolyMatrix 432 from which we want to compute all k x k - minors. 433 In the given setting, we want the entire matrix to form the sub-matrix. */ 434 int minorRows = rowCount; 435 int minorColumns = columnCount; 436 int myRowIndices[minorRows]; for (int i = 0; i < minorRows; i++) myRowIndices[i] = i; 437 int myColumnIndices[minorColumns]; for (int i = 0; i < minorColumns; i++) myColumnIndices[i] = i; 438 439 // setting sub-matrix and size of minors of interest within that sub-matrix: 440 mp.defineSubMatrix(minorRows, myRowIndices, minorColumns, myColumnIndices); 441 mp.setMinorSize(minorSize); 442 443 // containers for all upcoming results 444 IntMinorValue theMinor; 445 int theValue; 446 ideal iii = idInit(1, 0); 447 448 if (strategy == 0) 449 { 450 PrintLn(); PrintS("new code uses no cache"); 451 // iteration over all minors of size "minorSize x minorSize" 452 while (mp.hasNextMinor()) { 453 // retrieving the minor: 454 theMinor = mp.getNextMinor(characteristic); 455 theValue = theMinor.getResult(); 456 totalMultiplicationsAccumulated += theMinor.getAccumulatedMultiplications(); 457 totalMultiplications += theMinor.getMultiplications(); 458 totalAdditionsAccumulated += theMinor.getAccumulatedAdditions(); 459 totalAdditions += theMinor.getAdditions(); 460 idInsertPoly(iii, pISet(theValue)); // will include theValue only if it is not zero 461 } 462 } 463 else 464 { 465 PrintLn(); PrintS("new code uses cache with caching strategy "); 466 sprintf(h, "%d", strategy); PrintS(h); 467 MinorValue::SetRankingStrategy(strategy); 468 Cache<MinorKey, IntMinorValue> cch(cacheEntries, cacheWeight); 469 // iteration over all minors of size "minorSize x minorSize" 470 while (mp.hasNextMinor()) { 471 // retrieving the minor: 472 theMinor = mp.getNextMinor(cch, characteristic); 473 theValue = theMinor.getResult(); 474 totalMultiplicationsAccumulated += theMinor.getAccumulatedMultiplications(); 475 totalMultiplications += theMinor.getMultiplications(); 476 totalAdditionsAccumulated += theMinor.getAccumulatedAdditions(); 477 totalAdditions += theMinor.getAdditions(); 478 idInsertPoly(iii, pISet(theValue)); // will include theValue only if it is not zero 479 } 480 } 481 idSkipZeroes(iii); // remove zero generators (resulting from block-wise allocation of memory) 482 483 PrintLn(); PrintS("numbers of performed operations"); 484 PrintLn(); PrintS(" multiplications: "); 485 sprintf(h, "%d", totalMultiplications); PrintS(h); 486 PrintLn(); PrintS(" additions: "); 487 sprintf(h, "%d", totalAdditions); PrintS(h); 488 PrintLn(); PrintS(" (multiplications without cache would be: "); 489 sprintf(h, "%d", totalMultiplicationsAccumulated); PrintS(h); PrintS(")"); 490 PrintLn(); PrintS(" (additions without cache would be: "); 491 sprintf(h, "%d", totalAdditionsAccumulated); PrintS(h); PrintS(")"); 492 PrintLn(); PrintLn(); 493 494 return iii; 495 } 496 411 497 /** 412 498 * A method for testing the computation of one minor; without and with cache, respectively.<br> … … 442 528 prpr << "Results - " << testHeader << " - no cache"; 443 529 start = clock(); 444 IntMinorValue mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices );530 IntMinorValue mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, 0); 445 531 end = clock(); 446 532 ++prpr << "value of minor = " << mv.toString(); … … 459 545 IntMinorValue::SetRankingStrategy(strategy); 460 546 start = clock(); 461 mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, cch );547 mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, cch, 0); 462 548 end = clock(); 463 549 … … 526 612 while (mp.hasNextMinor()) { 527 613 // retrieving the minor: 528 theMinor = mp.getNextMinor( );614 theMinor = mp.getNextMinor(0); 529 615 printTimeStart = clock(); 530 616 … … 587 673 while (mp.hasNextMinor()) { 588 674 // retrieving the minor: 589 theMinor = mp.getNextMinor(cch );675 theMinor = mp.getNextMinor(cch, 0); 590 676 printTimeStart = clock(); 591 677 … … 697 783 698 784 // retrieving the minor: 699 theMinor = mp.getNextMinor( );785 theMinor = mp.getNextMinor(0); 700 786 printTimeStart = clock(); 701 787 minorFound = (checkForEquality ? (theMinor.getResult() == targetMinor) : (theMinor.getResult() != targetMinor)); … … 748 834 749 835 // retrieving the minor: 750 theMinor = mp.getNextMinor(cch );836 theMinor = mp.getNextMinor(cch, 0); 751 837 printTimeStart = clock(); 752 838 minorFound = (checkForEquality ? (theMinor.getResult() == targetMinor) : (theMinor.getResult() != targetMinor)); -
Singular/TestMinors.h
r70f63a r95a6f3 12 12 int dumpMinors, int dumpResults, int dumpComplete, int dumpConsole); 13 13 ideal testAllPolyMinorsAsIdeal(matrix m, int minorSize, int strategy, int cacheEntries, int cacheWeight); 14 ideal testAllIntMinorsAsIdeal(matrix m, int minorSize, int strategy, int cacheEntries, int cacheWeight, int characteristic); 14 15 void testStuff (const poly p); 15 16 -
Singular/extra.cc
r70f63a r95a6f3 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: extra.cc,v 1.32 4 2009-10-09 09:05:18seelisch Exp $ */4 /* $Id: extra.cc,v 1.325 2009-10-09 13:46:30 seelisch Exp $ */ 5 5 /* 6 6 * ABSTRACT: general interface to internals of Singular ("system" command) … … 2147 2147 // starts the computation of all k x k minors in the 2148 2148 // provided matrix m (which is assumed to have polynomial 2149 // entries) using a cache with 200 entries and a maximum total 2150 // number of 10000 cached monomials; 2149 // entries); 2151 2150 // when calling this method, a ring must be declared before; 2152 // there will be a run without using a cache; afterwards all 5 2153 // caching strategies will be run 2151 // there will be one run using a cache with specified properties 2152 res->rtyp = IDEAL_CMD; 2153 res->data = iii; 2154 } 2155 else if ((h->Typ() == MATRIX_CMD) && 2156 (h->next->Typ() == INT_CMD) && 2157 (h->next->next->Typ() == INT_CMD) && 2158 (h->next->next->next->Typ() == INT_CMD) && 2159 (h->next->next->next->next->Typ() == INT_CMD) && 2160 (h->next->next->next->next->next->Typ() == INT_CMD) && 2161 (h->next->next->next->next->next->next == NULL)) 2162 { 2163 const matrix m = (const matrix)h->Data(); 2164 const int k = (const int)(long)h->next->Data(); 2165 const int strategy = (const int)(long)h->next->next->Data(); 2166 const int cacheEntries = (const int)(long)h->next->next->next->Data(); 2167 const int cacheWeight = (const int)(long)h->next->next->next->next->Data(); 2168 const int characteristic = (const int)(long)h->next->next->next->next->next->Data(); 2169 ideal iii = testAllIntMinorsAsIdeal(m, k, strategy, cacheEntries, cacheWeight, characteristic); 2170 // starts the computation of all k x k minors in the 2171 // provided matrix m (which is assumed to have integer 2172 // entries); 2173 // when calling this method, a ring must be declared before; 2174 // there will be one run using a cache with specified properties; 2175 // the resulting minors will be computed modulo the given characteristic 2154 2176 res->rtyp = IDEAL_CMD; 2155 2177 res->data = iii; … … 2162 2184 (h->next->next->next->next->next->Typ() == INT_CMD) && 2163 2185 (h->next->next->next->next->next->next->Typ() == INT_CMD) && 2164 (h->next->next->next->next->next->next->next->Typ() == INT_CMD)) 2186 (h->next->next->next->next->next->next->next->Typ() == INT_CMD) && 2187 (h->next->next->next->next->next->next->next->next == NULL)) 2165 2188 { 2166 2189 const matrix m = (const matrix)h->Data();
Note: See TracChangeset
for help on using the changeset viewer.