From c4f9df38f7366e46a2472ff869d9261d08b5567a Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 20 Mar 2010 14:19:05 +0100 Subject: [PATCH] add isl_mat_move_cols --- include/isl_mat.h | 2 ++ isl_mat.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/isl_mat.h b/include/isl_mat.h index 6d93450..1925d87 100644 --- a/include/isl_mat.h +++ b/include/isl_mat.h @@ -83,6 +83,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_move_cols(__isl_take isl_mat *mat, + unsigned dst_col, unsigned src_col, unsigned n); void isl_mat_col_mul(struct isl_mat *mat, int dst_col, isl_int f, int src_col); void isl_mat_col_submul(struct isl_mat *mat, diff --git a/isl_mat.c b/isl_mat.c index b713cda..04d989c 100644 --- a/isl_mat.c +++ b/isl_mat.c @@ -1215,3 +1215,46 @@ __isl_give isl_mat *isl_mat_vec_concat(__isl_take isl_mat *top, { 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; +} -- 2.7.4