Polly 20.0.0git
polytope_scan.c
Go to the documentation of this file.
1/*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
9
10#include <assert.h>
11#include <isl_map_private.h>
12#include "isl_equalities.h"
13#include <isl_seq.h>
14#include "isl_scan.h"
15#include <isl_mat_private.h>
16#include <isl_vec_private.h>
17
18/* The input of this program is the same as that of the "polytope_scan"
19 * program from the barvinok distribution.
20 *
21 * Constraints of set is PolyLib format.
22 *
23 * The input set is assumed to be bounded.
24 */
25
29};
30
32 __isl_take isl_vec *sample)
33{
34 struct scan_samples *ss = (struct scan_samples *)cb;
35
36 ss->samples = isl_mat_extend(ss->samples, ss->samples->n_row + 1,
37 ss->samples->n_col);
38 if (!ss->samples)
39 goto error;
40
41 isl_seq_cpy(ss->samples->row[ss->samples->n_row - 1],
42 sample->el, sample->size);
43
44 isl_vec_free(sample);
45 return isl_stat_ok;
46error:
47 isl_vec_free(sample);
48 return isl_stat_error;
49}
50
53{
54 isl_ctx *ctx;
55 isl_size dim;
56 struct scan_samples ss;
57
58 ctx = isl_basic_set_get_ctx(bset);
59 dim = isl_basic_set_dim(bset, isl_dim_all);
60 if (dim < 0)
61 goto error;
63 ss.samples = isl_mat_alloc(ctx, 0, 1 + dim);
64 if (!ss.samples)
65 goto error;
66
67 if (isl_basic_set_scan(bset, &ss.callback) < 0) {
69 return NULL;
70 }
71
72 return ss.samples;
73error:
75 return NULL;
76}
77
79{
80 struct isl_mat *T;
81 struct isl_mat *samples;
82
83 if (!bset)
84 return NULL;
85
86 if (bset->n_eq == 0)
87 return isl_basic_set_scan_samples(bset);
88
89 bset = isl_basic_set_remove_equalities(bset, &T, NULL);
90 samples = isl_basic_set_scan_samples(bset);
91 return isl_mat_product(samples, isl_mat_transpose(T));
92}
93
94int main(int argc, char **argv)
95{
96 struct isl_ctx *ctx = isl_ctx_alloc();
97 struct isl_basic_set *bset;
98 struct isl_mat *samples;
99
100 bset = isl_basic_set_read_from_file(ctx, stdin);
101 samples = isl_basic_set_samples(bset);
102 isl_mat_print_internal(samples, stdout, 0);
103 isl_mat_free(samples);
105
106 return 0;
107}
#define __isl_take
Definition: ctx.h:22
isl_stat
Definition: ctx.h:84
@ isl_stat_error
Definition: ctx.h:85
@ isl_stat_ok
Definition: ctx.h:86
#define __isl_give
Definition: ctx.h:19
isl_ctx * isl_ctx_alloc(void)
Definition: isl_ctx.c:261
int isl_size
Definition: ctx.h:96
void isl_ctx_free(isl_ctx *ctx)
Definition: isl_ctx.c:288
__isl_give isl_basic_set * isl_basic_set_remove_equalities(__isl_take isl_basic_set *bset, __isl_give isl_mat **T, __isl_give isl_mat **T2)
isl_stat isl_basic_set_scan(__isl_take isl_basic_set *bset, struct isl_scan_callback *callback)
Definition: isl_scan.c:102
void isl_seq_cpy(isl_int *dst, isl_int *src, unsigned len)
Definition: isl_seq.c:42
struct isl_basic_set isl_basic_set
Definition: map_type.h:20
__isl_give isl_mat * isl_mat_transpose(__isl_take isl_mat *mat)
Definition: isl_mat.c:1203
__isl_give isl_mat * isl_mat_product(__isl_take isl_mat *left, __isl_take isl_mat *right)
Definition: isl_mat.c:1271
void isl_mat_print_internal(__isl_keep isl_mat *mat, FILE *out, int indent)
Definition: isl_mat.c:1471
__isl_null isl_mat * isl_mat_free(__isl_take isl_mat *mat)
Definition: isl_mat.c:240
__isl_give isl_mat * isl_mat_alloc(isl_ctx *ctx, unsigned n_row, unsigned n_col)
Definition: isl_mat.c:53
__isl_give isl_mat * isl_mat_extend(__isl_take isl_mat *mat, unsigned n_row, unsigned n_col)
Definition: isl_mat.c:91
static __isl_give isl_mat * isl_basic_set_scan_samples(__isl_take isl_basic_set *bset)
Definition: polytope_scan.c:51
static __isl_give isl_mat * isl_basic_set_samples(__isl_take isl_basic_set *bset)
Definition: polytope_scan.c:78
static isl_stat scan_samples_add_sample(struct isl_scan_callback *cb, __isl_take isl_vec *sample)
Definition: polytope_scan.c:31
isl_size isl_basic_set_dim(__isl_keep isl_basic_set *bset, enum isl_dim_type type)
Definition: isl_map.c:201
__isl_give isl_basic_set * isl_basic_set_read_from_file(isl_ctx *ctx, FILE *input)
Definition: isl_input.c:3296
__isl_null isl_basic_set * isl_basic_set_free(__isl_take isl_basic_set *bset)
Definition: isl_map.c:1523
isl_ctx * isl_basic_set_get_ctx(__isl_keep isl_basic_set *bset)
Definition: isl_map.c:386
@ isl_dim_all
Definition: space_type.h:20
unsigned n_row
unsigned n_col
struct isl_ctx * ctx
isl_int ** row
isl_stat(* add)(struct isl_scan_callback *cb, __isl_take isl_vec *sample)
Definition: isl_scan.h:17
struct isl_mat * samples
Definition: polytope_scan.c:28
struct isl_scan_callback callback
Definition: polytope_scan.c:27
__isl_null isl_vec * isl_vec_free(__isl_take isl_vec *vec)
Definition: isl_vec.c:234