isl_map_transitive_closure: break early if input map doesn't compose with itself
[platform/upstream/isl.git] / isl_mat.c
index 660ed23..04d989c 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -1,3 +1,12 @@
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
 #include "isl_dim.h"
 #include "isl_seq.h"
 #include "isl_mat.h"
@@ -713,7 +722,7 @@ struct isl_mat *isl_mat_right_inverse(struct isl_mat *mat)
                if (pivot < 0) {
                        isl_int_clear(a);
                        isl_int_clear(b);
-                       goto error;
+                       isl_assert(mat->ctx, pivot >= 0, goto error);
                }
                pivot += row;
                if (pivot != row)
@@ -1058,6 +1067,31 @@ struct isl_mat *isl_mat_drop_rows(struct isl_mat *mat, unsigned row, unsigned n)
        return mat;
 }
 
+__isl_give isl_mat *isl_mat_insert_cols(__isl_take isl_mat *mat,
+                               unsigned col, unsigned n)
+{
+       isl_mat *ext;
+
+       if (!mat)
+               return NULL;
+       if (n == 0)
+               return mat;
+
+       ext = isl_mat_alloc(mat->ctx, mat->n_row, mat->n_col + n);
+       if (!ext)
+               goto error;
+
+       isl_mat_sub_copy(mat->ctx, ext->row, mat->row, mat->n_row, 0, 0, col);
+       isl_mat_sub_copy(mat->ctx, ext->row, mat->row, mat->n_row,
+                               col + n, col, mat->n_col - col);
+
+       isl_mat_free(mat);
+       return ext;
+error:
+       isl_mat_free(mat);
+       return NULL;
+}
+
 void isl_mat_col_submul(struct isl_mat *mat,
                        int dst_col, isl_int f, int src_col)
 {
@@ -1156,3 +1190,71 @@ int isl_mat_is_equal(__isl_keep isl_mat *mat1, __isl_keep isl_mat *mat2)
 
        return 1;
 }
+
+__isl_give isl_mat *isl_mat_from_row_vec(__isl_take isl_vec *vec)
+{
+       struct isl_mat *mat;
+
+       if (!vec)
+               return NULL;
+       mat = isl_mat_alloc(vec->ctx, 1, vec->size);
+       if (!mat)
+               goto error;
+
+       isl_seq_cpy(mat->row[0], vec->el, vec->size);
+
+       isl_vec_free(vec);
+       return mat;
+error:
+       isl_vec_free(vec);
+       return NULL;
+}
+
+__isl_give isl_mat *isl_mat_vec_concat(__isl_take isl_mat *top,
+       __isl_take isl_vec *bot)
+{
+       return isl_mat_concat(top, isl_mat_from_row_vec(bot));
+}
+
+__isl_give isl_mat *isl_mat_move_cols(__isl_take isl_mat *mat,
+       unsigned dst_col, unsigned src_col, unsigned n)
+{
+       isl_mat *res;
+
+       if (!mat)
+               return NULL;
+       if (n == 0 || dst_col == src_col)
+               return mat;
+
+       res = isl_mat_alloc(mat->ctx, mat->n_row, mat->n_col);
+       if (!res)
+               goto error;
+
+       if (dst_col < src_col) {
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                0, 0, dst_col);
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                dst_col, src_col, n);
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                dst_col + n, dst_col, src_col - dst_col);
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                src_col + n, src_col + n,
+                                res->n_col - src_col - n);
+       } else {
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                0, 0, src_col);
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                src_col, src_col + n, dst_col - src_col);
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                dst_col, src_col, n);
+               isl_mat_sub_copy(res->ctx, res->row, mat->row, mat->n_row,
+                                dst_col + n, dst_col + n,
+                                res->n_col - dst_col - n);
+       }
+       isl_mat_free(mat);
+
+       return res;
+error:
+       isl_mat_free(mat);
+       return NULL;
+}