X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=isl_mat.c;h=6b548492147f9d3e64915a85a5bf5e8ab35040c6;hb=ac4859972aa9f08878590883ea2ed2071141284d;hp=ace8a43a9698f03ea9367ccf1d092a89683b4bb0;hpb=f76aa4201b6c75734aaca36626bc8afbfdf7e155;p=platform%2Fupstream%2Fisl.git diff --git a/isl_mat.c b/isl_mat.c index ace8a43..6b54849 100644 --- a/isl_mat.c +++ b/isl_mat.c @@ -1,18 +1,23 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * - * Use of this software is governed by the GNU LGPLv2.1 license + * Use of this software is governed by the MIT license * * Written by Sven Verdoolaege, K.U.Leuven, Departement * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium */ #include -#include +#include +#include #include #include -#include "isl_map_private.h" -#include +#include + +isl_ctx *isl_mat_get_ctx(__isl_keep isl_mat *mat) +{ + return mat ? mat->ctx : NULL; +} struct isl_mat *isl_mat_alloc(struct isl_ctx *ctx, unsigned n_row, unsigned n_col) @@ -199,19 +204,21 @@ struct isl_mat *isl_mat_cow(struct isl_mat *mat) return mat2; } -void isl_mat_free(struct isl_mat *mat) +void *isl_mat_free(struct isl_mat *mat) { if (!mat) - return; + return NULL; if (--mat->ref > 0) - return; + return NULL; if (!ISL_F_ISSET(mat, ISL_MAT_BORROWED)) isl_blk_free(mat->ctx, mat->block); isl_ctx_deref(mat->ctx); free(mat->row); free(mat); + + return NULL; } int isl_mat_rows(__isl_keep isl_mat *mat) @@ -276,7 +283,7 @@ error: return NULL; } -struct isl_mat *isl_mat_identity(struct isl_ctx *ctx, unsigned n_row) +__isl_give isl_mat *isl_mat_diag(isl_ctx *ctx, unsigned n_row, isl_int d) { int i; struct isl_mat *mat; @@ -286,13 +293,20 @@ struct isl_mat *isl_mat_identity(struct isl_ctx *ctx, unsigned n_row) return NULL; for (i = 0; i < n_row; ++i) { isl_seq_clr(mat->row[i], i); - isl_int_set_si(mat->row[i][i], 1); + isl_int_set(mat->row[i][i], d); isl_seq_clr(mat->row[i]+i+1, n_row-(i+1)); } return mat; } +__isl_give isl_mat *isl_mat_identity(isl_ctx *ctx, unsigned n_row) +{ + if (!ctx) + return NULL; + return isl_mat_diag(ctx, n_row, ctx->one); +} + struct isl_vec *isl_mat_vec_product(struct isl_mat *mat, struct isl_vec *vec) { int i; @@ -897,6 +911,9 @@ struct isl_mat *isl_mat_transpose(struct isl_mat *mat) struct isl_mat *transpose = NULL; int i, j; + if (!mat) + return NULL; + if (mat->n_col == mat->n_row) { mat = isl_mat_cow(mat); if (!mat) @@ -952,7 +969,8 @@ struct isl_mat *isl_mat_swap_rows(struct isl_mat *mat, unsigned i, unsigned j) return mat; } -struct isl_mat *isl_mat_product(struct isl_mat *left, struct isl_mat *right) +__isl_give isl_mat *isl_mat_product(__isl_take isl_mat *left, + __isl_take isl_mat *right) { int i, j, k; struct isl_mat *prod; @@ -1059,7 +1077,7 @@ struct isl_basic_set *isl_basic_set_preimage(struct isl_basic_set *bset, if (!bset) goto error; } else if (mat->n_col < mat->n_row) { - bset->dim = isl_dim_cow(bset->dim); + bset->dim = isl_space_cow(bset->dim); if (!bset->dim) goto error; bset->dim->n_out -= mat->n_row - mat->n_col; @@ -1110,7 +1128,7 @@ struct isl_set *isl_set_preimage(struct isl_set *set, struct isl_mat *mat) goto error; } if (mat->n_col != mat->n_row) { - set->dim = isl_dim_cow(set->dim); + set->dim = isl_space_cow(set->dim); if (!set->dim) goto error; set->dim->n_out += mat->n_col; @@ -1192,7 +1210,7 @@ error: return NULL; } -void isl_mat_dump(struct isl_mat *mat, FILE *out, int indent) +void isl_mat_print_internal(__isl_keep isl_mat *mat, FILE *out, int indent) { int i, j; @@ -1221,10 +1239,18 @@ void isl_mat_dump(struct isl_mat *mat, FILE *out, int indent) } } +void isl_mat_dump(__isl_keep isl_mat *mat) +{ + isl_mat_print_internal(mat, stderr, 0); +} + struct isl_mat *isl_mat_drop_cols(struct isl_mat *mat, unsigned col, unsigned n) { int r; + if (n == 0) + return mat; + mat = isl_mat_cow(mat); if (!mat) return NULL; @@ -1559,6 +1585,10 @@ __isl_give isl_mat *isl_mat_scale_down(__isl_take isl_mat *mat, isl_int m) { int i; + if (isl_int_is_one(m)) + return mat; + + mat = isl_mat_cow(mat); if (!mat) return NULL; @@ -1568,6 +1598,21 @@ __isl_give isl_mat *isl_mat_scale_down(__isl_take isl_mat *mat, isl_int m) return mat; } +__isl_give isl_mat *isl_mat_scale_down_row(__isl_take isl_mat *mat, int row, + isl_int m) +{ + if (isl_int_is_one(m)) + return mat; + + mat = isl_mat_cow(mat); + if (!mat) + return NULL; + + isl_seq_scale_down(mat->row[row], mat->row[row], m, mat->n_col); + + return mat; +} + __isl_give isl_mat *isl_mat_normalize(__isl_take isl_mat *mat) { isl_int gcd; @@ -1583,6 +1628,17 @@ __isl_give isl_mat *isl_mat_normalize(__isl_take isl_mat *mat) return mat; } +__isl_give isl_mat *isl_mat_normalize_row(__isl_take isl_mat *mat, int row) +{ + mat = isl_mat_cow(mat); + if (!mat) + return NULL; + + isl_seq_normalize(mat->ctx, mat->row[row], mat->n_col); + + return mat; +} + /* Number of initial non-zero columns. */ int isl_mat_initial_non_zero_cols(__isl_keep isl_mat *mat)