mark isl_space_drop_outputs as deprecated
[isl.git] / isl_multi_templ.c
blob1ea6e02ac364acf233e11438b4e712a75fb93170
1 /*
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
9 */
11 #include <isl_space_private.h>
12 #include <isl/set.h>
13 #include <isl_reordering.h>
15 #include <isl_multi_macro.h>
17 #define MULTI_NAME(BASE) "isl_multi_" #BASE
18 #define xLIST(EL) EL ## _list
19 #define LIST(EL) xLIST(EL)
21 isl_ctx *FN(MULTI(BASE),get_ctx)(__isl_keep MULTI(BASE) *multi)
23 return multi ? isl_space_get_ctx(multi->space) : NULL;
26 __isl_give isl_space *FN(MULTI(BASE),get_space)(__isl_keep MULTI(BASE) *multi)
28 return multi ? isl_space_copy(multi->space) : NULL;
31 /* Return the position of the dimension of the given type and name
32 * in "multi".
33 * Return -1 if no such dimension can be found.
35 int FN(MULTI(BASE),find_dim_by_name)(__isl_keep MULTI(BASE) *multi,
36 enum isl_dim_type type, const char *name)
38 if (!multi)
39 return -1;
40 return isl_space_find_dim_by_name(multi->space, type, name);
43 __isl_give isl_space *FN(MULTI(BASE),get_domain_space)(
44 __isl_keep MULTI(BASE) *multi)
46 return multi ? isl_space_domain(isl_space_copy(multi->space)) : NULL;
49 __isl_give MULTI(BASE) *FN(MULTI(BASE),alloc)(__isl_take isl_space *space)
51 isl_ctx *ctx;
52 int n;
53 MULTI(BASE) *multi;
55 if (!space)
56 return NULL;
58 ctx = isl_space_get_ctx(space);
59 n = isl_space_dim(space, isl_dim_out);
60 multi = isl_calloc(ctx, MULTI(BASE),
61 sizeof(MULTI(BASE)) + (n - 1) * sizeof(struct EL *));
62 if (!multi)
63 goto error;
65 multi->space = space;
66 multi->n = n;
67 multi->ref = 1;
68 return multi;
69 error:
70 isl_space_free(space);
71 return NULL;
74 __isl_give MULTI(BASE) *FN(MULTI(BASE),dup)(__isl_keep MULTI(BASE) *multi)
76 int i;
77 MULTI(BASE) *dup;
79 if (!multi)
80 return NULL;
82 dup = FN(MULTI(BASE),alloc)(isl_space_copy(multi->space));
83 if (!dup)
84 return NULL;
86 for (i = 0; i < multi->n; ++i)
87 dup = FN(FN(MULTI(BASE),set),BASE)(dup, i,
88 FN(EL,copy)(multi->p[i]));
90 return dup;
93 __isl_give MULTI(BASE) *FN(MULTI(BASE),cow)(__isl_take MULTI(BASE) *multi)
95 if (!multi)
96 return NULL;
98 if (multi->ref == 1)
99 return multi;
101 multi->ref--;
102 return FN(MULTI(BASE),dup)(multi);
105 __isl_give MULTI(BASE) *FN(MULTI(BASE),copy)(__isl_keep MULTI(BASE) *multi)
107 if (!multi)
108 return NULL;
110 multi->ref++;
111 return multi;
114 __isl_null MULTI(BASE) *FN(MULTI(BASE),free)(__isl_take MULTI(BASE) *multi)
116 int i;
118 if (!multi)
119 return NULL;
121 if (--multi->ref > 0)
122 return NULL;
124 isl_space_free(multi->space);
125 for (i = 0; i < multi->n; ++i)
126 FN(EL,free)(multi->p[i]);
127 free(multi);
129 return NULL;
132 #ifndef NO_DIMS
133 /* Check whether "multi" has non-zero coefficients for any dimension
134 * in the given range or if any of these dimensions appear
135 * with non-zero coefficients in any of the integer divisions involved.
137 isl_bool FN(MULTI(BASE),involves_dims)(__isl_keep MULTI(BASE) *multi,
138 enum isl_dim_type type, unsigned first, unsigned n)
140 int i;
142 if (!multi)
143 return isl_bool_error;
144 if (multi->n == 0 || n == 0)
145 return isl_bool_false;
147 for (i = 0; i < multi->n; ++i) {
148 isl_bool involves;
150 involves = FN(EL,involves_dims)(multi->p[i], type, first, n);
151 if (involves < 0 || involves)
152 return involves;
155 return isl_bool_false;
158 __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
159 __isl_take MULTI(BASE) *multi,
160 enum isl_dim_type type, unsigned first, unsigned n)
162 int i;
164 if (!multi)
165 return NULL;
166 if (type == isl_dim_out)
167 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
168 "cannot insert output/set dimensions",
169 return FN(MULTI(BASE),free)(multi));
170 if (n == 0 && !isl_space_is_named_or_nested(multi->space, type))
171 return multi;
173 multi = FN(MULTI(BASE),cow)(multi);
174 if (!multi)
175 return NULL;
177 multi->space = isl_space_insert_dims(multi->space, type, first, n);
178 if (!multi->space)
179 return FN(MULTI(BASE),free)(multi);
181 for (i = 0; i < multi->n; ++i) {
182 multi->p[i] = FN(EL,insert_dims)(multi->p[i], type, first, n);
183 if (!multi->p[i])
184 return FN(MULTI(BASE),free)(multi);
187 return multi;
190 __isl_give MULTI(BASE) *FN(MULTI(BASE),add_dims)(__isl_take MULTI(BASE) *multi,
191 enum isl_dim_type type, unsigned n)
193 unsigned pos;
195 pos = FN(MULTI(BASE),dim)(multi, type);
197 return FN(MULTI(BASE),insert_dims)(multi, type, pos, n);
199 #endif
201 unsigned FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi,
202 enum isl_dim_type type)
204 return multi ? isl_space_dim(multi->space, type) : 0;
207 /* Return the position of the first dimension of "type" with id "id".
208 * Return -1 if there is no such dimension.
210 int FN(MULTI(BASE),find_dim_by_id)(__isl_keep MULTI(BASE) *multi,
211 enum isl_dim_type type, __isl_keep isl_id *id)
213 if (!multi)
214 return -1;
215 return isl_space_find_dim_by_id(multi->space, type, id);
218 /* Return the id of the given dimension.
220 __isl_give isl_id *FN(MULTI(BASE),get_dim_id)(__isl_keep MULTI(BASE) *multi,
221 enum isl_dim_type type, unsigned pos)
223 return multi ? isl_space_get_dim_id(multi->space, type, pos) : NULL;
226 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)(
227 __isl_take MULTI(BASE) *multi,
228 enum isl_dim_type type, unsigned pos, const char *s)
230 int i;
232 multi = FN(MULTI(BASE),cow)(multi);
233 if (!multi)
234 return NULL;
236 multi->space = isl_space_set_dim_name(multi->space, type, pos, s);
237 if (!multi->space)
238 return FN(MULTI(BASE),free)(multi);
240 if (type == isl_dim_out)
241 return multi;
242 for (i = 0; i < multi->n; ++i) {
243 multi->p[i] = FN(EL,set_dim_name)(multi->p[i], type, pos, s);
244 if (!multi->p[i])
245 return FN(MULTI(BASE),free)(multi);
248 return multi;
251 const char *FN(MULTI(BASE),get_tuple_name)(__isl_keep MULTI(BASE) *multi,
252 enum isl_dim_type type)
254 return multi ? isl_space_get_tuple_name(multi->space, type) : NULL;
257 /* Does the specified tuple have an id?
259 isl_bool FN(MULTI(BASE),has_tuple_id)(__isl_keep MULTI(BASE) *multi,
260 enum isl_dim_type type)
262 if (!multi)
263 return isl_bool_error;
264 return isl_space_has_tuple_id(multi->space, type);
267 /* Return the id of the specified tuple.
269 __isl_give isl_id *FN(MULTI(BASE),get_tuple_id)(__isl_keep MULTI(BASE) *multi,
270 enum isl_dim_type type)
272 return multi ? isl_space_get_tuple_id(multi->space, type) : NULL;
275 __isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi,
276 int pos)
278 isl_ctx *ctx;
280 if (!multi)
281 return NULL;
282 ctx = FN(MULTI(BASE),get_ctx)(multi);
283 if (pos < 0 || pos >= multi->n)
284 isl_die(ctx, isl_error_invalid,
285 "index out of bounds", return NULL);
286 return FN(EL,copy)(multi->p[pos]);
289 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)(
290 __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
292 isl_space *multi_space = NULL;
293 isl_space *el_space = NULL;
294 isl_bool match;
296 multi = FN(MULTI(BASE),cow)(multi);
297 if (!multi || !el)
298 goto error;
300 multi_space = FN(MULTI(BASE),get_space)(multi);
301 match = FN(EL,matching_params)(el, multi_space);
302 if (match < 0)
303 goto error;
304 if (!match) {
305 multi = FN(MULTI(BASE),align_params)(multi,
306 FN(EL,get_space)(el));
307 isl_space_free(multi_space);
308 multi_space = FN(MULTI(BASE),get_space)(multi);
309 el = FN(EL,align_params)(el, isl_space_copy(multi_space));
311 if (FN(EL,check_match_domain_space)(el, multi_space) < 0)
312 goto error;
314 if (pos < 0 || pos >= multi->n)
315 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
316 "index out of bounds", goto error);
318 FN(EL,free)(multi->p[pos]);
319 multi->p[pos] = el;
321 isl_space_free(multi_space);
322 isl_space_free(el_space);
324 return multi;
325 error:
326 FN(MULTI(BASE),free)(multi);
327 FN(EL,free)(el);
328 isl_space_free(multi_space);
329 isl_space_free(el_space);
330 return NULL;
333 /* Reset the space of "multi". This function is called from isl_pw_templ.c
334 * and doesn't know if the space of an element object is represented
335 * directly or through its domain. It therefore passes along both,
336 * which we pass along to the element function since we don't how
337 * that is represented either.
339 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)(
340 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space,
341 __isl_take isl_space *domain)
343 int i;
345 multi = FN(MULTI(BASE),cow)(multi);
346 if (!multi || !space || !domain)
347 goto error;
349 for (i = 0; i < multi->n; ++i) {
350 multi->p[i] = FN(EL,reset_domain_space)(multi->p[i],
351 isl_space_copy(domain));
352 if (!multi->p[i])
353 goto error;
355 isl_space_free(domain);
356 isl_space_free(multi->space);
357 multi->space = space;
359 return multi;
360 error:
361 isl_space_free(domain);
362 isl_space_free(space);
363 FN(MULTI(BASE),free)(multi);
364 return NULL;
367 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_domain_space)(
368 __isl_take MULTI(BASE) *multi, __isl_take isl_space *domain)
370 isl_space *space;
372 space = isl_space_extend_domain_with_range(isl_space_copy(domain),
373 isl_space_copy(multi->space));
374 return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
377 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space)(
378 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
380 isl_space *domain;
382 domain = isl_space_domain(isl_space_copy(space));
383 return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
386 /* Set the id of the given dimension of "multi" to "id".
388 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_id)(
389 __isl_take MULTI(BASE) *multi,
390 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
392 isl_space *space;
394 multi = FN(MULTI(BASE),cow)(multi);
395 if (!multi || !id)
396 goto error;
398 space = FN(MULTI(BASE),get_space)(multi);
399 space = isl_space_set_dim_id(space, type, pos, id);
401 return FN(MULTI(BASE),reset_space)(multi, space);
402 error:
403 isl_id_free(id);
404 FN(MULTI(BASE),free)(multi);
405 return NULL;
408 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_name)(
409 __isl_keep MULTI(BASE) *multi, enum isl_dim_type type,
410 const char *s)
412 isl_space *space;
414 multi = FN(MULTI(BASE),cow)(multi);
415 if (!multi)
416 return NULL;
418 space = FN(MULTI(BASE),get_space)(multi);
419 space = isl_space_set_tuple_name(space, type, s);
421 return FN(MULTI(BASE),reset_space)(multi, space);
424 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_id)(
425 __isl_take MULTI(BASE) *multi, enum isl_dim_type type,
426 __isl_take isl_id *id)
428 isl_space *space;
430 multi = FN(MULTI(BASE),cow)(multi);
431 if (!multi)
432 goto error;
434 space = FN(MULTI(BASE),get_space)(multi);
435 space = isl_space_set_tuple_id(space, type, id);
437 return FN(MULTI(BASE),reset_space)(multi, space);
438 error:
439 isl_id_free(id);
440 return NULL;
443 /* Drop the id on the specified tuple.
445 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_tuple_id)(
446 __isl_take MULTI(BASE) *multi, enum isl_dim_type type)
448 isl_space *space;
450 if (!multi)
451 return NULL;
452 if (!FN(MULTI(BASE),has_tuple_id)(multi, type))
453 return multi;
455 multi = FN(MULTI(BASE),cow)(multi);
456 if (!multi)
457 return NULL;
459 space = FN(MULTI(BASE),get_space)(multi);
460 space = isl_space_reset_tuple_id(space, type);
462 return FN(MULTI(BASE),reset_space)(multi, space);
465 /* Reset the user pointer on all identifiers of parameters and tuples
466 * of the space of "multi".
468 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_user)(
469 __isl_take MULTI(BASE) *multi)
471 isl_space *space;
473 space = FN(MULTI(BASE),get_space)(multi);
474 space = isl_space_reset_user(space);
476 return FN(MULTI(BASE),reset_space)(multi, space);
479 __isl_give MULTI(BASE) *FN(MULTI(BASE),realign_domain)(
480 __isl_take MULTI(BASE) *multi, __isl_take isl_reordering *exp)
482 int i;
484 multi = FN(MULTI(BASE),cow)(multi);
485 if (!multi || !exp)
486 goto error;
488 for (i = 0; i < multi->n; ++i) {
489 multi->p[i] = FN(EL,realign_domain)(multi->p[i],
490 isl_reordering_copy(exp));
491 if (!multi->p[i])
492 goto error;
495 multi = FN(MULTI(BASE),reset_domain_space)(multi,
496 isl_space_copy(exp->dim));
498 isl_reordering_free(exp);
499 return multi;
500 error:
501 isl_reordering_free(exp);
502 FN(MULTI(BASE),free)(multi);
503 return NULL;
506 /* Align the parameters of "multi" to those of "model".
508 __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params)(
509 __isl_take MULTI(BASE) *multi, __isl_take isl_space *model)
511 isl_ctx *ctx;
512 isl_bool equal_params;
513 isl_reordering *exp;
515 if (!multi || !model)
516 goto error;
518 equal_params = isl_space_has_equal_params(multi->space, model);
519 if (equal_params < 0)
520 goto error;
521 if (equal_params) {
522 isl_space_free(model);
523 return multi;
526 ctx = isl_space_get_ctx(model);
527 if (!isl_space_has_named_params(model))
528 isl_die(ctx, isl_error_invalid,
529 "model has unnamed parameters", goto error);
530 if (!isl_space_has_named_params(multi->space))
531 isl_die(ctx, isl_error_invalid,
532 "input has unnamed parameters", goto error);
534 model = isl_space_params(model);
535 exp = isl_parameter_alignment_reordering(multi->space, model);
536 exp = isl_reordering_extend_space(exp,
537 FN(MULTI(BASE),get_domain_space)(multi));
538 multi = FN(MULTI(BASE),realign_domain)(multi, exp);
540 isl_space_free(model);
541 return multi;
542 error:
543 isl_space_free(model);
544 FN(MULTI(BASE),free)(multi);
545 return NULL;
548 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),LIST(BASE))(
549 __isl_take isl_space *space, __isl_take LIST(EL) *list)
551 int i;
552 int n;
553 isl_ctx *ctx;
554 MULTI(BASE) *multi;
556 if (!space || !list)
557 goto error;
559 ctx = isl_space_get_ctx(space);
560 n = FN(FN(LIST(EL),n),BASE)(list);
561 if (n != isl_space_dim(space, isl_dim_out))
562 isl_die(ctx, isl_error_invalid,
563 "invalid number of elements in list", goto error);
565 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
566 for (i = 0; i < n; ++i) {
567 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i,
568 FN(FN(LIST(EL),get),BASE)(list, i));
571 isl_space_free(space);
572 FN(LIST(EL),free)(list);
573 return multi;
574 error:
575 isl_space_free(space);
576 FN(LIST(EL),free)(list);
577 return NULL;
580 #ifndef NO_IDENTITY
581 /* Create a multi expression in the given space that maps each
582 * input dimension to the corresponding output dimension.
584 __isl_give MULTI(BASE) *FN(MULTI(BASE),identity)(__isl_take isl_space *space)
586 int i, n;
587 isl_local_space *ls;
588 MULTI(BASE) *multi;
590 if (!space)
591 return NULL;
593 if (isl_space_is_set(space))
594 isl_die(isl_space_get_ctx(space), isl_error_invalid,
595 "expecting map space", goto error);
597 n = isl_space_dim(space, isl_dim_out);
598 if (n != isl_space_dim(space, isl_dim_in))
599 isl_die(isl_space_get_ctx(space), isl_error_invalid,
600 "number of input and output dimensions needs to be "
601 "the same", goto error);
603 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
605 if (!n) {
606 isl_space_free(space);
607 return multi;
610 space = isl_space_domain(space);
611 ls = isl_local_space_from_space(space);
613 for (i = 0; i < n; ++i) {
614 EL *el;
615 el = FN(EL,var_on_domain)(isl_local_space_copy(ls),
616 isl_dim_set, i);
617 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, el);
620 isl_local_space_free(ls);
622 return multi;
623 error:
624 isl_space_free(space);
625 return NULL;
627 #endif
629 #ifndef NO_ZERO
630 /* Construct a multi expression in the given space with value zero in
631 * each of the output dimensions.
633 __isl_give MULTI(BASE) *FN(MULTI(BASE),zero)(__isl_take isl_space *space)
635 int n;
636 MULTI(BASE) *multi;
638 if (!space)
639 return NULL;
641 n = isl_space_dim(space , isl_dim_out);
642 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
644 if (!n)
645 isl_space_free(space);
646 else {
647 int i;
648 isl_local_space *ls;
649 EL *el;
651 space = isl_space_domain(space);
652 ls = isl_local_space_from_space(space);
653 el = FN(EL,zero_on_domain)(ls);
655 for (i = 0; i < n; ++i)
656 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i,
657 FN(EL,copy)(el));
659 FN(EL,free)(el);
662 return multi;
664 #endif
666 #ifndef NO_FROM_BASE
667 /* Create a multiple expression with a single output/set dimension
668 * equal to "el".
669 * For most multiple expression types, the base type has a single
670 * output/set dimension and the space of the result is therefore
671 * the same as the space of the input.
672 * In the case of isl_multi_union_pw_aff, however, the base type
673 * lives in a parameter space and we therefore need to add
674 * a single set dimension.
676 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),BASE)(__isl_take EL *el)
678 isl_space *space;
679 MULTI(BASE) *multi;
681 space = FN(EL,get_space(el));
682 if (isl_space_is_params(space)) {
683 space = isl_space_set_from_params(space);
684 space = isl_space_add_dims(space, isl_dim_set, 1);
686 multi = FN(MULTI(BASE),alloc)(space);
687 multi = FN(FN(MULTI(BASE),set),BASE)(multi, 0, el);
689 return multi;
691 #endif
693 __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
694 __isl_take MULTI(BASE) *multi,
695 enum isl_dim_type type, unsigned first, unsigned n)
697 int i;
698 unsigned dim;
700 multi = FN(MULTI(BASE),cow)(multi);
701 if (!multi)
702 return NULL;
704 dim = FN(MULTI(BASE),dim)(multi, type);
705 if (first + n > dim || first + n < first)
706 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
707 "index out of bounds",
708 return FN(MULTI(BASE),cow)(multi));
710 multi->space = isl_space_drop_dims(multi->space, type, first, n);
711 if (!multi->space)
712 return FN(MULTI(BASE),cow)(multi);
714 if (type == isl_dim_out) {
715 for (i = 0; i < n; ++i)
716 FN(EL,free)(multi->p[first + i]);
717 for (i = first; i + n < multi->n; ++i)
718 multi->p[i] = multi->p[i + n];
719 multi->n -= n;
721 return multi;
724 for (i = 0; i < multi->n; ++i) {
725 multi->p[i] = FN(EL,drop_dims)(multi->p[i], type, first, n);
726 if (!multi->p[i])
727 return FN(MULTI(BASE),cow)(multi);
730 return multi;
733 /* Align the parameters of "multi1" and "multi2" (if needed) and call "fn".
735 static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params_multi_multi_and)(
736 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
737 __isl_give MULTI(BASE) *(*fn)(__isl_take MULTI(BASE) *multi1,
738 __isl_take MULTI(BASE) *multi2))
740 isl_ctx *ctx;
741 isl_bool equal_params;
743 if (!multi1 || !multi2)
744 goto error;
745 equal_params = isl_space_has_equal_params(multi1->space, multi2->space);
746 if (equal_params < 0)
747 goto error;
748 if (equal_params)
749 return fn(multi1, multi2);
750 ctx = FN(MULTI(BASE),get_ctx)(multi1);
751 if (!isl_space_has_named_params(multi1->space) ||
752 !isl_space_has_named_params(multi2->space))
753 isl_die(ctx, isl_error_invalid,
754 "unaligned unnamed parameters", goto error);
755 multi1 = FN(MULTI(BASE),align_params)(multi1,
756 FN(MULTI(BASE),get_space)(multi2));
757 multi2 = FN(MULTI(BASE),align_params)(multi2,
758 FN(MULTI(BASE),get_space)(multi1));
759 return fn(multi1, multi2);
760 error:
761 FN(MULTI(BASE),free)(multi1);
762 FN(MULTI(BASE),free)(multi2);
763 return NULL;
766 /* Given two MULTI(BASE)s A -> B and C -> D,
767 * construct a MULTI(BASE) (A * C) -> [B -> D].
769 * The parameters are assumed to have been aligned.
771 static __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product_aligned)(
772 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
774 int i, n1, n2;
775 EL *el;
776 isl_space *space;
777 MULTI(BASE) *res;
779 if (!multi1 || !multi2)
780 goto error;
782 space = isl_space_range_product(FN(MULTI(BASE),get_space)(multi1),
783 FN(MULTI(BASE),get_space)(multi2));
784 res = FN(MULTI(BASE),alloc)(space);
786 n1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
787 n2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out);
789 for (i = 0; i < n1; ++i) {
790 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
791 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
794 for (i = 0; i < n2; ++i) {
795 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
796 res = FN(FN(MULTI(BASE),set),BASE)(res, n1 + i, el);
799 FN(MULTI(BASE),free)(multi1);
800 FN(MULTI(BASE),free)(multi2);
801 return res;
802 error:
803 FN(MULTI(BASE),free)(multi1);
804 FN(MULTI(BASE),free)(multi2);
805 return NULL;
808 /* Given two MULTI(BASE)s A -> B and C -> D,
809 * construct a MULTI(BASE) (A * C) -> [B -> D].
811 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product)(
812 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
814 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
815 &FN(MULTI(BASE),range_product_aligned));
818 /* Is the range of "multi" a wrapped relation?
820 isl_bool FN(MULTI(BASE),range_is_wrapping)(__isl_keep MULTI(BASE) *multi)
822 if (!multi)
823 return isl_bool_error;
824 return isl_space_range_is_wrapping(multi->space);
827 /* Given a function A -> [B -> C], extract the function A -> B.
829 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_factor_domain)(
830 __isl_take MULTI(BASE) *multi)
832 isl_space *space;
833 int total, keep;
835 if (!multi)
836 return NULL;
837 if (!isl_space_range_is_wrapping(multi->space))
838 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
839 "range is not a product",
840 return FN(MULTI(BASE),free)(multi));
842 space = FN(MULTI(BASE),get_space)(multi);
843 total = isl_space_dim(space, isl_dim_out);
844 space = isl_space_range_factor_domain(space);
845 keep = isl_space_dim(space, isl_dim_out);
846 multi = FN(MULTI(BASE),drop_dims)(multi,
847 isl_dim_out, keep, total - keep);
848 multi = FN(MULTI(BASE),reset_space)(multi, space);
850 return multi;
853 /* Given a function A -> [B -> C], extract the function A -> C.
855 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_factor_range)(
856 __isl_take MULTI(BASE) *multi)
858 isl_space *space;
859 int total, keep;
861 if (!multi)
862 return NULL;
863 if (!isl_space_range_is_wrapping(multi->space))
864 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
865 "range is not a product",
866 return FN(MULTI(BASE),free)(multi));
868 space = FN(MULTI(BASE),get_space)(multi);
869 total = isl_space_dim(space, isl_dim_out);
870 space = isl_space_range_factor_range(space);
871 keep = isl_space_dim(space, isl_dim_out);
872 multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, 0, total - keep);
873 multi = FN(MULTI(BASE),reset_space)(multi, space);
875 return multi;
878 /* Given a function [B -> C], extract the function C.
880 __isl_give MULTI(BASE) *FN(MULTI(BASE),factor_range)(
881 __isl_take MULTI(BASE) *multi)
883 isl_space *space;
884 int total, keep;
886 if (!multi)
887 return NULL;
888 if (!isl_space_is_wrapping(multi->space))
889 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
890 "not a product", return FN(MULTI(BASE),free)(multi));
892 space = FN(MULTI(BASE),get_space)(multi);
893 total = isl_space_dim(space, isl_dim_out);
894 space = isl_space_factor_range(space);
895 keep = isl_space_dim(space, isl_dim_out);
896 multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, 0, total - keep);
897 multi = FN(MULTI(BASE),reset_space)(multi, space);
899 return multi;
902 #ifndef NO_PRODUCT
903 /* Given two MULTI(BASE)s A -> B and C -> D,
904 * construct a MULTI(BASE) [A -> C] -> [B -> D].
906 * The parameters are assumed to have been aligned.
908 __isl_give MULTI(BASE) *FN(MULTI(BASE),product_aligned)(
909 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
911 int i;
912 EL *el;
913 isl_space *space;
914 MULTI(BASE) *res;
915 int in1, in2, out1, out2;
917 in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
918 in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
919 out1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
920 out2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out);
921 space = isl_space_product(FN(MULTI(BASE),get_space)(multi1),
922 FN(MULTI(BASE),get_space)(multi2));
923 res = FN(MULTI(BASE),alloc)(isl_space_copy(space));
924 space = isl_space_domain(space);
926 for (i = 0; i < out1; ++i) {
927 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
928 el = FN(EL,insert_dims)(el, isl_dim_in, in1, in2);
929 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
930 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
933 for (i = 0; i < out2; ++i) {
934 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
935 el = FN(EL,insert_dims)(el, isl_dim_in, 0, in1);
936 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
937 res = FN(FN(MULTI(BASE),set),BASE)(res, out1 + i, el);
940 isl_space_free(space);
941 FN(MULTI(BASE),free)(multi1);
942 FN(MULTI(BASE),free)(multi2);
943 return res;
946 /* Given two MULTI(BASE)s A -> B and C -> D,
947 * construct a MULTI(BASE) [A -> C] -> [B -> D].
949 __isl_give MULTI(BASE) *FN(MULTI(BASE),product)(
950 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
952 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
953 &FN(MULTI(BASE),product_aligned));
955 #endif
957 __isl_give MULTI(BASE) *FN(MULTI(BASE),flatten_range)(
958 __isl_take MULTI(BASE) *multi)
960 if (!multi)
961 return NULL;
963 if (!multi->space->nested[1])
964 return multi;
966 multi = FN(MULTI(BASE),cow)(multi);
967 if (!multi)
968 return NULL;
970 multi->space = isl_space_flatten_range(multi->space);
971 if (!multi->space)
972 return FN(MULTI(BASE),free)(multi);
974 return multi;
977 /* Given two MULTI(BASE)s A -> B and C -> D,
978 * construct a MULTI(BASE) (A * C) -> (B, D).
980 __isl_give MULTI(BASE) *FN(MULTI(BASE),flat_range_product)(
981 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
983 MULTI(BASE) *multi;
985 multi = FN(MULTI(BASE),range_product)(multi1, multi2);
986 multi = FN(MULTI(BASE),flatten_range)(multi);
987 return multi;
990 /* Given two multi expressions, "multi1"
992 * [A] -> [B1 B2]
994 * where B2 starts at position "pos", and "multi2"
996 * [A] -> [D]
998 * return the multi expression
1000 * [A] -> [B1 D B2]
1002 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_splice)(
1003 __isl_take MULTI(BASE) *multi1, unsigned pos,
1004 __isl_take MULTI(BASE) *multi2)
1006 MULTI(BASE) *res;
1007 unsigned dim;
1009 if (!multi1 || !multi2)
1010 goto error;
1012 dim = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
1013 if (pos > dim)
1014 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
1015 "index out of bounds", goto error);
1017 res = FN(MULTI(BASE),copy)(multi1);
1018 res = FN(MULTI(BASE),drop_dims)(res, isl_dim_out, pos, dim - pos);
1019 multi1 = FN(MULTI(BASE),drop_dims)(multi1, isl_dim_out, 0, pos);
1021 res = FN(MULTI(BASE),flat_range_product)(res, multi2);
1022 res = FN(MULTI(BASE),flat_range_product)(res, multi1);
1024 return res;
1025 error:
1026 FN(MULTI(BASE),free)(multi1);
1027 FN(MULTI(BASE),free)(multi2);
1028 return NULL;
1031 #ifndef NO_SPLICE
1032 /* Given two multi expressions, "multi1"
1034 * [A1 A2] -> [B1 B2]
1036 * where A2 starts at position "in_pos" and B2 starts at position "out_pos",
1037 * and "multi2"
1039 * [C] -> [D]
1041 * return the multi expression
1043 * [A1 C A2] -> [B1 D B2]
1045 * We first insert input dimensions to obtain
1047 * [A1 C A2] -> [B1 B2]
1049 * and
1051 * [A1 C A2] -> [D]
1053 * and then apply range_splice.
1055 __isl_give MULTI(BASE) *FN(MULTI(BASE),splice)(
1056 __isl_take MULTI(BASE) *multi1, unsigned in_pos, unsigned out_pos,
1057 __isl_take MULTI(BASE) *multi2)
1059 unsigned n_in1;
1060 unsigned n_in2;
1062 if (!multi1 || !multi2)
1063 goto error;
1065 n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
1066 if (in_pos > n_in1)
1067 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
1068 "index out of bounds", goto error);
1070 n_in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
1072 multi1 = FN(MULTI(BASE),insert_dims)(multi1, isl_dim_in, in_pos, n_in2);
1073 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, n_in2,
1074 n_in1 - in_pos);
1075 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, 0, in_pos);
1077 return FN(MULTI(BASE),range_splice)(multi1, out_pos, multi2);
1078 error:
1079 FN(MULTI(BASE),free)(multi1);
1080 FN(MULTI(BASE),free)(multi2);
1081 return NULL;
1083 #endif
1085 /* This function is currently only used from isl_aff.c
1087 static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
1088 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
1089 __isl_give EL *(*fn)(__isl_take EL *, __isl_take EL *))
1090 __attribute__ ((unused));
1092 /* Pairwise perform "fn" to the elements of "multi1" and "multi2" and
1093 * return the result.
1095 static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
1096 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
1097 __isl_give EL *(*fn)(__isl_take EL *, __isl_take EL *))
1099 int i;
1100 isl_ctx *ctx;
1102 multi1 = FN(MULTI(BASE),cow)(multi1);
1103 if (!multi1 || !multi2)
1104 goto error;
1106 ctx = FN(MULTI(BASE),get_ctx)(multi1);
1107 if (!isl_space_is_equal(multi1->space, multi2->space))
1108 isl_die(ctx, isl_error_invalid,
1109 "spaces don't match", goto error);
1111 for (i = 0; i < multi1->n; ++i) {
1112 multi1->p[i] = fn(multi1->p[i], FN(EL,copy)(multi2->p[i]));
1113 if (!multi1->p[i])
1114 goto error;
1117 FN(MULTI(BASE),free)(multi2);
1118 return multi1;
1119 error:
1120 FN(MULTI(BASE),free)(multi1);
1121 FN(MULTI(BASE),free)(multi2);
1122 return NULL;
1125 /* Add "multi2" from "multi1" and return the result.
1127 * The parameters of "multi1" and "multi2" are assumed to have been aligned.
1129 static __isl_give MULTI(BASE) *FN(MULTI(BASE),add_aligned)(
1130 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
1132 return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,add));
1135 /* Add "multi2" from "multi1" and return the result.
1137 __isl_give MULTI(BASE) *FN(MULTI(BASE),add)(__isl_take MULTI(BASE) *multi1,
1138 __isl_take MULTI(BASE) *multi2)
1140 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
1141 &FN(MULTI(BASE),add_aligned));
1144 /* Subtract "multi2" from "multi1" and return the result.
1146 * The parameters of "multi1" and "multi2" are assumed to have been aligned.
1148 static __isl_give MULTI(BASE) *FN(MULTI(BASE),sub_aligned)(
1149 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
1151 return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,sub));
1154 /* Subtract "multi2" from "multi1" and return the result.
1156 __isl_give MULTI(BASE) *FN(MULTI(BASE),sub)(__isl_take MULTI(BASE) *multi1,
1157 __isl_take MULTI(BASE) *multi2)
1159 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
1160 &FN(MULTI(BASE),sub_aligned));
1163 /* Multiply the elements of "multi" by "v" and return the result.
1165 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
1166 __isl_take isl_val *v)
1168 int i;
1170 if (!multi || !v)
1171 goto error;
1173 if (isl_val_is_one(v)) {
1174 isl_val_free(v);
1175 return multi;
1178 if (!isl_val_is_rat(v))
1179 isl_die(isl_val_get_ctx(v), isl_error_invalid,
1180 "expecting rational factor", goto error);
1182 multi = FN(MULTI(BASE),cow)(multi);
1183 if (!multi)
1184 return NULL;
1186 for (i = 0; i < multi->n; ++i) {
1187 multi->p[i] = FN(EL,scale_val)(multi->p[i], isl_val_copy(v));
1188 if (!multi->p[i])
1189 goto error;
1192 isl_val_free(v);
1193 return multi;
1194 error:
1195 isl_val_free(v);
1196 return FN(MULTI(BASE),free)(multi);
1199 /* Divide the elements of "multi" by "v" and return the result.
1201 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_val)(
1202 __isl_take MULTI(BASE) *multi, __isl_take isl_val *v)
1204 int i;
1206 if (!multi || !v)
1207 goto error;
1209 if (isl_val_is_one(v)) {
1210 isl_val_free(v);
1211 return multi;
1214 if (!isl_val_is_rat(v))
1215 isl_die(isl_val_get_ctx(v), isl_error_invalid,
1216 "expecting rational factor", goto error);
1217 if (isl_val_is_zero(v))
1218 isl_die(isl_val_get_ctx(v), isl_error_invalid,
1219 "cannot scale down by zero", goto error);
1221 multi = FN(MULTI(BASE),cow)(multi);
1222 if (!multi)
1223 return NULL;
1225 for (i = 0; i < multi->n; ++i) {
1226 multi->p[i] = FN(EL,scale_down_val)(multi->p[i],
1227 isl_val_copy(v));
1228 if (!multi->p[i])
1229 goto error;
1232 isl_val_free(v);
1233 return multi;
1234 error:
1235 isl_val_free(v);
1236 return FN(MULTI(BASE),free)(multi);
1239 /* Multiply the elements of "multi" by the corresponding element of "mv"
1240 * and return the result.
1242 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
1243 __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
1245 int i;
1247 if (!multi || !mv)
1248 goto error;
1250 if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
1251 mv->space, isl_dim_set))
1252 isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
1253 "spaces don't match", goto error);
1255 multi = FN(MULTI(BASE),cow)(multi);
1256 if (!multi)
1257 goto error;
1259 for (i = 0; i < multi->n; ++i) {
1260 isl_val *v;
1262 v = isl_multi_val_get_val(mv, i);
1263 multi->p[i] = FN(EL,scale_val)(multi->p[i], v);
1264 if (!multi->p[i])
1265 goto error;
1268 isl_multi_val_free(mv);
1269 return multi;
1270 error:
1271 isl_multi_val_free(mv);
1272 return FN(MULTI(BASE),free)(multi);
1275 /* Divide the elements of "multi" by the corresponding element of "mv"
1276 * and return the result.
1278 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
1279 __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
1281 int i;
1283 if (!multi || !mv)
1284 goto error;
1286 if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
1287 mv->space, isl_dim_set))
1288 isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
1289 "spaces don't match", goto error);
1291 multi = FN(MULTI(BASE),cow)(multi);
1292 if (!multi)
1293 return NULL;
1295 for (i = 0; i < multi->n; ++i) {
1296 isl_val *v;
1298 v = isl_multi_val_get_val(mv, i);
1299 multi->p[i] = FN(EL,scale_down_val)(multi->p[i], v);
1300 if (!multi->p[i])
1301 goto error;
1304 isl_multi_val_free(mv);
1305 return multi;
1306 error:
1307 isl_multi_val_free(mv);
1308 return FN(MULTI(BASE),free)(multi);
1311 /* Compute the residues of the elements of "multi" modulo
1312 * the corresponding element of "mv" and return the result.
1314 __isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)(
1315 __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
1317 int i;
1319 if (!multi || !mv)
1320 goto error;
1322 if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
1323 mv->space, isl_dim_set))
1324 isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
1325 "spaces don't match", goto error);
1327 multi = FN(MULTI(BASE),cow)(multi);
1328 if (!multi)
1329 return NULL;
1331 for (i = 0; i < multi->n; ++i) {
1332 isl_val *v;
1334 v = isl_multi_val_get_val(mv, i);
1335 multi->p[i] = FN(EL,mod_val)(multi->p[i], v);
1336 if (!multi->p[i])
1337 goto error;
1340 isl_multi_val_free(mv);
1341 return multi;
1342 error:
1343 isl_multi_val_free(mv);
1344 return FN(MULTI(BASE),free)(multi);
1347 #ifndef NO_MOVE_DIMS
1348 /* Move the "n" dimensions of "src_type" starting at "src_pos" of "multi"
1349 * to dimensions of "dst_type" at "dst_pos".
1351 * We only support moving input dimensions to parameters and vice versa.
1353 __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
1354 enum isl_dim_type dst_type, unsigned dst_pos,
1355 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
1357 int i;
1359 if (!multi)
1360 return NULL;
1362 if (n == 0 &&
1363 !isl_space_is_named_or_nested(multi->space, src_type) &&
1364 !isl_space_is_named_or_nested(multi->space, dst_type))
1365 return multi;
1367 if (dst_type == isl_dim_out || src_type == isl_dim_out)
1368 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1369 "cannot move output/set dimension",
1370 return FN(MULTI(BASE),free)(multi));
1371 if (dst_type == isl_dim_div || src_type == isl_dim_div)
1372 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1373 "cannot move divs",
1374 return FN(MULTI(BASE),free)(multi));
1375 if (src_pos + n > isl_space_dim(multi->space, src_type))
1376 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1377 "range out of bounds",
1378 return FN(MULTI(BASE),free)(multi));
1379 if (dst_type == src_type)
1380 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_unsupported,
1381 "moving dims within the same type not supported",
1382 return FN(MULTI(BASE),free)(multi));
1384 multi = FN(MULTI(BASE),cow)(multi);
1385 if (!multi)
1386 return NULL;
1388 multi->space = isl_space_move_dims(multi->space, dst_type, dst_pos,
1389 src_type, src_pos, n);
1390 if (!multi->space)
1391 return FN(MULTI(BASE),free)(multi);
1393 for (i = 0; i < multi->n; ++i) {
1394 multi->p[i] = FN(EL,move_dims)(multi->p[i], dst_type, dst_pos,
1395 src_type, src_pos, n);
1396 if (!multi->p[i])
1397 return FN(MULTI(BASE),free)(multi);
1400 return multi;
1402 #endif
1404 /* Convert a multiple expression defined over a parameter domain
1405 * into one that is defined over a zero-dimensional set.
1407 __isl_give MULTI(BASE) *FN(MULTI(BASE),from_range)(
1408 __isl_take MULTI(BASE) *multi)
1410 isl_space *space;
1412 if (!multi)
1413 return NULL;
1414 if (!isl_space_is_set(multi->space))
1415 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1416 "not living in a set space",
1417 return FN(MULTI(BASE),free)(multi));
1419 space = FN(MULTI(BASE),get_space)(multi);
1420 space = isl_space_from_range(space);
1421 multi = FN(MULTI(BASE),reset_space)(multi, space);
1423 return multi;
1426 /* Are "multi1" and "multi2" obviously equal?
1428 isl_bool FN(MULTI(BASE),plain_is_equal)(__isl_keep MULTI(BASE) *multi1,
1429 __isl_keep MULTI(BASE) *multi2)
1431 int i;
1432 isl_bool equal;
1434 if (!multi1 || !multi2)
1435 return isl_bool_error;
1436 if (multi1->n != multi2->n)
1437 return isl_bool_false;
1438 equal = isl_space_is_equal(multi1->space, multi2->space);
1439 if (equal < 0 || !equal)
1440 return equal;
1442 for (i = 0; i < multi1->n; ++i) {
1443 equal = FN(EL,plain_is_equal)(multi1->p[i], multi2->p[i]);
1444 if (equal < 0 || !equal)
1445 return equal;
1448 return isl_bool_true;
1451 /* Does "multi" involve any NaNs?
1453 isl_bool FN(MULTI(BASE),involves_nan)(__isl_keep MULTI(BASE) *multi)
1455 int i;
1457 if (!multi)
1458 return isl_bool_error;
1459 if (multi->n == 0)
1460 return isl_bool_false;
1462 for (i = 0; i < multi->n; ++i) {
1463 isl_bool has_nan = FN(EL,involves_nan)(multi->p[i]);
1464 if (has_nan < 0 || has_nan)
1465 return has_nan;
1468 return isl_bool_false;
1471 #ifndef NO_DOMAIN
1472 /* Return the shared domain of the elements of "multi".
1474 __isl_give isl_set *FN(MULTI(BASE),domain)(__isl_take MULTI(BASE) *multi)
1476 int i;
1477 isl_set *dom;
1479 if (!multi)
1480 return NULL;
1482 dom = isl_set_universe(FN(MULTI(BASE),get_domain_space)(multi));
1483 for (i = 0; i < multi->n; ++i) {
1484 isl_set *dom_i;
1486 dom_i = FN(EL,domain)(FN(FN(MULTI(BASE),get),BASE)(multi, i));
1487 dom = isl_set_intersect(dom, dom_i);
1490 FN(MULTI(BASE),free)(multi);
1491 return dom;
1493 #endif
1495 #ifndef NO_NEG
1496 /* Return the opposite of "multi".
1498 __isl_give MULTI(BASE) *FN(MULTI(BASE),neg)(__isl_take MULTI(BASE) *multi)
1500 int i;
1502 multi = FN(MULTI(BASE),cow)(multi);
1503 if (!multi)
1504 return NULL;
1506 for (i = 0; i < multi->n; ++i) {
1507 multi->p[i] = FN(EL,neg)(multi->p[i]);
1508 if (!multi->p[i])
1509 return FN(MULTI(BASE),free)(multi);
1512 return multi;
1514 #endif