2 #include <isl/stream.h>
3 #include <barvinok/barvinok.h>
4 #include <barvinok/options.h>
5 #include <barvinok/util.h>
9 struct verify_options
*verify
;
12 struct isl_arg options_arg
[] = {
13 ISL_ARG_CHILD(struct options
, verify
, NULL
,
14 verify_options_arg
, "verification")
18 ISL_ARG_DEF(options
, struct options
, options_arg
)
20 struct verify_point_sum
{
21 struct verify_point_data vpd
;
22 isl_pw_qpolynomial
*pwqp
;
23 isl_pw_qpolynomial
*sum
;
25 isl_pw_qpolynomial
*fixed
;
26 isl_qpolynomial
*manual
;
29 static int manual_sum(__isl_take isl_point
*pnt
, void *user
)
31 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
34 qp
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->fixed
), pnt
);
35 vps
->manual
= isl_qpolynomial_add(vps
->manual
, qp
);
40 static int verify_point(__isl_take isl_point
*pnt
, void *user
)
42 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
50 isl_qpolynomial
*eval
;
52 FILE *out
= vps
->vpd
.options
->print_all
? stdout
: stderr
;
57 vps
->fixed
= isl_pw_qpolynomial_copy(vps
->pwqp
);
58 nparam
= isl_pw_qpolynomial_dim(vps
->sum
, isl_dim_param
);
59 for (i
= 0; i
< nparam
; ++i
) {
60 isl_point_get_coordinate(pnt
, isl_dim_param
, i
, &v
);
61 vps
->fixed
= isl_pw_qpolynomial_fix_dim(vps
->fixed
,
65 eval
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->sum
),
68 space
= isl_pw_qpolynomial_get_domain_space(vps
->pwqp
);
69 vps
->manual
= isl_qpolynomial_zero_on_domain(space
);
70 dom
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(vps
->fixed
));
71 r
= isl_set_foreach_point(dom
, &manual_sum
, user
);
76 nvar
= isl_set_dim(dom
, isl_dim_set
);
77 vps
->manual
= isl_qpolynomial_project_domain_on_params(vps
->manual
);
79 ok
= isl_qpolynomial_plain_is_equal(eval
, vps
->manual
);
81 if (vps
->vpd
.options
->print_all
|| !ok
) {
82 isl_ctx
*ctx
= isl_pw_qpolynomial_get_ctx(vps
->pwqp
);
83 isl_printer
*p
= isl_printer_to_file(ctx
, out
);
85 for (i
= 0; i
< nparam
; ++i
) {
88 isl_point_get_coordinate(pnt
, isl_dim_param
, i
, &v
);
89 isl_int_print(out
, v
, 0);
92 p
= isl_printer_print_qpolynomial(p
, eval
);
93 fprintf(out
, ", sum(EP) = ");
94 p
= isl_printer_print_qpolynomial(p
, vps
->manual
);
96 fprintf(out
, ". OK\n");
98 fprintf(out
, ". NOT OK\n");
100 } else if ((vps
->vpd
.n
% vps
->vpd
.s
) == 0) {
109 isl_qpolynomial_free(vps
->manual
);
110 isl_pw_qpolynomial_free(vps
->fixed
);
111 isl_qpolynomial_free(eval
);
118 if (vps
->vpd
.options
->continue_on_error
)
121 return (vps
->vpd
.n
>= 1 && ok
) ? 0 : -1;
124 static int verify(__isl_keep isl_pw_qpolynomial
*pwqp
,
125 __isl_take isl_pw_qpolynomial
*sum
, struct verify_options
*options
)
127 struct verify_point_sum vps
= { { options
} };
134 context
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(sum
));
135 context
= verify_context_set_bounds(context
, options
);
137 r
= verify_point_data_init(&vps
.vpd
, context
);
140 isl_set_foreach_point(context
, verify_point
, &vps
);
144 isl_set_free(context
);
146 verify_point_data_fini(&vps
.vpd
);
151 int main(int argc
, char **argv
)
157 isl_pw_qpolynomial
*pwqp
;
158 isl_pw_qpolynomial
*sum
;
159 struct isl_stream
*s
;
160 struct options
*options
= options_new_with_defaults();
162 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
163 ctx
= isl_ctx_alloc_with_options(options_arg
, options
);
165 s
= isl_stream_new_file(ctx
, stdin
);
166 pwqp
= isl_stream_read_pw_qpolynomial(s
);
168 if (options
->verify
->verify
) {
169 isl_space
*dim
= isl_pw_qpolynomial_get_space(pwqp
);
170 unsigned total
= isl_space_dim(dim
, isl_dim_all
);
172 verify_options_set_range(options
->verify
, total
);
175 sum
= isl_pw_qpolynomial_sum(isl_pw_qpolynomial_copy(pwqp
));
176 if (options
->verify
->verify
)
177 result
= verify(pwqp
, sum
, options
->verify
);
179 isl_printer
*p
= isl_printer_to_file(ctx
, stdout
);
180 p
= isl_printer_print_pw_qpolynomial(p
, sum
);
181 p
= isl_printer_end_line(p
);
184 isl_pw_qpolynomial_free(sum
);
185 isl_pw_qpolynomial_free(pwqp
);