2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2014 Ecole Normale Superieure
5 * Use of this software is governed by the GNU GPLv2+ licenses
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
13 #include <isl/val_gmp.h>
15 #include "isl_aff_polylib.h"
17 /* Fill in row "row" of "M" from "aff".
18 * The input is assumed not to involve any integer divisions.
20 * The order of the coefficients in the rows of "M" is
22 * input-coefficients parameter-coefficients constant-term denominator
24 static Matrix
*add_row(Matrix
*M
, int row
, __isl_take isl_aff
*aff
)
26 enum isl_dim_type types
[] = { isl_dim_in
, isl_dim_param
};
33 if (isl_aff_dim(aff
, isl_dim_div
) != 0)
34 isl_die(isl_aff_get_ctx(aff
), isl_error_unsupported
,
35 "cannot handle integer divisions", goto error
);
37 d
= isl_aff_get_denominator_val(aff
);
38 aff
= isl_aff_scale_val(aff
, isl_val_copy(d
));
41 for (i
= 0; i
< 2; ++i
) {
42 int n
= isl_aff_dim(aff
, types
[i
]);
43 for (j
= 0; j
< n
; ++j
) {
44 v
= isl_aff_get_coefficient_val(aff
, types
[i
], j
);
45 isl_val_get_num_gmp(v
, M
->p
[row
][k
++]);
50 v
= isl_aff_get_constant_val(aff
);
51 isl_val_get_num_gmp(v
, M
->p
[row
][k
++]);
54 isl_val_get_num_gmp(d
, M
->p
[row
][k
++]);
67 /* Convert the multi-affine expression "ma" to a PolyLib Matrix.
68 * The input is assumed not to involve any integer divisions.
70 * The order of the coefficients in the rows of the Matrix is
72 * input-coefficients parameter-coefficients constant-term denominator
74 Matrix
*isl_multi_aff_to_polylib(__isl_keep isl_multi_aff
*ma
)
77 unsigned nparam
, n_in
, n_out
;
83 nparam
= isl_multi_aff_dim(ma
, isl_dim_param
);
84 n_in
= isl_multi_aff_dim(ma
, isl_dim_in
);
85 n_out
= isl_multi_aff_dim(ma
, isl_dim_out
);
86 M
= Matrix_Alloc(n_out
, n_in
+ nparam
+ 1 + 1);
87 for (i
= 0; i
< n_out
; ++i
)
88 M
= add_row(M
, i
, isl_multi_aff_get_aff(ma
, i
));