Optimize reshape idx lmbda lowering#656
Merged
kaushikcfd merged 3 commits intomainfrom Apr 14, 2026
Merged
Conversation
d318c3e to
c8e06ab
Compare
c8e06ab to
9ab995b
Compare
Collaborator
Author
|
Soft ping. |
9ab995b to
b32942d
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes reshape-to-IndexLambda lowering to avoid generating redundant arithmetic (e.g., * 1, % total_size, // 1) in the computed index expressions, and adds a regression test to lock in the improved form.
Changes:
- Simplify generated flattened-index arithmetic to avoid multiplying by 1 when forming the linearized index.
- Drop redundant modulo-by-total-size and floor-div-by-1 in reshape index reconstruction where safe.
- Add a regression test ensuring
reshape(-1)lowers to(_0 // 4, _0 % 4)for a(10, 4)input.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pytato/transform/lower_to_index_lambda.py |
Adds simplification logic in _generate_index_expressions to reduce redundant ops in reshape lowering. |
test/test_pytato.py |
Adds a regression test asserting the simplified IndexLambda index tuple for flatten-reshape. |
.basedpyright/baseline.json |
Removes baseline entries corresponding to pyright issues addressed by the updated lowering code. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b32942d to
20852cc
Compare
Owner
|
Thanks! Pushed a counterproposal that (I think) is easier on the eyes even if it's a tad bit more expensive. LMK if that works for you. |
inducer
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On main, reshape lowering generates sub-optimal indexing:
After this patch, the assignment becomes:
Notice the reduction in the redundant product with one and modulo with the size operations.