7 #include <isl/polynomial.h>
8 #include <isl/stream.h>
9 #include <isl/printer.h>
10 #include <barvinok/isl.h>
11 #include <barvinok/barvinok.h>
12 #include <barvinok/options.h>
13 #include <barvinok/util.h>
17 struct verify_options
*verify
;
20 ISL_ARGS_START(struct options
, options_args
)
21 ISL_ARG_CHILD(struct options
, verify
, NULL
,
22 &verify_options_args
, "verification")
25 ISL_ARG_DEF(options
, struct options
, options_args
)
27 struct verify_point_sum
{
28 struct verify_point_data vpd
;
29 isl_pw_qpolynomial
*pwqp
;
30 isl_pw_qpolynomial
*sum
;
32 isl_pw_qpolynomial
*fixed
;
36 static isl_stat
manual_sum(__isl_take isl_point
*pnt
, void *user
)
38 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
41 v
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->fixed
), pnt
);
42 vps
->manual
= isl_val_add(vps
->manual
, v
);
47 static isl_stat
verify_point(__isl_take isl_point
*pnt
, void *user
)
49 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
58 FILE *out
= vps
->vpd
.options
->print_all
? stdout
: stderr
;
62 vps
->fixed
= isl_pw_qpolynomial_copy(vps
->pwqp
);
63 nparam
= isl_pw_qpolynomial_dim(vps
->sum
, isl_dim_param
);
64 for (i
= 0; i
< nparam
; ++i
) {
65 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
66 vps
->fixed
= isl_pw_qpolynomial_fix_val(vps
->fixed
,
70 eval
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->sum
),
73 vps
->manual
= isl_val_zero(isl_point_get_ctx(pnt
));
74 dom
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(vps
->fixed
));
75 r
= isl_set_foreach_point(dom
, &manual_sum
, user
);
80 nvar
= isl_set_dim(dom
, isl_dim_set
);
82 ok
= isl_val_eq(eval
, vps
->manual
);
84 if (vps
->vpd
.options
->print_all
|| !ok
) {
85 isl_ctx
*ctx
= isl_pw_qpolynomial_get_ctx(vps
->pwqp
);
86 isl_printer
*p
= isl_printer_to_file(ctx
, out
);
88 for (i
= 0; i
< nparam
; ++i
) {
91 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
92 p
= isl_printer_print_val(p
, v
);
96 p
= isl_printer_print_val(p
, eval
);
97 fprintf(out
, ", sum(EP) = ");
98 p
= isl_printer_print_val(p
, vps
->manual
);
100 fprintf(out
, ". OK\n");
102 fprintf(out
, ". NOT OK\n");
104 } else if ((vps
->vpd
.n
% vps
->vpd
.s
) == 0) {
113 isl_val_free(vps
->manual
);
114 isl_pw_qpolynomial_free(vps
->fixed
);
121 if (vps
->vpd
.options
->continue_on_error
)
124 return (vps
->vpd
.n
>= 1 && ok
) ? isl_stat_ok
: isl_stat_error
;
127 static int verify(__isl_keep isl_pw_qpolynomial
*pwqp
,
128 __isl_take isl_pw_qpolynomial
*sum
, struct verify_options
*options
)
130 struct verify_point_sum vps
= { { options
} };
137 context
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(sum
));
138 context
= verify_context_set_bounds(context
, options
);
140 r
= verify_point_data_init(&vps
.vpd
, context
);
143 isl_set_foreach_point(context
, verify_point
, &vps
);
147 isl_set_free(context
);
149 verify_point_data_fini(&vps
.vpd
);
154 int main(int argc
, char **argv
)
158 isl_pw_qpolynomial
*pwqp
;
159 isl_pw_qpolynomial
*sum
;
160 struct isl_stream
*s
;
161 struct options
*options
= options_new_with_defaults();
163 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
164 ctx
= isl_ctx_alloc_with_options(&options_args
, options
);
166 s
= isl_stream_new_file(ctx
, stdin
);
167 pwqp
= isl_stream_read_pw_qpolynomial(s
);
169 if (options
->verify
->verify
) {
170 isl_space
*dim
= isl_pw_qpolynomial_get_space(pwqp
);
171 unsigned total
= isl_space_dim(dim
, isl_dim_all
);
173 verify_options_set_range(options
->verify
, total
);
176 sum
= isl_pw_qpolynomial_sum(isl_pw_qpolynomial_copy(pwqp
));
177 if (options
->verify
->verify
)
178 result
= verify(pwqp
, sum
, options
->verify
);
180 isl_printer
*p
= isl_printer_to_file(ctx
, stdout
);
181 p
= isl_printer_print_pw_qpolynomial(p
, sum
);
182 p
= isl_printer_end_line(p
);
185 isl_pw_qpolynomial_free(sum
);
186 isl_pw_qpolynomial_free(pwqp
);