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
;
48 isl_qpolynomial
*eval
;
50 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 isl_point_get_coordinate(pnt
, isl_dim_param
, i
, &v
);
59 vps
->fixed
= isl_pw_qpolynomial_fix_dim(vps
->fixed
,
63 eval
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->sum
),
66 vps
->manual
= isl_qpolynomial_zero(isl_pw_qpolynomial_get_dim(vps
->pwqp
));
67 dom
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(vps
->fixed
));
68 r
= isl_set_foreach_point(dom
, &manual_sum
, user
);
73 ok
= isl_qpolynomial_is_equal(eval
, vps
->manual
);
75 if (vps
->vpd
.options
->print_all
|| !ok
) {
76 isl_ctx
*ctx
= isl_pw_qpolynomial_get_ctx(vps
->pwqp
);
77 isl_printer
*p
= isl_printer_to_file(ctx
, out
);
79 for (i
= 0; i
< nparam
; ++i
) {
82 isl_point_get_coordinate(pnt
, isl_dim_param
, i
, &v
);
83 isl_int_print(out
, v
, 0);
86 p
= isl_printer_print_qpolynomial(p
, eval
);
87 fprintf(out
, ", sum(EP) = ");
88 p
= isl_printer_print_qpolynomial(p
, vps
->manual
);
90 fprintf(out
, ". OK\n");
92 fprintf(out
, ". NOT OK\n");
94 } else if ((vps
->vpd
.n
% vps
->vpd
.s
) == 0) {
103 isl_qpolynomial_free(vps
->manual
);
104 isl_pw_qpolynomial_free(vps
->fixed
);
105 isl_qpolynomial_free(eval
);
112 if (vps
->vpd
.options
->continue_on_error
)
115 return (vps
->vpd
.n
>= 1 && ok
) ? 0 : -1;
118 static int verify(__isl_keep isl_pw_qpolynomial
*pwqp
,
119 __isl_take isl_pw_qpolynomial
*sum
, struct verify_options
*options
)
121 struct verify_point_sum vps
= { { options
} };
128 context
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(sum
));
129 context
= verify_context_set_bounds(context
, options
);
131 r
= verify_point_data_init(&vps
.vpd
, context
);
134 isl_set_foreach_point(context
, verify_point
, &vps
);
138 isl_set_free(context
);
140 verify_point_data_fini(&vps
.vpd
);
145 int main(int argc
, char **argv
)
151 isl_pw_qpolynomial
*pwqp
;
152 isl_pw_qpolynomial
*sum
;
153 struct isl_stream
*s
;
154 struct options
*options
= options_new_with_defaults();
156 argc
= options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
157 ctx
= isl_ctx_alloc_with_options(options_arg
, options
);
159 s
= isl_stream_new_file(ctx
, stdin
);
160 pwqp
= isl_stream_read_pw_qpolynomial(s
);
162 if (options
->verify
->verify
) {
163 isl_dim
*dim
= isl_pw_qpolynomial_get_dim(pwqp
);
164 unsigned total
= isl_dim_total(dim
);
166 verify_options_set_range(options
->verify
, total
);
169 sum
= isl_pw_qpolynomial_sum(isl_pw_qpolynomial_copy(pwqp
));
170 if (options
->verify
->verify
)
171 result
= verify(pwqp
, sum
, options
->verify
);
173 isl_printer
*p
= isl_printer_to_file(ctx
, stdout
);
174 p
= isl_printer_print_pw_qpolynomial(p
, sum
);
175 p
= isl_printer_end_line(p
);
178 isl_pw_qpolynomial_free(sum
);
179 isl_pw_qpolynomial_free(pwqp
);