isl_pw_*_split_dims: drop spurious sanity check
[isl.git] / isl_pw_pullback_templ.c
blobdbfaa1e8e9e368dd31e9e7b4d7c460f70dd0f386
1 /*
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
8 */
10 #include <isl_pw_macro.h>
12 #undef SUFFIX
13 #define SUFFIX multi_aff
14 #undef ARG1
15 #define ARG1 PW
16 #undef ARG2
17 #define ARG2 isl_multi_aff
19 static
20 #include "isl_align_params_templ.c"
22 #undef SUFFIX
23 #define SUFFIX pw_multi_aff
24 #undef ARG1
25 #define ARG1 PW
26 #undef ARG2
27 #define ARG2 isl_pw_multi_aff
29 static
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)
38 int i;
39 isl_size n;
40 isl_space *space = NULL;
42 FN(PW,align_params_multi_aff)(&pw, &ma);
43 ma = isl_multi_aff_align_divs(ma);
44 pw = FN(PW,cow)(pw);
45 n = FN(PW,n_piece)(pw);
46 if (n < 0 || !ma)
47 goto error;
49 space = isl_space_join(isl_multi_aff_get_space(ma),
50 FN(PW,get_space)(pw));
52 for (i = 0; i < n; ++i) {
53 EL *el;
55 pw->p[i].set = isl_set_preimage_multi_aff(pw->p[i].set,
56 isl_multi_aff_copy(ma));
57 if (!pw->p[i].set)
58 goto error;
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);
62 if (!pw)
63 goto error;
66 pw = FN(PW,reset_space)(pw, space);
67 isl_multi_aff_free(ma);
68 return pw;
69 error:
70 isl_space_free(space);
71 isl_multi_aff_free(ma);
72 FN(PW,free)(pw);
73 return NULL;
76 /* Compute the pullback of "pw" by the function represented by "pma".
77 * In other words, plug in "pma" in "pw".
79 static __isl_give PW *FN(PW,pullback_pw_multi_aff_aligned)(__isl_take PW *pw,
80 __isl_take isl_pw_multi_aff *pma)
82 int i;
83 PW *res;
85 if (!pma)
86 goto error;
88 if (pma->n == 0) {
89 isl_space *space;
90 space = isl_space_join(isl_pw_multi_aff_get_space(pma),
91 FN(PW,get_space)(pw));
92 isl_pw_multi_aff_free(pma);
93 res = FN(PW,empty)(space);
94 FN(PW,free)(pw);
95 return res;
98 res = FN(PW,pullback_multi_aff)(FN(PW,copy)(pw),
99 isl_multi_aff_copy(pma->p[0].maff));
100 res = FN(PW,intersect_domain)(res, isl_set_copy(pma->p[0].set));
102 for (i = 1; i < pma->n; ++i) {
103 PW *res_i;
105 res_i = FN(PW,pullback_multi_aff)(FN(PW,copy)(pw),
106 isl_multi_aff_copy(pma->p[i].maff));
107 res_i = FN(PW,intersect_domain)(res_i,
108 isl_set_copy(pma->p[i].set));
109 res = FN(PW,add_disjoint)(res, res_i);
112 isl_pw_multi_aff_free(pma);
113 FN(PW,free)(pw);
114 return res;
115 error:
116 isl_pw_multi_aff_free(pma);
117 FN(PW,free)(pw);
118 return NULL;
121 __isl_give PW *FN(PW,pullback_pw_multi_aff)(__isl_take PW *pw,
122 __isl_take isl_pw_multi_aff *pma)
124 FN(PW,align_params_pw_multi_aff)(&pw, &pma);
125 return FN(PW,pullback_pw_multi_aff_aligned)(pw, pma);