Changeset e2afced in git
- Timestamp:
- Oct 8, 2009, 12:11:57 PM (14 years ago)
- Branches:
- (u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
- Children:
- 0a52b49fcfbb9270ac1d60e85d52e30fd24bbd96
- Parents:
- 967a9d48cc1d702f106bf47d327d87adbaf6833c
- Location:
- Singular
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/Cache.h
r967a9d re2afced 90 90 list<ValueClass> _value; 91 91 92 list< long> _weights;92 list<int> _weights; 93 93 94 94 mutable typename list<KeyClass>::const_iterator _itKey; … … 100 100 * i.e., over all cached values. 101 101 */ 102 long_weight;102 int _weight; 103 103 104 104 /** … … 114 114 * see Cache::shrink (const KeyClass&) and Cache::deleteLast (). 115 115 */ 116 long_maxWeight;116 int _maxWeight; 117 117 118 118 /** … … 179 179 * @param maxWeight the (positive) maximal weight of the cache 180 180 */ 181 Cache (const int maxEntries, const longmaxWeight);181 Cache (const int maxEntries, const int maxWeight); 182 182 183 183 /** … … 190 190 * @see MinorValue::getWeight () const 191 191 */ 192 longgetWeight () const;192 int getWeight () const; 193 193 194 194 /** … … 221 221 * @see Cache::Cache (const int, const int) 222 222 */ 223 longgetMaxWeight () const;223 int getMaxWeight () const; 224 224 225 225 /** -
Singular/CacheImplementation.h
r967a9d re2afced 5 5 6 6 template<class KeyClass, class ValueClass> 7 Cache<KeyClass, ValueClass>::Cache (const int maxEntries, const longmaxWeight) {7 Cache<KeyClass, ValueClass>::Cache (const int maxEntries, const int maxWeight) { 8 8 _maxEntries = maxEntries; 9 9 _maxWeight = maxWeight; … … 18 18 19 19 template<class KeyClass, class ValueClass> 20 longCache<KeyClass, ValueClass>::getWeight() const {20 int Cache<KeyClass, ValueClass>::getWeight() const { 21 21 return _weight; 22 22 } … … 91 91 92 92 template<class KeyClass, class ValueClass> 93 longCache<KeyClass, ValueClass>::getMaxWeight() const {93 int Cache<KeyClass, ValueClass>::getMaxWeight() const { 94 94 return _maxWeight; 95 95 } … … 114 114 typename list<KeyClass>::iterator itKey; 115 115 typename list<ValueClass>::iterator itValue = _value.begin(); 116 typename list< long>::iterator itWeights = _weights.begin();116 typename list<int>::iterator itWeights = _weights.begin(); 117 117 for (itKey = _key.begin(); itKey != _key.end(); itKey++) { 118 118 if (k == deleteIndex) { … … 125 125 } 126 126 _key.erase(itKey); 127 longdeleteWeight = *itWeights;127 int deleteWeight = *itWeights; 128 128 _value.erase(itValue); 129 129 _weights.erase(itWeights); … … 151 151 typename list<KeyClass>::iterator itKey; 152 152 typename list<ValueClass>::iterator itOldValue = _value.begin(); // will later only be used in the case keyWasContained == true 153 typename list< long>::iterator itOldWeights = _weights.begin(); // will later only be used in the case keyWasContained == true153 typename list<int>::iterator itOldWeights = _weights.begin(); // will later only be used in the case keyWasContained == true 154 154 for (itKey = _key.begin(); itKey != _key.end(); itKey++) { 155 155 int c = key.compare(*itKey); … … 168 168 } 169 169 int utility = value.getUtility(); 170 longnewWeight = value.getWeight();170 int newWeight = value.getWeight(); 171 171 k = 0; 172 172 typename list<ValueClass>::iterator itValue = _value.begin(); … … 266 266 // let's insert new key and new value at index newIndexInKey: 267 267 itValue = _value.begin(); 268 typename list< long>::iterator itWeights = _weights.begin();268 typename list<int>::iterator itWeights = _weights.begin(); 269 269 k = 0; 270 270 for (itKey = _key.begin(); itKey != _key.end(); itKey++) { … … 299 299 sprintf(h, "%d", getMaxNumberOfEntries()); s += h; 300 300 s += "\n weight: "; 301 sprintf(h, "% ld", getWeight()); s += h;301 sprintf(h, "%d", getWeight()); s += h; 302 302 s += " of at most "; 303 sprintf(h, "% ld", getMaxWeight()); s += h;303 sprintf(h, "%d", getMaxWeight()); s += h; 304 304 if (_key.size() == 0) { 305 305 s += "\n no pairs, i.e. cache is empty"; -
Singular/Minor.cc
r967a9d re2afced 6 6 #include "polys.h" 7 7 #include <Minor.h> 8 #include "febase.h" 8 9 9 10 void MinorKey::reset() { … … 21 22 22 23 // allocate memory for new entries in _rowKey and _columnKey; 23 _rowKey = new unsigned long[_numberOfRowBlocks];24 _columnKey = new unsigned long[_numberOfColumnBlocks];24 _rowKey = new unsigned int[_numberOfRowBlocks]; 25 _columnKey = new unsigned int[_numberOfColumnBlocks]; 25 26 26 27 // copying values from parameter arrays to private arrays … … 43 44 44 45 // allocate memory for new entries in _rowKey and _columnKey; 45 _rowKey = new unsigned long[_numberOfRowBlocks];46 _columnKey = new unsigned long[_numberOfColumnBlocks];46 _rowKey = new unsigned int[_numberOfRowBlocks]; 47 _columnKey = new unsigned int[_numberOfColumnBlocks]; 47 48 48 49 // copying values from parameter arrays to private arrays … … 55 56 } 56 57 57 void MinorKey::set(const int lengthOfRowArray, const unsigned long* rowKey,58 const int lengthOfColumnArray, const unsigned long* columnKey) {58 void MinorKey::set(const int lengthOfRowArray, const unsigned int* rowKey, 59 const int lengthOfColumnArray, const unsigned int* columnKey) { 59 60 // free memory of _rowKey and _columnKey 60 61 if (_numberOfRowBlocks > 0) { delete [] _rowKey; } … … 65 66 66 67 // allocate memory for new entries in _rowKey and _columnKey; 67 _rowKey = new unsigned long[_numberOfRowBlocks];68 _columnKey = new unsigned long[_numberOfColumnBlocks];68 _rowKey = new unsigned int[_numberOfRowBlocks]; 69 _columnKey = new unsigned int[_numberOfColumnBlocks]; 69 70 70 71 // copying values from parameter arrays to private arrays … … 75 76 } 76 77 77 MinorKey::MinorKey(const int lengthOfRowArray, const unsigned long* const rowKey,78 const int lengthOfColumnArray, const unsigned long* const columnKey) {78 MinorKey::MinorKey(const int lengthOfRowArray, const unsigned int* const rowKey, 79 const int lengthOfColumnArray, const unsigned int* const columnKey) { 79 80 _numberOfRowBlocks = lengthOfRowArray; 80 81 _numberOfColumnBlocks = lengthOfColumnArray; 81 82 82 83 // allocate memory for new entries in _rowKey and _columnKey; 83 _rowKey = new unsigned long[_numberOfRowBlocks];84 _columnKey = new unsigned long[_numberOfColumnBlocks];84 _rowKey = new unsigned int[_numberOfRowBlocks]; 85 _columnKey = new unsigned int[_numberOfColumnBlocks]; 85 86 86 87 // copying values from parameter arrays to private arrays … … 109 110 int matchedBits = -1; // counter for matched bits; this needs to reach i, then we're done 110 111 for (int block = 0; block < getNumberOfRowBlocks(); block ++) { // start with lowest bits, i.e. in block No. 0 111 unsigned longblockBits = getRowKey(block); // the bits in this block of 32 bits112 unsigned longshiftedBit = 1;112 unsigned int blockBits = getRowKey(block); // the bits in this block of 32 bits 113 unsigned int shiftedBit = 1; 113 114 int exponent = 0; 114 115 // The invariant "shiftedBit = 2^exponent" will hold throughout the entire while loop. … … 131 132 int matchedBits = -1; // counter for matched bits; this needs to reach i, then we're done 132 133 for (int block = 0; block < getNumberOfColumnBlocks(); block ++) { // start with lowest bits, i.e. in block No. 0 133 unsigned longblockBits = getColumnKey(block); // the bits in this block of 32 bits134 unsigned longshiftedBit = 1;134 unsigned int blockBits = getColumnKey(block); // the bits in this block of 32 bits 135 unsigned int shiftedBit = 1; 135 136 int exponent = 0; 136 137 // The invariant "shiftedBit = 2^exponent" will hold throughout the entire while loop. … … 149 150 int i = 0; // index for filling the target array 150 151 for (int block = 0; block < getNumberOfRowBlocks(); block ++) { // start with lowest bits, i.e. in block No. 0 151 unsigned longblockBits = getRowKey(block); // the bits in this block of 32 bits152 unsigned longshiftedBit = 1;152 unsigned int blockBits = getRowKey(block); // the bits in this block of 32 bits 153 unsigned int shiftedBit = 1; 153 154 int exponent = 0; 154 155 // The invariant "shiftedBit = 2^exponent" will hold throughout the entire while loop. … … 165 166 int i = 0; // index for filling the target array 166 167 for (int block = 0; block < getNumberOfColumnBlocks(); block ++) { // start with lowest bits, i.e. in block No. 0 167 unsigned longblockBits = getColumnKey(block); // the bits in this block of 32 bits168 unsigned longshiftedBit = 1;168 unsigned int blockBits = getColumnKey(block); // the bits in this block of 32 bits 169 unsigned int shiftedBit = 1; 169 170 int exponent = 0; 170 171 // The invariant "shiftedBit = 2^exponent" will hold throughout the entire while loop. … … 186 187 int matchedBits = -1; // counter for matched bits; this is going to contain our return value 187 188 for (int block = 0; block < getNumberOfRowBlocks(); block ++) { // start with lowest bits, i.e. in block No. 0 188 unsigned longblockBits = getRowKey(block); // the bits in this block of 32 bits189 unsigned longshiftedBit = 1;189 unsigned int blockBits = getRowKey(block); // the bits in this block of 32 bits 190 unsigned int shiftedBit = 1; 190 191 int exponent = 0; 191 192 // The invariant "shiftedBit = 2^exponent" will hold throughout the entire while loop. … … 209 210 int matchedBits = -1; // counter for matched bits; this is going to contain our return value 210 211 for (int block = 0; block < getNumberOfColumnBlocks(); block ++) { // start with lowest bits, i.e. in block No. 0 211 unsigned longblockBits = getColumnKey(block); // the bits in this block of 32 bits212 unsigned longshiftedBit = 1;212 unsigned int blockBits = getColumnKey(block); // the bits in this block of 32 bits 213 unsigned int shiftedBit = 1; 213 214 int exponent = 0; 214 215 // The invariant "shiftedBit = 2^exponent" will hold throughout the entire while loop. … … 224 225 } 225 226 226 unsigned longMinorKey::getRowKey(const int blockIndex) const {227 unsigned int MinorKey::getRowKey(const int blockIndex) const { 227 228 return _rowKey[blockIndex]; 228 229 } 229 230 230 unsigned longMinorKey::getColumnKey(const int blockIndex) const {231 unsigned int MinorKey::getColumnKey(const int blockIndex) const { 231 232 return _columnKey[blockIndex]; 232 233 } … … 244 245 if (a == 1) { // rows 245 246 for (int i = 0; i < _numberOfRowBlocks; i++) { 246 unsigned longm = _rowKey[i];247 unsigned longk = 1;247 unsigned int m = _rowKey[i]; 248 unsigned int k = 1; 248 249 for (int j = 0; j < 32; j++) { 249 250 // k = 2^j … … 255 256 else { // columns 256 257 for (int i = 0; i < _numberOfColumnBlocks; i++) { 257 unsigned longm = _columnKey[i];258 unsigned longk = 1;258 unsigned int m = _columnKey[i]; 259 unsigned int k = 1; 259 260 for (int j = 0; j < 32; j++) { 260 261 // k = 2^j … … 271 272 int rowBlock = absoluteEraseRowIndex / 32; 272 273 int exponent = absoluteEraseRowIndex % 32; 273 unsigned longnewRowBits = getRowKey(rowBlock) - (1 << exponent);274 unsigned int newRowBits = getRowKey(rowBlock) - (1 << exponent); 274 275 int highestRowBlock = getNumberOfRowBlocks() - 1; 275 276 // highestRowBlock will finally contain the highest block index with non-zero bit pattern … … 285 286 int columnBlock = absoluteEraseColumnIndex / 32; 286 287 exponent = absoluteEraseColumnIndex % 32; 287 unsigned longnewColumnBits = getColumnKey(columnBlock) - (1 << exponent);288 unsigned int newColumnBits = getColumnKey(columnBlock) - (1 << exponent); 288 289 int highestColumnBlock = getNumberOfColumnBlocks() - 1; 289 290 // highestColumnBlock will finally contain the highest block index with non-zero bit pattern … … 318 319 } 319 320 320 void MinorKey::setRowKey (const int blockIndex, const unsigned longrowKey) {321 void MinorKey::setRowKey (const int blockIndex, const unsigned int rowKey) { 321 322 _rowKey[blockIndex] = rowKey; 322 323 } 323 324 324 void MinorKey::setColumnKey (const int blockIndex, const unsigned longcolumnKey) {325 void MinorKey::setColumnKey (const int blockIndex, const unsigned int columnKey) { 325 326 _columnKey[blockIndex] = columnKey; 326 327 } … … 369 370 int hitBits = 0; // the number of bits we have hit; in the end, this has to be equal to k, 370 371 // the dimension of the minor 371 int blockIndex = -1; // the index of the current longin mk372 unsigned long highestLong= 0; // the new highest block of this MinorKey373 // We determine which longs of mk we can copy. Their indices will be 0, 1, ..., blockIndex - 1.374 // And highest Long is going to capture the highest long(which may be only a portion of375 // the corresponding longin mk. We loop until hitBits = k:372 int blockIndex = -1; // the index of the current int in mk 373 unsigned int highestInt = 0; // the new highest block of this MinorKey 374 // We determine which ints of mk we can copy. Their indices will be 0, 1, ..., blockIndex - 1. 375 // And highestInt is going to capture the highest int (which may be only a portion of 376 // the corresponding int in mk. We loop until hitBits = k: 376 377 while (hitBits < k) { 377 378 blockIndex++; 378 highest Long= 0;379 unsigned long currentLong= mk.getRowKey(blockIndex);380 unsigned longshiftedBit = 1;379 highestInt = 0; 380 unsigned int currentInt = mk.getRowKey(blockIndex); 381 unsigned int shiftedBit = 1; 381 382 int exponent = 0; 382 383 // invariant in the loop: shiftedBit = 2^exponent 383 384 while (exponent < 32 && hitBits < k) { 384 if (shiftedBit & current Long) {385 highest Long+= shiftedBit;385 if (shiftedBit & currentInt) { 386 highestInt += shiftedBit; 386 387 hitBits++; 387 388 } … … 394 395 _numberOfRowBlocks = blockIndex + 1; 395 396 // allocate memory for new entries in _rowKey; 396 _rowKey = new unsigned long[_numberOfRowBlocks];397 _rowKey = new unsigned int[_numberOfRowBlocks]; 397 398 // copying values from mk to this MinorKey 398 399 for (int r = 0; r < blockIndex; r++) 399 400 _rowKey[r] = mk.getRowKey(r); 400 _rowKey[blockIndex] = highest Long;401 _rowKey[blockIndex] = highestInt; 401 402 } 402 403 … … 404 405 int hitBits = 0; // the number of bits we have hit; in the end, this has to be equal to k, 405 406 // the dimension of the minor 406 int blockIndex = -1; // the index of the current longin mk407 unsigned long highestLong= 0; // the new highest block of this MinorKey408 // We determine which longs of mk we can copy. Their indices will be 0, 1, ..., blockIndex - 1.409 // And highest Long is going to capture the highest long(which may be only a portion of410 // the corresponding longin mk. We loop until hitBits = k:407 int blockIndex = -1; // the index of the current int in mk 408 unsigned int highestInt = 0; // the new highest block of this MinorKey 409 // We determine which ints of mk we can copy. Their indices will be 0, 1, ..., blockIndex - 1. 410 // And highestInt is going to capture the highest int (which may be only a portion of 411 // the corresponding int in mk. We loop until hitBits = k: 411 412 while (hitBits < k) { 412 413 blockIndex++; 413 highest Long= 0;414 unsigned long currentLong= mk.getColumnKey(blockIndex);415 unsigned longshiftedBit = 1;414 highestInt = 0; 415 unsigned int currentInt = mk.getColumnKey(blockIndex); 416 unsigned int shiftedBit = 1; 416 417 int exponent = 0; 417 418 // invariant in the loop: shiftedBit = 2^exponent 418 419 while (exponent < 32 && hitBits < k) { 419 if (shiftedBit & current Long) {420 highest Long+= shiftedBit;420 if (shiftedBit & currentInt) { 421 highestInt += shiftedBit; 421 422 hitBits++; 422 423 } … … 429 430 _numberOfColumnBlocks = blockIndex + 1; 430 431 // allocate memory for new entries in _columnKey; 431 _columnKey = new unsigned long[_numberOfColumnBlocks];432 _columnKey = new unsigned int[_numberOfColumnBlocks]; 432 433 // copying values from mk to this MinorKey 433 434 for (int c = 0; c < blockIndex; c++) 434 435 _columnKey[c] = mk.getColumnKey(c); 435 _columnKey[blockIndex] = highest Long;436 _columnKey[blockIndex] = highestInt; 436 437 } 437 438 … … 453 454 // In this case, the method will return false; otherwise always true. 454 455 int newBitBlockIndex = 0; // the block index of the bit 455 unsigned longnewBitToBeSet = 0; // the bit as 2^e, where 0 <= e <= 31456 457 int blockCount = this->getNumberOfRowBlocks(); // number of longs (representing rows) in this MinorKey456 unsigned int newBitToBeSet = 0; // the bit as 2^e, where 0 <= e <= 31 457 458 int blockCount = this->getNumberOfRowBlocks(); // number of ints (representing rows) in this MinorKey 458 459 int mkBlockIndex = mk.getNumberOfRowBlocks(); // for iterating along the blocks of mk 459 460 … … 463 464 while (hitBits < k) { 464 465 mkBlockIndex--; 465 unsigned long currentLong= mk.getRowKey(mkBlockIndex);466 unsigned longshiftedBit = 1 << 31; // initially, this equals 2^31, i.e. the highest bit466 unsigned int currentInt = mk.getRowKey(mkBlockIndex); 467 unsigned int shiftedBit = 1 << 31; // initially, this equals 2^31, i.e. the highest bit 467 468 while (hitBits < k && shiftedBit > 0) { 468 if ( blockCount - 1 >= mkBlockIndex&&469 shiftedBit & this->getRowKey(mkBlockIndex)) hitBits++;470 else if (shiftedBit & current Long) {469 if ((blockCount - 1 >= mkBlockIndex) && 470 (shiftedBit & this->getRowKey(mkBlockIndex))) hitBits++; 471 else if (shiftedBit & currentInt) { 471 472 newBitToBeSet = shiftedBit; 472 473 newBitBlockIndex = mkBlockIndex; … … 496 497 _numberOfRowBlocks = newBitBlockIndex + 1; 497 498 // allocate memory for new entries in _rowKey; 498 _rowKey = new unsigned long[_numberOfRowBlocks];499 _rowKey = new unsigned int[_numberOfRowBlocks]; 499 500 } 500 501 else { 501 502 // We need to delete all bits in _rowKey[newBitBlockIndex] that are below newBitToBeSet: 502 unsigned long aLong= this->getRowKey(newBitBlockIndex);503 unsigned longdeleteBit = newBitToBeSet >> 1; // in example: = 2^5503 unsigned int anInt = this->getRowKey(newBitBlockIndex); 504 unsigned int deleteBit = newBitToBeSet >> 1; // in example: = 2^5 504 505 while (deleteBit > 0) { 505 if (a Long & deleteBit) aLong-= deleteBit;506 if (anInt & deleteBit) anInt -= deleteBit; 506 507 deleteBit = deleteBit >> 1; 507 508 }; 508 _rowKey[newBitBlockIndex] = a Long;509 _rowKey[newBitBlockIndex] = anInt; 509 510 // ...and we delete all entries in _rowKey[i] for 0 <= i < newBitBlockIndex 510 511 for (int i = 0; i < newBitBlockIndex; i++) … … 525 526 while (bitCounter < k) { 526 527 mkBlockIndex++; 527 unsigned long currentLong= mk.getRowKey(mkBlockIndex);528 unsigned longshiftedBit = 1;528 unsigned int currentInt = mk.getRowKey(mkBlockIndex); 529 unsigned int shiftedBit = 1; 529 530 int exponent = 0; 530 531 // invariant: shiftedBit = 2^exponent 531 532 while (bitCounter < k && exponent < 32) { 532 if (shiftedBit & current Long) {533 if (shiftedBit & currentInt) { 533 534 _rowKey[mkBlockIndex] += shiftedBit; 534 535 bitCounter++; … … 561 562 // In this case, the method will return false; otherwise always true. 562 563 int newBitBlockIndex = 0; // the block index of the bit 563 unsigned longnewBitToBeSet = 0; // the bit as 2^e, where 0 <= e <= 31564 565 int blockCount = this->getNumberOfColumnBlocks(); // number of longs (representing columns) in this MinorKey564 unsigned int newBitToBeSet = 0; // the bit as 2^e, where 0 <= e <= 31 565 566 int blockCount = this->getNumberOfColumnBlocks(); // number of ints (representing columns) in this MinorKey 566 567 int mkBlockIndex = mk.getNumberOfColumnBlocks(); // for iterating along the blocks of mk 567 568 … … 571 572 while (hitBits < k) { 572 573 mkBlockIndex--; 573 unsigned long currentLong= mk.getColumnKey(mkBlockIndex);574 unsigned longshiftedBit = 1 << 31; // initially, this equals 2^31, i.e. the highest bit574 unsigned int currentInt = mk.getColumnKey(mkBlockIndex); 575 unsigned int shiftedBit = 1 << 31; // initially, this equals 2^31, i.e. the highest bit 575 576 while (hitBits < k && shiftedBit > 0) { 576 if ( blockCount - 1 >= mkBlockIndex&&577 shiftedBit & this->getColumnKey(mkBlockIndex)) hitBits++;578 else if (shiftedBit & current Long) {577 if ((blockCount - 1 >= mkBlockIndex) && 578 (shiftedBit & this->getColumnKey(mkBlockIndex))) hitBits++; 579 else if (shiftedBit & currentInt) { 579 580 newBitToBeSet = shiftedBit; 580 581 newBitBlockIndex = mkBlockIndex; … … 583 584 } 584 585 shiftedBit = shiftedBit >> 1; 585 } 586 } 586 587 } 587 588 … … 604 605 _numberOfColumnBlocks = newBitBlockIndex + 1; 605 606 // allocate memory for new entries in _columnKey; 606 _columnKey = new unsigned long[_numberOfColumnBlocks];607 _columnKey = new unsigned int[_numberOfColumnBlocks]; 607 608 } 608 609 else { 609 610 // We need to delete all bits in _columnKey[newBitBlockIndex] that are below newBitToBeSet: 610 unsigned long aLong= this->getColumnKey(newBitBlockIndex);611 unsigned longdeleteBit = newBitToBeSet >> 1; // in example: = 2^5611 unsigned int anInt = this->getColumnKey(newBitBlockIndex); 612 unsigned int deleteBit = newBitToBeSet >> 1; // in example: = 2^5 612 613 while (deleteBit > 0) { 613 if (a Long & deleteBit) aLong-= deleteBit;614 if (anInt & deleteBit) anInt -= deleteBit; 614 615 deleteBit = deleteBit >> 1; 615 616 }; 616 _columnKey[newBitBlockIndex] = a Long;617 _columnKey[newBitBlockIndex] = anInt; 617 618 // ...and we delete all entries in _columnKey[i] for 0 <= i < newBitBlockIndex 618 619 for (int i = 0; i < newBitBlockIndex; i++) … … 633 634 while (bitCounter < k) { 634 635 mkBlockIndex++; 635 unsigned long currentLong= mk.getColumnKey(mkBlockIndex);636 unsigned longshiftedBit = 1;636 unsigned int currentInt = mk.getColumnKey(mkBlockIndex); 637 unsigned int shiftedBit = 1; 637 638 int exponent = 0; 638 639 // invariant: shiftedBit = 2^exponent 639 640 while (bitCounter < k && exponent < 32) { 640 if (shiftedBit & current Long) {641 if (shiftedBit & currentInt) { 641 642 _columnKey[mkBlockIndex] += shiftedBit; 642 643 bitCounter++; … … 657 658 string s = "("; 658 659 for (int r = this->getNumberOfRowBlocks() - 1; r >= 0; r--) { 659 sprintf(h, "% ld", this->getRowKey(r)); t += h;660 sprintf(h, "%du", this->getRowKey(r)); t += h; 660 661 if (r < this->getNumberOfRowBlocks() - 1) 661 662 t = string(32 - t.length(), '0') + t; … … 664 665 s += ", "; 665 666 for (int c = this->getNumberOfColumnBlocks() - 1; c >= 0; c--) { 666 sprintf(h, "% ld", this->getColumnKey(c)); t += h;667 sprintf(h, "%du", this->getColumnKey(c)); t += h; 667 668 if (c < this->getNumberOfColumnBlocks() - 1) 668 669 t = string(32 - t.length(), '0') + t; … … 675 676 int MinorValue::_RankingStrategy = -1; 676 677 677 longMinorValue::getWeight () const678 int MinorValue::getWeight () const 678 679 { 679 680 assert(false); // must be overridden in derived classes … … 701 702 } 702 703 703 longMinorValue::getRetrievals() const {704 int MinorValue::getRetrievals() const { 704 705 return _retrievals; 705 706 } … … 709 710 } 710 711 711 longMinorValue::getPotentialRetrievals() const {712 int MinorValue::getPotentialRetrievals() const { 712 713 return _potentialRetrievals; 713 714 } 714 715 715 longMinorValue::getMultiplications() const {716 int MinorValue::getMultiplications() const { 716 717 return _multiplications; 717 718 } 718 719 719 longMinorValue::getAdditions() const {720 int MinorValue::getAdditions() const { 720 721 return _additions; 721 722 } 722 723 723 longMinorValue::getAccumulatedMultiplications() const {724 int MinorValue::getAccumulatedMultiplications() const { 724 725 return _accumulatedMult; 725 726 } 726 727 727 longMinorValue::getAccumulatedAdditions() const {728 int MinorValue::getAccumulatedAdditions() const { 728 729 return _accumulatedSum; 729 730 } … … 789 790 } 790 791 791 long LongMinorValue::getWeight () const {792 int IntMinorValue::getWeight () const { 792 793 // put measure for size of MinorValue here, i.e. number of monomials in polynomial; 793 794 // so far, we use the accumulated number of multiplications (i.e., including all nested ones) … … 796 797 } 797 798 798 LongMinorValue::LongMinorValue (const longresult, const int multiplications, const int additions,799 IntMinorValue::IntMinorValue (const int result, const int multiplications, const int additions, 799 800 const int accumulatedMultiplications, const int accumulatedAdditions, 800 801 const int retrievals, const int potentialRetrievals) { … … 808 809 } 809 810 810 LongMinorValue::LongMinorValue () {811 IntMinorValue::IntMinorValue () { 811 812 _result = -1; 812 813 _multiplications = -1; … … 818 819 } 819 820 820 LongMinorValue::~LongMinorValue()821 IntMinorValue::~IntMinorValue() 821 822 { 822 823 } 823 824 824 long LongMinorValue::getResult() const {825 int IntMinorValue::getResult() const { 825 826 return _result; 826 827 } 827 828 828 string LongMinorValue::toString () const {829 string IntMinorValue::toString () const { 829 830 char h[10]; 830 831 … … 833 834 if (this->getRetrievals() == -1) cacheHasBeenUsed = false; 834 835 835 sprintf(h, "% ld", this->getResult());836 sprintf(h, "%d", this->getResult()); 836 837 string s = h; 837 838 s += " [retrievals: "; 838 if (cacheHasBeenUsed) { sprintf(h, "% ld", this->getRetrievals()); s += h; }839 if (cacheHasBeenUsed) { sprintf(h, "%d", this->getRetrievals()); s += h; } 839 840 else s += "/"; 840 841 s += " (of "; 841 if (cacheHasBeenUsed) { sprintf(h, "% ld", this->getPotentialRetrievals()); s += h; }842 if (cacheHasBeenUsed) { sprintf(h, "%d", this->getPotentialRetrievals()); s += h; } 842 843 else s += "/"; 843 844 s += "), *: "; 844 sprintf(h, "% ld", this->getMultiplications()); s += h;845 sprintf(h, "%d", this->getMultiplications()); s += h; 845 846 s += " (accumulated: "; 846 sprintf(h, "% ld", this->getAccumulatedMultiplications()); s += h;847 sprintf(h, "%d", this->getAccumulatedMultiplications()); s += h; 847 848 s += "), +: "; 848 sprintf(h, "% ld", this->getAdditions()); s += h;849 sprintf(h, "%d", this->getAdditions()); s += h; 849 850 s += " (accumulated: "; 850 sprintf(h, "% ld", this->getAccumulatedAdditions()); s += h;851 sprintf(h, "%d", this->getAccumulatedAdditions()); s += h; 851 852 s += "), rank: "; 852 853 if (cacheHasBeenUsed) { sprintf(h, "%d", this->getUtility()); s += h; } … … 856 857 } 857 858 858 LongMinorValue::LongMinorValue (const LongMinorValue& mv) {859 IntMinorValue::IntMinorValue (const IntMinorValue& mv) { 859 860 _result = mv.getResult(); 860 861 _retrievals = mv.getRetrievals(); … … 899 900 } 900 901 901 longPolyMinorValue::getWeight () const {902 int PolyMinorValue::getWeight () const { 902 903 // put measure for size of PolyMinorValue here, e.g. the number of monomials 903 904 // the cached polynomial … … 914 915 string s = pString(_result); 915 916 s += " [retrievals: "; 916 if (cacheHasBeenUsed) { sprintf(h, "% ld", this->getRetrievals()); s += h; }917 if (cacheHasBeenUsed) { sprintf(h, "%d", this->getRetrievals()); s += h; } 917 918 else s += "/"; 918 919 s += " (of "; 919 if (cacheHasBeenUsed) { sprintf(h, "% ld", this->getPotentialRetrievals()); s += h; }920 if (cacheHasBeenUsed) { sprintf(h, "%d", this->getPotentialRetrievals()); s += h; } 920 921 else s += "/"; 921 922 s += "), *: "; 922 sprintf(h, "% ld", this->getMultiplications()); s += h;923 sprintf(h, "%d", this->getMultiplications()); s += h; 923 924 s += " (accumulated: "; 924 sprintf(h, "% ld", this->getAccumulatedMultiplications()); s += h;925 sprintf(h, "%d", this->getAccumulatedMultiplications()); s += h; 925 926 s += "), +: "; 926 sprintf(h, "% ld", this->getAdditions()); s += h;927 sprintf(h, "%d", this->getAdditions()); s += h; 927 928 s += " (accumulated: "; 928 sprintf(h, "% ld", this->getAccumulatedAdditions()); s += h;929 sprintf(h, "%d", this->getAccumulatedAdditions()); s += h; 929 930 s += "), rank: "; 930 931 if (cacheHasBeenUsed) { sprintf(h, "%d", this->getUtility()); s += h; } -
Singular/Minor.h
r967a9d re2afced 19 19 <c>bool MinorKey::operator< (const MinorKey& key),</c><br> 20 20 <c>bool MinorKey::operator== (const MinorKey& key),</c><br> 21 MinorKey uses two private arrays of unsigned longs \c _rowKey and \c _columnKey to encode rows and21 MinorKey uses two private arrays of ints \c _rowKey and \c _columnKey to encode rows and 22 22 columns of a pre-defined matrix. Semantically, the row indices and column indices form the key 23 23 for caching the value of the corresponding minor.<br> 24 24 More concretely, let us assume that the pre-defined matrix has <em>32*R+r, r<32,</em> rows and 25 <em>32*C+c, c<32,</em> columns. All row indices can then be captured using R+1 unsigned longs, since26 a long is a 32-bit-number. The analog holds for the columns. Consequently, each instance of MinorKey25 <em>32*C+c, c<32,</em> columns. All row indices can then be captured using R+1 ints, since 26 an int is a 32-bit-number (regardless of the platform). The analog holds for the columns. Consequently, each instance of MinorKey 27 27 encodes the sets of rows and columns which shall belong to the minor of interest (and which shall not).<br> 28 28 Example: The \c _rowKey with \c _rowKey[1] = 0...011 and \c _rowKey[0] = 0...01101 encodes the rows with … … 33 33 private: 34 34 /** 35 * a pointer to an array[0..k-1] of longs, capturing k*32 bits for determining which35 * a pointer to an array[0..k-1] of ints, capturing k*32 bits for determining which 36 36 * rows of a pre-defined matrix shall belong to the minor of interest; 37 37 * for i < j, _rowKey[i] holds lower bits than _rowKey[j] 38 38 */ 39 unsigned long* _rowKey;40 41 /** 42 * a pointer to an array[0..k-1] of longs, capturing k*32 bits for determining which39 unsigned int* _rowKey; 40 41 /** 42 * a pointer to an array[0..k-1] of ints, capturing k*32 bits for determining which 43 43 * columns of a pre-defined matrix shall belong to the minor of interest; 44 44 * for i < j, _columnKey[i] holds lower bits than _columnKey[j] 45 45 */ 46 unsigned long* _columnKey;47 48 /** 49 * the number of unsigned longs (i.e. 32-bit-numbers) we need to encode the set of rows;46 unsigned int* _columnKey; 47 48 /** 49 * the number of ints (i.e. 32-bit-numbers) we need to encode the set of rows; 50 50 * If the higest row index is 70, we need 3 blocks of 32 bits to also encode the 70th bit. 51 51 */ … … 53 53 54 54 /** 55 * the number of unsigned longs (i.e. 32-bit-numbers) we need to encode the set of columns;55 * the number of ints (i.e. 32-bit-numbers) we need to encode the set of columns; 56 56 * If the higest column index is 70, we need 3 blocks of 32 bits to also encode the 70th bit. 57 57 */ … … 60 60 /** 61 61 * Inlined accessor of blockIndex-th element of _rowKey. 62 * @param blockIndex the index of the longto be retrieved62 * @param blockIndex the index of the int to be retrieved 63 63 * @return an entry of _rowKey 64 64 */ 65 unsigned longgetRowKey (const int blockIndex) const;65 unsigned int getRowKey (const int blockIndex) const; 66 66 67 67 /** 68 68 * Inlined accessor of blockIndex-th element of _columnKey. 69 * @param blockIndex the index of the longto be retrieved69 * @param blockIndex the index of the int to be retrieved 70 70 * @return an entry of _columnKey 71 71 */ 72 unsigned longgetColumnKey (const int blockIndex) const;73 74 void setRowKey (const int blockIndex, const unsigned longrowKey);75 76 void setColumnKey (const int blockIndex, const unsigned longcolumnKey);72 unsigned int getColumnKey (const int blockIndex) const; 73 74 void setRowKey (const int blockIndex, const unsigned int rowKey); 75 76 void setColumnKey (const int blockIndex, const unsigned int columnKey); 77 77 78 78 /** … … 97 97 /** 98 98 * A constructor for class MinorKey. 99 * The longs given in the array rowKey encode all rows which shall belong to the minor.99 * The ints given in the array rowKey encode all rows which shall belong to the minor. 100 100 * Each array entry encodes 32 rows, e.g. the i-th array entry 0...01101 encodes the rows with 101 101 * absolute matrix row indices 3+i*32, 2+i*32, and 0+i*32. Analog for columns. 102 102 * @param lengthOfRowArray the length of the array rowKey 103 * @param rowKey a pointer to an array of longs encoding the set of rows of the minor103 * @param rowKey a pointer to an array of ints encoding the set of rows of the minor 104 104 * @param lengthOfColumnArray the length of the array columnKey 105 * @param columnKey a pointer to an array of longs encoding the set of columns of the minor106 */ 107 MinorKey (const int lengthOfRowArray = 0, const unsigned long* const rowKey = 0,108 const int lengthOfColumnArray = 0, const unsigned long* const columnKey = 0);105 * @param columnKey a pointer to an array of ints encoding the set of columns of the minor 106 */ 107 MinorKey (const int lengthOfRowArray = 0, const unsigned int* const rowKey = 0, 108 const int lengthOfColumnArray = 0, const unsigned int* const columnKey = 0); 109 109 110 110 /** … … 114 114 * instance of MinorKey. 115 115 * @param lengthOfRowArray the length of the array rowKey 116 * @param rowKey a pointer to an array of longs encoding the set of rows of the minor116 * @param rowKey a pointer to an array of ints encoding the set of rows of the minor 117 117 * @param lengthOfColumnArray the length of the array columnKey 118 * @param columnKey a pointer to an array of longs encoding the set of columns of the minor119 * @see MinorKey::MinorKey (const int lengthOfRowArray, const unsigned long* rowKey, const int lengthOfColumnArray, const unsigned long* columnKey)120 */ 121 void set(const int lengthOfRowArray, const unsigned long* rowKey,122 const int lengthOfColumnArray, const unsigned long* columnKey);118 * @param columnKey a pointer to an array of ints encoding the set of columns of the minor 119 * @see MinorKey::MinorKey (const int lengthOfRowArray, const int* rowKey, const int lengthOfColumnArray, const int* columnKey) 120 */ 121 void set(const int lengthOfRowArray, const unsigned int* rowKey, 122 const int lengthOfColumnArray, const unsigned int* columnKey); 123 123 124 124 /** … … 330 330 * -1 iff cache is not used, otherwise the number of retrievals so far of the current minor 331 331 */ 332 long_retrievals;332 int _retrievals; 333 333 334 334 /** … … 336 336 * this minor (e.g. when the minor would be kept in cache forever) 337 337 */ 338 long_potentialRetrievals;338 int _potentialRetrievals; 339 339 340 340 /** 341 341 * a store for the actual number of multiplications to compute the current minor 342 342 */ 343 long_multiplications;343 int _multiplications; 344 344 345 345 /** 346 346 * a store for the actual number of additions to compute the current minor 347 347 */ 348 long_additions;348 int _additions; 349 349 350 350 /** … … 353 353 * from a cache. (Thus, these nested operations do not need to be performed again.) 354 354 */ 355 long_accumulatedMult;355 int _accumulatedMult; 356 356 357 357 /** … … 360 360 * from a cache. (Thus, these nested operations do not need to be performed again.) 361 361 */ 362 long_accumulatedSum;362 int _accumulatedSum; 363 363 364 364 /** … … 459 459 * @see Cache::getWeight () const 460 460 */ 461 virtual longgetWeight () const;461 virtual int getWeight () const; 462 462 463 463 /** … … 468 468 * @see MinorValue::getPotentialRetrievals () const 469 469 */ 470 longgetRetrievals () const;470 int getRetrievals () const; 471 471 472 472 /** … … 478 478 * @see MinorValue::getRetrievals () const 479 479 */ 480 longgetPotentialRetrievals () const;480 int getPotentialRetrievals () const; 481 481 482 482 /** … … 490 490 * @see MinorValue::getAccumulatedMultiplications () const 491 491 */ 492 longgetMultiplications () const;492 int getMultiplications () const; 493 493 494 494 /** … … 501 501 * @see MinorValue::getMultiplications () const 502 502 */ 503 longgetAccumulatedMultiplications () const;503 int getAccumulatedMultiplications () const; 504 504 505 505 /** … … 510 510 * @see MinorValue::getAccumulatedAdditions () const 511 511 */ 512 longgetAdditions () const;512 int getAdditions () const; 513 513 514 514 /** … … 521 521 * @see MinorValue::getAdditions () const 522 522 */ 523 longgetAccumulatedAdditions () const;523 int getAccumulatedAdditions () const; 524 524 525 525 /** … … 572 572 }; 573 573 574 /*! \class LongMinorValue575 \brief Class LongMinorValue can be used for representing values in a cache for574 /*! \class IntMinorValue 575 \brief Class IntMinorValue can be used for representing values in a cache for 576 576 sub-determinantes; see class Cache. 577 577 … … 579 579 the declaration of class Cache. Following the documentation of class Cache, we 580 580 need to implement at least the methods:<br> 581 <c>bool LongMinorValue::operator< (const LongMinorValue& key),</c><br>582 <c>bool LongMinorValue::operator== (const LongMinorValue& key),</c><br>583 <c>int LongMinorValue::getWeight ().</c><br><br>584 The main purpose of LongMinorValue is to represent values of sub-determinantes of a pre-defined581 <c>bool IntMinorValue::operator< (const IntMinorValue& key),</c><br> 582 <c>bool IntMinorValue::operator== (const IntMinorValue& key),</c><br> 583 <c>int IntMinorValue::getWeight ().</c><br><br> 584 The main purpose of IntMinorValue is to represent values of sub-determinantes of a pre-defined 585 585 matrix. Class MinorKey is used to determine which rows and columns of this pre-defined matrix 586 ought to belong to the respective sub-determinante of interest. So far, LongMinorValue is just587 an example implementation which assumes matrices with longentries, such that the result588 of any minor is a long again.<br>589 Besides capturing the actual value of a minor, LongMinorValue also has built-in facilities to586 ought to belong to the respective sub-determinante of interest. So far, IntMinorValue is just 587 an example implementation which assumes matrices with int entries, such that the result 588 of any minor is again an int.<br> 589 Besides capturing the actual value of a minor, IntMinorValue also has built-in facilities to 590 590 count the number of additions and multiplications performed when computing a minor. These two 591 591 counters, especially the latter, are important measures when we want to investigate the complexity … … 596 596 \author Frank Seelisch, http://www.mathematik.uni-kl.de/~seelisch 597 597 */ 598 class LongMinorValue : public MinorValue {598 class IntMinorValue : public MinorValue { 599 599 private: 600 600 /** 601 601 * a store for the actual value of the minor 602 602 */ 603 long_result;603 int _result; 604 604 public: 605 605 /** … … 613 613 * @param potentialRetrievals maximum number of times this minor may be retrieved from cache 614 614 */ 615 LongMinorValue (const longresult, const int multiplications, const int additions,615 IntMinorValue (const int result, const int multiplications, const int additions, 616 616 const int accumulatedMultiplications, const int accumulatedAdditions, 617 617 const int retrievals, const int potentialRetrievals); 618 618 619 LongMinorValue (const LongMinorValue& mv);619 IntMinorValue (const IntMinorValue& mv); 620 620 621 621 // just to make the compiler happy 622 LongMinorValue ();622 IntMinorValue (); 623 623 624 virtual ~ LongMinorValue ();624 virtual ~IntMinorValue (); 625 625 626 longgetResult() const;627 628 longgetWeight () const;626 int getResult() const; 627 628 int getWeight () const; 629 629 630 630 /** … … 665 665 poly getResult() const; 666 666 667 longgetWeight () const;667 int getWeight () const; 668 668 669 669 /** -
Singular/MinorProcessor.cc
r967a9d re2afced 72 72 // The method assumes ascending row and column indices in the two argument arrays. 73 73 // These indices are understood to be zero-based. 74 // The method will set the two arrays of unsigned longs in _container.75 // Example: The indices 0, 2, 3, 7 will be converted to an array with one unsigned long74 // The method will set the two arrays of ints in _container. 75 // Example: The indices 0, 2, 3, 7 will be converted to an array with one int 76 76 // representing the binary number 10001101 (check bits from right to left). 77 77 … … 79 79 int highestRowIndex = rowIndices[numberOfRows - 1]; 80 80 int rowBlockCount = (highestRowIndex / 32) + 1; 81 unsigned longrowBlocks[rowBlockCount];81 unsigned int rowBlocks[rowBlockCount]; 82 82 for (int i = 0; i < rowBlockCount; i++) rowBlocks[i] = 0; 83 83 for (int i = 0; i < numberOfRows; i++) { … … 90 90 int highestColumnIndex = columnIndices[numberOfColumns - 1]; 91 91 int columnBlockCount = (highestColumnIndex / 32) + 1; 92 unsigned longcolumnBlocks[columnBlockCount];92 unsigned int columnBlocks[columnBlockCount]; 93 93 for (int i = 0; i < columnBlockCount; i++) columnBlocks[i] = 0; 94 94 for (int i = 0; i < numberOfColumns; i++) { … … 194 194 } 195 195 196 LongMinorProcessor::LongMinorProcessor () {196 IntMinorProcessor::IntMinorProcessor () { 197 197 _matrix = 0; 198 198 } 199 199 200 string LongMinorProcessor::toString () const {200 string IntMinorProcessor::toString () const { 201 201 char h[32]; 202 202 string t = ""; 203 string s = " LongMinorProcessor:";203 string s = "IntMinorProcessor:"; 204 204 s += "\n matrix: "; 205 205 sprintf(h, "%d", _rows); s += h; … … 236 236 } 237 237 238 bool LongMinorProcessor::isEntryZero (const int absoluteRowIndex, const int absoluteColumnIndex) const238 bool IntMinorProcessor::isEntryZero (const int absoluteRowIndex, const int absoluteColumnIndex) const 239 239 { 240 240 return _matrix[absoluteRowIndex][absoluteColumnIndex] == 0; 241 241 } 242 242 243 LongMinorProcessor::~LongMinorProcessor() {243 IntMinorProcessor::~IntMinorProcessor() { 244 244 // free memory of _matrix 245 245 for (int i = 0; i < _rows; i++) { … … 249 249 } 250 250 251 void LongMinorProcessor::defineMatrix (const int numberOfRows, const int numberOfColumns, const int* matrix) {251 void IntMinorProcessor::defineMatrix (const int numberOfRows, const int numberOfColumns, const int* matrix) { 252 252 // free memory of _matrix 253 253 for (int i = 0; i < _rows; i++) { … … 269 269 } 270 270 271 LongMinorValue LongMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices,272 Cache<MinorKey, LongMinorValue>& c) {271 IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices, 272 Cache<MinorKey, IntMinorValue>& c) { 273 273 defineSubMatrix(dimension, rowIndices, dimension, columnIndices); 274 274 _minorSize = dimension; … … 277 277 } 278 278 279 LongMinorValue LongMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices) {279 IntMinorValue IntMinorProcessor::getMinor(const int dimension, const int* rowIndices, const int* columnIndices) { 280 280 defineSubMatrix(dimension, rowIndices, dimension, columnIndices); 281 281 _minorSize = dimension; … … 284 284 } 285 285 286 LongMinorValue LongMinorProcessor::getNextMinor() {286 IntMinorValue IntMinorProcessor::getNextMinor() { 287 287 // computation without cache 288 288 return getMinorPrivate(_minorSize, _minor); 289 289 } 290 290 291 LongMinorValue LongMinorProcessor::getNextMinor(Cache<MinorKey, LongMinorValue>& c) {291 IntMinorValue IntMinorProcessor::getNextMinor(Cache<MinorKey, IntMinorValue>& c) { 292 292 // computation with cache 293 293 return getMinorPrivate(_minorSize, _minor, true, c); 294 294 } 295 295 296 LongMinorValue LongMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk) {296 IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk) { 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. 299 299 if (k == 1) { 300 return LongMinorValue(_matrix[mk.getAbsoluteRowIndex(0)][mk.getAbsoluteColumnIndex(0)],300 return IntMinorValue(_matrix[mk.getAbsoluteRowIndex(0)][mk.getAbsoluteColumnIndex(0)], 301 301 0, 0, 0, 0, -1, -1); // "-1" is to signal that any statistics about the 302 302 // number of retrievals does not make sense, as we do not use a cache. … … 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 LongMinorValue mv = getMinorPrivate(k - 1, subMk); // recursive call319 IntMinorValue mv = getMinorPrivate(k - 1, subMk); // recursive call 320 320 m += mv.getMultiplications(); 321 321 s += mv.getAdditions(); … … 339 339 MinorKey subMk = mk.getSubMinorKey(absoluteR, b); // This is MinorKey when we omit row absoluteR and column b. 340 340 if (_matrix[absoluteR][b] != 0) { // Only then do we have to consider this sub-determinante. 341 LongMinorValue mv = getMinorPrivate(k - 1, subMk); // recursive call341 IntMinorValue mv = getMinorPrivate(k - 1, subMk); // recursive call 342 342 m += mv.getMultiplications(); 343 343 s += mv.getAdditions(); … … 354 354 if (s < 0) s = 0; // may happen when all subminors are zero and no addition needs to be performed 355 355 if (as < 0) as = 0; // may happen when all subminors are zero and no addition needs to be performed 356 LongMinorValue newMV = LongMinorValue(result, m, s, am, as, -1, -1); // "-1" is to signal that any statistics about the356 IntMinorValue newMV = IntMinorValue(result, m, s, am, as, -1, -1); // "-1" is to signal that any statistics about the 357 357 // number of retrievals does not make sense, as we 358 358 // do not use a cache. … … 361 361 } 362 362 363 LongMinorValue LongMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk,363 IntMinorValue IntMinorProcessor::getMinorPrivate(const int k, const MinorKey& mk, 364 364 const bool multipleMinors, 365 Cache<MinorKey, LongMinorValue>& cch) {365 Cache<MinorKey, IntMinorValue>& cch) { 366 366 assert(k > 0); // k is the minor's dimension; the minor must be at least 1x1 367 367 // The method works by recursion, and using Lapace's Theorem along the row/column with the most zeros. 368 368 if (k == 1) { 369 return LongMinorValue(_matrix[mk.getAbsoluteRowIndex(0)][mk.getAbsoluteColumnIndex(0)],369 return IntMinorValue(_matrix[mk.getAbsoluteRowIndex(0)][mk.getAbsoluteColumnIndex(0)], 370 370 0, 0, 0, 0, -1, -1); // we set "-1" as, for k == 1, we do not have any cache retrievals 371 371 } … … 375 375 int s = 0; int m = 0; int as = 0; int am = 0; // counters for additions and multiplications, 376 376 // ..."a*" for accumulated operation counters 377 LongMinorValue mv = LongMinorValue(0, 0, 0, 0, 0, 0, 0); // for storing all intermediate minors377 IntMinorValue mv = IntMinorValue(0, 0, 0, 0, 0, 0, 0); // for storing all intermediate minors 378 378 if (b >= 0) { 379 379 // This means that the best line is the row with absolute (0-based) index b. … … 446 446 if (s < 0) s = 0; // may happen when all subminors are zero and no addition needs to be performed 447 447 if (as < 0) as = 0; // may happen when all subminors are zero and no addition needs to be performed 448 LongMinorValue newMV = LongMinorValue(result, m, s, am, as, 1, potentialRetrievals);448 IntMinorValue newMV = IntMinorValue(result, m, s, am, as, 1, potentialRetrievals); 449 449 cch.put(mk, newMV); // Here's the actual put inside the cache. 450 450 return newMV; -
Singular/MinorProcessor.h
r967a9d re2afced 217 217 }; 218 218 219 class LongMinorProcessor : public MinorProcessor {219 class IntMinorProcessor : public MinorProcessor { 220 220 private: 221 221 /** … … 236 236 * @see MinorProcessor::getMinorPrivate (const int, const MinorKey&) 237 237 */ 238 LongMinorValue getMinorPrivate (const int k, const MinorKey& mk,238 IntMinorValue getMinorPrivate (const int k, const MinorKey& mk, 239 239 const bool multipleMinors, 240 Cache<MinorKey, LongMinorValue>& c);240 Cache<MinorKey, IntMinorValue>& c); 241 241 242 242 /** … … 250 250 * @see MinorProcessor::getMinorPrivate (const int, const MinorKey&, const bool, Cache<MinorKey, MinorValue>&) 251 251 */ 252 LongMinorValue getMinorPrivate (const int k, const MinorKey& mk);252 IntMinorValue getMinorPrivate (const int k, const MinorKey& mk); 253 253 protected: 254 254 bool isEntryZero (const int absoluteRowIndex, const int absoluteColumnIndex) const; … … 257 257 * A constructor for creating an instance. 258 258 */ 259 LongMinorProcessor ();259 IntMinorProcessor (); 260 260 261 261 /** 262 262 * A destructor for deleting an instance. 263 263 */ 264 ~ LongMinorProcessor ();264 ~IntMinorProcessor (); 265 265 266 266 /** … … 277 277 * The sub-matrix is determined by \c rowIndices and \c columnIndices. Computation works recursively 278 278 * using Laplace's Theorem. We always develop along the row or column with most zeros; see 279 * MinorProcessor::getBestLine (const int, const unsigned long, const unsigned long).279 * MinorProcessor::getBestLine (const int, const int, const int). 280 280 * @param dimension the size of the minor to be computed 281 281 * @param rowIndices 0-based indices of the rows of the minor … … 284 284 * @see MinorProcessor::getMinor (const int, const int*, const int*, Cache<MinorKey, MinorValue>&) 285 285 */ 286 LongMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices);286 IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices); 287 287 288 288 /** … … 290 290 * The sub-matrix is determined by \c rowIndices and \c columnIndices. Computation works recursively 291 291 * using Laplace's Theorem. We always develop along the row or column with most zeros; see 292 * MinorProcessor::getBestLine (const int, const unsigned long, const unsigned long).292 * MinorProcessor::getBestLine (const int, const int, const int). 293 293 * @param dimension the size of the minor to be computed 294 294 * @param rowIndices 0-based indices of the rows of the minor … … 298 298 * @see MinorProcessor::getMinor (const int, const int*, const int*) 299 299 */ 300 LongMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices,301 Cache<MinorKey, LongMinorValue>& c);300 IntMinorValue getMinor (const int dimension, const int* rowIndices, const int* columnIndices, 301 Cache<MinorKey, IntMinorValue>& c); 302 302 303 303 /** … … 311 311 * @see MinorProcessor::hasNextMinor () 312 312 */ 313 LongMinorValue getNextMinor ();313 IntMinorValue getNextMinor (); 314 314 315 315 /** … … 324 324 * @see MinorProcessor::hasNextMinor () 325 325 */ 326 LongMinorValue getNextMinor (Cache<MinorKey, LongMinorValue>& c);326 IntMinorValue getNextMinor (Cache<MinorKey, IntMinorValue>& c); 327 327 328 328 /** … … 393 393 * The sub-matrix is determined by \c rowIndices and \c columnIndices. Computation works recursively 394 394 * using Laplace's Theorem. We always develop along the row or column with most zeros; see 395 * MinorProcessor::getBestLine (const int, const unsigned long, const unsigned long).395 * MinorProcessor::getBestLine (const int, const int, const int). 396 396 * @param dimension the size of the minor to be computed 397 397 * @param rowIndices 0-based indices of the rows of the minor … … 406 406 * The sub-matrix is determined by \c rowIndices and \c columnIndices. Computation works recursively 407 407 * using Laplace's Theorem. We always develop along the row or column with most zeros; see 408 * MinorProcessor::getBestLine (const int, const unsigned long, const unsigned long).408 * MinorProcessor::getBestLine (const int, const int, const int). 409 409 * @param dimension the size of the minor to be computed 410 410 * @param rowIndices 0-based indices of the rows of the minor -
Singular/TestMinors.cc
r967a9d re2afced 23 23 24 24 void testOneMinor(PrettyPrinter& prpr, string testHeader, int rowCount, int columnCount, int entryBound, int zeroPercentage, 25 int minorSize, int randomSeed, int cacheEntries, longcacheWeight);25 int minorSize, int randomSeed, int cacheEntries, int cacheWeight); 26 26 void testAllMinors(PrettyPrinter& prpr, string testHeader, int rowCount, int columnCount, int entryBound, int zeroPercentage, 27 int minorRows, int minorColumns, int minorSize, int randomSeed, int cacheEntries, longcacheWeight);27 int minorRows, int minorColumns, int minorSize, int randomSeed, int cacheEntries, int cacheWeight); 28 28 void testAllMinorsUntil(PrettyPrinter& prpr, string testHeader, int rowCount, int columnCount, int entryBound, int zeroPercentage, 29 int minorSize, int randomSeed, int cacheEntries, longcacheWeight, int targetMinor,29 int minorSize, int randomSeed, int cacheEntries, int cacheWeight, int targetMinor, 30 30 bool checkForEquality, int maxLoops); 31 31 … … 34 34 PrintS("\nType 'system(\"minors\", 0);' to run 5 default tests with a random"); 35 35 PrintS("\ninteger matrix. This test, for which no ring needs to be declared"); 36 PrintS("\nbeforehand, will generate the file 'minor_output_results_ longs.txt'");36 PrintS("\nbeforehand, will generate the file 'minor_output_results_ints.txt'"); 37 37 PrintS("\nincluding all results and runtimes, and a much more detailed file"); 38 PrintS("\n'minor_output_complete_ longs.txt' (both in the folder of the SIN-");38 PrintS("\n'minor_output_complete_ints.txt' (both in the folder of the SIN-"); 39 39 PrintS("\nGULAR executable)."); 40 40 PrintS("\n\nType 'system(\"minors\", m, k, strategies, nCache, wCache,"); … … 107 107 int testIntMinors (const int dummy) { 108 108 // for output of non-zero minors into file 109 PrettyPrinter prpr("minor_output_complete_ longs.txt", "minor_output_results_longs.txt", false, false, -1, " ");109 PrettyPrinter prpr("minor_output_complete_ints.txt", "minor_output_results_int.txt", false, false, -1, " "); 110 110 111 111 // computes just one minor: … … 140 140 } 141 141 142 int testAllPolyMinors(matrix mat, int minorSize, int strategies, int cacheEntries, longcacheWeight,142 int testAllPolyMinors(matrix mat, int minorSize, int strategies, int cacheEntries, int cacheWeight, 143 143 int dumpMinors, int dumpResults, int dumpComplete, int dumpConsole) { 144 144 // for pretty printing and file output of results and runtimes … … 327 327 } 328 328 329 ideal testAllPolyMinorsAsIdeal(matrix mat, int minorSize, int strategy, int cacheEntries, longcacheWeight)329 ideal testAllPolyMinorsAsIdeal(matrix mat, int minorSize, int strategy, int cacheEntries, int cacheWeight) 330 330 { 331 331 // counters + auxiliary stuff 332 longtotalMultiplications = 0;333 longtotalAdditions = 0;334 longtotalMultiplicationsAccumulated = 0;335 longtotalAdditionsAccumulated = 0;332 int totalMultiplications = 0; 333 int totalAdditions = 0; 334 int totalMultiplicationsAccumulated = 0; 335 int totalAdditionsAccumulated = 0; 336 336 char h[30]; 337 337 … … 397 397 PrintLn(); PrintS("numbers of performed operations"); 398 398 PrintLn(); PrintS(" polynomial-to-polynomial multiplications: "); 399 sprintf(h, "% ld", totalMultiplications); PrintS(h);399 sprintf(h, "%d", totalMultiplications); PrintS(h); 400 400 PrintLn(); PrintS(" polynomial-to-polynomial additions: "); 401 sprintf(h, "% ld", totalAdditions); PrintS(h);401 sprintf(h, "%d", totalAdditions); PrintS(h); 402 402 PrintLn(); PrintS(" (polynomial-to-polynomial multiplications without cache would be: "); 403 sprintf(h, "% ld", totalMultiplicationsAccumulated); PrintS(h); PrintS(")");403 sprintf(h, "%d", totalMultiplicationsAccumulated); PrintS(h); PrintS(")"); 404 404 PrintLn(); PrintS(" (polynomial-to-polynomial additions without cache would be: "); 405 sprintf(h, "% ld", totalAdditionsAccumulated); PrintS(h); PrintS(")");405 sprintf(h, "%d", totalAdditionsAccumulated); PrintS(h); PrintS(")"); 406 406 PrintLn(); PrintLn(); 407 407 … … 415 415 */ 416 416 void testOneMinor(PrettyPrinter& prpr, string testHeader, int rowCount, int columnCount, int entryBound, int zeroPercentage, 417 int minorSize, int randomSeed, int cacheEntries, longcacheWeight) {418 longstart, end;417 int minorSize, int randomSeed, int cacheEntries, int cacheWeight) { 418 int start, end; 419 419 420 420 prpr < testHeader; … … 426 426 fillRandomMatrix(rowCount, columnCount, randomSeed, zeroPercentage, entryBound, myMatrix); 427 427 428 LongMinorProcessor mp;428 IntMinorProcessor mp; 429 429 mp.defineMatrix(rowCount, columnCount, myMatrix); 430 430 … … 442 442 prpr << "Results - " << testHeader << " - no cache"; 443 443 start = clock(); 444 LongMinorValue mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices);444 IntMinorValue mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices); 445 445 end = clock(); 446 446 ++prpr << "value of minor = " << mv.toString(); … … 448 448 449 449 // define the cache: 450 Cache<MinorKey, LongMinorValue> cch = Cache<MinorKey, LongMinorValue>(cacheEntries, cacheWeight);450 Cache<MinorKey, IntMinorValue> cch = Cache<MinorKey, IntMinorValue>(cacheEntries, cacheWeight); 451 451 452 452 // compute minor using the cache, for all implemented caching strategies: … … 457 457 458 458 // compute the minor using the cache and current strategy 459 LongMinorValue::SetRankingStrategy(strategy);459 IntMinorValue::SetRankingStrategy(strategy); 460 460 start = clock(); 461 461 mv = mp.getMinor(minorSize, myRowIndices, myColumnIndices, cch); … … 480 480 */ 481 481 void testAllMinors(PrettyPrinter& prpr, string testHeader, int rowCount, int columnCount, int entryBound, int zeroPercentage, 482 int minorRows, int minorColumns, int minorSize, int randomSeed, int cacheEntries, longcacheWeight) {482 int minorRows, int minorColumns, int minorSize, int randomSeed, int cacheEntries, int cacheWeight) { 483 483 long totalTimeStart, totalTime, printTimeStart, printTime; 484 484 … … 491 491 fillRandomMatrix(rowCount, columnCount, randomSeed, zeroPercentage, entryBound, myMatrix); 492 492 493 LongMinorProcessor mp;493 IntMinorProcessor mp; 494 494 mp.defineMatrix(rowCount, columnCount, myMatrix); 495 495 … … 504 504 505 505 // define the cache: 506 Cache<MinorKey, LongMinorValue> cch = Cache<MinorKey, LongMinorValue>(cacheEntries, cacheWeight);506 Cache<MinorKey, IntMinorValue> cch = Cache<MinorKey, IntMinorValue>(cacheEntries, cacheWeight); 507 507 508 508 // container for all upcoming results 509 LongMinorValue theMinor;509 IntMinorValue theMinor; 510 510 511 511 // counters... … … 567 567 mp.defineSubMatrix(minorRows, myRowIndices, minorColumns, myColumnIndices); 568 568 mp.setMinorSize(minorSize); 569 LongMinorValue::SetRankingStrategy(strategy);569 IntMinorValue::SetRankingStrategy(strategy); 570 570 571 571 // counters... … … 578 578 // cleaning up and redefinition of the cache: 579 579 cch.clear(); 580 cch = Cache<MinorKey, LongMinorValue>(cacheEntries, cacheWeight);580 cch = Cache<MinorKey, IntMinorValue>(cacheEntries, cacheWeight); 581 581 582 582 +prpr; +prpr < "Results - " < testHeader < " - using cache - deploying caching strategy #" < strategy; … … 641 641 */ 642 642 void testAllMinorsUntil(PrettyPrinter& prpr, string testHeader, int rowCount, int columnCount, int entryBound, int zeroPercentage, 643 int minorSize, int randomSeed, int cacheEntries, longcacheWeight, int targetMinor,643 int minorSize, int randomSeed, int cacheEntries, int cacheWeight, int targetMinor, 644 644 bool checkForEquality, int maxLoops) { 645 645 long totalTimeStart, totalTime, printTimeStart, printTime; … … 661 661 fillRandomMatrix(rowCount, columnCount, randomSeed, zeroPercentage, entryBound, myMatrix); 662 662 663 LongMinorProcessor mp;663 IntMinorProcessor mp; 664 664 mp.defineMatrix(rowCount, columnCount, myMatrix); 665 665 … … 668 668 669 669 // define the cache: 670 Cache<MinorKey, LongMinorValue> cch = Cache<MinorKey, LongMinorValue>(cacheEntries, cacheWeight);670 Cache<MinorKey, IntMinorValue> cch = Cache<MinorKey, IntMinorValue>(cacheEntries, cacheWeight); 671 671 672 672 // container for all upcoming results 673 LongMinorValue theMinor;673 IntMinorValue theMinor; 674 674 675 675 // counters... … … 724 724 mp.defineSubMatrix(rowCount, myRowIndices, columnCount, myColumnIndices); 725 725 mp.setMinorSize(minorSize); 726 LongMinorValue::SetRankingStrategy(strategy);726 IntMinorValue::SetRankingStrategy(strategy); 727 727 728 728 // counters... … … 735 735 // cleaning up and redefinition of the cache: 736 736 cch.clear(); 737 cch = Cache<MinorKey, LongMinorValue>(cacheEntries, cacheWeight);737 cch = Cache<MinorKey, IntMinorValue>(cacheEntries, cacheWeight); 738 738 739 739 +prpr; +prpr < testHeader < " - using cache - deploying caching strategy #" < strategy; -
Singular/TestMinors.h
r967a9d re2afced 9 9 void minorUsageInfo(); 10 10 int testIntMinors (const int dummy); 11 int testAllPolyMinors(matrix m, int minorSize, int strategies, int cacheEntries, longcacheWeight,11 int testAllPolyMinors(matrix m, int minorSize, int strategies, int cacheEntries, int cacheWeight, 12 12 int dumpMinors, int dumpResults, int dumpComplete, int dumpConsole); 13 ideal testAllPolyMinorsAsIdeal(matrix m, int minorSize, int strategy, int cacheEntries, longcacheWeight);13 ideal testAllPolyMinorsAsIdeal(matrix m, int minorSize, int strategy, int cacheEntries, int cacheWeight); 14 14 void testStuff (const poly p); 15 15 -
Singular/claptmpl.cc
r967a9d re2afced 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 // $Id: claptmpl.cc,v 1.5 1 2009-10-07 09:05:27seelisch Exp $5 // $Id: claptmpl.cc,v 1.52 2009-10-08 10:11:56 seelisch Exp $ 6 6 /* 7 7 * ABSTRACT - instantiation of all templates … … 262 262 #include "Cache.h" 263 263 template class std::list<int>; 264 template class std::list<long>;265 264 template class std::list<MinorKey>; 266 template class std::list< LongMinorValue>;265 template class std::list<IntMinorValue>; 267 266 template class std::list<PolyMinorValue>; 268 template class Cache<MinorKey, LongMinorValue>;267 template class Cache<MinorKey, IntMinorValue>; 269 268 template class Cache<MinorKey, PolyMinorValue>; 270 269 #endif // HAVE_MINOR -
Singular/extra.cc
r967a9d re2afced 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: extra.cc,v 1.32 1 2009-10-06 12:09:00seelisch Exp $ */4 /* $Id: extra.cc,v 1.322 2009-10-08 10:11:57 seelisch Exp $ */ 5 5 /* 6 6 * ABSTRACT: general interface to internals of Singular ("system" command) … … 2143 2143 const int strategy = (const int)(long)h->next->next->Data(); 2144 2144 const int cacheEntries = (const int)(long)h->next->next->next->Data(); 2145 const long cacheWeight = (constlong)h->next->next->next->next->Data();2145 const int cacheWeight = (const int)(long)h->next->next->next->next->Data(); 2146 2146 ideal iii = testAllPolyMinorsAsIdeal(m, k, strategy, cacheEntries, cacheWeight); 2147 2147 // starts the computation of all k x k minors in the … … 2168 2168 const int strategies = (const int)(long)h->next->next->Data(); 2169 2169 const int cacheEntries = (const int)(long)h->next->next->next->Data(); 2170 const long cacheWeight = (constlong)h->next->next->next->next->Data();2170 const int cacheWeight = (const int)(long)h->next->next->next->next->Data(); 2171 2171 const int dumpMinors = (const int)(long)h->next->next->next->next->next->Data(); 2172 2172 const int dumpResults = (const int)(long)h->next->next->next->next->next->next->Data(); … … 2188 2188 testStuff(p); 2189 2189 } 2190 return FALSE; 2191 } 2192 else 2193 if(strcmp(sys_cmd,"changeVars")==0) 2194 { 2195 /* 2196 The following code changes the N variables names in currRing in 2197 the following way: var(i) is replaced by f(i), 1 <= i <= N, 2198 where f(j) is j written to the base of 26 with the digit '0' 2199 written as 'a', '1' as 'b', ..., '25' as 'z'. 2200 E.g. var(1) goes to f(1)='b', ..., var(25) goes to f(25)='z', 2201 var(26) goes to f(26)='ba', etc. 2202 The purpose of this rewriting is to eliminate indexed variables, 2203 as they may cause problems when generating scripts for Magma, 2204 Maple, or Macaulay2. 2205 */ 2206 ring newRing = rCopy0(currRing); 2207 int varN = newRing->N; 2208 char* alphabet = "abcdefghijklmnopqrstuvwxyz"; 2209 char theName[10]; 2210 char tempChars[10]; 2211 int j; int k; int l; 2212 for (int i = 1; i <= varN; i++) 2213 { 2214 k = i; 2215 l = 9; 2216 j = k % 26; 2217 tempChars[l--] = alphabet[j]; 2218 k = (k - j) / 26; 2219 while (k != 0) 2220 { 2221 j = k % 26; 2222 tempChars[l--] = alphabet[j]; 2223 k = (k - j) / 26; 2224 } 2225 l++; 2226 for (j = l; j < 10; j++) theName[j - l] = tempChars[j]; 2227 theName[10 - l] = '\0'; 2228 newRing->names[i - 1] = omStrDup(theName); 2229 } 2230 rComplete(newRing); 2231 currRing = newRing; 2190 2232 return FALSE; 2191 2233 }
Note: See TracChangeset
for help on using the changeset viewer.