#include "isl_dim.h"
#include "isl_seq.h"
-#include "isl_mat.h"
+#include <isl_mat_private.h>
#include "isl_map_private.h"
+#include <isl_dim_private.h>
struct isl_mat *isl_mat_alloc(struct isl_ctx *ctx,
unsigned n_row, unsigned n_col)
if (!mat)
goto error;
- assert(mat->ref == 1);
old = mat->block.data;
mat->block = isl_blk_extend(mat->ctx, mat->block, n_row * mat->max_col);
if (isl_blk_is_error(mat->block))
free(mat);
}
+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;
+}
+
+__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;
+}
+
struct isl_mat *isl_mat_identity(struct isl_ctx *ctx, unsigned n_row)
{
int i;
isl_assert(ctx, 1+bset->dim->n_out == mat->n_row, goto error);
isl_assert(ctx, mat->n_col > 0, goto error);
- if (mat->n_col > mat->n_row)
- bset = isl_basic_set_extend(bset, 0, mat->n_col-1, 0,
- 0, 0);
- else if (mat->n_col < mat->n_row) {
+ if (mat->n_col > mat->n_row) {
+ bset = isl_basic_set_extend(bset, 0, mat->n_col-1, 0, 0, 0);
+ if (!bset)
+ goto error;
+ } else if (mat->n_col < mat->n_row) {
bset->dim = isl_dim_cow(bset->dim);
if (!bset->dim)
goto error;
return NULL;
}
+__isl_give isl_mat *isl_mat_insert_zero_cols(__isl_take isl_mat *mat,
+ unsigned first, unsigned n)
+{
+ int i;
+
+ if (!mat)
+ return NULL;
+ mat = isl_mat_insert_cols(mat, first, n);
+ if (!mat)
+ return NULL;
+
+ for (i = 0; i < mat->n_row; ++i)
+ isl_seq_clr(mat->row[i] + first, n);
+
+ return mat;
+}
+
+__isl_give isl_mat *isl_mat_add_zero_cols(__isl_take isl_mat *mat, unsigned n)
+{
+ if (!mat)
+ return NULL;
+
+ return isl_mat_insert_zero_cols(mat, mat->n_col, n);
+}
+
__isl_give isl_mat *isl_mat_insert_rows(__isl_take isl_mat *mat,
unsigned row, unsigned n)
{
return NULL;
}
+__isl_give isl_mat *isl_mat_add_rows(__isl_take isl_mat *mat, unsigned n)
+{
+ if (!mat)
+ return NULL;
+
+ return isl_mat_insert_rows(mat, mat->n_row, n);
+}
+
void isl_mat_col_submul(struct isl_mat *mat,
int dst_col, isl_int f, int src_col)
{