gen_fun::Hadamard_product: don't assume equalities are independent
[barvinok.git] / randomtest.c
blobdc125cc1310c592881006a9ad6d01ba47f368bfc
1 #include <assert.h>
2 #include <unistd.h>
3 #include <polylib/polylibgmp.h>
4 #include <barvinok/util.h>
5 #include <barvinok/barvinok.h>
7 #ifdef HAVE_SYS_TIMES_H
9 #include <sys/times.h>
11 static void time_diff(struct tms *before, struct tms *after)
13 long ticks = sysconf(_SC_CLK_TCK);
14 printf("User: %g; Sys: %g\n",
15 (0.0 + after->tms_utime - before->tms_utime) / ticks,
16 (0.0 + after->tms_stime - before->tms_stime) / ticks);
19 #else
21 struct tms {};
22 static void times(struct tms* time)
25 static void time_diff(struct tms *before, struct tms *after)
29 #endif
31 int main()
33 static const int size = 1000;
34 static const int loop = 10;
35 int i, j, d, r, c;
36 Matrix *M;
37 Polyhedron *P;
38 Value cm, cb;
39 struct tms tms_before, tms_between, tms_after;
40 value_init(cm);
41 value_init(cb);
43 for (d = 2; d < 10; ++d) {
44 M = Matrix_Alloc(2*d, 2+d);
45 for (r = 0; r < 2*d; ++r)
46 value_set_si(M->p[r][0], 1);
47 for (i = 0; i < loop; ++i) {
48 for (r = 0; r < 2*d; ++r) {
49 for (c = 1; c < 1+d; ++c) {
50 value_set_si(M->p[r][c], random_int(size));
52 value_set_si(M->p[r][d+1], random_int(2)+1);
54 P = Rays2Polyhedron(M, 2*d);
55 Polyhedron_Print(stdout, P_VALUE_FMT, P);
56 times(&tms_before);
57 manual_count(P, &cm);
58 times(&tms_between);
59 barvinok_count(P, &cb, 100);
60 times(&tms_after);
61 printf("manual: ");
62 value_print(stdout, P_VALUE_FMT, cm);
63 puts("");
64 time_diff(&tms_before, &tms_between);
65 printf("Barvinok: ");
66 value_print(stdout, P_VALUE_FMT, cb);
67 puts("");
68 time_diff(&tms_between, &tms_after);
69 assert(value_eq(cm, cb));
71 Matrix_Free(M);
73 value_clear(cm);
74 value_clear(cb);
75 return 0;