Skip to content

Commit 0c9738f

Browse files
committed
Test no sub-optimality in reshape lowering.
1 parent aca8ac7 commit 0c9738f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎test/test_pytato.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,23 @@ def test_lower_to_index_lambda():
15611561
assert idx_lambda.expr.index_tuple[4] == Variable("_1")
15621562

15631563

1564+
def test_lower_to_index_lambda_flatten_reshape():
1565+
# Before commit<=577cb39, pytato would generate redundant floor div
1566+
# and modulo computations. Specifically, in this case we would get:
1567+
# out[_0] = x[((0 + _0*1) % 40) // 4, ((0 + _0*1) % 4) // 1].
1568+
1569+
from pymbolic import parse
1570+
1571+
from pytato.array import IndexLambda
1572+
x = pt.make_placeholder(name="x", dtype=float, shape=(10, 4))
1573+
idx_lambda = pt.to_index_lambda(x.reshape(-1))
1574+
assert isinstance(idx_lambda, IndexLambda)
1575+
assert idx_lambda.expr.index_tuple == (
1576+
parse("_0 // 4"),
1577+
parse("_0 % 4"),
1578+
)
1579+
1580+
15641581
def test_reserved_binding_name_patterns():
15651582
from pytato.transform.metadata import BINDING_NAME_RESERVED_PATTERN
15661583

0 commit comments

Comments
 (0)