[Mlir-commits] [mlir] [mlir][test] Add unittests for `getInversePermutation` (PR #116945)
Javed Absar
llvmlistbot at llvm.org
Thu Nov 21 03:59:34 PST 2024
================
@@ -76,3 +76,39 @@ TEST(AffineMapTest, isProjectedPermutation) {
AffineMap map10 = AffineMap::get(6, 0, {d5, d3, d2, d4}, &ctx);
EXPECT_TRUE(map10.isProjectedPermutation());
}
+
+TEST(AffineMapTest, getInversePermutation) {
+ MLIRContext ctx;
+ OpBuilder b(&ctx);
+
+ // 0. Empty map
+ AffineMap map0 = AffineMap::get(0, 0, {}, &ctx);
+ AffineMap inverseMap0 = inversePermutation(map0);
+ EXPECT_TRUE(inverseMap0.isEmpty());
+
+ auto d0 = b.getAffineDimExpr(0);
+ auto d1 = b.getAffineDimExpr(1);
+ auto d2 = b.getAffineDimExpr(2);
+
+ // 1. (d0, d1, d2) -> (d1, d1, d0, d2, d1, d2, d1, d0)
+ AffineMap map1 = AffineMap::get(3, 0, {d1, d1, d0, d2, d1, d2, d1, d0}, &ctx);
+ // (d0, d1, d2, d3, d4, d5, d6, d7) -> (d2, d0, d3)
+ AffineMap inverseMap1 = inversePermutation(map1);
+ auto resultsInv1 = inverseMap1.getResults();
+ EXPECT_EQ(resultsInv1.size(), 3UL);
+ EXPECT_TRUE(resultsInv1[0].isFunctionOfDim(2));
----------------
javedabsar1 wrote:
Please double check this instead of fully trusting me. But I think in case of `isFunctionOfDim`, `2` has to appear somewhere in the expression e.g. `d2+d1`, and so is a less restrictive ask then if we are really check `d2` and only `d2.
```
auto expr = llvm::dyn_cast<AffineDimExpr>(resultsInv1[0]);
if (!expr) EXPECT_EQ(0,1);
EXPECT_EQ(expr.getPosition(), 2)
```
https://github.com/llvm/llvm-project/pull/116945
More information about the Mlir-commits
mailing list