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 ISL_ARGS_START(struct options
, options_args
)
13 ISL_ARG_CHILD(struct options
, verify
, NULL
,
14 &verify_options_args
, "verification")
17 ISL_ARG_DEF(options
, struct options
, options_args
)
19 struct verify_point_sum
{
20 struct verify_point_data vpd
;
21 isl_pw_qpolynomial
*pwqp
;
22 isl_pw_qpolynomial
*sum
;
24 isl_pw_qpolynomial
*fixed
;
28 static int manual_sum(__isl_take isl_point
*pnt
, void *user
)
30 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
33 v
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->fixed
), pnt
);
34 vps
->manual
= isl_val_add(vps
->manual
, v
);
39 static int verify_point(__isl_take isl_point
*pnt
, void *user
)
41 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
51 FILE *out
= vps
->vpd
.options
->print_all
? stdout
: stderr
;
55 vps
->fixed
= isl_pw_qpolynomial_copy(vps
->pwqp
);
56 nparam
= isl_pw_qpolynomial_dim(vps
->sum
, isl_dim_param
);
57 for (i
= 0; i
< nparam
; ++i
) {
58 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
59 vps
->fixed
= isl_pw_qpolynomial_fix_val(vps
->fixed
,
63 eval
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->sum
),
66 vps
->manual
= isl_val_zero(isl_point_get_ctx(pnt
));
67 dom
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(vps
->fixed
));
68 r
= isl_set_foreach_point(dom
, &manual_sum
, user
);
73 nvar
= isl_set_dim(dom
, isl_dim_set
);
75 ok
= isl_val_eq(eval
, vps
->manual
);
77 if (vps
->vpd
.options
->print_all
|| !ok
) {
78 isl_ctx
*ctx
= isl_pw_qpolynomial_get_ctx(vps
->pwqp
);
79 isl_printer
*p
= isl_printer_to_file(ctx
, out
);
81 for (i
= 0; i
< nparam
; ++i
) {
84 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
85 p
= isl_printer_print_val(p
, v
);
89 p
= isl_printer_print_val(p
, eval
);
90 fprintf(out
, ", sum(EP) = ");
91 p
= isl_printer_print_val(p
, vps
->manual
);
93 fprintf(out
, ". OK\n");
95 fprintf(out
, ". NOT OK\n");
97 } else if ((vps
->vpd
.n
% vps
->vpd
.s
) == 0) {
106 isl_val_free(vps
->manual
);
107 isl_pw_qpolynomial_free(vps
->fixed
);
114 if (vps
->vpd
.options
->continue_on_error
)
117 return (vps
->vpd
.n
>= 1 && ok
) ? 0 : -1;
120 static int verify(__isl_keep isl_pw_qpolynomial
*pwqp
,
121 __isl_take isl_pw_qpolynomial
*sum
, struct verify_options
*options
)
123 struct verify_point_sum vps
= { { options
} };
130 context
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(sum
));
131 context
= verify_context_set_bounds(context
, options
);
133 r
= verify_point_data_init(&vps
.vpd
, context
);
136 isl_set_foreach_point(context
, verify_point
, &vps
);
140 isl_set_free(context
);
142 verify_point_data_fini(&vps
.vpd
);
147 int main(int argc
, char **argv
)
153 isl_pw_qpolynomial
*pwqp
;
154 isl_pw_qpolynomial
*sum
;
155 struct isl_stream
*s
;
156 struct options
*options
= options_new_with_defaults();
158 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
159 ctx
= isl_ctx_alloc_with_options(&options_args
, options
);
161 s
= isl_stream_new_file(ctx
, stdin
);
162 pwqp
= isl_stream_read_pw_qpolynomial(s
);
164 if (options
->verify
->verify
) {
165 isl_space
*dim
= isl_pw_qpolynomial_get_space(pwqp
);
166 unsigned total
= isl_space_dim(dim
, isl_dim_all
);
168 verify_options_set_range(options
->verify
, total
);
171 sum
= isl_pw_qpolynomial_sum(isl_pw_qpolynomial_copy(pwqp
));
172 if (options
->verify
->verify
)
173 result
= verify(pwqp
, sum
, options
->verify
);
175 isl_printer
*p
= isl_printer_to_file(ctx
, stdout
);
176 p
= isl_printer_print_pw_qpolynomial(p
, sum
);
177 p
= isl_printer_end_line(p
);
180 isl_pw_qpolynomial_free(sum
);
181 isl_pw_qpolynomial_free(pwqp
);