+
+ return NULL;
+}
+
+int isl_mat_rows(__isl_keep isl_mat *mat)
+{
+ return mat ? mat->n_row : -1;
+}
+
+int isl_mat_cols(__isl_keep isl_mat *mat)
+{
+ return mat ? mat->n_col : -1;
+}
+
+int isl_mat_get_element(__isl_keep isl_mat *mat, int row, int col, isl_int *v)
+{
+ if (!mat)
+ return -1;
+ if (row < 0 || row >= mat->n_row)
+ isl_die(mat->ctx, isl_error_invalid, "row out of range",
+ return -1);
+ if (col < 0 || col >= mat->n_col)
+ isl_die(mat->ctx, isl_error_invalid, "column out of range",
+ return -1);
+ isl_int_set(*v, mat->row[row][col]);
+ return 0;
+}
+
+/* Extract the element at row "row", oolumn "col" of "mat".
+ */
+__isl_give isl_val *isl_mat_get_element_val(__isl_keep isl_mat *mat,
+ int row, int col)
+{
+ isl_ctx *ctx;
+
+ if (!mat)
+ return NULL;
+ ctx = isl_mat_get_ctx(mat);
+ if (row < 0 || row >= mat->n_row)
+ isl_die(ctx, isl_error_invalid, "row out of range",
+ return NULL);
+ if (col < 0 || col >= mat->n_col)
+ isl_die(ctx, isl_error_invalid, "column out of range",
+ return NULL);
+ return isl_val_int_from_isl_int(ctx, mat->row[row][col]);
+}
+
+__isl_give isl_mat *isl_mat_set_element(__isl_take isl_mat *mat,
+ int row, int col, isl_int v)
+{
+ mat = isl_mat_cow(mat);
+ if (!mat)
+ return NULL;
+ if (row < 0 || row >= mat->n_row)
+ isl_die(mat->ctx, isl_error_invalid, "row out of range",
+ goto error);
+ if (col < 0 || col >= mat->n_col)
+ isl_die(mat->ctx, isl_error_invalid, "column out of range",
+ goto error);
+ isl_int_set(mat->row[row][col], v);
+ return mat;
+error:
+ isl_mat_free(mat);
+ return NULL;
+}
+
+__isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat,
+ int row, int col, int v)
+{
+ mat = isl_mat_cow(mat);
+ if (!mat)
+ return NULL;
+ if (row < 0 || row >= mat->n_row)
+ isl_die(mat->ctx, isl_error_invalid, "row out of range",
+ goto error);
+ if (col < 0 || col >= mat->n_col)
+ isl_die(mat->ctx, isl_error_invalid, "column out of range",
+ goto error);
+ isl_int_set_si(mat->row[row][col], v);
+ return mat;
+error:
+ isl_mat_free(mat);
+ 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);