[libcxx-commits] [libcxx] [MLIR][Presburger] Implement matrix inverse (PR #67382)
Arjun P via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 17 09:29:35 PDT 2023
================
@@ -432,4 +432,138 @@ MPInt IntMatrix::normalizeRow(unsigned row, unsigned cols) {
MPInt IntMatrix::normalizeRow(unsigned row) {
return normalizeRow(row, getNumColumns());
+}
+
+MPInt IntMatrix::determinant() {
+ unsigned r = getNumRows();
+ unsigned c = getNumColumns();
+ assert(r == c);
+
+ FracMatrix m(r, c);
+ for (unsigned i = 0; i < r; i++)
+ for (unsigned j = 0; j < c; j++)
+ m.at(i, j) = Fraction(at(i, j), 1);
+
+ Fraction det = m.determinant();
+
+ return det.getAsInteger();
+}
+
+std::optional<IntMatrix> IntMatrix::integerInverse() {
+ Fraction det = Fraction(determinant(), 1);
+ FracMatrix newMat(getNumRows(), getNumColumns());
+ for (unsigned i = 0; i < getNumRows(); i++)
+ for (unsigned j = 0; j < getNumColumns(); j++)
+ newMat(i, j) = Fraction(at(i, j), 1);
----------------
Superty wrote:
sure. make it an explicit constructor
https://github.com/llvm/llvm-project/pull/67382
More information about the libcxx-commits
mailing list