2 #include <NTL/mat_ZZ.h>
4 #include <polylib/polylibgmp.h>
6 #include "conversion.h"
8 #define SIZE(p) (((long *) (p))[1])
9 #define DATA(p) ((mp_limb_t *) (((long *) (p)) + 2))
11 void value2zz(Value v
, ZZ
& z
)
13 int sa
= v
[0]._mp_size
;
14 int abs_sa
= sa
< 0 ? -sa
: sa
;
16 _ntl_gsetlength(&z
.rep
, abs_sa
);
17 mp_limb_t
* adata
= DATA(z
.rep
);
18 for (int i
= 0; i
< abs_sa
; ++i
)
19 adata
[i
] = v
[0]._mp_d
[i
];
23 void zz2value(ZZ
& z
, Value
& v
)
31 int abs_sa
= sa
< 0 ? -sa
: sa
;
33 mp_limb_t
* adata
= DATA(z
.rep
);
34 _mpz_realloc(v
, abs_sa
);
35 for (int i
= 0; i
< abs_sa
; ++i
)
36 v
[0]._mp_d
[i
] = adata
[i
];
40 void values2zz(Value
*p
, vec_ZZ
& v
, int len
)
44 for (int i
= 0; i
< len
; ++i
) {
51 void zz2values(vec_ZZ
& v
, Value
*p
)
53 for (int i
= 0; i
< v
.length(); ++i
)
58 * We just ignore the last column and row
59 * If the final element is not equal to one
60 * then the result will actually be a multiple of the input
62 void matrix2zz(Matrix
*M
, mat_ZZ
& m
, unsigned nr
, unsigned nc
)
66 for (int i
= 0; i
< nr
; ++i
) {
67 // assert(value_one_p(M->p[i][M->NbColumns - 1]));
68 for (int j
= 0; j
< nc
; ++j
) {
69 value2zz(M
->p
[i
][j
], m
[i
][j
]);
74 Matrix
*rays(Polyhedron
*C
)
76 unsigned dim
= C
->NbRays
- 1; /* don't count zero vertex */
77 assert(C
->NbRays
- 1 == C
->Dimension
);
79 Matrix
*M
= Matrix_Alloc(dim
+1, dim
+1);
83 for (i
= 0, c
= 0; i
<= dim
&& c
< dim
; ++i
)
84 if (value_zero_p(C
->Ray
[i
][dim
+1])) {
85 Vector_Copy(C
->Ray
[i
] + 1, M
->p
[c
], dim
);
86 value_set_si(M
->p
[c
++][dim
], 0);
89 value_set_si(M
->p
[dim
][dim
], 1);
94 Matrix
* rays2(Polyhedron
*C
)
96 unsigned dim
= C
->NbRays
- 1; /* don't count zero vertex */
97 assert(C
->NbRays
- 1 == C
->Dimension
);
99 Matrix
*M
= Matrix_Alloc(dim
, dim
);
103 for (i
= 0, c
= 0; i
<= dim
&& c
< dim
; ++i
)
104 if (value_zero_p(C
->Ray
[i
][dim
+1]))
105 Vector_Copy(C
->Ray
[i
] + 1, M
->p
[c
++], dim
);