add isl_union_map_preimage_range_multi_aff
[isl.git] / isl_multi_templ.c
blob173d2ec6e4f06b46ba6ea60d7a824410b4864f99
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 #define xCAT(A,B) A ## B
16 #define CAT(A,B) xCAT(A,B)
17 #undef EL
18 #define EL CAT(isl_,BASE)
19 #define xFN(TYPE,NAME) TYPE ## _ ## NAME
20 #define FN(TYPE,NAME) xFN(TYPE,NAME)
21 #define xMULTI(BASE) isl_multi_ ## BASE
22 #define MULTI(BASE) xMULTI(BASE)
23 #define MULTI_NAME(BASE) "isl_multi_" #BASE
24 #define xLIST(EL) EL ## _list
25 #define LIST(EL) xLIST(EL)
27 isl_ctx *FN(MULTI(BASE),get_ctx)(__isl_keep MULTI(BASE) *multi)
29 return multi ? isl_space_get_ctx(multi->space) : NULL;
32 __isl_give isl_space *FN(MULTI(BASE),get_space)(__isl_keep MULTI(BASE) *multi)
34 return multi ? isl_space_copy(multi->space) : NULL;
37 __isl_give isl_space *FN(MULTI(BASE),get_domain_space)(
38 __isl_keep MULTI(BASE) *multi)
40 return multi ? isl_space_domain(isl_space_copy(multi->space)) : NULL;
43 __isl_give MULTI(BASE) *FN(MULTI(BASE),alloc)(__isl_take isl_space *space)
45 isl_ctx *ctx;
46 int n;
47 MULTI(BASE) *multi;
49 if (!space)
50 return NULL;
52 ctx = isl_space_get_ctx(space);
53 n = isl_space_dim(space, isl_dim_out);
54 multi = isl_calloc(ctx, MULTI(BASE),
55 sizeof(MULTI(BASE)) + (n - 1) * sizeof(struct EL *));
56 if (!multi)
57 goto error;
59 multi->space = space;
60 multi->n = n;
61 multi->ref = 1;
62 return multi;
63 error:
64 isl_space_free(space);
65 return NULL;
68 __isl_give MULTI(BASE) *FN(MULTI(BASE),dup)(__isl_keep MULTI(BASE) *multi)
70 int i;
71 MULTI(BASE) *dup;
73 if (!multi)
74 return NULL;
76 dup = FN(MULTI(BASE),alloc)(isl_space_copy(multi->space));
77 if (!dup)
78 return NULL;
80 for (i = 0; i < multi->n; ++i)
81 dup = FN(FN(MULTI(BASE),set),BASE)(dup, i,
82 FN(EL,copy)(multi->p[i]));
84 return dup;
87 __isl_give MULTI(BASE) *FN(MULTI(BASE),cow)(__isl_take MULTI(BASE) *multi)
89 if (!multi)
90 return NULL;
92 if (multi->ref == 1)
93 return multi;
95 multi->ref--;
96 return FN(MULTI(BASE),dup)(multi);
99 __isl_give MULTI(BASE) *FN(MULTI(BASE),copy)(__isl_keep MULTI(BASE) *multi)
101 if (!multi)
102 return NULL;
104 multi->ref++;
105 return multi;
108 void *FN(MULTI(BASE),free)(__isl_take MULTI(BASE) *multi)
110 int i;
112 if (!multi)
113 return NULL;
115 if (--multi->ref > 0)
116 return NULL;
118 isl_space_free(multi->space);
119 for (i = 0; i < multi->n; ++i)
120 FN(EL,free)(multi->p[i]);
121 free(multi);
123 return NULL;
126 /* Check whether "multi" has non-zero coefficients for any dimension
127 * in the given range or if any of these dimensions appear
128 * with non-zero coefficients in any of the integer divisions involved.
130 int FN(MULTI(BASE),involves_dims)(__isl_keep MULTI(BASE) *multi,
131 enum isl_dim_type type, unsigned first, unsigned n)
133 int i;
135 if (!multi)
136 return -1;
137 if (multi->n == 0 || n == 0)
138 return 0;
140 for (i = 0; i < multi->n; ++i) {
141 int involves;
143 involves = FN(EL,involves_dims)(multi->p[i], type, first, n);
144 if (involves < 0 || involves)
145 return involves;
148 return 0;
151 __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
152 __isl_take MULTI(BASE) *multi,
153 enum isl_dim_type type, unsigned first, unsigned n)
155 int i;
157 if (!multi)
158 return NULL;
159 if (type == isl_dim_out)
160 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
161 "cannot insert output/set dimensions",
162 return FN(MULTI(BASE),free)(multi));
163 if (n == 0 && !isl_space_is_named_or_nested(multi->space, type))
164 return multi;
166 multi = FN(MULTI(BASE),cow)(multi);
167 if (!multi)
168 return NULL;
170 multi->space = isl_space_insert_dims(multi->space, type, first, n);
171 if (!multi->space)
172 return FN(MULTI(BASE),free)(multi);
174 for (i = 0; i < multi->n; ++i) {
175 multi->p[i] = FN(EL,insert_dims)(multi->p[i], type, first, n);
176 if (!multi->p[i])
177 return FN(MULTI(BASE),free)(multi);
180 return multi;
183 __isl_give MULTI(BASE) *FN(MULTI(BASE),add_dims)(__isl_take MULTI(BASE) *multi,
184 enum isl_dim_type type, unsigned n)
186 unsigned pos;
188 pos = FN(MULTI(BASE),dim)(multi, type);
190 return FN(MULTI(BASE),insert_dims)(multi, type, pos, n);
193 unsigned FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi,
194 enum isl_dim_type type)
196 return multi ? isl_space_dim(multi->space, type) : 0;
199 /* Return the position of the first dimension of "type" with id "id".
200 * Return -1 if there is no such dimension.
202 int FN(MULTI(BASE),find_dim_by_id)(__isl_keep MULTI(BASE) *multi,
203 enum isl_dim_type type, __isl_keep isl_id *id)
205 if (!multi)
206 return -1;
207 return isl_space_find_dim_by_id(multi->space, type, id);
210 /* Return the id of the given dimension.
212 __isl_give isl_id *FN(MULTI(BASE),get_dim_id)(__isl_keep MULTI(BASE) *multi,
213 enum isl_dim_type type, unsigned pos)
215 return multi ? isl_space_get_dim_id(multi->space, type, pos) : NULL;
218 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)(
219 __isl_take MULTI(BASE) *multi,
220 enum isl_dim_type type, unsigned pos, const char *s)
222 int i;
224 multi = FN(MULTI(BASE),cow)(multi);
225 if (!multi)
226 return NULL;
228 multi->space = isl_space_set_dim_name(multi->space, type, pos, s);
229 if (!multi->space)
230 return FN(MULTI(BASE),free)(multi);
232 if (type == isl_dim_out)
233 return multi;
234 for (i = 0; i < multi->n; ++i) {
235 multi->p[i] = FN(EL,set_dim_name)(multi->p[i], type, pos, s);
236 if (!multi->p[i])
237 return FN(MULTI(BASE),free)(multi);
240 return multi;
243 const char *FN(MULTI(BASE),get_tuple_name)(__isl_keep MULTI(BASE) *multi,
244 enum isl_dim_type type)
246 return multi ? isl_space_get_tuple_name(multi->space, type) : NULL;
249 /* Does the specified tuple have an id?
251 int FN(MULTI(BASE),has_tuple_id)(__isl_keep MULTI(BASE) *multi,
252 enum isl_dim_type type)
254 return multi ? isl_space_has_tuple_id(multi->space, type) : -1;
257 /* Return the id of the specified tuple.
259 __isl_give isl_id *FN(MULTI(BASE),get_tuple_id)(__isl_keep MULTI(BASE) *multi,
260 enum isl_dim_type type)
262 return multi ? isl_space_get_tuple_id(multi->space, type) : NULL;
265 __isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi,
266 int pos)
268 isl_ctx *ctx;
270 if (!multi)
271 return NULL;
272 ctx = FN(MULTI(BASE),get_ctx)(multi);
273 if (pos < 0 || pos >= multi->n)
274 isl_die(ctx, isl_error_invalid,
275 "index out of bounds", return NULL);
276 return FN(EL,copy)(multi->p[pos]);
279 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)(
280 __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
282 isl_space *multi_space = NULL;
283 isl_space *el_space = NULL;
284 int match;
286 multi = FN(MULTI(BASE),cow)(multi);
287 if (!multi || !el)
288 goto error;
290 multi_space = FN(MULTI(BASE),get_space)(multi);
291 match = FN(EL,matching_params)(el, multi_space);
292 if (match < 0)
293 goto error;
294 if (!match) {
295 multi = FN(MULTI(BASE),align_params)(multi,
296 FN(EL,get_space)(el));
297 isl_space_free(multi_space);
298 multi_space = FN(MULTI(BASE),get_space)(multi);
299 el = FN(EL,align_params)(el, isl_space_copy(multi_space));
301 if (FN(EL,check_match_domain_space)(el, multi_space) < 0)
302 goto error;
304 if (pos < 0 || pos >= multi->n)
305 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
306 "index out of bounds", goto error);
308 FN(EL,free)(multi->p[pos]);
309 multi->p[pos] = el;
311 isl_space_free(multi_space);
312 isl_space_free(el_space);
314 return multi;
315 error:
316 FN(MULTI(BASE),free)(multi);
317 FN(EL,free)(el);
318 isl_space_free(multi_space);
319 isl_space_free(el_space);
320 return NULL;
323 /* Reset the space of "multi". This function is called from isl_pw_templ.c
324 * and doesn't know if the space of an element object is represented
325 * directly or through its domain. It therefore passes along both,
326 * which we pass along to the element function since we don't how
327 * that is represented either.
329 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)(
330 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space,
331 __isl_take isl_space *domain)
333 int i;
335 multi = FN(MULTI(BASE),cow)(multi);
336 if (!multi || !space || !domain)
337 goto error;
339 for (i = 0; i < multi->n; ++i) {
340 multi->p[i] = FN(EL,reset_domain_space)(multi->p[i],
341 isl_space_copy(domain));
342 if (!multi->p[i])
343 goto error;
345 isl_space_free(domain);
346 isl_space_free(multi->space);
347 multi->space = space;
349 return multi;
350 error:
351 isl_space_free(domain);
352 isl_space_free(space);
353 FN(MULTI(BASE),free)(multi);
354 return NULL;
357 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_domain_space)(
358 __isl_take MULTI(BASE) *multi, __isl_take isl_space *domain)
360 isl_space *space;
362 space = isl_space_extend_domain_with_range(isl_space_copy(domain),
363 isl_space_copy(multi->space));
364 return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
367 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space)(
368 __isl_take MULTI(BASE) *multi, __isl_take isl_space *space)
370 isl_space *domain;
372 domain = isl_space_domain(isl_space_copy(space));
373 return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain);
376 /* Set the id of the given dimension of "multi" to "id".
378 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_id)(
379 __isl_take MULTI(BASE) *multi,
380 enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
382 isl_space *space;
384 multi = FN(MULTI(BASE),cow)(multi);
385 if (!multi || !id)
386 goto error;
388 space = FN(MULTI(BASE),get_space)(multi);
389 space = isl_space_set_dim_id(space, type, pos, id);
391 return FN(MULTI(BASE),reset_space)(multi, space);
392 error:
393 isl_id_free(id);
394 FN(MULTI(BASE),free)(multi);
395 return NULL;
398 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_name)(
399 __isl_keep MULTI(BASE) *multi, enum isl_dim_type type,
400 const char *s)
402 isl_space *space;
404 multi = FN(MULTI(BASE),cow)(multi);
405 if (!multi)
406 return NULL;
408 space = FN(MULTI(BASE),get_space)(multi);
409 space = isl_space_set_tuple_name(space, type, s);
411 return FN(MULTI(BASE),reset_space)(multi, space);
414 __isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_id)(
415 __isl_take MULTI(BASE) *multi, enum isl_dim_type type,
416 __isl_take isl_id *id)
418 isl_space *space;
420 multi = FN(MULTI(BASE),cow)(multi);
421 if (!multi)
422 return isl_id_free(id);
424 space = FN(MULTI(BASE),get_space)(multi);
425 space = isl_space_set_tuple_id(space, type, id);
427 return FN(MULTI(BASE),reset_space)(multi, space);
430 /* Drop the id on the specified tuple.
432 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_tuple_id)(
433 __isl_take MULTI(BASE) *multi, enum isl_dim_type type)
435 isl_space *space;
437 if (!multi)
438 return NULL;
439 if (!FN(MULTI(BASE),has_tuple_id)(multi, type))
440 return multi;
442 multi = FN(MULTI(BASE),cow)(multi);
443 if (!multi)
444 return NULL;
446 space = FN(MULTI(BASE),get_space)(multi);
447 space = isl_space_reset_tuple_id(space, type);
449 return FN(MULTI(BASE),reset_space)(multi, space);
452 /* Reset the user pointer on all identifiers of parameters and tuples
453 * of the space of "multi".
455 __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_user)(
456 __isl_take MULTI(BASE) *multi)
458 isl_space *space;
460 space = FN(MULTI(BASE),get_space)(multi);
461 space = isl_space_reset_user(space);
463 return FN(MULTI(BASE),reset_space)(multi, space);
466 __isl_give MULTI(BASE) *FN(MULTI(BASE),realign_domain)(
467 __isl_take MULTI(BASE) *multi, __isl_take isl_reordering *exp)
469 int i;
471 multi = FN(MULTI(BASE),cow)(multi);
472 if (!multi || !exp)
473 goto error;
475 for (i = 0; i < multi->n; ++i) {
476 multi->p[i] = FN(EL,realign_domain)(multi->p[i],
477 isl_reordering_copy(exp));
478 if (!multi->p[i])
479 goto error;
482 multi = FN(MULTI(BASE),reset_domain_space)(multi,
483 isl_space_copy(exp->dim));
485 isl_reordering_free(exp);
486 return multi;
487 error:
488 isl_reordering_free(exp);
489 FN(MULTI(BASE),free)(multi);
490 return NULL;
493 /* Align the parameters of "multi" to those of "model".
495 __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params)(
496 __isl_take MULTI(BASE) *multi, __isl_take isl_space *model)
498 isl_ctx *ctx;
499 isl_reordering *exp;
501 if (!multi || !model)
502 goto error;
504 if (isl_space_match(multi->space, isl_dim_param,
505 model, isl_dim_param)) {
506 isl_space_free(model);
507 return multi;
510 ctx = isl_space_get_ctx(model);
511 if (!isl_space_has_named_params(model))
512 isl_die(ctx, isl_error_invalid,
513 "model has unnamed parameters", goto error);
514 if (!isl_space_has_named_params(multi->space))
515 isl_die(ctx, isl_error_invalid,
516 "input has unnamed parameters", goto error);
518 model = isl_space_params(model);
519 exp = isl_parameter_alignment_reordering(multi->space, model);
520 exp = isl_reordering_extend_space(exp,
521 FN(MULTI(BASE),get_domain_space)(multi));
522 multi = FN(MULTI(BASE),realign_domain)(multi, exp);
524 isl_space_free(model);
525 return multi;
526 error:
527 isl_space_free(model);
528 FN(MULTI(BASE),free)(multi);
529 return NULL;
532 #if !defined(NO_GIST) || !defined(NO_INTERSECT_DOMAIN)
533 static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params_multi_set_and)(
534 __isl_take MULTI(BASE) *multi, __isl_take isl_set *set,
535 __isl_give MULTI(BASE) *(*fn)(__isl_take MULTI(BASE) *multi,
536 __isl_take isl_set *set))
538 isl_ctx *ctx;
540 if (!multi || !set)
541 goto error;
542 if (isl_space_match(multi->space, isl_dim_param,
543 set->dim, isl_dim_param))
544 return fn(multi, set);
545 ctx = FN(MULTI(BASE),get_ctx)(multi);
546 if (!isl_space_has_named_params(multi->space) ||
547 !isl_space_has_named_params(set->dim))
548 isl_die(ctx, isl_error_invalid,
549 "unaligned unnamed parameters", goto error);
550 multi = FN(MULTI(BASE),align_params)(multi, isl_set_get_space(set));
551 set = isl_set_align_params(set, FN(MULTI(BASE),get_space)(multi));
552 return fn(multi, set);
553 error:
554 FN(MULTI(BASE),free)(multi);
555 isl_set_free(set);
556 return NULL;
558 #endif
560 #ifndef NO_GIST
561 __isl_give MULTI(BASE) *FN(MULTI(BASE),gist_aligned)(
562 __isl_take MULTI(BASE) *multi, __isl_take isl_set *context)
564 int i;
566 multi = FN(MULTI(BASE),cow)(multi);
567 if (!multi || !context)
568 goto error;
570 for (i = 0; i < multi->n; ++i) {
571 multi->p[i] = FN(EL,gist)(multi->p[i], isl_set_copy(context));
572 if (!multi->p[i])
573 goto error;
576 isl_set_free(context);
577 return multi;
578 error:
579 isl_set_free(context);
580 FN(MULTI(BASE),free)(multi);
581 return NULL;
584 __isl_give MULTI(BASE) *FN(MULTI(BASE),gist)(__isl_take MULTI(BASE) *multi,
585 __isl_take isl_set *context)
587 return FN(MULTI(BASE),align_params_multi_set_and)(multi, context,
588 &FN(MULTI(BASE),gist_aligned));
591 __isl_give MULTI(BASE) *FN(MULTI(BASE),gist_params)(
592 __isl_take MULTI(BASE) *multi, __isl_take isl_set *context)
594 isl_space *space = FN(MULTI(BASE),get_domain_space)(multi);
595 isl_set *dom_context = isl_set_universe(space);
596 dom_context = isl_set_intersect_params(dom_context, context);
597 return FN(MULTI(BASE),gist)(multi, dom_context);
599 #endif
601 #ifndef NO_INTERSECT_DOMAIN
602 /* Transform the domain of "multi" by combining it with "domain"
603 * using "fn".
605 * The parameters of "multi" and "domain" are assumed to have been aligned.
607 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_aligned)(
608 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain,
609 __isl_give EL *(*fn)(EL *el, __isl_take isl_set *set2))
611 int i;
613 if (!multi || !domain)
614 goto error;
616 if (multi->n == 0) {
617 isl_set_free(domain);
618 return multi;
621 multi = FN(MULTI(BASE),cow)(multi);
622 if (!multi)
623 goto error;
625 for (i = 0; i < multi->n; ++i) {
626 multi->p[i] = fn(multi->p[i], isl_set_copy(domain));
627 if (!multi->p[i])
628 goto error;
631 isl_set_free(domain);
632 return multi;
633 error:
634 isl_set_free(domain);
635 FN(MULTI(BASE),free)(multi);
636 return NULL;
639 /* Intersect the domain of "multi" with "domain".
641 * The parameters of "multi" and "domain" are assumed to have been aligned.
643 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain_aligned)(
644 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
646 return FN(MULTI(BASE),intersect_aligned)(multi, domain,
647 &FN(EL,intersect_domain));
650 /* Intersect the domain of "multi" with "domain".
652 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain)(
653 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
655 return FN(MULTI(BASE),align_params_multi_set_and)(multi, domain,
656 &FN(MULTI(BASE),intersect_domain_aligned));
659 /* Intersect the parameter domain of "multi" with "domain".
661 * The parameters of "multi" and "domain" are assumed to have been aligned.
663 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params_aligned)(
664 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
666 return FN(MULTI(BASE),intersect_aligned)(multi, domain,
667 &FN(EL,intersect_params));
670 /* Intersect the parameter domain of "multi" with "domain".
672 __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params)(
673 __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain)
675 return FN(MULTI(BASE),align_params_multi_set_and)(multi, domain,
676 &FN(MULTI(BASE),intersect_params_aligned));
678 #endif
680 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),LIST(BASE))(
681 __isl_take isl_space *space, __isl_take LIST(EL) *list)
683 int i;
684 int n;
685 isl_ctx *ctx;
686 MULTI(BASE) *multi;
688 if (!space || !list)
689 goto error;
691 ctx = isl_space_get_ctx(space);
692 n = FN(FN(LIST(EL),n),BASE)(list);
693 if (n != isl_space_dim(space, isl_dim_out))
694 isl_die(ctx, isl_error_invalid,
695 "invalid number of elements in list", goto error);
697 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
698 for (i = 0; i < n; ++i) {
699 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i,
700 FN(FN(LIST(EL),get),BASE)(list, i));
703 isl_space_free(space);
704 FN(LIST(EL),free)(list);
705 return multi;
706 error:
707 isl_space_free(space);
708 FN(LIST(EL),free)(list);
709 return NULL;
712 #ifndef NO_IDENTITY
713 /* Create a multi expression in the given space that maps each
714 * input dimension to the corresponding output dimension.
716 __isl_give MULTI(BASE) *FN(MULTI(BASE),identity)(__isl_take isl_space *space)
718 int i, n;
719 isl_local_space *ls;
720 MULTI(BASE) *multi;
722 if (!space)
723 return NULL;
725 if (isl_space_is_set(space))
726 isl_die(isl_space_get_ctx(space), isl_error_invalid,
727 "expecting map space", goto error);
729 n = isl_space_dim(space, isl_dim_out);
730 if (n != isl_space_dim(space, isl_dim_in))
731 isl_die(isl_space_get_ctx(space), isl_error_invalid,
732 "number of input and output dimensions needs to be "
733 "the same", goto error);
735 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
737 if (!n) {
738 isl_space_free(space);
739 return multi;
742 space = isl_space_domain(space);
743 ls = isl_local_space_from_space(space);
745 for (i = 0; i < n; ++i) {
746 EL *el;
747 el = FN(EL,var_on_domain)(isl_local_space_copy(ls),
748 isl_dim_set, i);
749 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, el);
752 isl_local_space_free(ls);
754 return multi;
755 error:
756 isl_space_free(space);
757 return NULL;
759 #endif
761 /* Construct a multi expression in the given space with value zero in
762 * each of the output dimensions.
764 __isl_give MULTI(BASE) *FN(MULTI(BASE),zero)(__isl_take isl_space *space)
766 int n;
767 MULTI(BASE) *multi;
769 if (!space)
770 return NULL;
772 n = isl_space_dim(space , isl_dim_out);
773 multi = FN(MULTI(BASE),alloc)(isl_space_copy(space));
775 if (!n)
776 isl_space_free(space);
777 else {
778 int i;
779 isl_local_space *ls;
780 EL *el;
782 space = isl_space_domain(space);
783 ls = isl_local_space_from_space(space);
784 el = FN(EL,zero_on_domain)(ls);
786 for (i = 0; i < n; ++i)
787 multi = FN(FN(MULTI(BASE),set),BASE)(multi, i,
788 FN(EL,copy)(el));
790 FN(EL,free)(el);
793 return multi;
796 #ifndef NO_FROM_BASE
797 __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),BASE)(__isl_take EL *el)
799 MULTI(BASE) *multi;
801 multi = FN(MULTI(BASE),alloc)(FN(EL,get_space)(el));
802 multi = FN(FN(MULTI(BASE),set),BASE)(multi, 0, el);
804 return multi;
806 #endif
808 __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)(
809 __isl_take MULTI(BASE) *multi,
810 enum isl_dim_type type, unsigned first, unsigned n)
812 int i;
813 unsigned dim;
815 multi = FN(MULTI(BASE),cow)(multi);
816 if (!multi)
817 return NULL;
819 dim = FN(MULTI(BASE),dim)(multi, type);
820 if (first + n > dim || first + n < first)
821 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
822 "index out of bounds",
823 return FN(MULTI(BASE),cow)(multi));
825 multi->space = isl_space_drop_dims(multi->space, type, first, n);
826 if (!multi->space)
827 return FN(MULTI(BASE),cow)(multi);
829 if (type == isl_dim_out) {
830 for (i = 0; i < n; ++i)
831 FN(EL,free)(multi->p[first + i]);
832 for (i = first; i + n < multi->n; ++i)
833 multi->p[i] = multi->p[i + n];
834 multi->n -= n;
836 return multi;
839 for (i = 0; i < multi->n; ++i) {
840 multi->p[i] = FN(EL,drop_dims)(multi->p[i], type, first, n);
841 if (!multi->p[i])
842 return FN(MULTI(BASE),cow)(multi);
845 return multi;
848 /* Align the parameters of "multi1" and "multi2" (if needed) and call "fn".
850 static __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params_multi_multi_and)(
851 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
852 __isl_give MULTI(BASE) *(*fn)(__isl_take MULTI(BASE) *multi1,
853 __isl_take MULTI(BASE) *multi2))
855 isl_ctx *ctx;
857 if (!multi1 || !multi2)
858 goto error;
859 if (isl_space_match(multi1->space, isl_dim_param,
860 multi2->space, isl_dim_param))
861 return fn(multi1, multi2);
862 ctx = FN(MULTI(BASE),get_ctx)(multi1);
863 if (!isl_space_has_named_params(multi1->space) ||
864 !isl_space_has_named_params(multi2->space))
865 isl_die(ctx, isl_error_invalid,
866 "unaligned unnamed parameters", goto error);
867 multi1 = FN(MULTI(BASE),align_params)(multi1,
868 FN(MULTI(BASE),get_space)(multi2));
869 multi2 = FN(MULTI(BASE),align_params)(multi2,
870 FN(MULTI(BASE),get_space)(multi1));
871 return fn(multi1, multi2);
872 error:
873 FN(MULTI(BASE),free)(multi1);
874 FN(MULTI(BASE),free)(multi2);
875 return NULL;
878 /* Given two MULTI(BASE)s A -> B and C -> D,
879 * construct a MULTI(BASE) (A * C) -> [B -> D].
881 * The parameters are assumed to have been aligned.
883 static __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product_aligned)(
884 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
886 int i, n1, n2;
887 EL *el;
888 isl_space *space;
889 MULTI(BASE) *res;
891 if (!multi1 || !multi2)
892 goto error;
894 space = isl_space_range_product(FN(MULTI(BASE),get_space)(multi1),
895 FN(MULTI(BASE),get_space)(multi2));
896 res = FN(MULTI(BASE),alloc)(space);
898 n1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
899 n2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out);
901 for (i = 0; i < n1; ++i) {
902 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
903 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
906 for (i = 0; i < n2; ++i) {
907 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
908 res = FN(FN(MULTI(BASE),set),BASE)(res, n1 + i, el);
911 FN(MULTI(BASE),free)(multi1);
912 FN(MULTI(BASE),free)(multi2);
913 return res;
914 error:
915 FN(MULTI(BASE),free)(multi1);
916 FN(MULTI(BASE),free)(multi2);
917 return NULL;
920 /* Given two MULTI(BASE)s A -> B and C -> D,
921 * construct a MULTI(BASE) (A * C) -> [B -> D].
923 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product)(
924 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
926 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
927 &FN(MULTI(BASE),range_product_aligned));
930 /* Is the range of "multi" a wrapped relation?
932 int FN(MULTI(BASE),range_is_wrapping)(__isl_keep MULTI(BASE) *multi)
934 if (!multi)
935 return -1;
936 return isl_space_range_is_wrapping(multi->space);
939 /* Given a function A -> [B -> C], extract the function A -> B.
941 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_factor_domain)(
942 __isl_take MULTI(BASE) *multi)
944 isl_space *space;
945 int total, keep;
947 if (!multi)
948 return NULL;
949 if (!isl_space_range_is_wrapping(multi->space))
950 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
951 "range is not a product",
952 return FN(MULTI(BASE),free)(multi));
954 space = FN(MULTI(BASE),get_space)(multi);
955 total = isl_space_dim(space, isl_dim_out);
956 space = isl_space_range_factor_domain(space);
957 keep = isl_space_dim(space, isl_dim_out);
958 multi = FN(MULTI(BASE),drop_dims)(multi,
959 isl_dim_out, keep, total - keep);
960 multi = FN(MULTI(BASE),reset_space)(multi, space);
962 return multi;
965 /* Given a function A -> [B -> C], extract the function A -> C.
967 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_factor_range)(
968 __isl_take MULTI(BASE) *multi)
970 isl_space *space;
971 int total, keep;
973 if (!multi)
974 return NULL;
975 if (!isl_space_range_is_wrapping(multi->space))
976 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
977 "range is not a product",
978 return FN(MULTI(BASE),free)(multi));
980 space = FN(MULTI(BASE),get_space)(multi);
981 total = isl_space_dim(space, isl_dim_out);
982 space = isl_space_range_factor_range(space);
983 keep = isl_space_dim(space, isl_dim_out);
984 multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, 0, total - keep);
985 multi = FN(MULTI(BASE),reset_space)(multi, space);
987 return multi;
990 /* Given two MULTI(BASE)s A -> B and C -> D,
991 * construct a MULTI(BASE) [A -> C] -> [B -> D].
993 * The parameters are assumed to have been aligned.
995 __isl_give MULTI(BASE) *FN(MULTI(BASE),product_aligned)(
996 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
998 int i;
999 EL *el;
1000 isl_space *space;
1001 MULTI(BASE) *res;
1002 int in1, in2, out1, out2;
1004 in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
1005 in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
1006 out1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
1007 out2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out);
1008 space = isl_space_product(FN(MULTI(BASE),get_space)(multi1),
1009 FN(MULTI(BASE),get_space)(multi2));
1010 res = FN(MULTI(BASE),alloc)(isl_space_copy(space));
1011 space = isl_space_domain(space);
1013 for (i = 0; i < out1; ++i) {
1014 el = FN(FN(MULTI(BASE),get),BASE)(multi1, i);
1015 el = FN(EL,insert_dims)(el, isl_dim_in, in1, in2);
1016 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
1017 res = FN(FN(MULTI(BASE),set),BASE)(res, i, el);
1020 for (i = 0; i < out2; ++i) {
1021 el = FN(FN(MULTI(BASE),get),BASE)(multi2, i);
1022 el = FN(EL,insert_dims)(el, isl_dim_in, 0, in1);
1023 el = FN(EL,reset_domain_space)(el, isl_space_copy(space));
1024 res = FN(FN(MULTI(BASE),set),BASE)(res, out1 + i, el);
1027 isl_space_free(space);
1028 FN(MULTI(BASE),free)(multi1);
1029 FN(MULTI(BASE),free)(multi2);
1030 return res;
1033 /* Given two MULTI(BASE)s A -> B and C -> D,
1034 * construct a MULTI(BASE) [A -> C] -> [B -> D].
1036 __isl_give MULTI(BASE) *FN(MULTI(BASE),product)(
1037 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
1039 return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2,
1040 &FN(MULTI(BASE),product_aligned));
1043 __isl_give MULTI(BASE) *FN(MULTI(BASE),flatten_range)(
1044 __isl_take MULTI(BASE) *multi)
1046 if (!multi)
1047 return NULL;
1049 if (!multi->space->nested[1])
1050 return multi;
1052 multi = FN(MULTI(BASE),cow)(multi);
1053 if (!multi)
1054 return NULL;
1056 multi->space = isl_space_flatten_range(multi->space);
1057 if (!multi->space)
1058 return FN(MULTI(BASE),free)(multi);
1060 return multi;
1063 /* Given two MULTI(BASE)s A -> B and C -> D,
1064 * construct a MULTI(BASE) (A * C) -> (B, D).
1066 __isl_give MULTI(BASE) *FN(MULTI(BASE),flat_range_product)(
1067 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2)
1069 MULTI(BASE) *multi;
1071 multi = FN(MULTI(BASE),range_product)(multi1, multi2);
1072 multi = FN(MULTI(BASE),flatten_range)(multi);
1073 return multi;
1076 /* Given two multi expressions, "multi1"
1078 * [A] -> [B1 B2]
1080 * where B2 starts at position "pos", and "multi2"
1082 * [A] -> [D]
1084 * return the multi expression
1086 * [A] -> [B1 D B2]
1088 __isl_give MULTI(BASE) *FN(MULTI(BASE),range_splice)(
1089 __isl_take MULTI(BASE) *multi1, unsigned pos,
1090 __isl_take MULTI(BASE) *multi2)
1092 MULTI(BASE) *res;
1093 unsigned dim;
1095 if (!multi1 || !multi2)
1096 goto error;
1098 dim = FN(MULTI(BASE),dim)(multi1, isl_dim_out);
1099 if (pos > dim)
1100 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
1101 "index out of bounds", goto error);
1103 res = FN(MULTI(BASE),copy)(multi1);
1104 res = FN(MULTI(BASE),drop_dims)(res, isl_dim_out, pos, dim - pos);
1105 multi1 = FN(MULTI(BASE),drop_dims)(multi1, isl_dim_out, 0, pos);
1107 res = FN(MULTI(BASE),flat_range_product)(res, multi2);
1108 res = FN(MULTI(BASE),flat_range_product)(res, multi1);
1110 return res;
1111 error:
1112 FN(MULTI(BASE),free)(multi1);
1113 FN(MULTI(BASE),free)(multi2);
1114 return NULL;
1117 /* Given two multi expressions, "multi1"
1119 * [A1 A2] -> [B1 B2]
1121 * where A2 starts at position "in_pos" and B2 starts at position "out_pos",
1122 * and "multi2"
1124 * [C] -> [D]
1126 * return the multi expression
1128 * [A1 C A2] -> [B1 D B2]
1130 * We first insert input dimensions to obtain
1132 * [A1 C A2] -> [B1 B2]
1134 * and
1136 * [A1 C A2] -> [D]
1138 * and then apply range_splice.
1140 __isl_give MULTI(BASE) *FN(MULTI(BASE),splice)(
1141 __isl_take MULTI(BASE) *multi1, unsigned in_pos, unsigned out_pos,
1142 __isl_take MULTI(BASE) *multi2)
1144 unsigned n_in1;
1145 unsigned n_in2;
1147 if (!multi1 || !multi2)
1148 goto error;
1150 n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
1151 if (in_pos > n_in1)
1152 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
1153 "index out of bounds", goto error);
1155 n_in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
1157 multi1 = FN(MULTI(BASE),insert_dims)(multi1, isl_dim_in, in_pos, n_in2);
1158 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, n_in2,
1159 n_in1 - in_pos);
1160 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, 0, in_pos);
1162 return FN(MULTI(BASE),range_splice)(multi1, out_pos, multi2);
1163 error:
1164 FN(MULTI(BASE),free)(multi1);
1165 FN(MULTI(BASE),free)(multi2);
1166 return NULL;
1169 /* This function is currently only used from isl_aff.c
1171 static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
1172 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
1173 __isl_give EL *(*fn)(__isl_take EL *, __isl_take EL *))
1174 __attribute__ ((unused));
1176 /* Pairwise perform "fn" to the elements of "multi1" and "multi2" and
1177 * return the result.
1179 static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)(
1180 __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2,
1181 __isl_give EL *(*fn)(__isl_take EL *, __isl_take EL *))
1183 int i;
1184 isl_ctx *ctx;
1186 multi1 = FN(MULTI(BASE),cow)(multi1);
1187 if (!multi1 || !multi2)
1188 goto error;
1190 ctx = FN(MULTI(BASE),get_ctx)(multi1);
1191 if (!isl_space_is_equal(multi1->space, multi2->space))
1192 isl_die(ctx, isl_error_invalid,
1193 "spaces don't match", goto error);
1195 for (i = 0; i < multi1->n; ++i) {
1196 multi1->p[i] = fn(multi1->p[i], FN(EL,copy)(multi2->p[i]));
1197 if (!multi1->p[i])
1198 goto error;
1201 FN(MULTI(BASE),free)(multi2);
1202 return multi1;
1203 error:
1204 FN(MULTI(BASE),free)(multi1);
1205 FN(MULTI(BASE),free)(multi2);
1206 return NULL;
1209 /* Multiply the elements of "multi" by "v" and return the result.
1211 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
1212 __isl_take isl_val *v)
1214 int i;
1216 if (!multi || !v)
1217 goto error;
1219 if (isl_val_is_one(v)) {
1220 isl_val_free(v);
1221 return multi;
1224 if (!isl_val_is_rat(v))
1225 isl_die(isl_val_get_ctx(v), isl_error_invalid,
1226 "expecting rational factor", goto error);
1228 multi = FN(MULTI(BASE),cow)(multi);
1229 if (!multi)
1230 return NULL;
1232 for (i = 0; i < multi->n; ++i) {
1233 multi->p[i] = FN(EL,scale_val)(multi->p[i], isl_val_copy(v));
1234 if (!multi->p[i])
1235 goto error;
1238 isl_val_free(v);
1239 return multi;
1240 error:
1241 isl_val_free(v);
1242 return FN(MULTI(BASE),free)(multi);
1245 /* Multiply the elements of "multi" by the corresponding element of "mv"
1246 * and return the result.
1248 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
1249 __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
1251 int i;
1253 if (!multi || !mv)
1254 goto error;
1256 if (!isl_space_tuple_match(multi->space, isl_dim_out,
1257 mv->space, isl_dim_set))
1258 isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
1259 "spaces don't match", goto error);
1261 multi = FN(MULTI(BASE),cow)(multi);
1262 if (!multi)
1263 return NULL;
1265 for (i = 0; i < multi->n; ++i) {
1266 isl_val *v;
1268 v = isl_multi_val_get_val(mv, i);
1269 multi->p[i] = FN(EL,scale_val)(multi->p[i], v);
1270 if (!multi->p[i])
1271 goto error;
1274 isl_multi_val_free(mv);
1275 return multi;
1276 error:
1277 isl_multi_val_free(mv);
1278 return FN(MULTI(BASE),free)(multi);
1281 /* Divide the elements of "multi" by the corresponding element of "mv"
1282 * and return the result.
1284 __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
1285 __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
1287 int i;
1289 if (!multi || !mv)
1290 goto error;
1292 if (!isl_space_tuple_match(multi->space, isl_dim_out,
1293 mv->space, isl_dim_set))
1294 isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
1295 "spaces don't match", goto error);
1297 multi = FN(MULTI(BASE),cow)(multi);
1298 if (!multi)
1299 return NULL;
1301 for (i = 0; i < multi->n; ++i) {
1302 isl_val *v;
1304 v = isl_multi_val_get_val(mv, i);
1305 multi->p[i] = FN(EL,scale_down_val)(multi->p[i], v);
1306 if (!multi->p[i])
1307 goto error;
1310 isl_multi_val_free(mv);
1311 return multi;
1312 error:
1313 isl_multi_val_free(mv);
1314 return FN(MULTI(BASE),free)(multi);
1317 #ifndef NO_MOVE_DIMS
1318 /* Move the "n" dimensions of "src_type" starting at "src_pos" of "multi"
1319 * to dimensions of "dst_type" at "dst_pos".
1321 * We only support moving input dimensions to parameters and vice versa.
1323 __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
1324 enum isl_dim_type dst_type, unsigned dst_pos,
1325 enum isl_dim_type src_type, unsigned src_pos, unsigned n)
1327 int i;
1329 if (!multi)
1330 return NULL;
1332 if (n == 0 &&
1333 !isl_space_is_named_or_nested(multi->space, src_type) &&
1334 !isl_space_is_named_or_nested(multi->space, dst_type))
1335 return multi;
1337 if (dst_type == isl_dim_out || src_type == isl_dim_out)
1338 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1339 "cannot move output/set dimension",
1340 return FN(MULTI(BASE),free)(multi));
1341 if (dst_type == isl_dim_div || src_type == isl_dim_div)
1342 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1343 "cannot move divs",
1344 return FN(MULTI(BASE),free)(multi));
1345 if (src_pos + n > isl_space_dim(multi->space, src_type))
1346 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1347 "range out of bounds",
1348 return FN(MULTI(BASE),free)(multi));
1349 if (dst_type == src_type)
1350 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_unsupported,
1351 "moving dims within the same type not supported",
1352 return FN(MULTI(BASE),free)(multi));
1354 multi = FN(MULTI(BASE),cow)(multi);
1355 if (!multi)
1356 return NULL;
1358 multi->space = isl_space_move_dims(multi->space, dst_type, dst_pos,
1359 src_type, src_pos, n);
1360 if (!multi->space)
1361 return FN(MULTI(BASE),free)(multi);
1363 for (i = 0; i < multi->n; ++i) {
1364 multi->p[i] = FN(EL,move_dims)(multi->p[i], dst_type, dst_pos,
1365 src_type, src_pos, n);
1366 if (!multi->p[i])
1367 return FN(MULTI(BASE),free)(multi);
1370 return multi;
1372 #endif
1374 /* Convert a multiple expression defined over a parameter domain
1375 * into one that is defined over a zero-dimensional set.
1377 __isl_give MULTI(BASE) *FN(MULTI(BASE),from_range)(
1378 __isl_take MULTI(BASE) *multi)
1380 isl_space *space;
1382 if (!multi)
1383 return NULL;
1384 if (!isl_space_is_set(multi->space))
1385 isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
1386 "not living in a set space",
1387 return FN(MULTI(BASE),free)(multi));
1389 space = FN(MULTI(BASE),get_space)(multi);
1390 space = isl_space_from_range(space);
1391 multi = FN(MULTI(BASE),reset_space)(multi, space);
1393 return multi;
1396 /* Are "multi1" and "multi2" obviously equal?
1398 int FN(MULTI(BASE),plain_is_equal)(__isl_keep MULTI(BASE) *multi1,
1399 __isl_keep MULTI(BASE) *multi2)
1401 int i;
1402 int equal;
1404 if (!multi1 || !multi2)
1405 return -1;
1406 if (multi1->n != multi2->n)
1407 return 0;
1408 equal = isl_space_is_equal(multi1->space, multi2->space);
1409 if (equal < 0 || !equal)
1410 return equal;
1412 for (i = 0; i < multi1->n; ++i) {
1413 equal = FN(EL,plain_is_equal)(multi1->p[i], multi2->p[i]);
1414 if (equal < 0 || !equal)
1415 return equal;
1418 return 1;
1421 #ifndef NO_DOMAIN
1422 /* Return the shared domain of the elements of "multi".
1424 __isl_give isl_set *FN(MULTI(BASE),domain)(__isl_take MULTI(BASE) *multi)
1426 int i;
1427 isl_set *dom;
1429 if (!multi)
1430 return NULL;
1432 dom = isl_set_universe(FN(MULTI(BASE),get_domain_space)(multi));
1433 for (i = 0; i < multi->n; ++i) {
1434 isl_set *dom_i;
1436 dom_i = FN(EL,domain)(FN(FN(MULTI(BASE),get),BASE)(multi, i));
1437 dom = isl_set_intersect(dom, dom_i);
1440 FN(MULTI(BASE),free)(multi);
1441 return dom;
1443 #endif