isl_qpolynomial_move_dims: use isl_qpolynomial_domain_dim
[isl.git] / isl_multi_identity_templ.c
blob1ffeadf57a4607e8b203ceaa537dcad6f0dccfb0
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/space.h>
11 #include <isl/local_space.h>
13 #include <isl_multi_macro.h>
15 /* Create a multi expression in the given space that maps each
16 * input dimension to the corresponding output dimension.
18 __isl_give MULTI(BASE) *FN(MULTI(BASE),identity)(__isl_take isl_space *space)
20 int i;
21 isl_size n_in, n_out;
22 isl_local_space *ls;
23 MULTI(BASE) *multi;
25 if (!space)
26 return NULL;
28 if (isl_space_is_set(space))
29 isl_die(isl_space_get_ctx(space), isl_error_invalid,
30 "expecting map space", goto error);
32 n_in = isl_space_dim(space, isl_dim_in);
33 n_out = isl_space_dim(space, isl_dim_out);
34 if (n_in < 0 || n_out < 0)
35 goto error;
36 if (n_in != n_out)
37 isl_die(isl_space_get_ctx(space), isl_error_invalid,
38 "number of input and output dimensions needs to be "
39 "the same", goto error);
41 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
43 if (!n_out) {
44 isl_space_free(space);
45 return multi;
48 space = isl_space_domain(space);
49 ls = isl_local_space_from_space(space);
51 for (i = 0; i < n_out; ++i) {
52 EL *el;
53 el = FN(EL,var_on_domain)(isl_local_space_copy(ls),
54 isl_dim_set, i);
55 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, el);
58 isl_local_space_free(ls);
60 return multi;
61 error:
62 isl_space_free(space);
63 return NULL;
66 /* Create a multi expression that maps elements in the given space
67 * to themselves.
69 __isl_give MULTI(BASE) *FN(MULTI(BASE),identity_on_domain_space)(
70 __isl_take isl_space *space)
72 return FN(MULTI(BASE),identity)(isl_space_map_from_set(space));
75 /* This function performs the same operation as
76 * isl_multi_*_identity_on_domain_space,
77 * but is considered as a function on an isl_space when exported.
79 __isl_give MULTI(BASE) *FN(FN(isl_space_identity_multi,BASE),on_domain)(
80 __isl_take isl_space *space)
82 return FN(MULTI(BASE),identity_on_domain_space)(space);
85 /* Create a multi expression in the same space as "multi" that maps each
86 * input dimension to the corresponding output dimension.
88 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),identity_multi),BASE)(
89 __isl_take MULTI(BASE) *multi)
91 isl_space *space;
93 space = FN(MULTI(BASE),get_space)(multi);
94 FN(MULTI(BASE),free)(multi);
95 return FN(MULTI(BASE),identity)(space);