add isl_mat_concat
[platform/upstream/isl.git] / isl_mat.c
index 1479993..e0f55b5 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -603,11 +603,11 @@ struct isl_mat *isl_mat_inverse_product(struct isl_mat *left,
                        isl_int_gcd(a, left->row[row][row], left->row[i][row]);
                        isl_int_divexact(b, left->row[i][row], a);
                        isl_int_divexact(a, left->row[row][row], a);
-                       isl_int_neg(a, a);
-                       isl_seq_combine(left->row[i]+row,
-                                       a, left->row[i]+row,
-                                       b, left->row[row]+row,
-                                       left->n_col-row);
+                       isl_int_neg(b, b);
+                       isl_seq_combine(left->row[i] + i,
+                                       a, left->row[i] + i,
+                                       b, left->row[row] + i,
+                                       left->n_col - i);
                        isl_seq_combine(right->row[i], a, right->row[i],
                                        b, right->row[row], right->n_col);
                }
@@ -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;
+}