Fix static shape inference in pt.linalg.kron and add regression test#1898
Merged
jessegrabowski merged 1 commit intopymc-devs:mainfrom Feb 23, 2026
Merged
Conversation
Contributor
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.
jessegrabowski
requested changes
Feb 21, 2026
3ac70a5 to
63948ca
Compare
jessegrabowski
requested changes
Feb 23, 2026
85756b5 to
302e014
Compare
Co-authored-by: Jesse Grabowski <48652735+jessegrabowski@users.noreply.github.com>
302e014 to
6f0e23c
Compare
ricardoV94
reviewed
Feb 23, 2026
| pytest.skip("Sum of shp0 and shp1 must be more than 2") | ||
| x = tensor(dtype="floatX", shape=(None,) * len(shp0)) | ||
|
|
||
| x = tensor(dtype="floatX", shape=shp0) |
Member
There was a problem hiding this comment.
I think this was a bit short-sighted. It's useful to make sure these shape Ops work correctly with non static shapes. In the future it could be accidentally relying on x.type.shape internally and fail with non-static shapes and we may not notice it.
The separate test for static shape would have been fine, and we do that for other Ops.
Contributor
Author
There was a problem hiding this comment.
@ricardoV94 should i open another PR to get both non-static and static shapes tests implemented to avoid future hassles, cuz it is right that for long term it would be better
ayulockedin
added a commit
to ayulockedin/pytensor
that referenced
this pull request
Feb 24, 2026
11 tasks
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