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