add isl_pw_multi_aff_from_map
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 16 Aug 2011 16:46:37 +0000 (18:46 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 2 Oct 2011 09:03:36 +0000 (11:03 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/aff.h
isl_aff.c

index f624ff1..9e54f96 100644 (file)
@@ -2955,6 +2955,15 @@ be created using the following functions.
                __isl_take isl_set *set,
                __isl_take isl_multi_aff *maff);
 
+A piecewise multiple quasi affine expression can also be initialized
+from an C<isl_set> or C<isl_map>, provided the C<isl_set> is a singleton
+and the C<isl_map> is single-valued.
+
+       __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(
+               __isl_take isl_set *set);
+       __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(
+               __isl_take isl_map *map);
+
 Multiple quasi affine expressions can be copied and freed using
 
        #include <isl/aff.h>
index 2bc5037..8815caf 100644 (file)
@@ -305,6 +305,9 @@ __isl_give isl_set *isl_set_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma);
 __isl_give isl_printer *isl_printer_print_pw_multi_aff(__isl_take isl_printer *p,
        __isl_keep isl_pw_multi_aff *pma);
 
+__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(__isl_take isl_set *set);
+__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(__isl_take isl_map *map);
+
 void isl_pw_multi_aff_dump(__isl_keep isl_pw_multi_aff *pma);
 
 #if defined(__cplusplus)
index 59216bb..a4b2790 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -2159,6 +2159,54 @@ __isl_give isl_set *isl_set_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma)
        return isl_map_from_pw_multi_aff(pma);
 }
 
+/* Try and create an isl_pw_multi_aff that is equivalent to the given isl_map.
+ * This obivously only works if the input "map" is single-valued.
+ * If so, we compute the lexicographic minimum of the image in the form
+ * of an isl_pw_multi_aff.  Since the image is unique, it is equal
+ * to its lexicographic minimum.
+ * If the input is not single-valued, we produce an error.
+ */
+__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(__isl_take isl_map *map)
+{
+       int i;
+       int sv;
+       isl_pw_multi_aff *pma;
+
+       if (!map)
+               return NULL;
+
+       sv = isl_map_is_single_valued(map);
+       if (sv < 0)
+               goto error;
+       if (!sv)
+               isl_die(isl_map_get_ctx(map), isl_error_invalid,
+                       "map is not single-valued", goto error);
+       map = isl_map_make_disjoint(map);
+       if (!map)
+               return NULL;
+
+       pma = isl_pw_multi_aff_empty(isl_map_get_space(map));
+
+       for (i = 0; i < map->n; ++i) {
+               isl_pw_multi_aff *pma_i;
+               isl_basic_map *bmap;
+               bmap = isl_basic_map_copy(map->p[i]);
+               pma_i = isl_basic_map_lexmin_pw_multi_aff(bmap);
+               pma = isl_pw_multi_aff_add_disjoint(pma, pma_i);
+       }
+
+       isl_map_free(map);
+       return pma;
+error:
+       isl_map_free(map);
+       return NULL;
+}
+
+__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(__isl_take isl_set *set)
+{
+       return isl_pw_multi_aff_from_map(set);
+}
+
 /* Plug in "subs" for dimension "type", "pos" of "aff".
  *
  * Let i be the dimension to replace and let "subs" be of the form