1 | /* |
2 | * Copyright 2013 Ecole Normale Superieure |
3 | * |
4 | * Use of this software is governed by the MIT license |
5 | * |
6 | * Written by Sven Verdoolaege, |
7 | * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France |
8 | */ |
9 | |
10 | /* Apply "fn" to each of the elements of "multi" with as second argument "v". |
11 | */ |
12 | static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_val)( |
13 | __isl_take MULTI(BASE) *multi, |
14 | __isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v), |
15 | __isl_take isl_val *v) |
16 | { |
17 | isl_size n; |
18 | int i; |
19 | |
20 | n = FN(MULTI(BASE),size)(multi); |
21 | if (n < 0 || !v) |
22 | goto error; |
23 | |
24 | for (i = 0; i < n; ++i) { |
25 | EL *el; |
26 | |
27 | el = FN(MULTI(BASE),take_at)(multi, pos: i); |
28 | el = fn(el, isl_val_copy(v)); |
29 | multi = FN(MULTI(BASE),restore_at)(multi, pos: i, el); |
30 | } |
31 | |
32 | isl_val_free(v); |
33 | return multi; |
34 | error: |
35 | isl_val_free(v); |
36 | FN(MULTI(BASE),free)(multi); |
37 | return NULL; |
38 | } |
39 | |
40 | #undef TYPE |
41 | #define TYPE MULTI(BASE) |
42 | #include "isl_type_check_match_range_multi_val.c" |
43 | |
44 | /* Elementwise apply "fn" to "multi" and "mv". |
45 | */ |
46 | static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_multi_val)( |
47 | __isl_take MULTI(BASE) *multi, |
48 | __isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v), |
49 | __isl_take isl_multi_val *mv) |
50 | { |
51 | isl_size n; |
52 | int i; |
53 | |
54 | n = FN(MULTI(BASE),size)(multi); |
55 | if (n < 0 || FN(MULTI(BASE),check_match_range_multi_val)(obj: multi, mv) < 0) |
56 | goto error; |
57 | |
58 | for (i = 0; i < n; ++i) { |
59 | isl_val *v; |
60 | EL *el; |
61 | |
62 | v = isl_multi_val_get_val(multi: mv, pos: i); |
63 | el = FN(MULTI(BASE),take_at)(multi, pos: i); |
64 | el = fn(el, v); |
65 | multi = FN(MULTI(BASE),restore_at)(multi, pos: i, el); |
66 | } |
67 | |
68 | isl_multi_val_free(multi: mv); |
69 | return multi; |
70 | error: |
71 | isl_multi_val_free(multi: mv); |
72 | return FN(MULTI(BASE),free)(multi); |
73 | } |
74 | |