[Mlir-commits] [mlir] [MLIR][Presburger] Implement function to evaluate the number of terms in a generating function. (PR #78078)

Arjun P llvmlistbot at llvm.org
Sun Jan 21 12:21:23 PST 2024


================
@@ -537,4 +537,31 @@ Fraction presburger::dotProduct(ArrayRef<Fraction> a, ArrayRef<Fraction> b) {
   for (unsigned i = 0, e = a.size(); i < e; i++)
     sum += a[i] * b[i];
   return sum;
+}
+
+/// Find the product of two polynomials, each given by an array of
+/// coefficients, by taking the convolution.
+std::vector<Fraction> presburger::multiplyPolynomials(ArrayRef<Fraction> a,
+                                                      ArrayRef<Fraction> b) {
+  // The length of the convolution is the sum of the lengths
+  // of the two sequences. We pad the shorter one with zeroes.
+  unsigned len = a.size() + b.size() - 1;
+
+  // We define accessors to avoid out-of-bounds errors.
+  auto getItem = [](ArrayRef<Fraction> arr, unsigned i) -> Fraction {
----------------
Superty wrote:

getCoeff makes more sense as a name since it explains why we should return zero for higher indices

https://github.com/llvm/llvm-project/pull/78078


More information about the Mlir-commits mailing list