Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail when squeezing specific non-broadcastable axis #705

Closed
ricardoV94 opened this issue Apr 12, 2024 · 2 comments · Fixed by #713
Closed

Don't fail when squeezing specific non-broadcastable axis #705

ricardoV94 opened this issue Apr 12, 2024 · 2 comments · Fixed by #713
Labels
beginner friendly enhancement New feature or request

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Apr 12, 2024

Description

The following snippet fails:

import pytensor.tensor as pt

x = pt.vector("x")
pt.squeeze(x, axis=0)
# ValueError: Cannot drop a non-broadcastable dimension: [False], []

The user provided us information that this dimension will be of length 1, so we could add a specify_broadcastable and only then call squeeze. I think this behavior is more intuitive, and I don't see any drawbacks.

This can only be done when the user provides specific axis, not when axis=None

pt.squeeze(pt.specify_broadcastable(x, 0), axis=0).eval({x: [0]}) 
# array(0.)
pt.squeeze(pt.specify_broadcastable(x, 0), axis=0).eval({x: [0, 1, 2]})
# AssertionError: SpecifyShape: dim 0 of input has shape 3, expected 1.
@ricardoV94 ricardoV94 added enhancement New feature or request beginner friendly labels Apr 12, 2024
@Dhruvanshu-Joshi
Copy link
Member

So here we'll have to first make the axis(given it is not None) broadcastable manually in the pt.squeeze function itself is what is to be done?

@ricardoV94
Copy link
Member Author

Yeah, but only if it's not already broadcastable (in which case it would be useless)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner friendly enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants