Fix static shape inference in pt.linalg.kron and add regression test#1898
Open
ayulockedin wants to merge 4 commits intopymc-devs:mainfrom
Open
Fix static shape inference in pt.linalg.kron and add regression test#1898ayulockedin wants to merge 4 commits intopymc-devs:mainfrom
ayulockedin wants to merge 4 commits intopymc-devs:mainfrom
Conversation
Author
|
@jessegrabowski can you have a look at this when u have a moment thx |
jessegrabowski
requested changes
Feb 20, 2026
Member
jessegrabowski
left a comment
There was a problem hiding this comment.
Solution looks good. Just needs some cleanup.
Co-authored-by: Jesse Grabowski <48652735+jessegrabowski@users.noreply.github.com>
Co-authored-by: Jesse Grabowski <48652735+jessegrabowski@users.noreply.github.com>
jessegrabowski
requested changes
Feb 21, 2026
tests/tensor/test_nlinalg.py
Outdated
| np_val = np.kron(a, b) | ||
|
|
||
| # Regression test for issue #1867 | ||
| assert out.shape == np_val.shape |
Member
There was a problem hiding this comment.
out is a numpy array. You need to test the shape of symbolic kron(x, y), not the numerical output of the compiled function.
Author
There was a problem hiding this comment.
Good catch. I was asserting against the compiled numerical output instead of the symbolic graph. I've updated the test to instantiate explicitly static tensors and assert against kron(x_static, y_static).type.shape to ensure the static shape information is properly preserved by the shape inference engine.
3ac70a5 to
63948ca
Compare
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.
Description
This PR resolves the issue where
pt.linalg.krondestroys static shape information, returning(None, None)even when input shapes are fully known.The previous implementation relied on a vector-wise symbolic multiplication of shapes:
out_shape = tuple(a.shape * b.shape)This forced the underlying
ReshapeOp to treat the entire shape vector as a single symbolic entity, which prevented the ShapeFeature from constant-folding individual dimensions into their static values.The Fix
I implemented element-wise symbolic multiplication for the output shape:
[a.shape[i] * b.shape[i] for i in range(a.ndim)]This provides the shape inference engine with enough granularity to resolve static constants (e.g., 4 * 3 = 12) at compile time while maintaining the symbolic integrity required for downstream operations like
clone_replace.Related Issue
Checklist
Type of change