@@ -26,39 +26,53 @@ TEST(AffineMapTest, isProjectedPermutation) {
26
26
MLIRContext ctx;
27
27
OpBuilder b (&ctx);
28
28
29
- // 1. Empty map - a projected permutation.
29
+ // 1. Empty map
30
30
AffineMap map1 = b.getEmptyAffineMap ();
31
31
EXPECT_TRUE (map1.isProjectedPermutation ());
32
32
33
- // 2. Contains a symbol - not a projected permutation.
33
+ // 2. Map with a symbol
34
34
AffineMap map2 = AffineMap::get (0 , 1 , &ctx);
35
35
EXPECT_FALSE (map2.isProjectedPermutation ());
36
36
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_.
39
38
auto zero = b.getAffineConstantExpr (0 );
40
39
AffineMap map3 = AffineMap::get (1 , 0 , {zero}, &ctx);
41
40
EXPECT_TRUE (map3.isProjectedPermutation (/* allowZeroInResults=*/ true ));
42
41
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_
45
43
AffineMap map4 = AffineMap::get (1 , 0 , {zero}, &ctx);
46
44
EXPECT_FALSE (map4.isProjectedPermutation (/* allowZeroInResults=*/ false ));
47
45
48
- // 5. The number of results > inputs, not a projected permutation.
46
+ // 5. The number of results > inputs
49
47
AffineMap map5 = AffineMap::get (1 , 0 , {zero, zero}, &ctx);
50
48
EXPECT_FALSE (map5.isProjectedPermutation (/* allowZeroInResults=*/ true ));
51
49
52
- // 6. A constant result that's not a {0} - not a projected permutation.
50
+ // 6. A constant result that's not a {0}
53
51
auto one = b.getAffineConstantExpr (1 );
54
52
AffineMap map6 = AffineMap::get (1 , 0 , {one}, &ctx);
55
53
EXPECT_FALSE (map6.isProjectedPermutation (/* allowZeroInResults=*/ true ));
56
54
57
- // 7. Not a dim expression - not a projected permutation.
55
+ // 7. Not a dim expression
58
56
auto d0 = b.getAffineDimExpr (0 );
59
57
auto d1 = b.getAffineDimExpr (1 );
60
58
61
59
auto sum = d0 + d1;
62
60
AffineMap map7 = AffineMap::get (2 , 0 , {sum}, &ctx);
63
61
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 ());
64
78
}
0 commit comments