[Mlir-commits] [mlir] [MLIR][Presburger] Add support for Smith normal form (PR #185328)
Arjun Pitchanathan
llvmlistbot at llvm.org
Mon Mar 16 06:45:50 PDT 2026
================
@@ -535,6 +553,151 @@ std::pair<IntMatrix, IntMatrix> IntMatrix::computeHermiteNormalForm() const {
return {h, u};
}
+// In the submatrix `mat(from:, from:)`, the function finds the position (row,
+// col) of the element with smallest non-zero absolute value. When all elements
+// in the submatrix are zero, returns std::nullopt.
+static std::optional<std::pair<unsigned, unsigned>>
+nonZeroMinInSubmatrix(const IntMatrix &mat, unsigned from) {
+ unsigned numRows = mat.getNumRows();
+ unsigned numCols = mat.getNumColumns();
+ unsigned minRow = from, minCol = from;
+
+ std::optional<DynamicAPInt> minVal;
+ for (unsigned r = from; r < numRows; r++) {
+ for (unsigned c = from; c < numCols; c++) {
+ DynamicAPInt val = llvm::abs(mat(r, c));
+ if (val == 0 || (minVal && val >= *minVal))
+ continue;
+
+ minVal = val;
+ minRow = r;
+ minCol = c;
+ }
+ }
+
+ if (!minVal)
+ return std::nullopt;
+
+ return std::make_pair(minRow, minCol);
+}
+
+// Finds the first row in submatrix `mat(from:, from:)` that contains an element
+// `d` such that `d` is not a multiple of `pivot`. When there is no such row,
+// returns std::nullopt.
+static std::optional<unsigned> findNonMultipleRow(const IntMatrix &mat,
+ unsigned from,
+ const DynamicAPInt &pivot) {
----------------
superty wrote:
nit: the term `pivot` has no meaning in this function's context, so you can name it like `divisor` or whatever
https://github.com/llvm/llvm-project/pull/185328
More information about the Mlir-commits
mailing list