add isl_mat_concat
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 2 Oct 2009 12:34:39 +0000 (14:34 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 7 Oct 2009 15:20:07 +0000 (17:20 +0200)
include/isl_mat.h
isl_mat.c

index 55d39b0..00d8757 100644 (file)
@@ -77,6 +77,9 @@ void isl_mat_col_submul(struct isl_mat *mat,
 
 struct isl_mat *isl_mat_unimodular_complete(struct isl_mat *M, int row);
 
+__isl_give isl_mat *isl_mat_concat(__isl_take isl_mat *top,
+       __isl_take isl_mat *bot);
+
 void isl_mat_dump(struct isl_mat *mat, FILE *out, int indent);
 
 #if defined(__cplusplus)
index 3b92458..e0f55b5 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -1073,3 +1073,37 @@ error:
        isl_mat_free(M);
        return NULL;
 }
+
+__isl_give isl_mat *isl_mat_concat(__isl_take isl_mat *top,
+       __isl_take isl_mat *bot)
+{
+       struct isl_mat *mat;
+
+       if (!top || !bot)
+               goto error;
+
+       isl_assert(top->ctx, top->n_col == bot->n_col, goto error);
+       if (top->n_row == 0) {
+               isl_mat_free(top);
+               return bot;
+       }
+       if (bot->n_row == 0) {
+               isl_mat_free(bot);
+               return top;
+       }
+
+       mat = isl_mat_alloc(top->ctx, top->n_row + bot->n_row, top->n_col);
+       if (!mat)
+               goto error;
+       isl_mat_sub_copy(mat->ctx, mat->row, top->row, top->n_row,
+                        0, 0, mat->n_col);
+       isl_mat_sub_copy(mat->ctx, mat->row + top->n_row, bot->row, bot->n_row,
+                        0, 0, mat->n_col);
+       isl_mat_free(top);
+       isl_mat_free(bot);
+       return mat;
+error:
+       isl_mat_free(top);
+       isl_mat_free(bot);
+       return NULL;
+}