|
24 | 24 | """ |
25 | 25 |
|
26 | 26 |
|
27 | | -from typing import ClassVar, Tuple |
| 27 | +from typing import ClassVar, Tuple, Union |
28 | 28 | from functools import reduce, cached_property |
29 | 29 | from sys import intern |
30 | 30 | import re |
|
69 | 69 | from loopy.diagnostic import LoopyError |
70 | 70 | from loopy.diagnostic import (ExpressionToAffineConversionError, |
71 | 71 | UnableToDetermineAccessRangeError) |
| 72 | +from loopy.typing import ExpressionT |
72 | 73 |
|
73 | 74 |
|
74 | 75 | __doc__ = """ |
@@ -2792,4 +2793,29 @@ def is_tuple_of_expressions_equal(a, b): |
2792 | 2793 |
|
2793 | 2794 | # }}} |
2794 | 2795 |
|
| 2796 | + |
| 2797 | +def _is_isl_set_universe(isl_set: Union[isl.BasicSet, isl.Set]): |
| 2798 | + if isinstance(isl_set, isl.BasicSet): |
| 2799 | + return isl_set.is_universe() |
| 2800 | + else: |
| 2801 | + assert isinstance(isl_set, isl.Set) |
| 2802 | + return isl_set.complement().is_empty() |
| 2803 | + |
| 2804 | + |
| 2805 | +def pw_qpolynomial_to_expr(pw_qpoly: isl.PwQPolynomial |
| 2806 | + ) -> ExpressionT: |
| 2807 | + from pymbolic.primitives import If |
| 2808 | + |
| 2809 | + result = 0 |
| 2810 | + |
| 2811 | + for bset, qpoly in reversed(pw_qpoly.get_pieces()): |
| 2812 | + if _is_isl_set_universe(bset): |
| 2813 | + result = qpolynomial_to_expr(qpoly) |
| 2814 | + else: |
| 2815 | + result = If(set_to_cond_expr(bset), |
| 2816 | + qpolynomial_to_expr(qpoly), |
| 2817 | + result) |
| 2818 | + |
| 2819 | + return result |
| 2820 | + |
2795 | 2821 | # vim: foldmethod=marker |
0 commit comments