|
| 1 | +#include "mlir/Analysis/Presburger/Barvinok.h" |
| 2 | +#include "./Utils.h" |
| 3 | +#include <gmock/gmock.h> |
| 4 | +#include <gtest/gtest.h> |
| 5 | + |
| 6 | +using namespace mlir; |
| 7 | +using namespace presburger; |
| 8 | +using namespace mlir::presburger::detail; |
| 9 | + |
| 10 | +/// The following are 3 randomly generated vectors with 4 |
| 11 | +/// entries each and define a cone's H-representation |
| 12 | +/// using these numbers. We check that the dual contains |
| 13 | +/// the same numbers. |
| 14 | +/// We do the same in the reverse case. |
| 15 | +TEST(BarvinokTest, getDual) { |
| 16 | + ConeH cone1 = defineHRep(4); |
| 17 | + cone1.addInequality({1, 2, 3, 4, 0}); |
| 18 | + cone1.addInequality({3, 4, 2, 5, 0}); |
| 19 | + cone1.addInequality({6, 2, 6, 1, 0}); |
| 20 | + |
| 21 | + ConeV dual1 = getDual(cone1); |
| 22 | + |
| 23 | + EXPECT_EQ_INT_MATRIX( |
| 24 | + dual1, makeIntMatrix(3, 4, {{1, 2, 3, 4}, {3, 4, 2, 5}, {6, 2, 6, 1}})); |
| 25 | + |
| 26 | + ConeV cone2 = makeIntMatrix(3, 4, {{3, 6, 1, 5}, {3, 1, 7, 2}, {9, 3, 2, 7}}); |
| 27 | + |
| 28 | + ConeH dual2 = getDual(cone2); |
| 29 | + |
| 30 | + ConeH expected = defineHRep(4); |
| 31 | + expected.addInequality({3, 6, 1, 5, 0}); |
| 32 | + expected.addInequality({3, 1, 7, 2, 0}); |
| 33 | + expected.addInequality({9, 3, 2, 7, 0}); |
| 34 | + |
| 35 | + EXPECT_TRUE(dual2.isEqual(expected)); |
| 36 | +} |
| 37 | + |
| 38 | +/// We randomly generate a nxn matrix to use as a cone |
| 39 | +/// with n inequalities in n variables and check for |
| 40 | +/// the determinant being equal to the index. |
| 41 | +TEST(BarvinokTest, getIndex) { |
| 42 | + ConeV cone = makeIntMatrix(3, 3, {{4, 2, 1}, {5, 2, 7}, {4, 1, 6}}); |
| 43 | + EXPECT_EQ(getIndex(cone), cone.determinant()); |
| 44 | + |
| 45 | + cone = makeIntMatrix( |
| 46 | + 4, 4, {{4, 2, 5, 1}, {4, 1, 3, 6}, {8, 2, 5, 6}, {5, 2, 5, 7}}); |
| 47 | + EXPECT_EQ(getIndex(cone), cone.determinant()); |
| 48 | +} |
0 commit comments