add public API for matrices
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 15 Aug 2010 13:06:26 +0000 (15:06 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 4 Sep 2010 09:04:28 +0000 (11:04 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
23 files changed:
Makefile.am
doc/user.pod
include/isl_mat.h
isl_affine_hull.c
isl_basis_reduction.h
isl_coalesce.c
isl_convex_hull.c
isl_equalities.c
isl_factorization.c
isl_fold.c
isl_input.c
isl_map.c
isl_map_simplify.c
isl_mat.c
isl_mat_private.h [new file with mode: 0644]
isl_morph.c
isl_output.c
isl_polynomial.c
isl_tab.c
isl_tab_pip.c
isl_transitive_closure.c
isl_vertices.c
polytope_scan.c

index e9eb8a3..12c7e2d 100644 (file)
@@ -66,6 +66,7 @@ libisl_la_SOURCES = \
        isl_map_private.h \
        isl_map_piplib.h \
        isl_mat.c \
+       isl_mat_private.h \
        isl_morph.c \
        isl_morph.h \
        isl_name.c \
index b49d43d..cbe08e3 100644 (file)
@@ -1423,6 +1423,42 @@ In case of union relations, the optimum is computed per space.
        __isl_give isl_union_map *isl_union_map_lexmax(
                __isl_take isl_union_map *umap);
 
+=head2 Matrices
+
+Matrices can be created, copied and freed using the following functions.
+
+       #include <isl_mat.h>
+       __isl_give isl_mat *isl_mat_alloc(struct isl_ctx *ctx,
+               unsigned n_row, unsigned n_col);
+       __isl_give isl_mat *isl_mat_copy(__isl_keep isl_mat *mat);
+       void isl_mat_free(__isl_take isl_mat *mat);
+
+Note that the elements of a newly created matrix may have arbitrary values.
+The elements can be changed and inspected using the following functions.
+
+       int isl_mat_rows(__isl_keep isl_mat *mat);
+       int isl_mat_cols(__isl_keep isl_mat *mat);
+       int isl_mat_get_element(__isl_keep isl_mat *mat,
+               int row, int col, isl_int *v);
+       __isl_give isl_mat *isl_mat_set_element(__isl_take isl_mat *mat,
+               int row, int col, isl_int v);
+
+C<isl_mat_get_element> will return a negative value if anything went wrong.
+In that case, the value of C<*v> is undefined.
+
+The following function can be used to compute the (right) inverse
+of a matrix, i.e., a matrix such that the product of the original
+and the inverse (in that order) is a multiple of the identity matrix.
+The input matrix is assumed to be of full row-rank.
+
+       __isl_give isl_mat *isl_mat_right_inverse(__isl_take isl_mat *mat);
+
+The following function can be used to compute the (right) kernel
+(or null space) of a matrix, i.e., a matrix such that the product of
+the original and the kernel (in that order) is the zero matrix.
+
+       __isl_give isl_mat *isl_mat_right_kernel(__isl_take isl_mat *mat);
+
 =head2 Points
 
 Points are elements of a set.  They can be used to construct
index 4f81b71..8536df1 100644 (file)
 extern "C" {
 #endif
 
-struct isl_mat {
-       int ref;
-
-       struct isl_ctx *ctx;
-
-#define ISL_MAT_BORROWED               (1 << 0)
-       unsigned flags;
-
-       unsigned n_row;
-       unsigned n_col;
-
-       isl_int **row;
-
-       /* actual size of the rows in memory; n_col <= max_col */
-       unsigned max_col;
-
-       struct isl_blk block;
-};
+struct isl_mat;
 typedef struct isl_mat isl_mat;
 
-struct isl_mat *isl_mat_alloc(struct isl_ctx *ctx,
+__isl_give isl_mat *isl_mat_alloc(struct isl_ctx *ctx,
        unsigned n_row, unsigned n_col);
 struct isl_mat *isl_mat_dup(struct isl_mat *mat);
 struct isl_mat *isl_mat_extend(struct isl_mat *mat,
        unsigned n_row, unsigned n_col);
 struct isl_mat *isl_mat_identity(struct isl_ctx *ctx, unsigned n_row);
-struct isl_mat *isl_mat_copy(struct isl_mat *mat);
+__isl_give isl_mat *isl_mat_copy(__isl_keep isl_mat *mat);
 struct isl_mat *isl_mat_cow(struct isl_mat *mat);
-void isl_mat_free(struct isl_mat *mat);
+void isl_mat_free(__isl_take isl_mat *mat);
+
+int isl_mat_rows(__isl_keep isl_mat *mat);
+int isl_mat_cols(__isl_keep isl_mat *mat);
+int isl_mat_get_element(__isl_keep isl_mat *mat, int row, int col, isl_int *v);
+__isl_give isl_mat *isl_mat_set_element(__isl_take isl_mat *mat,
+       int row, int col, isl_int v);
 
 struct isl_mat *isl_mat_sub_alloc(struct isl_ctx *ctx, isl_int **row,
        unsigned first_row, unsigned n_row, unsigned first_col, unsigned n_col);
@@ -76,8 +65,8 @@ struct isl_mat *isl_mat_inverse_product(struct isl_mat *left,
        struct isl_mat *right);
 struct isl_mat *isl_mat_product(struct isl_mat *left, struct isl_mat *right);
 struct isl_mat *isl_mat_transpose(struct isl_mat *mat);
-struct isl_mat *isl_mat_right_inverse(struct isl_mat *mat);
-struct isl_mat *isl_mat_right_kernel(struct isl_mat *mat);
+__isl_give isl_mat *isl_mat_right_inverse(__isl_take isl_mat *mat);
+__isl_give isl_mat *isl_mat_right_kernel(__isl_take isl_mat *mat);
 
 __isl_give isl_mat *isl_mat_normalize(__isl_take isl_mat *mat);
 
index dcb3d18..894670b 100644 (file)
@@ -16,6 +16,7 @@
 #include "isl_equalities.h"
 #include "isl_sample.h"
 #include "isl_tab.h"
+#include <isl_mat_private.h>
 
 struct isl_basic_map *isl_basic_map_implicit_equalities(
                                                struct isl_basic_map *bmap)
index 8a00fb0..e9eb760 100644 (file)
@@ -11,7 +11,7 @@
 #define ISL_BASIS_REDUCTION_H
 
 #include "isl_set.h"
-#include "isl_mat.h"
+#include <isl_mat_private.h>
 #include "isl_tab.h"
 
 #if defined(__cplusplus)
index 86c3715..dbd2a7e 100644 (file)
@@ -13,6 +13,7 @@
 #include "isl_map_private.h"
 #include "isl_seq.h"
 #include "isl_tab.h"
+#include <isl_mat_private.h>
 
 #define STATUS_ERROR           -1
 #define STATUS_REDUNDANT        1
index d267747..b355cda 100644 (file)
@@ -10,7 +10,7 @@
 #include "isl_lp.h"
 #include "isl_map.h"
 #include "isl_map_private.h"
-#include "isl_mat.h"
+#include <isl_mat_private.h>
 #include "isl_set.h"
 #include "isl_seq.h"
 #include "isl_equalities.h"
index 60c5e94..8c36dbc 100644 (file)
@@ -7,7 +7,7 @@
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
  */
 
-#include "isl_mat.h"
+#include <isl_mat_private.h>
 #include "isl_seq.h"
 #include "isl_map_private.h"
 #include "isl_equalities.h"
index 379222b..3b32e19 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <isl_factorization.h>
 #include <isl_dim_private.h>
+#include <isl_mat_private.h>
 
 static __isl_give isl_factorizer *isl_factorizer_alloc(
        __isl_take isl_morph *morph, int n_group)
index 803a769..fb841f5 100644 (file)
@@ -15,6 +15,7 @@
 #include <isl_map_private.h>
 #include <isl_lp.h>
 #include <isl_seq.h>
+#include <isl_mat_private.h>
 
 static __isl_give isl_qpolynomial_fold *qpolynomial_fold_alloc(
        enum isl_fold type, __isl_take isl_dim *dim, int n)
index 4ac4416..4c5e6cf 100644 (file)
@@ -22,6 +22,7 @@
 #include "isl_obj.h"
 #include "isl_polynomial_private.h"
 #include <isl_union_map.h>
+#include <isl_mat_private.h>
 
 struct variable {
        char                    *name;
index c6eeaf8..6b934f6 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -27,6 +27,7 @@
 #include "isl_sample.h"
 #include "isl_tab.h"
 #include "isl_vec.h"
+#include <isl_mat_private.h>
 
 /* Maps dst positions to src positions */
 struct isl_dim_map {
index 767ad22..d862f9a 100644 (file)
@@ -13,6 +13,7 @@
 #include "isl_seq.h"
 #include "isl_tab.h"
 #include <isl_dim_private.h>
+#include <isl_mat_private.h>
 
 static void swap_equality(struct isl_basic_map *bmap, int a, int b)
 {
index 1c56388..f425359 100644 (file)
--- a/isl_mat.c
+++ b/isl_mat.c
@@ -9,7 +9,7 @@
 
 #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>
 
@@ -202,6 +202,49 @@ void isl_mat_free(struct isl_mat *mat)
        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;
diff --git a/isl_mat_private.h b/isl_mat_private.h
new file mode 100644 (file)
index 0000000..ef7474e
--- /dev/null
@@ -0,0 +1,20 @@
+#include <isl_mat.h>
+
+struct isl_mat {
+       int ref;
+
+       struct isl_ctx *ctx;
+
+#define ISL_MAT_BORROWED               (1 << 0)
+       unsigned flags;
+
+       unsigned n_row;
+       unsigned n_col;
+
+       isl_int **row;
+
+       /* actual size of the rows in memory; n_col <= max_col */
+       unsigned max_col;
+
+       struct isl_blk block;
+};
index 20a4063..8bc4db8 100644 (file)
@@ -11,6 +11,7 @@
 #include <isl_morph.h>
 #include <isl_seq.h>
 #include <isl_map_private.h>
+#include <isl_mat_private.h>
 #include <isl_dim_private.h>
 #include <isl_equalities.h>
 
index e04fbc7..fc70284 100644 (file)
@@ -18,6 +18,7 @@
 #include <isl_printer_private.h>
 #include <isl_dim_private.h>
 #include <isl_map_private.h>
+#include <isl_mat_private.h>
 #include <isl_union_map.h>
 
 static const char *s_to[2] = { " -> ", " \\to " };
index a8dfc20..2d52894 100644 (file)
@@ -16,6 +16,7 @@
 #include <isl_point_private.h>
 #include <isl_dim_private.h>
 #include <isl_map_private.h>
+#include <isl_mat_private.h>
 
 static unsigned pos(__isl_keep isl_dim *dim, enum isl_dim_type type)
 {
index b8a80be..7a71ce6 100644 (file)
--- a/isl_tab.c
+++ b/isl_tab.c
@@ -7,7 +7,7 @@
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
  */
 
-#include "isl_mat.h"
+#include <isl_mat_private.h>
 #include "isl_map_private.h"
 #include "isl_tab.h"
 #include "isl_seq.h"
index 6fc6459..1cbc013 100644 (file)
@@ -11,6 +11,7 @@
 #include "isl_seq.h"
 #include "isl_tab.h"
 #include "isl_sample.h"
+#include <isl_mat_private.h>
 
 /*
  * The implementation of parametric integer linear programming in this file
index 049a2f4..5b97a07 100644 (file)
@@ -14,6 +14,7 @@
 #include <isl_dim_private.h>
 #include <isl_lp.h>
 #include <isl_union_map.h>
+#include <isl_mat_private.h>
 
 int isl_map_is_transitively_closed(__isl_keep isl_map *map)
 {
index 5d2b718..4abd3ae 100644 (file)
@@ -15,6 +15,7 @@
 #include <isl_dim_private.h>
 #include <isl_morph.h>
 #include <isl_vertices_private.h>
+#include <isl_mat_private.h>
 
 #define SELECTED       1
 #define DESELECTED     -1
index fbd80ae..269bd81 100644 (file)
@@ -11,6 +11,7 @@
 #include "isl_equalities.h"
 #include "isl_seq.h"
 #include "isl_scan.h"
+#include <isl_mat_private.h>
 
 /* The input of this program is the same as that of the "polytope_scan"
  * program from the barvinok distribution.