3135
3578
#define BASE aff
3579
#define NO_INTERSECT_DOMAIN
3137
3582
#include <isl_multi_templ.c>
3585
#undef NO_INTERSECT_DOMAIN
3587
/* Remove any internal structure of the domain of "ma".
3588
* If there is any such internal structure in the input,
3589
* then the name of the corresponding space is also removed.
3591
__isl_give isl_multi_aff *isl_multi_aff_flatten_domain(
3592
__isl_take isl_multi_aff *ma)
3599
if (!ma->space->nested[0])
3602
space = isl_multi_aff_get_space(ma);
3603
space = isl_space_flatten_domain(space);
3604
ma = isl_multi_aff_reset_space(ma, space);
3609
/* Given a map space, return an isl_multi_aff that maps a wrapped copy
3610
* of the space to its domain.
3612
__isl_give isl_multi_aff *isl_multi_aff_domain_map(__isl_take isl_space *space)
3615
isl_local_space *ls;
3620
if (!isl_space_is_map(space))
3621
isl_die(isl_space_get_ctx(space), isl_error_invalid,
3622
"not a map space", goto error);
3624
n_in = isl_space_dim(space, isl_dim_in);
3625
space = isl_space_domain_map(space);
3627
ma = isl_multi_aff_alloc(isl_space_copy(space));
3629
isl_space_free(space);
3633
space = isl_space_domain(space);
3634
ls = isl_local_space_from_space(space);
3635
for (i = 0; i < n_in; ++i) {
3638
aff = isl_aff_var_on_domain(isl_local_space_copy(ls),
3640
ma = isl_multi_aff_set_aff(ma, i, aff);
3642
isl_local_space_free(ls);
3645
isl_space_free(space);
3649
/* Given a map space, return an isl_multi_aff that maps a wrapped copy
3650
* of the space to its range.
3652
__isl_give isl_multi_aff *isl_multi_aff_range_map(__isl_take isl_space *space)
3655
isl_local_space *ls;
3660
if (!isl_space_is_map(space))
3661
isl_die(isl_space_get_ctx(space), isl_error_invalid,
3662
"not a map space", goto error);
3664
n_in = isl_space_dim(space, isl_dim_in);
3665
n_out = isl_space_dim(space, isl_dim_out);
3666
space = isl_space_range_map(space);
3668
ma = isl_multi_aff_alloc(isl_space_copy(space));
3670
isl_space_free(space);
3674
space = isl_space_domain(space);
3675
ls = isl_local_space_from_space(space);
3676
for (i = 0; i < n_out; ++i) {
3679
aff = isl_aff_var_on_domain(isl_local_space_copy(ls),
3680
isl_dim_set, n_in + i);
3681
ma = isl_multi_aff_set_aff(ma, i, aff);
3683
isl_local_space_free(ls);
3686
isl_space_free(space);
3690
/* Given the space of a set and a range of set dimensions,
3691
* construct an isl_multi_aff that projects out those dimensions.
3693
__isl_give isl_multi_aff *isl_multi_aff_project_out_map(
3694
__isl_take isl_space *space, enum isl_dim_type type,
3695
unsigned first, unsigned n)
3698
isl_local_space *ls;
3703
if (!isl_space_is_set(space))
3704
isl_die(isl_space_get_ctx(space), isl_error_unsupported,
3705
"expecting set space", goto error);
3706
if (type != isl_dim_set)
3707
isl_die(isl_space_get_ctx(space), isl_error_invalid,
3708
"only set dimensions can be projected out", goto error);
3710
dim = isl_space_dim(space, isl_dim_set);
3711
if (first + n > dim)
3712
isl_die(isl_space_get_ctx(space), isl_error_invalid,
3713
"range out of bounds", goto error);
3715
space = isl_space_from_domain(space);
3716
space = isl_space_add_dims(space, isl_dim_out, dim - n);
3719
return isl_multi_aff_alloc(space);
3721
ma = isl_multi_aff_alloc(isl_space_copy(space));
3722
space = isl_space_domain(space);
3723
ls = isl_local_space_from_space(space);
3725
for (i = 0; i < first; ++i) {
3728
aff = isl_aff_var_on_domain(isl_local_space_copy(ls),
3730
ma = isl_multi_aff_set_aff(ma, i, aff);
3733
for (i = 0; i < dim - (first + n); ++i) {
3736
aff = isl_aff_var_on_domain(isl_local_space_copy(ls),
3737
isl_dim_set, first + n + i);
3738
ma = isl_multi_aff_set_aff(ma, first + i, aff);
3741
isl_local_space_free(ls);
3744
isl_space_free(space);
3748
/* Given the space of a set and a range of set dimensions,
3749
* construct an isl_pw_multi_aff that projects out those dimensions.
3751
__isl_give isl_pw_multi_aff *isl_pw_multi_aff_project_out_map(
3752
__isl_take isl_space *space, enum isl_dim_type type,
3753
unsigned first, unsigned n)
3757
ma = isl_multi_aff_project_out_map(space, type, first, n);
3758
return isl_pw_multi_aff_from_multi_aff(ma);
3139
3761
/* Create an isl_pw_multi_aff with the given isl_multi_aff on a universe
5293
5955
isl_union_pw_multi_aff_free(upma);
5959
/* Construct and return a piecewise multi affine expression
5960
* in the given space with value zero in each of the output dimensions and
5961
* a universe domain.
5963
__isl_give isl_pw_multi_aff *isl_pw_multi_aff_zero(__isl_take isl_space *space)
5965
return isl_pw_multi_aff_from_multi_aff(isl_multi_aff_zero(space));
5968
/* Construct and return a piecewise multi affine expression
5969
* that is equal to the given piecewise affine expression.
5971
__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_pw_aff(
5972
__isl_take isl_pw_aff *pa)
5976
isl_pw_multi_aff *pma;
5981
space = isl_pw_aff_get_space(pa);
5982
pma = isl_pw_multi_aff_alloc_size(space, pa->n);
5984
for (i = 0; i < pa->n; ++i) {
5988
set = isl_set_copy(pa->p[i].set);
5989
ma = isl_multi_aff_from_aff(isl_aff_copy(pa->p[i].aff));
5990
pma = isl_pw_multi_aff_add_piece(pma, set, ma);
5993
isl_pw_aff_free(pa);
5997
/* Construct a set or map mapping the shared (parameter) domain
5998
* of the piecewise affine expressions to the range of "mpa"
5999
* with each dimension in the range equated to the
6000
* corresponding piecewise affine expression.
6002
static __isl_give isl_map *map_from_multi_pw_aff(
6003
__isl_take isl_multi_pw_aff *mpa)
6012
if (isl_space_dim(mpa->space, isl_dim_out) != mpa->n)
6013
isl_die(isl_multi_pw_aff_get_ctx(mpa), isl_error_internal,
6014
"invalid space", goto error);
6016
space = isl_multi_pw_aff_get_domain_space(mpa);
6017
map = isl_map_universe(isl_space_from_domain(space));
6019
for (i = 0; i < mpa->n; ++i) {
6023
pa = isl_pw_aff_copy(mpa->p[i]);
6024
map_i = map_from_pw_aff(pa);
6026
map = isl_map_flat_range_product(map, map_i);
6029
map = isl_map_reset_space(map, isl_multi_pw_aff_get_space(mpa));
6031
isl_multi_pw_aff_free(mpa);
6034
isl_multi_pw_aff_free(mpa);
6038
/* Construct a map mapping the shared domain
6039
* of the piecewise affine expressions to the range of "mpa"
6040
* with each dimension in the range equated to the
6041
* corresponding piecewise affine expression.
6043
__isl_give isl_map *isl_map_from_multi_pw_aff(__isl_take isl_multi_pw_aff *mpa)
6047
if (isl_space_is_set(mpa->space))
6048
isl_die(isl_multi_pw_aff_get_ctx(mpa), isl_error_internal,
6049
"space of input is not a map", goto error);
6051
return map_from_multi_pw_aff(mpa);
6053
isl_multi_pw_aff_free(mpa);
6057
/* Construct a set mapping the shared parameter domain
6058
* of the piecewise affine expressions to the space of "mpa"
6059
* with each dimension in the range equated to the
6060
* corresponding piecewise affine expression.
6062
__isl_give isl_set *isl_set_from_multi_pw_aff(__isl_take isl_multi_pw_aff *mpa)
6066
if (!isl_space_is_set(mpa->space))
6067
isl_die(isl_multi_pw_aff_get_ctx(mpa), isl_error_internal,
6068
"space of input is not a set", goto error);
6070
return map_from_multi_pw_aff(mpa);
6072
isl_multi_pw_aff_free(mpa);
6076
/* Construct and return a piecewise multi affine expression
6077
* that is equal to the given multi piecewise affine expression
6078
* on the shared domain of the piecewise affine expressions.
6080
__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_multi_pw_aff(
6081
__isl_take isl_multi_pw_aff *mpa)
6086
isl_pw_multi_aff *pma;
6091
space = isl_multi_pw_aff_get_space(mpa);
6094
isl_multi_pw_aff_free(mpa);
6095
return isl_pw_multi_aff_zero(space);
6098
pa = isl_multi_pw_aff_get_pw_aff(mpa, 0);
6099
pma = isl_pw_multi_aff_from_pw_aff(pa);
6101
for (i = 1; i < mpa->n; ++i) {
6102
isl_pw_multi_aff *pma_i;
6104
pa = isl_multi_pw_aff_get_pw_aff(mpa, i);
6105
pma_i = isl_pw_multi_aff_from_pw_aff(pa);
6106
pma = isl_pw_multi_aff_range_product(pma, pma_i);
6109
pma = isl_pw_multi_aff_reset_space(pma, space);
6111
isl_multi_pw_aff_free(mpa);
6115
/* Construct and return a multi piecewise affine expression
6116
* that is equal to the given multi affine expression.
6118
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_multi_aff(
6119
__isl_take isl_multi_aff *ma)
6122
isl_multi_pw_aff *mpa;
6127
n = isl_multi_aff_dim(ma, isl_dim_out);
6128
mpa = isl_multi_pw_aff_alloc(isl_multi_aff_get_space(ma));
6130
for (i = 0; i < n; ++i) {
6133
pa = isl_pw_aff_from_aff(isl_multi_aff_get_aff(ma, i));
6134
mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, pa);
6137
isl_multi_aff_free(ma);
6141
/* Construct and return a multi piecewise affine expression
6142
* that is equal to the given piecewise multi affine expression.
6144
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_pw_multi_aff(
6145
__isl_take isl_pw_multi_aff *pma)
6149
isl_multi_pw_aff *mpa;
6154
n = isl_pw_multi_aff_dim(pma, isl_dim_out);
6155
space = isl_pw_multi_aff_get_space(pma);
6156
mpa = isl_multi_pw_aff_alloc(space);
6158
for (i = 0; i < n; ++i) {
6161
pa = isl_pw_multi_aff_get_pw_aff(pma, i);
6162
mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, pa);
6165
isl_pw_multi_aff_free(pma);
6169
/* Do "pa1" and "pa2" represent the same function?
6171
* We first check if they are obviously equal.
6172
* If not, we convert them to maps and check if those are equal.
6174
int isl_pw_aff_is_equal(__isl_keep isl_pw_aff *pa1, __isl_keep isl_pw_aff *pa2)
6177
isl_map *map1, *map2;
6182
equal = isl_pw_aff_plain_is_equal(pa1, pa2);
6183
if (equal < 0 || equal)
6186
map1 = map_from_pw_aff(isl_pw_aff_copy(pa1));
6187
map2 = map_from_pw_aff(isl_pw_aff_copy(pa2));
6188
equal = isl_map_is_equal(map1, map2);
6195
/* Do "mpa1" and "mpa2" represent the same function?
6197
* Note that we cannot convert the entire isl_multi_pw_aff
6198
* to a map because the domains of the piecewise affine expressions
6199
* may not be the same.
6201
int isl_multi_pw_aff_is_equal(__isl_keep isl_multi_pw_aff *mpa1,
6202
__isl_keep isl_multi_pw_aff *mpa2)
6210
if (!isl_space_match(mpa1->space, isl_dim_param,
6211
mpa2->space, isl_dim_param)) {
6212
if (!isl_space_has_named_params(mpa1->space))
6214
if (!isl_space_has_named_params(mpa2->space))
6216
mpa1 = isl_multi_pw_aff_copy(mpa1);
6217
mpa2 = isl_multi_pw_aff_copy(mpa2);
6218
mpa1 = isl_multi_pw_aff_align_params(mpa1,
6219
isl_multi_pw_aff_get_space(mpa2));
6220
mpa2 = isl_multi_pw_aff_align_params(mpa2,
6221
isl_multi_pw_aff_get_space(mpa1));
6222
equal = isl_multi_pw_aff_is_equal(mpa1, mpa2);
6223
isl_multi_pw_aff_free(mpa1);
6224
isl_multi_pw_aff_free(mpa2);
6228
equal = isl_space_is_equal(mpa1->space, mpa2->space);
6229
if (equal < 0 || !equal)
6232
for (i = 0; i < mpa1->n; ++i) {
6233
equal = isl_pw_aff_is_equal(mpa1->p[i], mpa2->p[i]);
6234
if (equal < 0 || !equal)
6241
/* Coalesce the elements of "mpa".
6243
* Note that such coalescing does not change the meaning of "mpa"
6244
* so there is no need to cow. We do need to be careful not to
6245
* destroy any other copies of "mpa" in case of failure.
6247
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_coalesce(
6248
__isl_take isl_multi_pw_aff *mpa)
6255
for (i = 0; i < mpa->n; ++i) {
6256
isl_pw_aff *pa = isl_pw_aff_copy(mpa->p[i]);
6257
pa = isl_pw_aff_coalesce(pa);
6259
return isl_multi_pw_aff_free(mpa);
6260
isl_pw_aff_free(mpa->p[i]);
6267
/* Compute the pullback of "mpa" by the function represented by "ma".
6268
* In other words, plug in "ma" in "mpa".
6270
* The parameters of "mpa" and "ma" are assumed to have been aligned.
6272
static __isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff_aligned(
6273
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
6276
isl_space *space = NULL;
6278
mpa = isl_multi_pw_aff_cow(mpa);
6282
space = isl_space_join(isl_multi_aff_get_space(ma),
6283
isl_multi_pw_aff_get_space(mpa));
6287
for (i = 0; i < mpa->n; ++i) {
6288
mpa->p[i] = isl_pw_aff_pullback_multi_aff(mpa->p[i],
6289
isl_multi_aff_copy(ma));
6294
isl_multi_aff_free(ma);
6295
isl_space_free(mpa->space);
6299
isl_space_free(space);
6300
isl_multi_pw_aff_free(mpa);
6301
isl_multi_aff_free(ma);
6305
/* Compute the pullback of "mpa" by the function represented by "ma".
6306
* In other words, plug in "ma" in "mpa".
6308
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff(
6309
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma)
6313
if (isl_space_match(mpa->space, isl_dim_param,
6314
ma->space, isl_dim_param))
6315
return isl_multi_pw_aff_pullback_multi_aff_aligned(mpa, ma);
6316
mpa = isl_multi_pw_aff_align_params(mpa, isl_multi_aff_get_space(ma));
6317
ma = isl_multi_aff_align_params(ma, isl_multi_pw_aff_get_space(mpa));
6318
return isl_multi_pw_aff_pullback_multi_aff_aligned(mpa, ma);
6320
isl_multi_pw_aff_free(mpa);
6321
isl_multi_aff_free(ma);
6325
/* Compute the pullback of "mpa" by the function represented by "pma".
6326
* In other words, plug in "pma" in "mpa".
6328
* The parameters of "mpa" and "mpa" are assumed to have been aligned.
6330
static __isl_give isl_multi_pw_aff *
6331
isl_multi_pw_aff_pullback_pw_multi_aff_aligned(
6332
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_multi_aff *pma)
6335
isl_space *space = NULL;
6337
mpa = isl_multi_pw_aff_cow(mpa);
6341
space = isl_space_join(isl_pw_multi_aff_get_space(pma),
6342
isl_multi_pw_aff_get_space(mpa));
6344
for (i = 0; i < mpa->n; ++i) {
6345
mpa->p[i] = isl_pw_aff_pullback_pw_multi_aff_aligned(mpa->p[i],
6346
isl_pw_multi_aff_copy(pma));
6351
isl_pw_multi_aff_free(pma);
6352
isl_space_free(mpa->space);
6356
isl_space_free(space);
6357
isl_multi_pw_aff_free(mpa);
6358
isl_pw_multi_aff_free(pma);
6362
/* Compute the pullback of "mpa" by the function represented by "pma".
6363
* In other words, plug in "pma" in "mpa".
6365
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_pw_multi_aff(
6366
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_multi_aff *pma)
6370
if (isl_space_match(mpa->space, isl_dim_param, pma->dim, isl_dim_param))
6371
return isl_multi_pw_aff_pullback_pw_multi_aff_aligned(mpa, pma);
6372
mpa = isl_multi_pw_aff_align_params(mpa,
6373
isl_pw_multi_aff_get_space(pma));
6374
pma = isl_pw_multi_aff_align_params(pma,
6375
isl_multi_pw_aff_get_space(mpa));
6376
return isl_multi_pw_aff_pullback_pw_multi_aff_aligned(mpa, pma);
6378
isl_multi_pw_aff_free(mpa);
6379
isl_pw_multi_aff_free(pma);
6383
/* Apply "aff" to "mpa". The range of "mpa" needs to be compatible
6384
* with the domain of "aff". The domain of the result is the same
6386
* "mpa" and "aff" are assumed to have been aligned.
6388
* We first extract the parametric constant from "aff", defined
6389
* over the correct domain.
6390
* Then we add the appropriate combinations of the members of "mpa".
6391
* Finally, we add the integer divisions through recursive calls.
6393
static __isl_give isl_pw_aff *isl_multi_pw_aff_apply_aff_aligned(
6394
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_aff *aff)
6396
int i, n_param, n_in, n_div;
6402
n_param = isl_aff_dim(aff, isl_dim_param);
6403
n_in = isl_aff_dim(aff, isl_dim_in);
6404
n_div = isl_aff_dim(aff, isl_dim_div);
6406
space = isl_space_domain(isl_multi_pw_aff_get_space(mpa));
6407
tmp = isl_aff_copy(aff);
6408
tmp = isl_aff_drop_dims(tmp, isl_dim_div, 0, n_div);
6409
tmp = isl_aff_drop_dims(tmp, isl_dim_in, 0, n_in);
6410
tmp = isl_aff_add_dims(tmp, isl_dim_in,
6411
isl_space_dim(space, isl_dim_set));
6412
tmp = isl_aff_reset_domain_space(tmp, space);
6413
pa = isl_pw_aff_from_aff(tmp);
6415
for (i = 0; i < n_in; ++i) {
6418
if (!isl_aff_involves_dims(aff, isl_dim_in, i, 1))
6420
v = isl_aff_get_coefficient_val(aff, isl_dim_in, i);
6421
pa_i = isl_multi_pw_aff_get_pw_aff(mpa, i);
6422
pa_i = isl_pw_aff_scale_val(pa_i, v);
6423
pa = isl_pw_aff_add(pa, pa_i);
6426
for (i = 0; i < n_div; ++i) {
6430
if (!isl_aff_involves_dims(aff, isl_dim_div, i, 1))
6432
div = isl_aff_get_div(aff, i);
6433
pa_i = isl_multi_pw_aff_apply_aff_aligned(
6434
isl_multi_pw_aff_copy(mpa), div);
6435
pa_i = isl_pw_aff_floor(pa_i);
6436
v = isl_aff_get_coefficient_val(aff, isl_dim_div, i);
6437
pa_i = isl_pw_aff_scale_val(pa_i, v);
6438
pa = isl_pw_aff_add(pa, pa_i);
6441
isl_multi_pw_aff_free(mpa);
6447
/* Apply "aff" to "mpa". The range of "mpa" needs to be compatible
6448
* with the domain of "aff". The domain of the result is the same
6451
__isl_give isl_pw_aff *isl_multi_pw_aff_apply_aff(
6452
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_aff *aff)
6456
if (isl_space_match(aff->ls->dim, isl_dim_param,
6457
mpa->space, isl_dim_param))
6458
return isl_multi_pw_aff_apply_aff_aligned(mpa, aff);
6460
aff = isl_aff_align_params(aff, isl_multi_pw_aff_get_space(mpa));
6461
mpa = isl_multi_pw_aff_align_params(mpa, isl_aff_get_space(aff));
6463
return isl_multi_pw_aff_apply_aff_aligned(mpa, aff);
6466
isl_multi_pw_aff_free(mpa);
6470
/* Apply "pa" to "mpa". The range of "mpa" needs to be compatible
6471
* with the domain of "pa". The domain of the result is the same
6473
* "mpa" and "pa" are assumed to have been aligned.
6475
* We consider each piece in turn. Note that the domains of the
6476
* pieces are assumed to be disjoint and they remain disjoint
6477
* after taking the preimage (over the same function).
6479
static __isl_give isl_pw_aff *isl_multi_pw_aff_apply_pw_aff_aligned(
6480
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_aff *pa)
6489
space = isl_space_join(isl_multi_pw_aff_get_space(mpa),
6490
isl_pw_aff_get_space(pa));
6491
res = isl_pw_aff_empty(space);
6493
for (i = 0; i < pa->n; ++i) {
6497
pa_i = isl_multi_pw_aff_apply_aff_aligned(
6498
isl_multi_pw_aff_copy(mpa),
6499
isl_aff_copy(pa->p[i].aff));
6500
domain = isl_set_copy(pa->p[i].set);
6501
domain = isl_set_preimage_multi_pw_aff(domain,
6502
isl_multi_pw_aff_copy(mpa));
6503
pa_i = isl_pw_aff_intersect_domain(pa_i, domain);
6504
res = isl_pw_aff_add_disjoint(res, pa_i);
6507
isl_pw_aff_free(pa);
6508
isl_multi_pw_aff_free(mpa);
6511
isl_pw_aff_free(pa);
6512
isl_multi_pw_aff_free(mpa);
6516
/* Apply "pa" to "mpa". The range of "mpa" needs to be compatible
6517
* with the domain of "pa". The domain of the result is the same
6520
__isl_give isl_pw_aff *isl_multi_pw_aff_apply_pw_aff(
6521
__isl_take isl_multi_pw_aff *mpa, __isl_take isl_pw_aff *pa)
6525
if (isl_space_match(pa->dim, isl_dim_param, mpa->space, isl_dim_param))
6526
return isl_multi_pw_aff_apply_pw_aff_aligned(mpa, pa);
6528
pa = isl_pw_aff_align_params(pa, isl_multi_pw_aff_get_space(mpa));
6529
mpa = isl_multi_pw_aff_align_params(mpa, isl_pw_aff_get_space(pa));
6531
return isl_multi_pw_aff_apply_pw_aff_aligned(mpa, pa);
6533
isl_pw_aff_free(pa);
6534
isl_multi_pw_aff_free(mpa);
6538
/* Compute the pullback of "pa" by the function represented by "mpa".
6539
* In other words, plug in "mpa" in "pa".
6540
* "pa" and "mpa" are assumed to have been aligned.
6542
* The pullback is computed by applying "pa" to "mpa".
6544
static __isl_give isl_pw_aff *isl_pw_aff_pullback_multi_pw_aff_aligned(
6545
__isl_take isl_pw_aff *pa, __isl_take isl_multi_pw_aff *mpa)
6547
return isl_multi_pw_aff_apply_pw_aff_aligned(mpa, pa);
6550
/* Compute the pullback of "pa" by the function represented by "mpa".
6551
* In other words, plug in "mpa" in "pa".
6553
* The pullback is computed by applying "pa" to "mpa".
6555
__isl_give isl_pw_aff *isl_pw_aff_pullback_multi_pw_aff(
6556
__isl_take isl_pw_aff *pa, __isl_take isl_multi_pw_aff *mpa)
6558
return isl_multi_pw_aff_apply_pw_aff(mpa, pa);
6561
/* Compute the pullback of "mpa1" by the function represented by "mpa2".
6562
* In other words, plug in "mpa2" in "mpa1".
6564
* The parameters of "mpa1" and "mpa2" are assumed to have been aligned.
6566
* We pullback each member of "mpa1" in turn.
6568
static __isl_give isl_multi_pw_aff *
6569
isl_multi_pw_aff_pullback_multi_pw_aff_aligned(
6570
__isl_take isl_multi_pw_aff *mpa1, __isl_take isl_multi_pw_aff *mpa2)
6573
isl_space *space = NULL;
6575
mpa1 = isl_multi_pw_aff_cow(mpa1);
6579
space = isl_space_join(isl_multi_pw_aff_get_space(mpa2),
6580
isl_multi_pw_aff_get_space(mpa1));
6582
for (i = 0; i < mpa1->n; ++i) {
6583
mpa1->p[i] = isl_pw_aff_pullback_multi_pw_aff_aligned(
6584
mpa1->p[i], isl_multi_pw_aff_copy(mpa2));
6589
mpa1 = isl_multi_pw_aff_reset_space(mpa1, space);
6591
isl_multi_pw_aff_free(mpa2);
6594
isl_space_free(space);
6595
isl_multi_pw_aff_free(mpa1);
6596
isl_multi_pw_aff_free(mpa2);
6600
/* Compute the pullback of "mpa1" by the function represented by "mpa2".
6601
* In other words, plug in "mpa2" in "mpa1".
6603
__isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_pw_aff(
6604
__isl_take isl_multi_pw_aff *mpa1, __isl_take isl_multi_pw_aff *mpa2)
6606
return isl_multi_pw_aff_align_params_multi_multi_and(mpa1, mpa2,
6607
&isl_multi_pw_aff_pullback_multi_pw_aff_aligned);
6610
/* Compare two isl_affs.
6612
* Return -1 if "aff1" is "smaller" than "aff2", 1 if "aff1" is "greater"
6613
* than "aff2" and 0 if they are equal.
6615
* The order is fairly arbitrary. We do consider expressions that only involve
6616
* earlier dimensions as "smaller".
6618
int isl_aff_plain_cmp(__isl_keep isl_aff *aff1, __isl_keep isl_aff *aff2)
6631
cmp = isl_local_space_cmp(aff1->ls, aff2->ls);
6635
last1 = isl_seq_last_non_zero(aff1->v->el + 1, aff1->v->size - 1);
6636
last2 = isl_seq_last_non_zero(aff2->v->el + 1, aff1->v->size - 1);
6638
return last1 - last2;
6640
return isl_seq_cmp(aff1->v->el, aff2->v->el, aff1->v->size);
6643
/* Compare two isl_pw_affs.
6645
* Return -1 if "pa1" is "smaller" than "pa2", 1 if "pa1" is "greater"
6646
* than "pa2" and 0 if they are equal.
6648
* The order is fairly arbitrary. We do consider expressions that only involve
6649
* earlier dimensions as "smaller".
6651
int isl_pw_aff_plain_cmp(__isl_keep isl_pw_aff *pa1,
6652
__isl_keep isl_pw_aff *pa2)
6665
cmp = isl_space_cmp(pa1->dim, pa2->dim);
6669
if (pa1->n != pa2->n)
6670
return pa1->n - pa2->n;
6672
for (i = 0; i < pa1->n; ++i) {
6673
cmp = isl_set_plain_cmp(pa1->p[i].set, pa2->p[i].set);
6676
cmp = isl_aff_plain_cmp(pa1->p[i].aff, pa2->p[i].aff);