isl_tab_rollback: return isl_stat
[isl.git] / isl_multi_identity_templ.c
blob9675d34c3d8b81632cecbd6e2e04921557d0ad00
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;