2 * Copyright 2011 Sven Verdoolaege
3 * Copyright 2012-2013 Ecole Normale Superieure
5 * Use of this software is governed by the MIT license
7 * Written by Sven Verdoolaege,
8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
11 #include <isl_multi_macro.h>
13 /* Transform the elements of "multi" by applying "fn" to them
14 * with extra argument "set".
16 * The parameters of "multi" and "set" are assumed to have been aligned.
18 __isl_give
MULTI(BASE
) *FN(FN(MULTI(BASE
),apply_aligned
),APPLY_DOMBASE
)(
19 __isl_take
MULTI(BASE
) *multi
, __isl_take APPLY_DOM
*set
,
20 __isl_give EL
*(*fn
)(EL
*el
, __isl_take APPLY_DOM
*set
))
25 n
= FN(MULTI(BASE
),size
)(multi
);
29 for (i
= 0; i
< n
; ++i
) {
32 el
= FN(MULTI(BASE
),take_at
)(multi
, i
);
33 el
= fn(el
, FN(APPLY_DOM
,copy
)(set
));
34 multi
= FN(MULTI(BASE
),restore_at
)(multi
, i
, el
);
37 FN(APPLY_DOM
,free
)(set
);
40 FN(APPLY_DOM
,free
)(set
);
41 FN(MULTI(BASE
),free
)(multi
);
45 /* Transform the elements of "multi" by applying "fn" to them
46 * with extra argument "set".
48 * Align the parameters if needed and call apply_set_aligned.
50 static __isl_give
MULTI(BASE
) *FN(FN(MULTI(BASE
),apply
),APPLY_DOMBASE
)(
51 __isl_take
MULTI(BASE
) *multi
, __isl_take APPLY_DOM
*set
,
52 __isl_give EL
*(*fn
)(EL
*el
, __isl_take APPLY_DOM
*set
))
60 aligned
= FN(APPLY_DOM
,space_has_equal_params
)(set
, multi
->space
);
64 return FN(FN(MULTI(BASE
),apply_aligned
),APPLY_DOMBASE
)(multi
,
66 ctx
= FN(MULTI(BASE
),get_ctx
)(multi
);
67 if (!isl_space_has_named_params(multi
->space
) ||
68 !isl_space_has_named_params(set
->dim
))
69 isl_die(ctx
, isl_error_invalid
,
70 "unaligned unnamed parameters", goto error
);
71 multi
= FN(MULTI(BASE
),align_params
)(multi
,
72 FN(APPLY_DOM
,get_space
)(set
));
73 set
= FN(APPLY_DOM
,align_params
)(set
, FN(MULTI(BASE
),get_space
)(multi
));
74 return FN(FN(MULTI(BASE
),apply_aligned
),APPLY_DOMBASE
)(multi
, set
, fn
);
76 FN(MULTI(BASE
),free
)(multi
);
77 FN(APPLY_DOM
,free
)(set
);