add check for isl_map_lexmin_pw_multi_aff returning single cell expression
authorSven Verdoolaege <sven@cerebras.net>
Tue, 14 Feb 2023 14:23:51 +0000 (14 15:23 +0100)
committerSven Verdoolaege <sven@cerebras.net>
Sat, 30 Mar 2024 13:41:51 +0000 (30 14:41 +0100)
This will illustrate the effect of an upcoming commit.
In particular, the test currently checks for the opposite
of the desired result.

It would be nicer if the actual result of isl_map_lexmin_pw_multi_aff
could be compared, but this is complicated by the fact that parsing
may change the representation of an isl_pw_multi_aff so that
it is no longer obviously equal to the input.
In particular, the result of isl_map_lexmin_pw_multi_aff is
{ [a] -> [(2a - 2*floor((5 + 5a)/6))] : 0 <= a <= 11 },
but it gets parsed as
{ [a] -> [(-2 - 2*floor((-1 - a)/6))] : 0 <= a <= 11 }.
Comparing the piecewise expressions using
isl_pw_multi_aff_is_equal instead of isl_pw_multi_aff_plain_is_equal
would not help since then it wouldn't be possible to make a distinction
based on the number of cells in the expression.

Signed-off-by: Sven Verdoolaege <sven@cerebras.net>
isl_test2.cc

index 40b570b..0ce552d 100644 (file)
@@ -435,6 +435,29 @@ static void test_intersect(isl::ctx ctx)
        });
 }
 
+/* Is the expression for the lexicographic minimum of "obj"
+ * defined over a single cell?
+ */
+template <typename T>
+static bool lexmin_has_single_cell(const T &obj)
+{
+       return has_single_cell(obj.lexmin_pw_multi_aff());
+}
+
+/* Perform some basic lexicographic minimization tests.
+ */
+static void test_lexmin(isl::ctx ctx)
+{
+       C(&lexmin_has_single_cell<isl::map>, {
+       /* The following two inputs represent the same binary relation,
+        * the second with extra redundant constraints.
+        * The lexicographic minimum of both should consist of a single cell.
+        */
+       { "{ [a=0:11] -> [b] : -1 + b <= 2*floor((a)/6) <= b }", true },
+       { "{ [a=0:11] -> [b=0:3] : -1 + b <= 2*floor((a)/6) <= b }", false },
+       });
+}
+
 /* Perform some basic gist tests.
  */
 static void test_gist(isl::ctx ctx)
@@ -692,6 +715,7 @@ static std::vector<std::pair<const char *, void (*)(isl::ctx)>> tests =
        { "preimage", &test_preimage },
        { "fixed power", &test_fixed_power },
        { "intersect", &test_intersect },
+       { "lexmin", &test_lexmin },
        { "gist", &test_gist },
        { "project out parameters", &test_project },
        { "reverse", &test_reverse },