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
;
57 FILE *out
= vps
->vpd
.options
->print_all
? stdout
: stderr
;
61 vps
->fixed
= isl_pw_qpolynomial_copy(vps
->pwqp
);
62 nparam
= isl_pw_qpolynomial_dim(vps
->sum
, isl_dim_param
);
63 for (i
= 0; i
< nparam
; ++i
) {
64 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
65 vps
->fixed
= isl_pw_qpolynomial_fix_val(vps
->fixed
,
69 eval
= isl_pw_qpolynomial_eval(isl_pw_qpolynomial_copy(vps
->sum
),
72 vps
->manual
= isl_val_zero(isl_point_get_ctx(pnt
));
73 dom
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(vps
->fixed
));
74 r
= isl_set_foreach_point(dom
, &manual_sum
, user
);
79 nvar
= isl_set_dim(dom
, isl_dim_set
);
81 ok
= isl_val_eq(eval
, vps
->manual
);
83 if (vps
->vpd
.options
->print_all
|| !ok
) {
84 isl_ctx
*ctx
= isl_pw_qpolynomial_get_ctx(vps
->pwqp
);
85 isl_printer
*p
= isl_printer_to_file(ctx
, out
);
87 for (i
= 0; i
< nparam
; ++i
) {
90 v
= isl_point_get_coordinate_val(pnt
, isl_dim_param
, i
);
91 p
= isl_printer_print_val(p
, v
);
95 p
= isl_printer_print_val(p
, eval
);
96 fprintf(out
, ", sum(EP) = ");
97 p
= isl_printer_print_val(p
, vps
->manual
);
99 fprintf(out
, ". OK\n");
101 fprintf(out
, ". NOT OK\n");
103 } else if ((vps
->vpd
.n
% vps
->vpd
.s
) == 0) {
112 isl_val_free(vps
->manual
);
113 isl_pw_qpolynomial_free(vps
->fixed
);
120 if (vps
->vpd
.options
->continue_on_error
)
123 return (vps
->vpd
.n
>= 1 && ok
) ? isl_stat_ok
: isl_stat_error
;
126 static int verify(__isl_keep isl_pw_qpolynomial
*pwqp
,
127 __isl_take isl_pw_qpolynomial
*sum
, struct verify_options
*options
)
129 struct verify_point_sum vps
= { { options
} };
136 context
= isl_pw_qpolynomial_domain(isl_pw_qpolynomial_copy(sum
));
137 context
= verify_context_set_bounds(context
, options
);
139 r
= verify_point_data_init(&vps
.vpd
, context
);
142 isl_set_foreach_point(context
, verify_point
, &vps
);
146 isl_set_free(context
);
148 verify_point_data_fini(&vps
.vpd
);
153 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_args
, 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
);