add isl_set_preimage_pw_multi_aff
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 25 Aug 2012 09:18:40 +0000 (11:18 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 18 Sep 2012 13:08:21 +0000 (15:08 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/set.h
isl_map.c

index 7a4707e..f5ca6e6 100644 (file)
@@ -2782,11 +2782,14 @@ a parametric set as well.
        __isl_give isl_set *isl_set_preimage_multi_aff(
                __isl_take isl_set *set,
                __isl_take isl_multi_aff *ma);
+       __isl_give isl_set *isl_set_preimage_pw_multi_aff(
+               __isl_take isl_set *set,
+               __isl_take isl_pw_multi_aff *pma);
 
 These functions compute the preimage of the given set under
 the given function.  In other words, the expression is plugged
 into the set description.
-Objects of type C<isl_multi_aff> are described in
+Objects of types C<isl_multi_aff> and C<isl_pw_multi_aff> are described in
 L</"Piecewise Multiple Quasi Affine Expressions">.
 
 =item * Cartesian Product
index 8ade721..9dc59e8 100644 (file)
@@ -305,6 +305,8 @@ __isl_give isl_set *isl_set_apply(
                __isl_take isl_map *map);
 __isl_give isl_set *isl_set_preimage_multi_aff(__isl_take isl_set *set,
        __isl_take isl_multi_aff *ma);
+__isl_give isl_set *isl_set_preimage_pw_multi_aff(__isl_take isl_set *set,
+       __isl_take isl_pw_multi_aff *pma);
 __isl_give isl_set *isl_set_fix(__isl_take isl_set *set,
                enum isl_dim_type type, unsigned pos, isl_int value);
 struct isl_set *isl_set_fix_dim_si(struct isl_set *set,
index e862aac..5c693b0 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -11210,3 +11210,67 @@ error:
        isl_multi_aff_free(ma);
        return isl_set_free(set);
 }
+
+/* Compute the preimage of "set" under the function represented by "pma".
+ * In other words, plug in "pma" in "set.  The result is a set
+ * that lives in the domain space of "pma".
+ */
+static __isl_give isl_set *set_preimage_pw_multi_aff(__isl_take isl_set *set,
+       __isl_take isl_pw_multi_aff *pma)
+{
+       int i;
+       isl_set *res;
+
+       if (!pma)
+               goto error;
+
+       if (pma->n == 0) {
+               isl_pw_multi_aff_free(pma);
+               res = isl_set_empty(isl_set_get_space(set));
+               isl_set_free(set);
+               return res;
+       }
+
+       res = isl_set_preimage_multi_aff(isl_set_copy(set),
+                                       isl_multi_aff_copy(pma->p[0].maff));
+       res = isl_set_intersect(res, isl_set_copy(pma->p[0].set));
+
+       for (i = 1; i < pma->n; ++i) {
+               isl_set *res_i;
+
+               res_i = isl_set_preimage_multi_aff(isl_set_copy(set),
+                                       isl_multi_aff_copy(pma->p[i].maff));
+               res_i = isl_set_intersect(res_i, isl_set_copy(pma->p[i].set));
+               res = isl_set_union(res, res_i);
+       }
+
+       isl_pw_multi_aff_free(pma);
+       isl_set_free(set);
+       return res;
+error:
+       isl_pw_multi_aff_free(pma);
+       isl_set_free(set);
+       return NULL;
+}
+
+__isl_give isl_set *isl_set_preimage_pw_multi_aff(__isl_take isl_set *set,
+       __isl_take isl_pw_multi_aff *pma)
+{
+       if (!set || !pma)
+               goto error;
+
+       if (isl_space_match(set->dim, isl_dim_param, pma->dim, isl_dim_param))
+               return set_preimage_pw_multi_aff(set, pma);
+
+       if (!isl_space_has_named_params(set->dim) ||
+           !isl_space_has_named_params(pma->dim))
+               isl_die(set->ctx, isl_error_invalid,
+                       "unaligned unnamed parameters", goto error);
+       set = isl_set_align_params(set, isl_pw_multi_aff_get_space(pma));
+       pma = isl_pw_multi_aff_align_params(pma, isl_set_get_space(set));
+
+       return set_preimage_pw_multi_aff(set, pma);
+error:
+       isl_pw_multi_aff_free(pma);
+       return isl_set_free(set);
+}