[Mlir-commits] [mlir] [MLIR][Presburger] Implement computation of generating function for unimodular cones (PR #77235)
Arjun P
llvmlistbot at llvm.org
Tue Jan 9 07:33:42 PST 2024
================
@@ -63,3 +64,80 @@ MPInt mlir::presburger::detail::getIndex(ConeV cone) {
return cone.determinant();
}
+
+/// Compute the generating function for a unimodular cone.
+/// This consists of a single term of the form
+/// sign * x^num / prod_j (1 - x^den_j)
+///
+/// sign is either +1 or -1.
+/// den_j is defined as the set of generators of the cone.
+/// num is computed by expressing the vertex as a weighted
+/// sum of the generators, and then taking the floor of the
+/// coefficients.
+GeneratingFunction mlir::presburger::detail::unimodularConeGeneratingFunction(
+ ParamPoint vertex, int sign, ConeH cone) {
+ // `cone` must be unimodular.
+ assert(getIndex(getDual(cone)) == 1 && "input cone is not unimodular!");
+
+ unsigned numVar = cone.getNumVars();
+ unsigned numIneq = cone.getNumInequalities();
+
+ // Thus its ray matrix, U, is the inverse of the
+ // transpose of its inequality matrix, `cone`.
+ // The last column of the inequality matrix is null,
+ // so we remove it to obtain a square matrix.
+ FracMatrix transp = FracMatrix(cone.getInequalities()).transpose();
+ transp.removeRow(numVar);
+
+ FracMatrix generators(numVar, numIneq);
+ transp.determinant(/*inverse=*/&generators); // This is the U-matrix.
+
+ // The powers in the denominator of the generating
+ // function are given by the generators of the cone,
+ // i.e., the rows of the matrix U.
+ std::vector<Point> denominator(numIneq);
+ ArrayRef<Fraction> row;
+ for (auto i : llvm::seq<int>(0, numVar)) {
+ row = generators.getRow(i);
+ denominator[i] = Point(row);
+ }
+
+ // The vertex is v \in Z^{d x (n+1)}
+ // We need to find affine functions of parameters λ_i(p)
+ // such that v = Σ λ_i(p)*u_i.
----------------
Superty wrote:
what are u_i?
https://github.com/llvm/llvm-project/pull/77235
More information about the Mlir-commits
mailing list