Changeset 7cc3fd in git
- Timestamp:
- Aug 8, 2016, 2:16:42 PM (7 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 0d1bcb7165ef371658ad444b7547d9fdf53d7136
- Parents:
- 6a97c544535256c37da0f10bcb6821b592546c6815813d0947d4221b8c060256fd6994a48e3c6605
- Files:
-
- 12 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/dyn_modules/gfanlib/bbcone.cc
r6a97c54 r7cc3fd 353 353 BOOLEAN coneViaNormals(leftv res, leftv args) 354 354 { 355 gfan::initializeCddlibIfRequired(); 355 356 leftv u = args; 356 357 if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) … … 508 509 BOOLEAN coneViaRays(leftv res, leftv args) 509 510 { 511 gfan::initializeCddlibIfRequired(); 510 512 leftv u = args; 511 513 if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) … … 529 531 BOOLEAN inequalities(leftv res, leftv args) 530 532 { 533 gfan::initializeCddlibIfRequired(); 531 534 leftv u = args; 532 535 if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) … … 545 548 BOOLEAN equations(leftv res, leftv args) 546 549 { 550 gfan::initializeCddlibIfRequired(); 547 551 leftv u = args; 548 552 if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) … … 560 564 BOOLEAN facets(leftv res, leftv args) 561 565 { 566 gfan::initializeCddlibIfRequired(); 562 567 leftv u = args; 563 568 if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) … … 575 580 BOOLEAN impliedEquations(leftv res, leftv args) 576 581 { 582 gfan::initializeCddlibIfRequired(); 577 583 leftv u = args; 578 584 if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) … … 590 596 BOOLEAN generatorsOfSpan(leftv res, leftv args) 591 597 { 598 gfan::initializeCddlibIfRequired(); 592 599 leftv u = args; 593 600 if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) … … 605 612 BOOLEAN generatorsOfLinealitySpace(leftv res, leftv args) 606 613 { 614 gfan::initializeCddlibIfRequired(); 607 615 leftv u = args; 608 616 if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) … … 620 628 BOOLEAN rays(leftv res, leftv args) 621 629 { 630 gfan::initializeCddlibIfRequired(); 622 631 leftv u = args; 623 632 if ((u != NULL) && (u->Typ() == coneID)) … … 643 652 BOOLEAN quotientLatticeBasis(leftv res, leftv args) 644 653 { 654 gfan::initializeCddlibIfRequired(); 645 655 leftv u = args; 646 656 if ((u != NULL) && (u->Typ() == coneID)) … … 658 668 BOOLEAN getLinearForms(leftv res, leftv args) 659 669 { 670 gfan::initializeCddlibIfRequired(); 660 671 leftv u = args; 661 672 if ((u != NULL) && (u->Typ() == coneID)) … … 673 684 BOOLEAN ambientDimension(leftv res, leftv args) 674 685 { 686 gfan::initializeCddlibIfRequired(); 675 687 leftv u=args; 676 688 if ((u != NULL) && (u->Typ() == coneID)) … … 701 713 BOOLEAN dimension(leftv res, leftv args) 702 714 { 715 gfan::initializeCddlibIfRequired(); 703 716 leftv u=args; 704 717 if ((u != NULL) && (u->Typ() == coneID)) … … 729 742 BOOLEAN codimension(leftv res, leftv args) 730 743 { 744 gfan::initializeCddlibIfRequired(); 731 745 leftv u=args; 732 746 if ((u != NULL) && (u->Typ() == coneID)) … … 757 771 BOOLEAN linealityDimension(leftv res, leftv args) 758 772 { 773 gfan::initializeCddlibIfRequired(); 759 774 leftv u=args; 760 775 if ((u != NULL) && (u->Typ() == coneID)) … … 778 793 BOOLEAN getMultiplicity(leftv res, leftv args) 779 794 { 795 gfan::initializeCddlibIfRequired(); 780 796 leftv u = args; 781 797 if ((u != NULL) && (u->Typ() == coneID)) … … 793 809 BOOLEAN isOrigin(leftv res, leftv args) 794 810 { 811 gfan::initializeCddlibIfRequired(); 795 812 leftv u = args; 796 813 if ((u != NULL) && (u->Typ() == coneID)) … … 808 825 BOOLEAN isFullSpace(leftv res, leftv args) 809 826 { 827 gfan::initializeCddlibIfRequired(); 810 828 leftv u = args; 811 829 if ((u != NULL) && (u->Typ() == coneID)) … … 823 841 BOOLEAN isSimplicial(leftv res, leftv args) 824 842 { 843 gfan::initializeCddlibIfRequired(); 825 844 leftv u=args; 826 845 if ((u != NULL) && (u->Typ() == coneID)) … … 846 865 BOOLEAN containsPositiveVector(leftv res, leftv args) 847 866 { 867 gfan::initializeCddlibIfRequired(); 848 868 leftv u = args; 849 869 if ((u != NULL) && (u->Typ() == coneID)) … … 861 881 BOOLEAN linealitySpace(leftv res, leftv args) 862 882 { 883 gfan::initializeCddlibIfRequired(); 863 884 leftv u = args; 864 885 if ((u != NULL) && (u->Typ() == coneID)) … … 876 897 BOOLEAN dualCone(leftv res, leftv args) 877 898 { 899 gfan::initializeCddlibIfRequired(); 878 900 leftv u = args; 879 901 if ((u != NULL) && (u->Typ() == coneID)) … … 891 913 BOOLEAN negatedCone(leftv res, leftv args) 892 914 { 915 gfan::initializeCddlibIfRequired(); 893 916 leftv u = args; 894 917 if ((u != NULL) && (u->Typ() == coneID)) … … 906 929 BOOLEAN semigroupGenerator(leftv res, leftv args) 907 930 { 931 gfan::initializeCddlibIfRequired(); 908 932 leftv u = args; 909 933 if ((u != NULL) && (u->Typ() == coneID)) … … 928 952 BOOLEAN relativeInteriorPoint(leftv res, leftv args) 929 953 { 954 gfan::initializeCddlibIfRequired(); 930 955 leftv u = args; 931 956 if ((u != NULL) && (u->Typ() == coneID)) … … 943 968 BOOLEAN uniquePoint(leftv res, leftv args) 944 969 { 970 gfan::initializeCddlibIfRequired(); 945 971 leftv u = args; 946 972 if ((u != NULL) && (u->Typ() == coneID)) … … 964 990 { 965 991 int n = siRand(); 966 rp = rp + n * rays[i] ;992 rp = rp + n * rays[i].toVector(); 967 993 } 968 994 … … 971 997 { 972 998 int n = siRand(); 973 rp = rp + n * lins[i] ;999 rp = rp + n * lins[i].toVector(); 974 1000 } 975 1001 … … 979 1005 BOOLEAN randomPoint(leftv res, leftv args) 980 1006 { 1007 gfan::initializeCddlibIfRequired(); 981 1008 leftv u = args; 982 1009 if ((u != NULL) && (u->Typ() == coneID)) … … 994 1021 BOOLEAN setMultiplicity(leftv res, leftv args) 995 1022 { 1023 gfan::initializeCddlibIfRequired(); 996 1024 leftv u = args; 997 1025 if ((u != NULL) && (u->Typ() == coneID)) … … 1014 1042 BOOLEAN setLinearForms(leftv res, leftv args) 1015 1043 { 1044 gfan::initializeCddlibIfRequired(); 1016 1045 leftv u = args; 1017 1046 if ((u != NULL) && (u->Typ() == coneID)) … … 1066 1095 BOOLEAN coneToPolytope(leftv res, leftv args) 1067 1096 { 1097 gfan::initializeCddlibIfRequired(); 1068 1098 leftv u = args; 1069 1099 if ((u != NULL) && (u->Typ() == coneID)) … … 1083 1113 BOOLEAN intersectCones(leftv res, leftv args) 1084 1114 { 1115 gfan::initializeCddlibIfRequired(); 1085 1116 leftv u = args; 1086 1117 if ((u != NULL) && (u->Typ() == coneID)) … … 1172 1203 BOOLEAN convexHull(leftv res, leftv args) 1173 1204 { 1205 gfan::initializeCddlibIfRequired(); 1174 1206 leftv u = args; 1175 1207 if ((u != NULL) && (u->Typ() == coneID)) … … 1278 1310 BOOLEAN coneLink(leftv res, leftv args) 1279 1311 { 1312 gfan::initializeCddlibIfRequired(); 1280 1313 leftv u = args; 1281 1314 if ((u != NULL) && (u->Typ() == coneID)) … … 1323 1356 BOOLEAN containsInSupport(leftv res, leftv args) 1324 1357 { 1358 gfan::initializeCddlibIfRequired(); 1325 1359 leftv u=args; 1326 1360 if ((u != NULL) && (u->Typ() == coneID)) … … 1381 1415 BOOLEAN containsRelatively(leftv res, leftv args) 1382 1416 { 1417 gfan::initializeCddlibIfRequired(); 1383 1418 leftv u = args; 1384 1419 if ((u != NULL) && (u->Typ() == coneID)) … … 1422 1457 BOOLEAN hasFace(leftv res, leftv args) 1423 1458 { 1459 gfan::initializeCddlibIfRequired(); 1424 1460 leftv u=args; 1425 1461 if ((u != NULL) && (u->Typ() == coneID)) … … 1455 1491 BOOLEAN canonicalizeCone(leftv res, leftv args) 1456 1492 { 1493 gfan::initializeCddlibIfRequired(); 1457 1494 leftv u=args; 1458 1495 if ((u != NULL) && (u->Typ() == coneID)) … … 1471 1508 BOOLEAN containsCone(leftv res, leftv args) 1472 1509 { 1510 gfan::initializeCddlibIfRequired(); 1473 1511 leftv u=args; 1474 1512 if ((u != NULL) && (u->Typ() == LIST_CMD)) … … 1544 1582 BOOLEAN listOfFacets(leftv res, leftv args) 1545 1583 { 1584 gfan::initializeCddlibIfRequired(); 1546 1585 leftv u=args; 1547 1586 if ((u != NULL) && (u->Typ() == coneID)) … … 1582 1621 BOOLEAN facetContaining(leftv res, leftv args) 1583 1622 { 1623 gfan::initializeCddlibIfRequired(); 1584 1624 leftv u = args; 1585 1625 if ((u != NULL) && (u->Typ() == coneID)) … … 1700 1740 { 1701 1741 relativeInteriorPoints.appendRow(interiorPoint); 1702 outerFacetNormals.appendRow(-inequalities[0] );1742 outerFacetNormals.appendRow(-inequalities[0].toVector()); 1703 1743 } 1704 1744 } … … 1718 1758 { 1719 1759 relativeInteriorPoints.appendRow(interiorPoint); 1720 outerFacetNormals.appendRow(-inequalities[i] );1760 outerFacetNormals.appendRow(-inequalities[i].toVector()); 1721 1761 } 1722 1762 } … … 1734 1774 { 1735 1775 relativeInteriorPoints.appendRow(interiorPoint); 1736 outerFacetNormals.appendRow(-inequalities[r-1] );1776 outerFacetNormals.appendRow(-inequalities[r-1].toVector()); 1737 1777 } 1738 1778 } -
Singular/dyn_modules/gfanlib/bbfan.cc
r6a97c54 r7cc3fd 175 175 BOOLEAN emptyFan(leftv res, leftv args) 176 176 { 177 gfan::initializeCddlibIfRequired(); 177 178 leftv u = args; 178 179 if (u == NULL) … … 227 228 BOOLEAN fullFan(leftv res, leftv args) 228 229 { 230 gfan::initializeCddlibIfRequired(); 229 231 leftv u = args; 230 232 if (u == NULL) … … 264 266 BOOLEAN numberOfConesOfDimension(leftv res, leftv args) 265 267 { 268 gfan::initializeCddlibIfRequired(); 266 269 leftv u=args; 267 270 if ((u != NULL) && (u->Typ() == fanID)) … … 308 311 BOOLEAN ncones(leftv res, leftv args) 309 312 { 313 gfan::initializeCddlibIfRequired(); 310 314 leftv u=args; 311 315 if ((u != NULL) && (u->Typ() == fanID)) … … 328 332 BOOLEAN nmaxcones(leftv res, leftv args) 329 333 { 334 gfan::initializeCddlibIfRequired(); 330 335 leftv u=args; 331 336 if ((u != NULL) && (u->Typ() == fanID)) … … 366 371 BOOLEAN isCompatible(leftv res, leftv args) 367 372 { 373 gfan::initializeCddlibIfRequired(); 368 374 leftv u=args; 369 375 if ((u != NULL) && (u->Typ() == fanID)) … … 386 392 BOOLEAN insertCone(leftv res, leftv args) 387 393 { 394 gfan::initializeCddlibIfRequired(); 388 395 leftv u=args; 389 396 if ((u != NULL) && (u->rtyp==IDHDL) && (u->e==NULL) && (u->Typ() == fanID)) … … 443 450 BOOLEAN containsInCollection(leftv res, leftv args) 444 451 { 452 gfan::initializeCddlibIfRequired(); 445 453 leftv u=args; 446 454 if ((u != NULL) && (u->Typ() == fanID)) … … 501 509 BOOLEAN removeCone(leftv res, leftv args) 502 510 { 511 gfan::initializeCddlibIfRequired(); 503 512 leftv u=args; 504 513 if ((u != NULL) && (u->Typ() == fanID)) … … 537 546 BOOLEAN getCone(leftv res, leftv args) 538 547 { 548 gfan::initializeCddlibIfRequired(); 539 549 leftv u=args; 540 550 if ((u != NULL) && (u->Typ() == fanID)) … … 612 622 BOOLEAN getCones(leftv res, leftv args) 613 623 { 624 gfan::initializeCddlibIfRequired(); 614 625 leftv u=args; 615 626 if ((u != NULL) && (u->Typ() == fanID)) … … 686 697 BOOLEAN isPure(leftv res, leftv args) 687 698 { 699 gfan::initializeCddlibIfRequired(); 688 700 leftv u=args; 689 701 if ((u != NULL) && (u->Typ() == fanID)) … … 716 728 BOOLEAN fVector(leftv res, leftv args) 717 729 { 730 gfan::initializeCddlibIfRequired(); 718 731 leftv u=args; 719 732 if ((u != NULL) && (u->Typ() == fanID)) … … 731 744 gfan::ZMatrix rays(const gfan::ZFan* const zf) 732 745 { 746 gfan::initializeCddlibIfRequired(); 733 747 gfan::ZMatrix rays(0,zf->getAmbientDimension()); 734 748 for (int i=0; i<zf->numberOfConesOfDimension(1,0,0); i++) … … 742 756 int numberOfConesWithVector(gfan::ZFan* zf, gfan::ZVector* v) 743 757 { 758 gfan::initializeCddlibIfRequired(); 744 759 int count = 0; 745 760 int ambientDim = zf->getAmbientDimension(); … … 759 774 BOOLEAN numberOfConesWithVector(leftv res, leftv args) 760 775 { 776 gfan::initializeCddlibIfRequired(); 761 777 leftv u=args; 762 778 if ((u != NULL) && (u->Typ() == fanID)) … … 787 803 BOOLEAN fanFromString(leftv res, leftv args) 788 804 { 805 gfan::initializeCddlibIfRequired(); 789 806 leftv u=args; 790 807 if ((u != NULL) && (u->Typ() == STRING_CMD)) … … 803 820 BOOLEAN fanViaCones(leftv res, leftv args) 804 821 { 822 gfan::initializeCddlibIfRequired(); 805 823 leftv u=args; 806 824 if ((u != NULL) && (u->Typ() == LIST_CMD)) … … 953 971 BOOLEAN commonRefinement(leftv res, leftv args) 954 972 { 973 gfan::initializeCddlibIfRequired(); 955 974 leftv u=args; 956 975 if ((u != NULL) && (u->Typ() == fanID)) -
Singular/dyn_modules/gfanlib/bbpolytope.cc
r6a97c54 r7cc3fd 185 185 BOOLEAN polytopeViaVertices(leftv res, leftv args) 186 186 { 187 gfan::initializeCddlibIfRequired(); 187 188 leftv u = args; 188 189 if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) … … 319 320 BOOLEAN polytopeViaNormals(leftv res, leftv args) 320 321 { 322 gfan::initializeCddlibIfRequired(); 321 323 leftv u = args; 322 324 if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) … … 340 342 BOOLEAN vertices(leftv res, leftv args) 341 343 { 344 gfan::initializeCddlibIfRequired(); 342 345 leftv u = args; 343 346 if ((u != NULL) && (u->Typ() == polytopeID)) … … 379 382 } 380 383 384 gfan::ZCone newtonPolytope(poly p, ring r) 385 { 386 int N = rVar(r); 387 gfan::ZMatrix zm(0,N+1); 388 int *leadexpv = (int*)omAlloc((N+1)*sizeof(int)); 389 while (p!=NULL) 390 { 391 p_GetExpV(p,leadexpv,r); 392 gfan::ZVector zv = intStar2ZVectorWithLeadingOne(N, leadexpv); 393 zm.appendRow(zv); 394 pIter(p); 395 } 396 omFreeSize(leadexpv,(N+1)*sizeof(int)); 397 gfan::ZCone Delta = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth())); 398 return Delta; 399 } 400 381 401 BOOLEAN newtonPolytope(leftv res, leftv args) 382 402 { 403 gfan::initializeCddlibIfRequired(); 383 404 leftv u = args; 384 405 if ((u != NULL) && (u->Typ() == POLY_CMD)) 385 406 { 386 407 poly p = (poly)u->Data(); 387 int N = rVar(currRing);388 gfan::ZMatrix zm(1,N+1);389 int *leadexpv = (int*)omAlloc((N+1)*sizeof(int));390 while (p!=NULL)391 {392 pGetExpV(p,leadexpv);393 gfan::ZVector zv = intStar2ZVectorWithLeadingOne(N, leadexpv);394 zm.appendRow(zv);395 pIter(p);396 }397 omFreeSize(leadexpv,(N+1)*sizeof(int));398 gfan::ZCone* zc = new gfan::ZCone();399 *zc = gfan::ZCone::givenByRays(zm, gfan::ZMatrix(0, zm.getWidth()));400 408 res->rtyp = polytopeID; 401 res->data = (void*) zc;409 res->data = (void*) new gfan::ZCone(newtonPolytope(p,currRing)); 402 410 return FALSE; 403 411 } … … 408 416 BOOLEAN scalePolytope(leftv res, leftv args) 409 417 { 418 gfan::initializeCddlibIfRequired(); 410 419 leftv u = args; 411 420 if ((u != NULL) && (u->Typ() == INT_CMD)) … … 433 442 BOOLEAN dualPolytope(leftv res, leftv args) 434 443 { 444 gfan::initializeCddlibIfRequired(); 435 445 leftv u = args; 436 446 if ((u != NULL) && (u->Typ() == polytopeID)) … … 445 455 return TRUE; 446 456 } 457 458 BOOLEAN mixedVolume(leftv res, leftv args) 459 { 460 gfan::initializeCddlibIfRequired(); 461 leftv u = args; 462 if ((u != NULL) && (u->Typ() == LIST_CMD)) 463 { 464 lists l = (lists) u->Data(); 465 int k = lSize(l)+1; 466 std::vector<gfan::IntMatrix> P(k); 467 for (int i=0; i<k; i++) 468 { 469 if (l->m[i].Typ() == polytopeID) 470 { 471 gfan::ZCone* p = (gfan::ZCone*) l->m[i].Data(); 472 gfan::ZMatrix pv = p->extremeRays(); 473 int r = pv.getHeight(); 474 int c = pv.getWidth(); 475 gfan::IntMatrix pw(r,c-1); 476 for (int n=0; n<r; n++) 477 for (int m=1; m<c; m++) 478 pw[n][m-1] = pv[n][m].toInt(); 479 P[i]=pw.transposed(); 480 } else if (l->m[i].Typ() == POLY_CMD) 481 { 482 poly p = (poly) l->m[i].Data(); 483 int N = rVar(currRing); 484 gfan::IntMatrix pw(0,N); 485 int *leadexpv = (int*)omAlloc((N+1)*sizeof(int)); 486 while (p!=NULL) 487 { 488 p_GetExpV(p,leadexpv,currRing); 489 gfan::IntVector zv(N); 490 for (int i=0; i<N; i++) 491 zv[i] = leadexpv[i+1]; 492 pw.appendRow(zv); 493 pIter(p); 494 } 495 P[i]=pw.transposed(); 496 omFreeSize(leadexpv,(N+1)*sizeof(int)); 497 } 498 else 499 { 500 WerrorS("mixedVolume: entries of unsupported type in list"); 501 return TRUE; 502 } 503 } 504 gfan::Integer mv = gfan::mixedVolume(P); 505 506 res->rtyp = BIGINT_CMD; 507 res->data = (void*) integerToNumber(mv); 508 return FALSE; 509 } 510 WerrorS("mixedVolume: unexpected parameters"); 511 return TRUE; 512 } 513 514 447 515 448 516 void bbpolytope_setup(SModulFunctions* p) … … 464 532 p->iiAddCproc("","scalePolytope",FALSE,scalePolytope); 465 533 p->iiAddCproc("","dualPolytope",FALSE,dualPolytope); 534 p->iiAddCproc("","mixedVolume",FALSE,mixedVolume); 466 535 /********************************************************/ 467 536 /* the following functions are implemented in bbcone.cc */ -
Singular/dyn_modules/gfanlib/gfanlib.cc
r6a97c54 r7cc3fd 20 20 extern "C" int SI_MOD_INIT(gfanlib)(SModulFunctions* p) 21 21 { 22 gfan::initializeCddlibIfRequired(); 22 23 bbcone_setup(p); 23 24 bbfan_setup(p); -
Singular/dyn_modules/gfanlib/groebnerFan.cc
r6a97c54 r7cc3fd 72 72 { 73 73 if (i!=j) 74 inequalities.appendRow(exponents[i] -exponents[j]);74 inequalities.appendRow(exponents[i].toVector()-exponents[j].toVector()); 75 75 } 76 76 gfan::ZCone zc = gfan::ZCone(inequalities,gfan::ZMatrix(0,inequalities.getWidth())); -
Singular/dyn_modules/gfanlib/startingCone.cc
r6a97c54 r7cc3fd 129 129 for (int i=0; i<ray.getHeight(); i++) 130 130 { 131 if (ray[i]. isPositive())131 if (ray[i].toVector().isPositive()) 132 132 { 133 133 res->rtyp = BIGINTMAT_CMD; 134 res->data = (void*) zVectorToBigintmat(ray[i] );134 res->data = (void*) zVectorToBigintmat(ray[i].toVector()); 135 135 return FALSE; 136 136 } … … 164 164 for (int i=0; i<ray.getHeight(); i++) 165 165 { 166 if (ray[i]. isNonNegative())166 if (ray[i].toVector().isNonNegative()) 167 167 { 168 168 res->rtyp = BIGINTMAT_CMD; 169 res->data = (void*) zVectorToBigintmat(ray[i] );169 res->data = (void*) zVectorToBigintmat(ray[i].toVector()); 170 170 return FALSE; 171 171 } … … 199 199 for (int i=0; i<ray.getHeight(); i++) 200 200 { 201 gfan::ZVector negatedRay = gfan::Integer(-1)*ray[i] ;201 gfan::ZVector negatedRay = gfan::Integer(-1)*ray[i].toVector(); 202 202 if (negatedRay.isPositive()) 203 203 { 204 204 res->rtyp = BIGINTMAT_CMD; 205 res->data = (void*) zVectorToBigintmat(ray[i] );205 res->data = (void*) zVectorToBigintmat(ray[i].toVector()); 206 206 return FALSE; 207 207 } … … 235 235 for (int i=0; i<ray.getHeight(); i++) 236 236 { 237 gfan::ZVector negatedRay = gfan::Integer(-1)*ray[i] ;237 gfan::ZVector negatedRay = gfan::Integer(-1)*ray[i].toVector(); 238 238 if (negatedRay.isNonNegative()) 239 239 { -
Singular/dyn_modules/gfanlib/tropicalVarietyOfPolynomials.cc
r6a97c54 r7cc3fd 43 43 { 44 44 gfan::ZMatrix equation = gfan::ZMatrix(0,n); 45 equation.appendRow(exponents[i] -exponents[j]);45 equation.appendRow(exponents[i].toVector()-exponents[j].toVector()); 46 46 gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); 47 47 if (currentCase->restrictToLowerHalfSpace()) 48 48 inequalities.appendRow(lowerHalfSpaceCondition); 49 49 for (int k=0; k<l; k++) 50 if (k!=i && k!=j) inequalities.appendRow( exponents[i]-exponents[k]);50 if (k!=i && k!=j) inequalities.appendRow(((gfan::ZVector)exponents[i])-exponents[k]); 51 51 gfan::ZCone zc = gfan::ZCone(inequalities,equation); 52 52 if (zc.dimension()>=n-1) … … 85 85 { 86 86 gfan::ZMatrix equation = gfan::ZMatrix(0,n); 87 equation.appendRow(exponents[i] -exponents[j]);87 equation.appendRow(exponents[i].toVector()-exponents[j].toVector()); 88 88 gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); 89 89 if (currentCase->restrictToLowerHalfSpace()) 90 90 inequalities.appendRow(lowerHalfSpaceCondition); 91 91 for (int k=0; k<l; k++) 92 if (k!=i && k!=j) inequalities.appendRow(exponents[i] -exponents[k]);92 if (k!=i && k!=j) inequalities.appendRow(exponents[i].toVector()-exponents[k].toVector()); 93 93 gfan::ZCone zc = gfan::ZCone(inequalities,equation); 94 94 if (zc.dimension()>=n-1) -
gfanlib/Makefile.am
r6a97c54 r7cc3fd 9 9 AM_CPPFLAGS = -I${top_srcdir} -I${top_builddir} -DGMPRATIONAL 10 10 11 SOURCES = gfanlib_zcone.cpp gfanlib_symmetry.cpp gfanlib_symmetriccomplex.cpp gfanlib_polyhedralfan.cpp gfanlib_zfan.cpp gfanlib_polymakefile.cpp 12 libgfan_la_SOURCES = $(SOURCES)11 # forcefully enable exceptions 12 CXXFLAGS+= $(FEXCEPTIONSFRTTI_CXXFLAGS) 13 13 14 libgfan_includedir =$(includedir)/gfanlib 14 AM_CXXFLAGS = -std=c++11 15 15 16 libgfan_include_HEADERS = gfanlib_z.h gfanlib_q.h gfanlib_vector.h gfanlib_matrix.h gfanlib_zcone.h gfanlib.h gfanlib_polyhedralfan.h gfanlib_polymakefile.h gfanlib_symmetriccomplex.h gfanlib_symmetry.h gfanlib_zfan.h 16 17 SOURCES = gfanlib_circuittableint.cpp gfanlib_mixedvolume.cpp gfanlib_paralleltraverser.cpp gfanlib_polyhedralfan.cpp gfanlib_polymakefile.cpp gfanlib_symmetriccomplex.cpp gfanlib_symmetry.cpp gfanlib_traversal.cpp gfanlib_zcone.cpp gfanlib_zfan.cpp 18 libgfan_la_SOURCES = $(SOURCES) 19 20 libgfan_includedir =$(includedir)/gfanlib 21 libgfan_include_HEADERS = config.h gfanlib_mixedvolume.h gfanlib_polymakefile.h gfanlib_symmetry.h gfanlib_vector.h gfanlib_z.h _config.h gfanlib.h gfanlib_paralleltraverser.h gfanlib_q.h gfanlib_traversal.h gfanlib_zcone.h gfanlib_circuittableint.h gfanlib_matrix.h gfanlib_polyhedralfan.h gfanlib_symmetriccomplex.h gfanlib_tropicalhomotopy.h gfanlib_zfan.h 17 22 18 23 DISTCLEANFILES = config.h -
gfanlib/gfanlib.h
r6a97c54 r7cc3fd 16 16 #include "gfanlib_polyhedralfan.h" 17 17 #include "gfanlib_zfan.h" 18 #include "gfanlib_mixedvolume.h" 18 19 19 20 #endif /* GFANLIB_H_ */ -
gfanlib/gfanlib_matrix.h
r6a97c54 r7cc3fd 9 9 #define LIB_ZMATRIX_H_ 10 10 11 #include <sstream>12 11 #include <vector> 13 12 #include <algorithm> … … 18 17 template <class typ> class Matrix{ 19 18 int width,height; 20 std::vector<Vector<typ> > rows; 19 // std::vector<Vector<typ> > rows; 20 std::vector<typ> data; 21 21 public: 22 22 // rowIterator; … … 25 25 inline int getHeight()const{return height;}; 26 26 inline int getWidth()const{return width;}; 27 Matrix(const Matrix &a):width(a.getWidth()),height(a.getHeight()), rows(a.rows){28 } 29 Matrix(int height_, int width_):width(width_),height(height_), rows(height_){27 Matrix(const Matrix &a):width(a.getWidth()),height(a.getHeight()),data(a.data){ 28 } 29 Matrix(int height_, int width_):width(width_),height(height_),data(width_*height_){ 30 30 assert(height>=0); 31 31 assert(width>=0); 32 for(int i=0;i<getHeight();i++)rows[i]=Vector<typ>(width);33 32 }; 34 33 ~Matrix(){ … … 36 35 Matrix():width(0),height(0){ 37 36 }; 38 Matrix rowVectorMatrix(Vector<typ> const &v)37 static Matrix rowVectorMatrix(Vector<typ> const &v) 39 38 { 40 39 Matrix ret(1,v.size()); 41 for( unsignedi=0;i<v.size();i++)ret[0][i]=v[i];40 for(int i=0;i<v.size();i++)ret[0][i]=v[i]; 42 41 return ret; 43 42 } … … 47 46 assert(i<getWidth()); 48 47 Vector<typ> ret(getHeight()); 49 for(int j=0;j<getHeight();j++)ret[j]= rows[j][i];48 for(int j=0;j<getHeight();j++)ret[j]=(*this)[j][i]; 50 49 return ret; 51 50 } … … 54 53 Matrix ret(getWidth(),getHeight()); 55 54 for(int i=0;i<getWidth();i++) 56 ret.rows[i]=column(i); 55 for(int j=0;j<getHeight();j++) 56 ret[i][j]=(*this)[j][i]; 57 57 return ret; 58 58 } … … 60 60 { 61 61 Matrix m(n,n); 62 for(int i=0;i<n;i++)m .rows[i]=Vector<typ>::standardVector(n,i);62 for(int i=0;i<n;i++)m[i][i]=typ(1); 63 63 return m; 64 64 } 65 65 void append(Matrix const &m) 66 66 { 67 assert(m.getWidth()==width); 68 data.resize((height+m.height)*width); 69 int oldHeight=height; 70 height+=m.height; 67 71 for(int i=0;i<m.height;i++) 68 72 { 69 rows.push_back(m[i]); 73 for(int j=0;j<m.width;j++) 74 (*this)[i+oldHeight][j]=m[i][j]; 70 75 } 71 height+=m.height;72 76 } 73 77 void appendRow(Vector<typ> const &v) 74 { 75 assert((int)v.size()==width); 76 rows.push_back(v); 77 height++; 78 } 79 void prependRow(Vector<typ> const &v) 80 { 81 assert((int)v.size()==width); 82 rows.insert(rows.begin(),v); 83 height++; 84 } 78 { 79 assert(v.size()==width); 80 data.resize((height+1)*width); 81 height++; 82 for(int j=0;j<width;j++) 83 (*this)[height-1][j]=v[j]; 84 } 85 85 void eraseLastRow() 86 86 { 87 assert( rows.size()>0);88 rows.pop_back();87 assert(height>0); 88 data.resize((height-1)*width); 89 89 height--; 90 90 } … … 111 111 { 112 112 Matrix p=q; 113 for(int i=0;i<q.height;i++)p[i]=s*(q[i]); 113 for(int i=0;i<q.height;i++) 114 for(int j=0;j<q.width;j++) 115 p[i][j]=s*(q[i][j]); 114 116 return p; 115 117 } … … 147 149 for(int i=startRow;i<endRow;i++) 148 150 for(int j=startColumn;j<endColumn;j++) 149 ret[i-startRow][j-startColumn]=rows[i][j]; 150 return ret; 151 } 152 const Vector<typ>& operator[](int n)const{assert(n>=0 && n<getHeight());return (rows[n]);} 153 // Bugfix for gcc4.5 (passing assertion to the above operator): 154 Vector<typ>& operator[](int n){if(!(n>=0 && n<getHeight())){(*(const Matrix<typ>*)(this))[n];}return (rows[n]);} 151 ret[i-startRow][j-startColumn]=(*this)[i][j]; 152 return ret; 153 } 154 155 class RowRef; 156 class const_RowRef{ 157 int rowNumM; 158 Matrix const &matrix; 159 friend class RowRef; 160 public: 161 inline const_RowRef(const Matrix &matrix_, int rowNum_)__attribute__((always_inline)): 162 rowNumM(rowNum_*matrix_.width), 163 matrix(matrix_) 164 { 165 } 166 inline typ const &operator[](int j)const __attribute__((always_inline)) 167 { 168 assert(j>=0); 169 assert(j<matrix.width); 170 return matrix.data[rowNumM+j]; 171 } 172 inline typ const &UNCHECKEDACCESS(int j)const __attribute__((always_inline)) 173 { 174 return matrix.data[rowNumM+j]; 175 } 176 const Vector<typ> toVector()const 177 { 178 Vector<typ> ret(matrix.width); 179 for(int j=0;j<matrix.width;j++) 180 ret[j]=matrix.data[rowNumM+j]; 181 return ret; 182 } 183 operator Vector<typ>()const 184 { 185 return toVector(); 186 } 187 bool operator==(Vector<typ> const &b)const 188 { 189 return toVector()==b; 190 } 191 /* typ dot(Vector<typ> const &b)const 192 { 193 return dot(toVector(),b); 194 }*/ 195 Vector<typ> operator-()const 196 { 197 return -toVector(); 198 } 199 }; 200 class RowRef{ 201 int rowNumM; 202 Matrix &matrix; 203 public: 204 inline RowRef(Matrix &matrix_, int rowNum_): 205 rowNumM(rowNum_*matrix_.width), 206 matrix(matrix_) 207 { 208 } 209 inline typ &operator[](int j) __attribute__((always_inline)) 210 { 211 assert(j>=0); 212 assert(j<matrix.width); 213 return matrix.data[rowNumM+j]; 214 } 215 inline typ &UNCHECKEDACCESS(int j) 216 { 217 return matrix.data[rowNumM+j]; 218 } 219 RowRef &operator=(Vector<typ> const &v) 220 { 221 assert(v.size()==matrix.width); 222 for(int j=0;j<matrix.width;j++) 223 matrix.data[rowNumM+j]=v[j]; 224 225 return *this; 226 } 227 RowRef &operator=(RowRef const &v) 228 { 229 assert(v.matrix.width==matrix.width); 230 for(int j=0;j<matrix.width;j++) 231 matrix.data[rowNumM+j]=v.matrix.data[v.rowNumM+j]; 232 233 return *this; 234 } 235 /* RowRef &operator+=(Vector<typ> const &v) 236 { 237 assert(v.size()==matrix.width); 238 for(int j=0;j<matrix.width;j++) 239 matrix.data[rowNumM+j]+=v.v[j]; 240 241 return *this; 242 }*/ 243 RowRef &operator+=(RowRef const &v) 244 { 245 assert(v.matrix.width==matrix.width); 246 for(int j=0;j<matrix.width;j++) 247 matrix.data[rowNumM+j]+=v.matrix.data[v.rowNumM+j]; 248 249 return *this; 250 } 251 RowRef &operator+=(const_RowRef const &v) 252 { 253 assert(v.matrix.width==matrix.width); 254 for(int j=0;j<matrix.width;j++) 255 matrix.data[rowNumM+j]+=v.matrix.data[v.rowNumM+j]; 256 257 return *this; 258 } 259 RowRef &operator=(const_RowRef const &v) 260 { 261 assert(v.matrix.width==matrix.width); 262 for(int j=0;j<matrix.width;j++) 263 matrix.data[rowNumM+j]=v.matrix.data[v.rowNumM+j]; 264 265 return *this; 266 } 267 const Vector<typ> toVector()const 268 { 269 Vector<typ> ret(matrix.width); 270 for(int j=0;j<matrix.width;j++) 271 ret[j]=matrix.data[rowNumM+j]; 272 return ret; 273 } 274 operator Vector<typ>()const 275 { 276 return toVector(); 277 } 278 /* typ dot(Vector<typ> const &b)const 279 { 280 return dot(toVector(),b); 281 }*/ 282 bool isZero()const 283 { 284 for(int j=0;j<matrix.width;j++)if(!(matrix.data[rowNumM+j].isZero()))return false; 285 return true; 286 } 287 }; 288 289 290 inline RowRef operator[](int i) __attribute__((always_inline)) 291 { 292 assert(i>=0); 293 assert(i<height); 294 return RowRef(*this,i); 295 } 296 inline const_RowRef operator[](int i)const __attribute__((always_inline)) 297 { 298 assert(i>=0); 299 assert(i<height); 300 return const_RowRef(*this,i); 301 } 302 303 304 const typ& UNCHECKEDACCESS(int i,int j)const __attribute__((always_inline)){ 305 /* assert(i>=0); 306 assert(i<height); 307 assert(j>=0); 308 assert(j<width);*/ 309 return data[i*width+j];} 310 typ& UNCHECKEDACCESS(int i,int j) __attribute__((always_inline)){ 311 /* assert(i>=0); 312 assert(i<height); 313 assert(j>=0); 314 assert(j<width);*/ 315 return data[i*width+j];} 316 155 317 156 318 … … 164 326 for(int i=0;i<getHeight();i++) 165 327 { 166 if((*this)[i] <b[i])return true;167 if(b[i] <(*this)[i])return false;328 if((*this)[i].toVector()<b[i].toVector())return true; 329 if(b[i].toVector()<(*this)[i].toVector())return false; 168 330 } 169 331 return false; … … 180 342 if(!a.isZero()) 181 343 for(int k=0;k<width;k++) 182 if(! rows[i][k].isZero())183 rows[j][k].madd(rows[i][k],a);344 if(!(*this)[i][k].isZero()) 345 (*this)[j][k].madd((*this)[i][k],a); 184 346 } 185 347 … … 189 351 { 190 352 if(i)f<<","<<std::endl; 191 f<<a .rows[i];353 f<<a[i].toVector(); 192 354 } 193 355 f<<"}"<<std::endl; … … 207 369 void swapRows(int i, int j) 208 370 { 209 std::swap(rows[i],rows[j]);371 for(int a=0;a<width;a++)std::swap((*this)[i][a],(*this)[j][a]); 210 372 } 211 373 /** … … 222 384 while(++j<width) 223 385 { 224 if(! rows[i][j].isZero()) return true;386 if(!(*this)[i][j].isZero()) return true; 225 387 } 226 388 return false; … … 295 457 int bestNumberOfNonZero=0; 296 458 for(int i=currentRow;i<height;i++) 297 if(! rows[i][column].isZero())459 if(!(*this)[i][column].isZero()) 298 460 { 299 461 int nz=0; 300 462 for(int k=column+1;k<width;k++) 301 if(! rows[i][k].isZero())nz++;463 if(!(*this)[i][k].isZero())nz++; 302 464 if(best==-1) 303 465 { … … 345 507 if(makePivotsOne) 346 508 {//THE PIVOT SHOULD BE SET TO ONE IF INTEGRAL IS FALSE 347 if( rows[currentRow][i].sign()>=0)retSwaps++;348 typ inverse=typ(1)/ rows[currentRow][i];509 if((*this)[currentRow][i].sign()>=0)retSwaps++; 510 typ inverse=typ(1)/(*this)[currentRow][i]; 349 511 // if(!rows[currentRow][i].isOne()) 350 512 { 351 513 for(int k=0;k<width;k++) 352 if(! rows[currentRow][k].isZero())353 rows[currentRow][k]*=inverse;514 if(!(*this)[currentRow][k].isZero()) 515 (*this)[currentRow][k]*=inverse; 354 516 } 355 517 } … … 357 519 if(integral) 358 520 { 359 if(! rows[j][i].isZero())521 if(!(*this)[j][i].isZero()) 360 522 { 361 523 typ s; 362 524 typ t; 363 525 364 typ g=typ::gcd( rows[currentRow][i],rows[j][i],s,t);365 typ u=- rows[j][i]/g;366 typ v= rows[currentRow][i]/g;526 typ g=typ::gcd((*this)[currentRow][i],(*this)[j][i],s,t); 527 typ u=-(*this)[j][i]/g; 528 typ v=(*this)[currentRow][i]/g; 367 529 /* We want the (s,t) vector to be as small as possible. 368 530 * We are allowed to adjust by multiples of (u,v). … … 378 540 for(int k=0;k<width;k++) 379 541 { 380 typ A= rows[currentRow][k];381 typ B= rows[j][k];382 383 rows[currentRow][k]=s*A+t*B;384 rows[j][k]=u*A+v*B;542 typ A=(*this)[currentRow][k]; 543 typ B=(*this)[j][k]; 544 545 (*this)[currentRow][k]=s*A+t*B; 546 (*this)[j][k]=u*A+v*B; 385 547 } 386 548 } … … 388 550 else 389 551 { 390 if(! rows[j][i].isZero())391 madd(currentRow,- rows[j][i]/rows[currentRow][i],j);552 if(!(*this)[j][i].isZero()) 553 madd(currentRow,-(*this)[j][i]/(*this)[currentRow][i],j); 392 554 } 393 555 currentRow++; … … 412 574 while(nextPivot(pivotI,pivotJ)) 413 575 { 414 if(scalePivotsToOne)415 rows[pivotI]=rows[pivotI]/rows[pivotI][pivotJ];576 if(scalePivotsToOne) 577 (*this)[pivotI]=(*this)[pivotI].toVector()/(*this)[pivotI][pivotJ]; 416 578 for(int i=0;i<pivotI;i++) 417 if(! rows[i][pivotJ].isZero())418 madd(pivotI,- rows[i][pivotJ]/rows[pivotI][pivotJ],i);419 }579 if(!(*this)[i][pivotJ].isZero()) 580 madd(pivotI,-(*this)[i][pivotJ]/(*this)[pivotI][pivotJ],i); 581 } 420 582 return ret; 421 583 } … … 438 600 if(!v[pivotJ].isZero()) 439 601 { 440 typ s=-v[pivotJ]/ rows[pivotI][pivotJ];602 typ s=-v[pivotJ]/(*this)[pivotI][pivotJ]; 441 603 442 604 for(int k=0;k<width;k++) 443 if(! rows[pivotI][k].isZero())444 v[k].madd( rows[pivotI][k],s);605 if(!(*this)[pivotI][k].isZero()) 606 v[k].madd((*this)[pivotI][k],s); 445 607 } 446 608 return v; … … 472 634 while(nextPivot(pivot2I,pivot2J)) 473 635 { 474 ret[k][pivot2J]= rows[pivot2I][j]/rows[pivot2I][pivot2J];636 ret[k][pivot2J]=(*this)[pivot2I][j]/(*this)[pivot2I][pivot2J]; 475 637 } 476 638 ret[k][j]=typ(-1); … … 508 670 while(nextPivot(pivot2I,pivot2J)) 509 671 { 510 diagonalProduct*= rows[pivot2I][pivot2J];672 diagonalProduct*=(*this)[pivot2I][pivot2J]; 511 673 } 512 674 } … … 522 684 while(nextPivot(pivot2I,pivot2J)) 523 685 { 524 ret[pivot2J]= rows[pivot2I][j]/rows[pivot2I][pivot2J];686 ret[pivot2J]=(*this)[pivot2I][j]/(*this)[pivot2I][pivot2J]; 525 687 lastEntry-=ret[pivot2J]*ret[pivot2J]; 526 688 } … … 546 708 * Sort the rows of the matrix. 547 709 */ 710 struct rowComparer{ 711 bool operator()(std::pair<Matrix*,int> i, std::pair<Matrix*,int> j) {return ((*i.first)[i.second].toVector()<(*j.first)[j.second].toVector());} 712 } theRowComparer; 548 713 void sortRows() 549 714 { 550 std::sort(rows.begin(),rows.end()); 715 std::vector<std::pair<Matrix*,int> > v; 716 for(int i=0;i<height;i++)v.push_back(std::pair<Matrix*,int>(this,i)); 717 std::sort(v.begin(),v.end(),theRowComparer); 718 Matrix result(height,width); 719 for(int i=0;i<height;i++) 720 result[i]=(*this)[v[i].second].toVector(); 721 data=result.data; 551 722 } 552 723 /** … … 560 731 B.appendRow((*this)[0]); 561 732 for(int i=1;i<getHeight();i++) 562 if( rows[i]!=rows[i-1])B.appendRow((*this)[i]);733 if((*this)[i].toVector()!=(*this)[i-1].toVector())B.appendRow((*this)[i].toVector()); 563 734 *this=B; 564 735 } … … 573 744 assert(bottom.getWidth()==top.getWidth()); 574 745 Matrix ret(top.getHeight()+bottom.getHeight(),top.getWidth()); 575 for(int i=0;i<top.getHeight();i++)ret .rows[i]=top.rows[i];576 for(int i=0;i<bottom.getHeight();i++)ret .rows[i+top.getHeight()]=bottom.rows[i];746 for(int i=0;i<top.getHeight();i++)ret[i]=top[i]; 747 for(int i=0;i<bottom.getHeight();i++)ret[i+top.getHeight()]=bottom[i]; 577 748 578 749 return ret; … … 590 761 for(int i=0;i<left.getHeight();i++) 591 762 { 592 for(int j=0;j<left.getWidth();j++)ret .rows[i][j]=left.rows[i][j];593 for(int j=0;j<right.getWidth();j++)ret .rows[i][j+left.getWidth()]=right.rows[i][j];763 for(int j=0;j<left.getWidth();j++)ret[i][j]=left[i][j]; 764 for(int j=0;j<right.getWidth();j++)ret[i][j+left.getWidth()]=right[i][j]; 594 765 } 595 766 return ret; -
gfanlib/gfanlib_polyhedralfan.cpp
r6a97c54 r7cc3fd 71 71 int PolyhedralFan::getMaxDimension()const 72 72 { 73 if (cones.empty()) 74 return -1; 73 assert(!cones.empty()); 75 74 76 75 return cones.begin()->dimension(); … … 79 78 int PolyhedralFan::getMinDimension()const 80 79 { 81 if (cones.empty()) 82 return -1; 80 assert(!cones.empty()); 83 81 84 82 return cones.rbegin()->dimension(); … … 355 353 bool notAll=false; 356 354 for(unsigned j=0;j<theCone.indices.size();j++) 357 if(dot(rays[theCone.indices[j]] ,facetCandidates[i]).sign()==0)355 if(dot(rays[theCone.indices[j]].toVector(),facetCandidates[i].toVector()).sign()==0) 358 356 indices.insert(theCone.indices[j]); 359 357 else … … 864 862 int PolyhedralFan::dimensionOfLinealitySpace()const 865 863 { 866 if (cones.empty()) 867 return n; 864 assert(cones.size());//slow! 868 865 return cones.begin()->dimensionOfLinealitySpace(); 869 866 } -
gfanlib/gfanlib_q.h
r6a97c54 r7cc3fd 11 11 #include <string.h> 12 12 #include <ostream> 13 #include <assert.h> 13 14 #include "gmp.h" 14 15 … … 160 161 return mpq_sgn(value); 161 162 } 162 static Rational gcd(Rational const &a, Rational const /*&b*/, Rational /*&s*/, Rational /*&t*/)163 static Rational gcd(Rational const &a, Rational const &b, Rational &s, Rational &t) 163 164 { 164 165 /* mpz_t r; … … 167 168 Integer ret(r); 168 169 mpz_clear(r);*/ 169 assert(0); 170 return a; 171 } 172 static Rational gcd(Rational const &a, Rational const /*&b*/) 173 { 174 /* mpz_t r; 175 mpz_init(r); 176 mpz_gcdext(r,s.value,t.value,a.value,b.value); 177 Integer ret(r); 178 mpz_clear(r);*/ 179 assert(0); 170 assert(0 && "gcd for Rational not defined"); 180 171 return a; 181 172 } -
gfanlib/gfanlib_symmetriccomplex.cpp
r6a97c54 r7cc3fd 185 185 int SymmetricComplex::getLinDim()const 186 186 { 187 return linealitySpace.getHeight();187 return linealitySpace.getHeight(); 188 188 } 189 189 … … 595 595 596 596 if(flags&FPF_cones)polymakeFile.writeStringProperty("CONES",toStringJustCones(getMinDim(),getMaxDim(),false,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); 597 std::stringstream multiplicities; 598 if(flags&FPF_maximalCones)polymakeFile.writeStringProperty("MAXIMAL_CONES",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, &multiplicities,false,flags&FPF_tPlaneSort)); 597 if(flags&FPF_maximalCones)polymakeFile.writeStringProperty("MAXIMAL_CONES",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,false,flags&FPF_tPlaneSort)); 599 598 if(flags&FPF_conesCompressed)polymakeFile.writeStringProperty("CONES_ORBITS",toStringJustCones(getMinDim(),getMaxDim(),false,flags&FPF_group, 0,true,flags&FPF_tPlaneSort)); 600 599 if((flags&FPF_conesCompressed) && (flags&FPF_maximalCones))polymakeFile.writeStringProperty("MAXIMAL_CONES_ORBITS",toStringJustCones(getMinDim(),getMaxDim(),true,flags&FPF_group, 0,true,flags&FPF_tPlaneSort)); 601 if(flags&FPF_multiplicities)polymakeFile.writeStringProperty("MULTIPLICITIES",multiplicities.str());602 600 603 601 if(!sym.isTrivial()) … … 637 635 stringstream multiplicities; 638 636 polymakeFile.writeStringProperty("MAXIMAL_CONES",symCom.toString(symCom.getMinDim(),symCom.getMaxDim(),true,flags&FPF_group, &multiplicities,false,flags&FPF_tPlaneSort)); 637 if(flags&FPF_multiplicities)polymakeFile.writeStringProperty("MULTIPLICITIES",multiplicities.str()); 639 638 // log1 fprintf(Stderr,"Done producing list of maximal cones.\n"); 640 639 } -
gfanlib/gfanlib_vector.h
r6a97c54 r7cc3fd 72 72 // Access 73 73 //-------- 74 typ& operator[](int n) 74 typ& operator[](int n)__attribute__((always_inline)) 75 75 { 76 76 if(!(n>=0 && n<(int)v.size()))outOfRange(n,v.size()); 77 77 return (v[n]); 78 78 } 79 const typ& operator[](int n)const{assert(n>=0 && n<(int)v.size());return (v[n]);} 80 const typ& UNCHECKEDACCESS(int n)const{return (v[n]);} 79 const typ& operator[](int n)const __attribute__((always_inline)){assert(n>=0 && n<(int)v.size());return (v[n]);} 80 typ& UNCHECKEDACCESS(int n)__attribute__((always_inline)){return (v[n]);} 81 const typ& UNCHECKEDACCESS(int n)const __attribute__((always_inline)){return (v[n]);} 81 82 82 83 //------------- … … 85 86 unsigned int size()const{return v.size();}; 86 87 void resize(int n){v.resize(n,typ());}; 87 void grow(int i){if( (int)size()<i)resize(i);}88 void grow(int i){if(size()<i)resize(i);} 88 89 void push_back(typ a) 89 90 { … … 293 294 std::string toString()const 294 295 { 295 std::stringstream f;296 f<<*this;297 return f.str();296 std::stringstream f; 297 f<<*this; 298 return f.str(); 298 299 } 299 300 300 301 typ gcd()const 301 302 { 303 typ temp1,temp2; 302 304 typ ret(1); 303 305 for(unsigned i=0;i<size();i++) 304 ret=typ::gcd(ret,v[i] );306 ret=typ::gcd(ret,v[i],temp1,temp2); 305 307 return ret; 306 308 } … … 309 311 assert(!typ::isField()); 310 312 return (*this)/gcd(); 311 }312 313 void debugPrint()const314 {315 std::stringstream s;316 s<<"(";317 for(typename std::vector<typ>::const_iterator i=this->v.begin();i!=this->v.end();i++)318 {319 if(i!=this->v.begin()) s<<",";320 s<<*i;321 }322 s<<")"<<std::endl;323 std::cout << s.str();324 return;325 313 } 326 314 }; … … 415 403 416 404 return ret; 417 } ;418 419 } ;405 } 406 407 } 420 408 421 409 #endif /* LIB_ZVECTOR_H_ */ -
gfanlib/gfanlib_z.h
r6a97c54 r7cc3fd 10 10 11 11 #include <string.h> 12 #include <iostream>13 12 #include <ostream> 14 13 … … 41 40 mpz_init_set(value,value_.value); 42 41 } 43 Integer(mpz_t value_)42 Integer(mpz_t const value_) 44 43 { 45 44 mpz_init_set(value,value_); … … 60 59 bool isZero()const{ 61 60 return mpz_sgn(value)==0; 62 }63 bool isOne()const{64 return mpz_cmp_si(value,1);65 61 } 66 62 friend std::ostream &operator<<(std::ostream &f, Integer const &a) … … 73 69 return f; 74 70 } 75 void debugPrint() const76 {77 void (*freefunc)(void *, size_t);78 mp_get_memory_functions(0,0,&freefunc);79 char *str=mpz_get_str(0,10,value);80 std::cout << str;81 freefunc(str,strlen(str)+1);82 return;83 }84 71 Integer& operator+=(const Integer& a) 85 72 { … … 161 148 mpz_init(r); 162 149 mpz_gcdext(r,s.value,t.value,a.value,b.value); 163 Integer ret(r);164 mpz_clear(r);165 return ret;166 }167 static Integer gcd(Integer const &a, Integer const &b)168 {169 if (a.isOne() || b.isOne())170 return Integer(1);171 mpz_t r;172 mpz_init(r);173 mpz_gcd(r,a.value,b.value);174 150 Integer ret(r); 175 151 mpz_clear(r); … … 354 330 return f; 355 331 } 356 friend void debugPrint(IntegerTemplate const &a)357 {358 std::cout << a << std::endl;359 return;360 }361 332 LimbWord signExtension(LimbWord a) 362 333 { -
gfanlib/gfanlib_zcone.cpp
r6a97c54 r7cc3fd 26 26 #endif //HAVE_CDD_SETOPER_H 27 27 28 28 29 namespace gfan{ 29 30 static void cddinitGmp() 31 { 32 static bool initialized; 33 if(!initialized) 30 bool isCddlibRequired() 31 { 32 return true; 33 } 34 void initializeCddlibIfRequired() // calling this frequently will cause memory leaks because deinitialisation is not possible with old versions of cddlib. 35 { 36 dd_set_global_constants(); 37 } 38 void deinitializeCddlibIfRequired() 39 { 40 #ifdef HAVE_DD_FREE_GLOBAL_CONSTANTS 41 dd_free_global_constants(); 42 #endif 43 } 44 static void ensureCddInitialisation() 45 { 46 // A more complicated initialisation than the following (meaning attempts to count the number of times 47 // cddlib was requested to be initialised) would require cddlib to be thread aware. 48 // The error below is implemented with an assert(0) because throwing an exception may leave the impression that 49 // it is possible to recover from this error. While that may be true, it would not work in full generality, 50 // as the following if statement cannot test whether dd_free_global_constants() has also been called. 51 // Moverover, in multithreaded environments it would be quite difficult to decide if cddlib was initialised. 52 if(!dd_one[0]._mp_num._mp_d) 53 { 54 std::cerr<<"CDDLIB HAS NOT BEEN INITIALISED!\n" 55 "\n" 56 "Fix this problem by calling the following function in your initialisation code:\n" 57 "dd_set_global_constants();\n" 58 "(after possibly setting the gmp allocators) and\n" 59 "dd_free_global_constants()\n" 60 "in your deinitialisation code (only available for cddlib version>=094d).\n" 61 "This requires the header includes:\n" 62 "#include \"cdd/setoper.h\"\n" 63 "#include \"cdd/cdd.h\"\n" 64 "\n" 65 "Alternatively, you may call gfan:initializeCddlibIfRequired() and deinitializeCddlibIfRequired()\n" 66 "if gfanlib is the only code using cddlib. If at some point cddlib is no longer required by gfanlib\n" 67 "these functions may do nothing.\n" 68 "Because deinitialisation is not possible in cddlib <094d, the functions may leak memory and should not be called often.\n" 69 "\n" 70 "This error message will never appear if the initialisation was done properly, and therefore never appear in a shipping version of your software.\n"; 71 assert(0); 72 } 73 /* 74 static bool initialized; 75 if(!initialized) 34 76 { 35 dd_set_global_constants(); /* First, this must be called. */36 initialized=true;37 } 77 dd_set_global_constants(); 78 initialized=true; 79 }*/ 38 80 } 39 81 … … 85 127 int numberOfRows=g.getHeight(); 86 128 dd_MatrixPtr A=NULL; 87 cddinitGmp();129 ensureCddInitialisation(); 88 130 A=ZMatrix2MatrixGmp(g, err); 89 131 for(int i=numberOfInequalities;i<numberOfRows;i++) … … 121 163 FILE *reading=NULL; 122 164 123 cddinitGmp();165 ensureCddInitialisation(); 124 166 125 167 M=ZMatrix2MatrixGmp(g, &err); … … 128 170 // d=M->colsize; 129 171 130 static dd_Arow temp; 172 //static dd_Arow temp; 173 dd_Arow temp; 131 174 dd_InitializeArow(g.getWidth()+1,&temp); 132 175 … … 268 311 for(int i=0;i<a.getHeight();i++) 269 312 { 270 assert(!(a[i]. isZero()));271 b.insert(a[i]. normalized());313 assert(!(a[i].toVector().isZero())); 314 b.insert(a[i].toVector().normalized()); 272 315 } 273 316 … … 302 345 for(int i=0;i!=original.getHeight();i++) 303 346 for(int j=0;j!=a.getHeight();j++) 304 if(!dependent(original[i] ,a[j]))347 if(!dependent(original[i].toVector(),a[j].toVector())) 305 348 { 306 349 ZVector const &I=original[i]; … … 337 380 void removeRedundantRows(ZMatrix &inequalities, ZMatrix &equations, bool removeInequalityRedundancies) 338 381 { 339 cddinitGmp();382 ensureCddInitialisation(); 340 383 341 384 int numberOfEqualities=equations.getHeight(); … … 403 446 { 404 447 QVector retUnscaled(inequalities.getWidth()); 405 cddinitGmp();448 ensureCddInitialisation(); 406 449 int numberOfEqualities=equations.getHeight(); 407 450 int numberOfInequalities=inequalities.getHeight(); … … 459 502 dd_ErrorType err=dd_NoError; 460 503 461 cddinitGmp();504 ensureCddInitialisation(); 462 505 463 506 A=ZMatrix2MatrixGmp(inequalities, equations, &err); … … 567 610 dd_ErrorType err=dd_NoError; 568 611 569 cddinitGmp();612 ensureCddInitialisation(); 570 613 A=ZMatrix2MatrixGmp(inequalities, &err); 571 614 … … 751 794 f<<*this; 752 795 return f.str(); 753 // =======754 // std::stringstream s;755 // s<<"AMBIENT_DIM"<<std::endl;756 // s<<this->ambientDimension()<<std::endl;757 758 // gfan::ZMatrix i=this->getInequalities();759 // if (this->areFacetsKnown())760 // s<<"FACETS"<<std::endl;761 // else762 // s<<"INEQUALITIES"<<std::endl;763 // s<<i<<std::endl;764 765 // gfan::ZMatrix e=this->getEquations();766 // if (this->areImpliedEquationsKnown())767 // s<<"LINEAR_SPAN"<<std::endl;768 // else769 // s<<"EQUATIONS"<<std::endl;770 // s<<e<<std::endl;771 772 // gfan::ZMatrix r=this->extremeRays();773 // s<<"RAYS"<<std::endl;774 // s<<r<<std::endl;775 776 // gfan::ZMatrix l=this->generatorsOfLinealitySpace();777 // s<<"LINEALITY_SPACE"<<std::endl;778 // s<<l<<std::endl;779 780 // std::cout << s.str();781 // return;782 // >>>>>>> chg: status update 17.07.783 796 } 784 797 … … 1238 1251 1239 1252 for(int i=0;i<M.getHeight();i++) 1240 if(M[i]. subvector(0,a).isZero()&&!M[i].subvector(a,a+b).isZero())1253 if(M[i].toVector().subvector(0,a).isZero()&&!M[i].toVector().subvector(a,a+b).isZero()) 1241 1254 { 1242 ret.appendRow(M[i]. subvector(a+b,a+b+n));1255 ret.appendRow(M[i].toVector().subvector(a+b,a+b+n)); 1243 1256 } 1244 1257 … … 1252 1265 assert(temp.getHeight()==1); 1253 1266 for(int i=0;i<inequalities.getHeight();i++) 1254 if(dot(temp[0] ,inequalities[i]).sign()<0)1267 if(dot(temp[0].toVector(),inequalities[i].toVector()).sign()<0) 1255 1268 { 1256 temp[0]=-temp[0] ;1269 temp[0]=-temp[0].toVector(); 1257 1270 break; 1258 1271 } … … 1338 1351 } 1339 1352 1340 } ;1353 } -
gfanlib/gfanlib_zcone.h
r6a97c54 r7cc3fd 10 10 11 11 #include "gfanlib_matrix.h" 12 #include <sstream>13 12 14 13 namespace gfan{ 15 14 /** 15 * Returns true if cddlib is needed for the ZCone implementation. 16 */ 17 bool isCddlibRequired(); 18 /** 19 * Only call this function if gfanlib is the only code in your program using cddlib. 20 * Should be paired with a deinitializeCddlibIfRequired() call. 21 * Calling the function repeatedly may cause memory leaks even if deinitializeCddlibIfRequired() is also called. 22 */ 23 void initializeCddlibIfRequired(); 24 /** 25 * This function may do nothing. 26 */ 27 void deinitializeCddlibIfRequired(); 16 28 17 29 /** … … 358 370 }; 359 371 360 }; 372 } 373 374 361 375 362 376 -
m4/gfanlib-check.m4
r6a97c54 r7cc3fd 55 55 AC_LANG_POP() 56 56 57 AC_CHECK_FUNCS(dd_free_global_constants) 58 57 59 LIBS=$BACKUP_LIBS 58 60
Note: See TracChangeset
for help on using the changeset viewer.