diff options
author | Sven Verdoolaege <skimo@kotnet.org> | 2009-03-12 14:44:21 +0100 |
---|---|---|
committer | Sven Verdoolaege <skimo@kotnet.org> | 2009-03-20 16:46:53 +0100 |
commit | 41e3ee5cb867ae47dfa4d1a4828110722ab3d7ed (patch) | |
tree | 21aebeefeac438b6b9ba99b1b26300409eb68b2a /isl_mat.c | |
parent | ba4d1333b50530cf581e1bfcc96c2afc18b0d2c7 (diff) | |
download | isl-41e3ee5cb867ae47dfa4d1a4828110722ab3d7ed.tar.gz isl-41e3ee5cb867ae47dfa4d1a4828110722ab3d7ed.tar.bz2 isl-41e3ee5cb867ae47dfa4d1a4828110722ab3d7ed.zip |
isl_mat_transpose: handle non-rectangular matrices
Diffstat (limited to 'isl_mat.c')
-rw-r--r-- | isl_mat.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -700,16 +700,26 @@ error: struct isl_mat *isl_mat_transpose(struct isl_ctx *ctx, struct isl_mat *mat) { + struct isl_mat *transpose = NULL; int i, j; - mat = isl_mat_cow(ctx, mat); - if (!mat) - return NULL; - isl_assert(ctx, mat->n_col == mat->n_row, goto error); + if (mat->n_col == mat->n_row) { + mat = isl_mat_cow(ctx, mat); + if (!mat) + return NULL; + for (i = 0; i < mat->n_row; ++i) + for (j = i + 1; j < mat->n_col; ++j) + isl_int_swap(mat->row[i][j], mat->row[j][i]); + return mat; + } + transpose = isl_mat_alloc(ctx, mat->n_col, mat->n_row); + if (!transpose) + goto error; for (i = 0; i < mat->n_row; ++i) - for (j = i + 1; j < mat->n_col; ++j) - isl_int_swap(mat->row[i][j], mat->row[j][i]); - return mat; + for (j = 0; j < mat->n_col; ++j) + isl_int_set(transpose->row[j][i], mat->row[i][j]); + isl_mat_free(ctx, mat); + return transpose; error: isl_mat_free(ctx, mat); return NULL; |