add isl_mat_vec_inverse_product
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 4 Oct 2009 07:12:45 +0000 (09:12 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 7 Oct 2009 15:21:51 +0000 (17:21 +0200)
include/isl_mat.h
isl_mat.c

index 00d8757..0034a7c 100644 (file)
@@ -54,6 +54,8 @@ struct isl_mat *isl_mat_swap_rows(struct isl_mat *mat, unsigned i, unsigned j);
 
 struct isl_vec *isl_mat_vec_product(struct isl_mat *mat, struct isl_vec *vec);
 struct isl_vec *isl_vec_mat_product(struct isl_vec *vec, struct isl_mat *mat);
+__isl_give isl_vec *isl_mat_vec_inverse_product(__isl_take isl_mat *mat,
+                                               __isl_take isl_vec *vec);
 struct isl_mat *isl_mat_aff_direct_sum(struct isl_mat *left,
                                        struct isl_mat *right);
 struct isl_mat *isl_mat_left_hermite(struct isl_mat *M,
index e0f55b5..2b8f540 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -236,6 +236,35 @@ error:
        return NULL;
 }
 
+__isl_give isl_vec *isl_mat_vec_inverse_product(__isl_take isl_mat *mat,
+       __isl_take isl_vec *vec)
+{
+       struct isl_mat *vec_mat;
+       int i;
+
+       if (!mat || !vec)
+               goto error;
+       vec_mat = isl_mat_alloc(vec->ctx, vec->size, 1);
+       if (!vec_mat)
+               goto error;
+       for (i = 0; i < vec->size; ++i)
+               isl_int_set(vec_mat->row[i][0], vec->el[i]);
+       vec_mat = isl_mat_inverse_product(mat, vec_mat);
+       isl_vec_free(vec);
+       if (!vec_mat)
+               return NULL;
+       vec = isl_vec_alloc(vec_mat->ctx, vec_mat->n_row);
+       if (vec)
+               for (i = 0; i < vec->size; ++i)
+                       isl_int_set(vec->el[i], vec_mat->row[i][0]);
+       isl_mat_free(vec_mat);
+       return vec;
+error:
+       isl_mat_free(mat);
+       isl_vec_free(vec);
+       return NULL;
+}
+
 struct isl_vec *isl_vec_mat_product(struct isl_vec *vec, struct isl_mat *mat)
 {
        int i, j;