Changeset 5c44339 in git
- Timestamp:
- Mar 30, 2010, 11:45:15 AM (14 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 2e1b74af4c420fc8a67df76abb2cc0c8da9990db
- Parents:
- d0164d9b24d76e7796cf29d9c51710744319272d
- Location:
- Singular
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/MinorInterface.cc
rd0164d9 r5c44339 4 4 #include "ideals.h" 5 5 #include "kstd1.h" 6 #include <MinorInterface.h> 6 7 #include <MinorProcessor.h> 7 #include <MinorInterface.h>8 9 #ifdef COUNT_AND_PRINT_OPERATIONS10 int addsPoly = 0; /* for the number of additions of two polynomials */11 int multsPoly = 0; /* for the number of multiplications of two polynomials */12 int addsMon = 0; /* for the number of additions of two monomials */13 int multsMon = 0; /* for the number of multiplications of two monomials */14 void printCounters ()15 {16 printf("\n");17 printf("\n ~~~> performed %d monomial-monomial-additions,",18 addsMon);19 printf("\n ~~~> performed %d monomial-monomial-multiplications",20 multsMon);21 printf("\n ~~~> performed %d polynomial-polynomial-additions,",22 addsPoly);23 printf("\n ~~~> performed %d polynomial-polynomial-multiplications",24 multsPoly);25 printf("\n");26 }27 #endif28 8 29 9 bool currRingIsOverIntegralDomain () … … 173 153 bool duplicatesOk = (allDifferent ? false : true); 174 154 int kk = ((k < 0) ? -k : k); /* absolute value of k */ 175 155 #ifdef COUNT_AND_PRINT_OPERATIONS 156 printCounters ("starting", true); 157 int qqq = 0; 158 #endif 176 159 /* looping over all minors: */ 177 160 while (mp.hasNextMinor() && ((kk == 0) || (collectedMinors < kk))) … … 179 162 /* retrieving the next minor: */ 180 163 theMinor = mp.getNextMinor(algorithm, i); 164 #if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 1) 165 qqq++; 166 printf("after %d", qqq); 167 printCounters ("-th minor", false); 168 #endif 181 169 f = theMinor.getResult(); 182 170 if (idInsertPolyWithTests(iii, collectedMinors, pCopy(f), … … 184 172 collectedMinors++; 185 173 } 174 #ifdef COUNT_AND_PRINT_OPERATIONS 175 printCounters ("ending", true); 176 #endif 186 177 187 178 /* before we return the result, let's omit zero generators … … 387 378 bool duplicatesOk = (allDifferent ? false : true); 388 379 int kk = ((k < 0) ? -k : k); /* absolute value of k */ 389 380 #ifdef COUNT_AND_PRINT_OPERATIONS 381 printCounters ("starting", true); 382 int qqq = 0; 383 #endif 390 384 /* looping over all minors: */ 391 385 while (mp.hasNextMinor() && ((kk == 0) || (collectedMinors < kk))) … … 393 387 /* retrieving the next minor: */ 394 388 theMinor = mp.getNextMinor(cch, i); 389 #if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 1) 390 qqq++; 391 printf("after %d", qqq); 392 printCounters ("-th minor", false); 393 #endif 395 394 f = theMinor.getResult(); 396 395 if (idInsertPolyWithTests(iii, collectedMinors, pCopy(f), zeroOk, … … 398 397 collectedMinors++; 399 398 } 399 #ifdef COUNT_AND_PRINT_OPERATIONS 400 printCounters ("ending", true); 401 #endif 400 402 401 403 /* before we return the result, let's omit zero generators -
Singular/MinorInterface.h
rd0164d9 r5c44339 1 1 #ifndef MINOR_INTERFACE_H 2 2 #define MINOR_INTERFACE_H 3 4 /* activate the next define if you want all basic operations5 counted and printed when one of the methods documented6 herein will be invoked (not fully implemented yet) */7 /* #define COUNT_AND_PRINT_OPERATIONS 1 */8 3 9 4 /* all computations are module char, if char <> 0; -
Singular/MinorProcessor.cc
rd0164d9 r5c44339 6 6 #include "kstd1.h" 7 7 #include "kbuckets.h" 8 9 #ifdef COUNT_AND_PRINT_OPERATIONS 10 long addsPoly = 0; /* for the number of additions of two polynomials */ 11 long multsPoly = 0; /* for the number of multiplications of two polynomials */ 12 long addsPolyForDiv = 0; /* for the number of additions of two polynomials for 13 polynomial division part */ 14 long multsPolyForDiv = 0; /* for the number of multiplications of two polynomials 15 for polynomial division part */ 16 long multsMon = 0; /* for the number of multiplications of two monomials */ 17 long multsMonForDiv = 0; /* for the number of m-m-multiplications for polynomial 18 division part */ 19 long savedMultsMFD = 0; /* number of m-m-multiplications that could be saved 20 when polynomial division would be optimal 21 (if p / t1 = t2 + ..., then t1 * t2 = LT(p), i.e., 22 this multiplication need not be performed which 23 would save one m-m-multiplication) */ 24 long divsMon = 0; /* for the number of divisions of two monomials; 25 these are all guaranteed to work, i.e., m1/m2 only 26 when exponentVector(m1) >= exponentVector(m2) */ 27 void printCounters (char* prefix, bool resetToZero) 28 { 29 printf("%s [p+p(div) | p*p(div) | m*m(div, -save) | m/m ]", prefix); 30 printf(" = [%ld(%ld) | %ld(%ld) | %ld(%d, -%ld) | %ld]\n", 31 addsPoly, addsPolyForDiv, multsPoly, multsPolyForDiv, 32 multsMon, multsMonForDiv, savedMultsMFD, divsMon); 33 if (resetToZero) 34 { 35 multsMon = 0; addsPoly = 0; multsPoly = 0; divsMon = 0; 36 savedMultsMFD = 0; multsMonForDiv = 0; addsPolyForDiv = 0; 37 multsPolyForDiv = 0; 38 } 39 } 40 #endif 41 /* COUNT_AND_PRINT_OPERATIONS */ 8 42 9 43 void MinorProcessor::print() const … … 430 464 for accumulated operation 431 465 counters */ 466 bool hadNonZeroEntry = false; 432 467 if (b >= 0) 433 468 { … … 443 478 this sub-determinante. */ 444 479 { 480 hadNonZeroEntry = true; 445 481 /* Next MinorKey is mk with row b and column absoluteC omitted: */ 446 482 MinorKey subMk = mk.getSubMinorKey(b, absoluteC); … … 477 513 this sub-determinante. */ 478 514 { 515 hadNonZeroEntry = true; 479 516 /* Next MinorKey is mk with row absoluteR and column b omitted. */ 480 517 MinorKey subMk = mk.getSubMinorKey(absoluteR, b); … … 494 531 } 495 532 } 533 if (hadNonZeroEntry) 534 { 496 535 s--; as--; /* first addition was 0 + ..., so we do not count it */ 497 if (s < 0) s = 0; /* may happen when all subminors are zero and no 536 } 537 if (s < 0) s = 0; /* may happen when all subminors are zero and no 538 addition needs to be performed */ 539 if (as < 0) as = 0; /* may happen when all subminors are zero and no 498 540 addition needs to be performed */ 499 if (as < 0) as = 0; /* may happen when all subminors are zero and no 500 addition needs to be performed */ 501 if (iSB != 0) result = getReduction(result, iSB); 502 IntMinorValue newMV(result, m, s, am, as, -1, -1); 503 /* "-1" is to signal that any statistics about the number of retrievals 504 does not make sense, as we do not use a cache. */ 505 return newMV; 541 if (iSB != 0) result = getReduction(result, iSB); 542 IntMinorValue newMV(result, m, s, am, as, -1, -1); 543 /* "-1" is to signal that any statistics about the number of retrievals 544 does not make sense, as we do not use a cache. */ 545 return newMV; 506 546 } 507 547 } … … 626 666 IntMinorValue mv(0, 0, 0, 0, 0, 0, 0); /* for storing all 627 667 intermediate minors */ 668 bool hadNonZeroEntry = false; 628 669 if (b >= 0) 629 670 { … … 641 682 this sub-determinante. */ 642 683 { 684 hadNonZeroEntry = true; 643 685 /* Next MinorKey is mk with row b and column absoluteC omitted. */ 644 686 MinorKey subMk = mk.getSubMinorKey(b, absoluteC); … … 692 734 this sub-determinante. */ 693 735 { 736 hadNonZeroEntry = true; 694 737 /* Next MinorKey is mk with row absoluteR and column b omitted. */ 695 738 MinorKey subMk = mk.getSubMinorKey(absoluteR, b); … … 731 774 _minorSize, k, 732 775 multipleMinors); 733 s--; as--; /* first addition was 0 + ..., so we do not count it */ 776 if (hadNonZeroEntry) 777 { 778 s--; as--; /* first addition was 0 + ..., so we do not count it */ 779 } 734 780 if (s < 0) s = 0; /* may happen when all subminors are zero and no 735 781 addition needs to be performed */ … … 911 957 ..."a*" for accumulated 912 958 operation counters */ 959 bool hadNonZeroEntry = false; 913 960 if (b >= 0) 914 961 { … … 925 972 this sub-determinante. */ 926 973 { 974 hadNonZeroEntry = true; 927 975 /* Next MinorKey is mk with row b and column absoluteC omitted. */ 928 976 MinorKey subMk = mk.getSubMinorKey(b, absoluteC); … … 939 987 temp = p_Mult_q(signPoly, temp, currRing); 940 988 result = p_Add_q(result, temp, currRing); 989 #ifdef COUNT_AND_PRINT_OPERATIONS 990 multsPoly++; 991 addsPoly++; 992 multsMon += pLength(mv.getResult()) * pLength(getEntry(b, absoluteC)); 993 #endif 941 994 signPoly = NULL; 942 995 s++; m++; as++, am++; /* This is for the addition and multiplication … … 962 1015 this sub-determinante. */ 963 1016 { 1017 hadNonZeroEntry = true; 964 1018 /* This is mk with row absoluteR and column b omitted. */ 965 1019 MinorKey subMk = mk.getSubMinorKey(absoluteR, b); … … 976 1030 temp = p_Mult_q(signPoly, temp, currRing); 977 1031 result = p_Add_q(result, temp, currRing); 1032 #ifdef COUNT_AND_PRINT_OPERATIONS 1033 multsPoly++; 1034 addsPoly++; 1035 multsMon += pLength(mv.getResult()) * pLength(getEntry(absoluteR, b)); 1036 #endif 978 1037 signPoly = NULL; 979 1038 s++; m++; as++, am++; /* This is for the addition and multiplication … … 983 1042 } 984 1043 } 985 s--; as--; /* first addition was 0 + ..., so we do not count it */ 1044 if (hadNonZeroEntry) 1045 { 1046 s--; as--; /* first addition was 0 + ..., so we do not count it */ 1047 #ifdef COUNT_AND_PRINT_OPERATIONS 1048 addsPoly--; 1049 #endif 1050 } 986 1051 if (s < 0) s = 0; /* may happen when all subminors are zero and no 987 1052 addition needs to be performed */ … … 1027 1092 ..."a*" for accumulated 1028 1093 operation counters */ 1094 bool hadNonZeroEntry = false; 1029 1095 if (b >= 0) 1030 1096 { … … 1042 1108 this sub-determinante. */ 1043 1109 { 1110 hadNonZeroEntry = true; 1044 1111 PolyMinorValue mv; /* for storing all intermediate minors */ 1045 1112 /* Next MinorKey is mk with row b and column absoluteC omitted. */ … … 1075 1142 temp = p_Mult_q(signPoly, temp, currRing); 1076 1143 result = p_Add_q(result, temp, currRing); 1144 #ifdef COUNT_AND_PRINT_OPERATIONS 1145 multsPoly++; 1146 addsPoly++; 1147 multsMon += pLength(mv.getResult()) * pLength(getEntry(b, absoluteC)); 1148 #endif 1077 1149 signPoly = NULL; 1078 1150 s++; m++; as++; am++; /* This is for the addition and multiplication … … 1098 1170 this sub-determinante. */ 1099 1171 { 1172 hadNonZeroEntry = true; 1100 1173 PolyMinorValue mv; /* for storing all intermediate minors */ 1101 1174 /* Next MinorKey is mk with row absoluteR and column b omitted. */ … … 1130 1203 temp = p_Mult_q(signPoly, temp, currRing); 1131 1204 result = p_Add_q(result, temp, currRing); 1205 #ifdef COUNT_AND_PRINT_OPERATIONS 1206 multsPoly++; 1207 addsPoly++; 1208 multsMon += pLength(mv.getResult()) * pLength(getEntry(absoluteR, b)); 1209 #endif 1132 1210 signPoly = NULL; 1133 1211 s++; m++; as++; am++; /* This is for the addition and multiplication … … 1143 1221 k, 1144 1222 multipleMinors); 1145 s--; as--; /* first addition was 0 + ..., so we do not count it */ 1223 if (hadNonZeroEntry) 1224 { 1225 s--; as--; /* first addition was 0 + ..., so we do not count it */ 1226 #ifdef COUNT_AND_PRINT_OPERATIONS 1227 addsPoly--; 1228 #endif 1229 } 1146 1230 if (s < 0) s = 0; /* may happen when all subminors are zero and no 1147 1231 addition needs to be performed */ … … 1181 1265 p2, p3, and p4 may be pNormalize-d but must, apart from that, 1182 1266 not be changed; 1183 This can only be used in the case of coefficients coming from a field!!! */ 1267 This can only be used in the case of coefficients coming from a field 1268 or at least an integral domain. */ 1184 1269 void elimOperationBucketNoDiv(poly &p1, poly &p2, poly &p3, poly &p4) 1185 1270 { 1271 #ifdef COUNT_AND_PRINT_OPERATIONS 1272 if ((pLength(p1) != 0) && (pLength(p2) != 0)) 1273 { 1274 multsPoly++; 1275 multsMon += pLength(p1) * pLength(p2); 1276 } 1277 if ((pLength(p3) != 0) && (pLength(p4) != 0)) 1278 { 1279 multsPoly++; 1280 multsMon += pLength(p3) * pLength(p4); 1281 } 1282 if ((pLength(p1) != 0) && (pLength(p2) != 0) && 1283 (pLength(p3) != 0) && (pLength(p4) != 0)) 1284 addsPoly++; 1285 #endif 1186 1286 kBucket_pt myBucket = kBucketCreate(); 1187 1287 addOperationBucket(p1, p2, myBucket); … … 1200 1300 c5 is assumed to be the leading coefficient of p5; 1201 1301 p5Len is assumed to be the length of p5; 1202 This can only be used in the case of coefficients coming from a field!!! */ 1302 This can only be used in the case of coefficients coming from a field 1303 or at least an integral domain. */ 1203 1304 void elimOperationBucket(poly &p1, poly &p2, poly &p3, poly &p4, poly &p5, 1204 1305 number &c5, int p5Len) 1205 1306 { 1307 #ifdef COUNT_AND_PRINT_OPERATIONS 1308 if ((pLength(p1) != 0) && (pLength(p2) != 0)) 1309 { 1310 multsPoly++; 1311 multsMon += pLength(p1) * pLength(p2); 1312 } 1313 if ((pLength(p3) != 0) && (pLength(p4) != 0)) 1314 { 1315 multsPoly++; 1316 multsMon += pLength(p3) * pLength(p4); 1317 } 1318 if ((pLength(p1) != 0) && (pLength(p2) != 0) && 1319 (pLength(p3) != 0) && (pLength(p4) != 0)) 1320 addsPoly++; 1321 #endif 1206 1322 kBucket_pt myBucket = kBucketCreate(); 1207 1323 addOperationBucket(p1, p2, myBucket); … … 1227 1343 quotient */ 1228 1344 p_ExpVectorSub(bucketLm, p5, currRing); 1345 #ifdef COUNT_AND_PRINT_OPERATIONS 1346 divsMon++; 1347 multsMonForDiv += p5Len; 1348 multsMon += p5Len; 1349 savedMultsMFD++; 1350 multsPoly++; 1351 multsPolyForDiv++; 1352 addsPoly++; 1353 addsPolyForDiv++; 1354 #endif 1229 1355 kBucket_Minus_m_Mult_p(myBucket, bucketLm, p5, &p5Len); 1230 1356 /* The following lines make bucketLm the new leading term of p1, … … 1324 1450 sign = -sign; 1325 1451 } 1452 #if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 2) 1453 poly w = NULL; int wl = 0; 1454 printf("matrix after %d steps:\n", r); 1455 for (int u = 0; u < k; u++) 1456 { 1457 for (int v = 0; v < k; v++) 1458 { 1459 if ((v < r) && (u > v)) 1460 wl = 0; 1461 else 1462 { 1463 w = tempMatrix[rowPermutation[u] * k + v]; 1464 wl = pLength(w); 1465 } 1466 printf("%5d ", wl); 1467 } 1468 printf("\n"); 1469 } 1470 printCounters ("", false); 1471 #endif 1326 1472 if (r != 0) 1327 1473 { … … 1347 1493 } 1348 1494 } 1495 #if (defined COUNT_AND_PRINT_OPERATIONS) && (COUNT_AND_PRINT_OPERATIONS > 2) 1496 poly w = NULL; int wl = 0; 1497 printf("matrix after %d steps:\n", k - 1); 1498 for (int u = 0; u < k; u++) 1499 { 1500 for (int v = 0; v < k; v++) 1501 { 1502 if ((v < k - 1) && (u > v)) 1503 wl = 0; 1504 else 1505 { 1506 w = tempMatrix[rowPermutation[u] * k + v]; 1507 wl = pLength(w); 1508 } 1509 printf("%5d ", wl); 1510 } 1511 printf("\n"); 1512 } 1513 #endif 1349 1514 poly result = tempMatrix[rowPermutation[k - 1] * k + k - 1]; 1350 1515 if (sign == -1) result = pNeg(result); -
Singular/MinorProcessor.h
rd0164d9 r5c44339 6 6 #include <assert.h> 7 7 #include <string> 8 9 /* write "##define COUNT_AND_PRINT_OPERATIONS x" if you want 10 to count all basic operations and have them printed when 11 one of the methods documented herein will be invoked; 12 otherwise, comment this line; 13 x = 1: only final counters (after computing ALL 14 specified minors) will be printed, i.e., no 15 intermediate results; 16 x = 2: print counters after the computation of each 17 minor; this will be much more information 18 x = 3: print also all intermediate matrices with the 19 numbers of monomials in each entry; 20 this will be much much more information */ 21 #define COUNT_AND_PRINT_OPERATIONS 2 22 23 void printCounters (char* prefix, bool resetToZero); 8 24 9 25 /*! \class MinorProcessor
Note: See TracChangeset
for help on using the changeset viewer.