[Mlir-commits] [mlir] e213af7 - [MLIR][Presburger] Fix a bug with determinant of IntMatrix (#76622)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Dec 30 12:03:06 PST 2023
Author: Abhinav271828
Date: 2023-12-30T22:03:01+02:00
New Revision: e213af78b2571764d87dabb183fdc1a344a822aa
URL: https://github.com/llvm/llvm-project/commit/e213af78b2571764d87dabb183fdc1a344a822aa
DIFF: https://github.com/llvm/llvm-project/commit/e213af78b2571764d87dabb183fdc1a344a822aa.diff
LOG: [MLIR][Presburger] Fix a bug with determinant of IntMatrix (#76622)
Fixed a bug where IntMatrix determinant() had a bug where it would try to assign to a null
pointer.
Added a test case that triggers this bug to avoid regressions.
Added:
Modified:
mlir/lib/Analysis/Presburger/Matrix.cpp
mlir/unittests/Analysis/Presburger/MatrixTest.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 25300f84cfc047..1f1188c115a8b5 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -452,6 +452,9 @@ MPInt IntMatrix::determinant(IntMatrix *inverse) const {
if (detM == 0)
return MPInt(0);
+ if (!inverse)
+ return detM;
+
*inverse = IntMatrix(nRows, nColumns);
for (unsigned i = 0; i < nRows; i++)
for (unsigned j = 0; j < nColumns; j++)
diff --git a/mlir/unittests/Analysis/Presburger/MatrixTest.cpp b/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
index e6e452790f82d1..103619518c15a2 100644
--- a/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
@@ -251,6 +251,9 @@ TEST(MatrixTest, computeHermiteNormalForm) {
}
TEST(MatrixTest, inverse) {
+ IntMatrix mat1 = makeIntMatrix(2, 2, {{2, 1}, {7, 0}});
+ EXPECT_EQ(mat1.determinant(), -7);
+
FracMatrix mat = makeFracMatrix(
2, 2, {{Fraction(2), Fraction(1)}, {Fraction(7), Fraction(0)}});
FracMatrix inverse = makeFracMatrix(
More information about the Mlir-commits
mailing list