Skip to content

Commit ef83b59

Browse files
committed
fixup! [mlir][affine] Add unit tests for isProjectedPermutation
Fix comments, add more cases
1 parent 9f03639 commit ef83b59

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

mlir/unittests/IR/AffineMapTest.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,53 @@ TEST(AffineMapTest, isProjectedPermutation) {
2626
MLIRContext ctx;
2727
OpBuilder b(&ctx);
2828

29-
// 1. Empty map - a projected permutation.
29+
// 1. Empty map
3030
AffineMap map1 = b.getEmptyAffineMap();
3131
EXPECT_TRUE(map1.isProjectedPermutation());
3232

33-
// 2. Contains a symbol - not a projected permutation.
33+
// 2. Map with a symbol
3434
AffineMap map2 = AffineMap::get(0, 1, &ctx);
3535
EXPECT_FALSE(map2.isProjectedPermutation());
3636

37-
// 3. The result map is {0} - since zero results are _allowed_, this _is_ a
38-
// projected permutation.
37+
// 3. The result map is {0} and zero results are _allowed_.
3938
auto zero = b.getAffineConstantExpr(0);
4039
AffineMap map3 = AffineMap::get(1, 0, {zero}, &ctx);
4140
EXPECT_TRUE(map3.isProjectedPermutation(/*allowZeroInResults=*/true));
4241

43-
// 4. The result map is {0} - since zero results are _not allowed_, this _is
44-
// not_ a projected permutation.
42+
// 4. The result map is {0} and zero results are _not allowed_
4543
AffineMap map4 = AffineMap::get(1, 0, {zero}, &ctx);
4644
EXPECT_FALSE(map4.isProjectedPermutation(/*allowZeroInResults=*/false));
4745

48-
// 5. The number of results > inputs, not a projected permutation.
46+
// 5. The number of results > inputs
4947
AffineMap map5 = AffineMap::get(1, 0, {zero, zero}, &ctx);
5048
EXPECT_FALSE(map5.isProjectedPermutation(/*allowZeroInResults=*/true));
5149

52-
// 6. A constant result that's not a {0} - not a projected permutation.
50+
// 6. A constant result that's not a {0}
5351
auto one = b.getAffineConstantExpr(1);
5452
AffineMap map6 = AffineMap::get(1, 0, {one}, &ctx);
5553
EXPECT_FALSE(map6.isProjectedPermutation(/*allowZeroInResults=*/true));
5654

57-
// 7. Not a dim expression - not a projected permutation.
55+
// 7. Not a dim expression
5856
auto d0 = b.getAffineDimExpr(0);
5957
auto d1 = b.getAffineDimExpr(1);
6058

6159
auto sum = d0 + d1;
6260
AffineMap map7 = AffineMap::get(2, 0, {sum}, &ctx);
6361
EXPECT_FALSE(map7.isProjectedPermutation());
62+
63+
// 8. (d0, d1, d2, d3, d4, d5) ->(d5, d3, d0, d1, d2, d4)
64+
auto d2 = b.getAffineDimExpr(2);
65+
auto d3 = b.getAffineDimExpr(3);
66+
auto d4 = b.getAffineDimExpr(4);
67+
auto d5 = b.getAffineDimExpr(5);
68+
AffineMap map8 = AffineMap::get(6, 0, {d5, d3, d0, d1, d2, d4}, &ctx);
69+
EXPECT_TRUE(map8.isProjectedPermutation());
70+
71+
// 9. (d0, d1, d2, d3, d4, d5) ->(d5, d3, d0 + d1, d2, d4)
72+
AffineMap map9 = AffineMap::get(6, 0, {d5, d3, sum, d2, d4}, &ctx);
73+
EXPECT_FALSE(map9.isProjectedPermutation());
74+
75+
// 10. (d0, d1, d2, d3, d4, d5) ->(d5, d3, d2, d4)
76+
AffineMap map10 = AffineMap::get(6, 0, {d5, d3, d2, d4}, &ctx);
77+
EXPECT_TRUE(map10.isProjectedPermutation());
6478
}

0 commit comments

Comments
 (0)