[Mlir-commits] [mlir] [mlir][affine] Add unit tests for `isProjectedPermutation` (PR #114775)
Javed Absar
llvmlistbot at llvm.org
Mon Nov 4 11:32:32 PST 2024
================
@@ -21,3 +21,44 @@ TEST(AffineMapTest, inferMapFromAffineExprs) {
map.replace(replacements);
EXPECT_EQ(map, map);
}
+
+TEST(AffineMapTest, isProjectedPermutation) {
+ MLIRContext ctx;
+ OpBuilder b(&ctx);
+
+ // 1. Empty map - a projected permutation.
+ AffineMap map1 = b.getEmptyAffineMap();
+ EXPECT_TRUE(map1.isProjectedPermutation());
+
+ // 2. Contains a symbol - not a projected permutation.
+ AffineMap map2 = AffineMap::get(0, 1, &ctx);
+ EXPECT_FALSE(map2.isProjectedPermutation());
+
+ // 3. The result map is {0} - since zero results are _allowed_, this _is_ a
+ // projected permutation.
+ auto zero = b.getAffineConstantExpr(0);
+ AffineMap map3 = AffineMap::get(1, 0, {zero}, &ctx);
+ EXPECT_TRUE(map3.isProjectedPermutation(/*allowZeroInResults=*/true));
+
+ // 4. The result map is {0} - since zero results are _not allowed_, this _is
+ // not_ a projected permutation.
+ AffineMap map4 = AffineMap::get(1, 0, {zero}, &ctx);
+ EXPECT_FALSE(map4.isProjectedPermutation(/*allowZeroInResults=*/false));
+
+ // 5. The number of results > inputs, not a projected permutation.
+ AffineMap map5 = AffineMap::get(1, 0, {zero, zero}, &ctx);
+ EXPECT_FALSE(map5.isProjectedPermutation(/*allowZeroInResults=*/true));
+
+ // 6. A constant result that's not a {0} - not a projected permutation.
+ auto one = b.getAffineConstantExpr(1);
+ AffineMap map6 = AffineMap::get(1, 0, {one}, &ctx);
+ EXPECT_FALSE(map6.isProjectedPermutation(/*allowZeroInResults=*/true));
+
+ // 7. Not a dim expression - not a projected permutation.
+ auto d0 = b.getAffineDimExpr(0);
+ auto d1 = b.getAffineDimExpr(1);
+
----------------
javedabsar1 wrote:
Maybe add some tougher tests
(d0,d1, d2, d3,d4,d5) ->(d5,d3,d0,d1,d2,d4)
(d0,d1, d2, d3,d4,d5) ->(d5,d3,d0+d1,d2,d4)
(d0,d1, d2, d3,d4,d5) ->(d5,d3,d2,d4)
https://github.com/llvm/llvm-project/pull/114775
More information about the Mlir-commits
mailing list