2 * Copyright 2012 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
10 #include <isl_pw_macro.h>
13 #define SUFFIX multi_aff
17 #define ARG2 isl_multi_aff
20 #include "isl_align_params_templ.c"
23 #define SUFFIX pw_multi_aff
27 #define ARG2 isl_pw_multi_aff
30 #include "isl_align_params_templ.c"
32 /* Compute the pullback of "pw" by the function represented by "ma".
33 * In other words, plug in "ma" in "pw".
35 __isl_give PW
*FN(PW
,pullback_multi_aff
)(__isl_take PW
*pw
,
36 __isl_take isl_multi_aff
*ma
)
40 isl_space
*space
= NULL
;
42 FN(PW
,align_params_multi_aff
)(&pw
, &ma
);
43 ma
= isl_multi_aff_align_divs(ma
);
44 n
= FN(PW
,n_piece
)(pw
);
48 space
= isl_space_join(isl_multi_aff_get_space(ma
),
49 FN(PW
,get_space
)(pw
));
51 for (i
= 0; i
< n
; ++i
) {
55 domain
= FN(PW
,take_domain_at
)(pw
, i
);
56 domain
= isl_set_preimage_multi_aff(domain
,
57 isl_multi_aff_copy(ma
));
58 pw
= FN(PW
,restore_domain_at
)(pw
, i
, domain
);
59 el
= FN(PW
,take_base_at
)(pw
, i
);
60 el
= FN(EL
,pullback_multi_aff
)(el
, isl_multi_aff_copy(ma
));
61 pw
= FN(PW
,restore_base_at
)(pw
, i
, el
);
64 pw
= FN(PW
,reset_space
)(pw
, space
);
65 isl_multi_aff_free(ma
);
68 isl_space_free(space
);
69 isl_multi_aff_free(ma
);
74 /* Compute the pullback of "pw" by the function represented by "pma".
75 * In other words, plug in "pma" in "pw".
77 static __isl_give PW
*FN(PW
,pullback_pw_multi_aff_aligned
)(__isl_take PW
*pw
,
78 __isl_take isl_pw_multi_aff
*pma
)
88 space
= isl_space_join(isl_pw_multi_aff_get_space(pma
),
89 FN(PW
,get_space
)(pw
));
90 isl_pw_multi_aff_free(pma
);
91 res
= FN(PW
,empty
)(space
);
96 res
= FN(PW
,pullback_multi_aff
)(FN(PW
,copy
)(pw
),
97 isl_multi_aff_copy(pma
->p
[0].maff
));
98 res
= FN(PW
,intersect_domain
)(res
, isl_set_copy(pma
->p
[0].set
));
100 for (i
= 1; i
< pma
->n
; ++i
) {
103 res_i
= FN(PW
,pullback_multi_aff
)(FN(PW
,copy
)(pw
),
104 isl_multi_aff_copy(pma
->p
[i
].maff
));
105 res_i
= FN(PW
,intersect_domain
)(res_i
,
106 isl_set_copy(pma
->p
[i
].set
));
107 res
= FN(PW
,add_disjoint
)(res
, res_i
);
110 isl_pw_multi_aff_free(pma
);
114 isl_pw_multi_aff_free(pma
);
119 __isl_give PW
*FN(PW
,pullback_pw_multi_aff
)(__isl_take PW
*pw
,
120 __isl_take isl_pw_multi_aff
*pma
)
122 FN(PW
,align_params_pw_multi_aff
)(&pw
, &pma
);
123 return FN(PW
,pullback_pw_multi_aff_aligned
)(pw
, pma
);