add isl_mat_insert_rows
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 12 May 2010 09:36:19 +0000 (11:36 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 13 May 2010 16:53:54 +0000 (18:53 +0200)
include/isl_mat.h
isl_mat.c

index 013eb54..0caf023 100644 (file)
@@ -87,6 +87,8 @@ struct isl_mat *isl_mat_drop_rows(struct isl_mat *mat,
                                unsigned row, unsigned n);
 __isl_give isl_mat *isl_mat_insert_cols(__isl_take isl_mat *mat,
                                unsigned col, unsigned n);
+__isl_give isl_mat *isl_mat_insert_rows(__isl_take isl_mat *mat,
+                               unsigned row, unsigned n);
 __isl_give isl_mat *isl_mat_move_cols(__isl_take isl_mat *mat,
        unsigned dst_col, unsigned src_col, unsigned n);
 
index df0ac2f..38bee99 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -1132,6 +1132,31 @@ error:
        return NULL;
 }
 
+__isl_give isl_mat *isl_mat_insert_rows(__isl_take isl_mat *mat,
+                               unsigned row, unsigned n)
+{
+       isl_mat *ext;
+
+       if (!mat)
+               return NULL;
+       if (n == 0)
+               return mat;
+
+       ext = isl_mat_alloc(mat->ctx, mat->n_row + n, mat->n_col);
+       if (!ext)
+               goto error;
+
+       isl_mat_sub_copy(mat->ctx, ext->row, mat->row, row, 0, 0, mat->n_col);
+       isl_mat_sub_copy(mat->ctx, ext->row + row + n, mat->row + row,
+                               mat->n_row - row, 0, 0, mat->n_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)
 {