7 #include <isl/polynomial.h>
8 #include <isl/stream.h>
9 #include <isl/printer.h>
10 #include <barvinok/isl.h>
11 #include <barvinok/options.h>
12 #include <barvinok/util.h>
16 struct verify_options
*verify
;
19 ISL_ARGS_START(struct options
, options_args
)
20 ISL_ARG_CHILD(struct options
, verify
, NULL
,
21 &verify_options_args
, "verification")
24 ISL_ARG_DEF(options
, struct options
, options_args
)
26 struct verify_point_sum
{
27 struct verify_point_data vpd
;
28 isl_pw_qpolynomial
*pwqp
;
29 isl_pw_qpolynomial
*sum
;
31 isl_pw_qpolynomial
*fixed
;
35 static isl_stat
manual_sum(__isl_take isl_point
*pnt
, void *user
)
37 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
40 v
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->fixed
), pnt
);
41 vps
->manual
= isl_val_add(vps
->manual
, v
);
46 static isl_stat
verify_point(__isl_take isl_point
*pnt
, void *user
)
48 struct verify_point_sum
*vps
= (struct verify_point_sum
*) user
;
56 FILE *out
= vps
->vpd
.options
->print_all
? stdout
: stderr
;
60 vps
->fixed
= isl_pw_qpolynomial_copy(vps
->pwqp
);
61 nparam
= isl_pw_qpolynomial_dim(vps
->sum
, isl_dim_param
);
62 for (i
= 0; i
< nparam
; ++i
) {
63 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
64 vps
->fixed
= isl_pw_qpolynomial_fix_val(vps
->fixed
,
68 eval
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->sum
),
71 vps
->manual
= isl_val_zero(isl_point_get_ctx(pnt
));
72 dom
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(vps
->fixed
));
73 r
= isl_set_foreach_point(dom
, &manual_sum
, user
);
78 ok
= isl_val_eq(eval
, vps
->manual
);
80 if (vps
->vpd
.options
->print_all
|| !ok
) {
81 isl_ctx
*ctx
= isl_pw_qpolynomial_get_ctx(vps
->pwqp
);
82 isl_printer
*p
= isl_printer_to_file(ctx
, out
);
84 for (i
= 0; i
< nparam
; ++i
) {
87 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
88 p
= isl_printer_print_val(p
, v
);
92 p
= isl_printer_print_val(p
, eval
);
93 fprintf(out
, ", sum(EP) = ");
94 p
= isl_printer_print_val(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_val_free(vps
->manual
);
110 isl_pw_qpolynomial_free(vps
->fixed
);
117 if (vps
->vpd
.options
->continue_on_error
)
120 return (vps
->vpd
.n
>= 1 && ok
) ? isl_stat_ok
: isl_stat_error
;
123 static int verify(__isl_keep isl_pw_qpolynomial
*pwqp
,
124 __isl_keep isl_pw_qpolynomial
*sum
, struct verify_options
*options
)
126 struct verify_point_sum vps
= { { options
} };
133 context
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(sum
));
134 context
= verify_context_set_bounds(context
, options
);
136 r
= verify_point_data_init(&vps
.vpd
, context
);
139 isl_set_foreach_point(context
, verify_point
, &vps
);
143 isl_set_free(context
);
145 verify_point_data_fini(&vps
.vpd
);
150 int main(int argc
, char **argv
)
154 isl_pw_qpolynomial
*pwqp
;
155 isl_pw_qpolynomial
*sum
;
156 struct isl_stream
*s
;
157 struct options
*options
= options_new_with_defaults();
159 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
160 ctx
= isl_ctx_alloc_with_options(&options_args
, options
);
162 s
= isl_stream_new_file(ctx
, stdin
);
163 pwqp
= isl_stream_read_pw_qpolynomial(s
);
165 if (options
->verify
->verify
) {
166 if (verify_options_set_range_pwqp(options
->verify
, pwqp
) < 0)
167 pwqp
= isl_pw_qpolynomial_free(pwqp
);
170 sum
= isl_pw_qpolynomial_sum(isl_pw_qpolynomial_copy(pwqp
));
171 if (options
->verify
->verify
)
172 result
= verify(pwqp
, sum
, options
->verify
);
174 isl_printer
*p
= isl_printer_to_file(ctx
, stdout
);
175 p
= isl_printer_print_pw_qpolynomial(p
, sum
);
176 p
= isl_printer_end_line(p
);
179 isl_pw_qpolynomial_free(sum
);
180 isl_pw_qpolynomial_free(pwqp
);