From fbdf8af4f16b910d7493c419885f939364096a0e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 9 Apr 2013 16:23:48 +0200 Subject: [PATCH] add isl_mat_set_element_val Signed-off-by: Sven Verdoolaege --- doc/user.pod | 3 +++ include/isl/mat.h | 3 +++ isl_mat.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index bd26ecf..3fec840 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -3491,6 +3491,9 @@ The elements can be changed and inspected using the following functions. int row, int col, isl_int v); __isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat, int row, int col, int v); + __isl_give isl_mat *isl_mat_set_element_val( + __isl_take isl_mat *mat, int row, int col, + __isl_take isl_val *v); C will return a negative value if anything went wrong. In that case, the value of C<*v> is undefined. diff --git a/include/isl/mat.h b/include/isl/mat.h index 13db7e2..f5205f9 100644 --- a/include/isl/mat.h +++ b/include/isl/mat.h @@ -16,6 +16,7 @@ #include #include #include +#include #if defined(__cplusplus) extern "C" { @@ -43,6 +44,8 @@ __isl_give isl_mat *isl_mat_set_element(__isl_take isl_mat *mat, int row, int col, isl_int v); __isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat, int row, int col, int v); +__isl_give isl_mat *isl_mat_set_element_val(__isl_take isl_mat *mat, + int row, int col, __isl_take isl_val *v); struct isl_mat *isl_mat_swap_cols(struct isl_mat *mat, unsigned i, unsigned j); struct isl_mat *isl_mat_swap_rows(struct isl_mat *mat, unsigned i, unsigned j); diff --git a/isl_mat.c b/isl_mat.c index 6b54849..dc256ce 100644 --- a/isl_mat.c +++ b/isl_mat.c @@ -13,6 +13,7 @@ #include #include #include +#include isl_ctx *isl_mat_get_ctx(__isl_keep isl_mat *mat) { @@ -283,6 +284,24 @@ error: return NULL; } +/* Replace the element at row "row", column "col" of "mat" by "v". + */ +__isl_give isl_mat *isl_mat_set_element_val(__isl_take isl_mat *mat, + int row, int col, __isl_take isl_val *v) +{ + if (!v) + return isl_mat_free(mat); + if (!isl_val_is_int(v)) + isl_die(isl_val_get_ctx(v), isl_error_invalid, + "expecting integer value", goto error); + mat = isl_mat_set_element(mat, row, col, v->n); + isl_val_free(v); + return mat; +error: + isl_val_free(v); + return isl_mat_free(mat); +} + __isl_give isl_mat *isl_mat_diag(isl_ctx *ctx, unsigned n_row, isl_int d) { int i; -- 2.7.4