add isl_basic_map_neg
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 10 Feb 2009 16:30:43 +0000 (17:30 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 11 Feb 2009 10:29:10 +0000 (11:29 +0100)
include/isl_map.h
isl_map.c

index e874261..6100c33 100644 (file)
@@ -160,6 +160,7 @@ struct isl_basic_map *isl_basic_map_read_from_file(struct isl_ctx *ctx,
 
 struct isl_basic_map *isl_basic_map_sum(
                struct isl_basic_map *bmap1, struct isl_basic_map *bmap2);
+struct isl_basic_map *isl_basic_map_neg(struct isl_basic_map *bmap);
 
 struct isl_map *isl_basic_map_lexmax(
                struct isl_basic_map *bmap, struct isl_basic_set *dom,
index 9d0c9d1..99d247d 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -1820,6 +1820,31 @@ error:
        return NULL;
 }
 
+/* Given a basic map A -> f(A), construct A -> -f(A).
+ */
+struct isl_basic_map *isl_basic_map_neg(struct isl_basic_map *bmap)
+{
+       int i, j;
+       unsigned off, n;
+
+       bmap = isl_basic_map_cow(bmap);
+       if (!bmap)
+               return NULL;
+
+       n = isl_basic_map_dim(bmap, isl_dim_out);
+       off = basic_map_offset(bmap, isl_dim_out);
+       for (i = 0; i < bmap->n_eq; ++i)
+               for (j = 0; j < n; ++j)
+                       isl_int_neg(bmap->eq[i][off+j], bmap->eq[i][off+j]);
+       for (i = 0; i < bmap->n_ineq; ++i)
+               for (j = 0; j < n; ++j)
+                       isl_int_neg(bmap->ineq[i][off+j], bmap->ineq[i][off+j]);
+       for (i = 0; i < bmap->n_div; ++i)
+               for (j = 0; j < n; ++j)
+                       isl_int_neg(bmap->div[i][1+off+j], bmap->div[i][1+off+j]);
+       return isl_basic_map_finalize(bmap);
+}
+
 static struct isl_basic_map *var_equal(struct isl_ctx *ctx,
                struct isl_basic_map *bmap, unsigned pos)
 {