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

Mehdi Amini llvmlistbot at llvm.org
Sat Jan 20 10:14:08 PST 2024


================
@@ -537,4 +537,35 @@ 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;
+}
+
+std::vector<Fraction> presburger::convolution(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();
+
+  // We define accessors to avoid out-of-bounds errors.
+  std::function<Fraction(unsigned i)> aGetItem = [a](unsigned i) -> Fraction {
+    if (i < a.size())
+      return a[i];
+    else
+      return 0;
+  };
+  std::function<Fraction(unsigned i)> bGetItem = [b](unsigned i) -> Fraction {
----------------
joker-eph wrote:

Nit: use auto for lambda capture.
And function_ref instead of std::function when the functor isn't stored.

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


More information about the Mlir-commits mailing list