From f1d94290bd5e6200ec21fcc4f0df3f76e9f7f3bc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 21 Mar 2016 16:43:09 +0100 Subject: [PATCH] add isl_map_is_identity Signed-off-by: Sven Verdoolaege --- doc/user.pod | 9 +++++++++ include/isl/map.h | 1 + isl_map.c | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index c5e23797..e747f8d6 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -3772,6 +3772,15 @@ is already known to be empty. isl_bool isl_union_map_is_bijective( __isl_keep isl_union_map *umap); +=item * Identity + +The following function tests whether the given relation +only maps elements to themselves. + + #include + isl_bool isl_map_is_identity( + __isl_keep isl_map *map); + =item * Position __isl_give isl_val * diff --git a/include/isl/map.h b/include/isl/map.h index fdbac8cc..c46d2572 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -541,6 +541,7 @@ __isl_export isl_bool isl_map_is_injective(__isl_keep isl_map *map); __isl_export isl_bool isl_map_is_bijective(__isl_keep isl_map *map); +isl_bool isl_map_is_identity(__isl_keep isl_map *map); int isl_map_is_translation(__isl_keep isl_map *map); int isl_map_has_equal_space(__isl_keep isl_map *map1, __isl_keep isl_map *map2); diff --git a/isl_map.c b/isl_map.c index 50c0521b..a34368b0 100644 --- a/isl_map.c +++ b/isl_map.c @@ -3,6 +3,7 @@ * Copyright 2010 INRIA Saclay * Copyright 2012-2014 Ecole Normale Superieure * Copyright 2014 INRIA Rocquencourt + * Copyright 2016 Sven Verdoolaege * * Use of this software is governed by the MIT license * @@ -10898,6 +10899,32 @@ isl_bool isl_set_is_singleton(__isl_keep isl_set *set) return isl_map_is_single_valued((isl_map *)set); } +/* Does "map" only map elements to themselves? + * + * If the domain and range spaces are different, then "map" + * is considered not to be an identity relation, even if it is empty. + * Otherwise, construct the maximal identity relation and + * check whether "map" is a subset of this relation. + */ +isl_bool isl_map_is_identity(__isl_keep isl_map *map) +{ + isl_space *space; + isl_map *id; + isl_bool equal, is_identity; + + space = isl_map_get_space(map); + equal = isl_space_tuple_is_equal(space, isl_dim_in, space, isl_dim_out); + isl_space_free(space); + if (equal < 0 || !equal) + return equal; + + id = isl_map_identity(isl_map_get_space(map)); + is_identity = isl_map_is_subset(map, id); + isl_map_free(id); + + return is_identity; +} + int isl_map_is_translation(__isl_keep isl_map *map) { int ok; -- 2.11.4.GIT