Parametric max value of expression

9 views
Skip to first unread message

Pedro Silvestre

unread,
May 6, 2025, 6:13:10 AMMay 6
to isl Development
Hello,

I need to compute the max/min value of affine expressions.
The current behaviour of isl is:

>>> isl.PwAff("[D0] -> { [d0] -> [d0+1]: 0 <= d0 < D0 and D0 > 0 }").max_val()
Val("infty")
>>> isl.PwAff("[D0=50] -> { [d0] -> [d0+1]: 0 <= d0 < D0 and D0 > 0 }").max_val()
Val("50")

Is there a way to get D0 as the return for the first case? Or do I need to take a completely different approach to this?

Best,
Pedro 

Sven Verdoolaege

unread,
May 6, 2025, 5:09:26 PMMay 6
to Pedro Silvestre, isl Development
On Tue, May 06, 2025 at 03:13:08AM -0700, Pedro Silvestre wrote:
> Hello,
>
> I need to compute the max/min value of affine expressions.
> The current behaviour of isl is:
>
> >>> isl.PwAff("[D0] -> { [d0] -> [d0+1]: 0 <= d0 < D0 and D0 > 0
> }").max_val()
> Val("infty")
> >>> isl.PwAff("[D0=50] -> { [d0] -> [d0+1]: 0 <= d0 < D0 and D0 > 0
> }").max_val()
> Val("50")
>
> Is there a way to get D0 as the return for the first case?

Not using max_val() since that returns a *value*, so the result couldn't
be some expression.

Do you want to compute the maximum value attained by the affine
expression over its domain?
If so, you should compute the set of all values attained by
the expression and then compute the maximum.

Here are two ways to do that:

>>> isl.pw_aff("[D0] -> { [d0] -> [d0+1]: 0 <= d0 < D0 and D0 > 0}").as_map().range().lexmax_pw_multi_aff().at(0)
isl.pw_aff("[D0] -> { [(D0)] : D0 > 0 }")
>>> isl.pw_aff("[D0] -> { [d0] -> [d0+1]: 0 <= d0 < D0 and D0 > 0}").as_map().range().max_multi_pw_aff().at(0)
isl.pw_aff("[D0] -> { [(D0)] : D0 > 0 }")

skimo
Reply all
Reply to author
Forward
0 new messages