-
Notifications
You must be signed in to change notification settings - Fork 123
Trailing singleton dimensions are removed during dtype conversion #491
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
Comments
I looked into this a bit and it seems like the problem is occurring here: Lines 152 to 161 in 8bfbb27
which attempts to extract an array-like with dynamic dimensionality as a So it makes sense why an input of this form is converted to an array of shape This doesn't happen for arrays with exactly matching dtypes, since an earlier check for an exact downcast succeeds, which avoids this behavior: Lines 146 to 148 in 8bfbb27
It seems to me like the solution here is to not attempt to extract from a |
Sorry for the slow reply. Your suggestion seems reasonable to me; if you're willing to provide a PR and tests pass seems right 👍 |
No worries! PR created. This is my first contribution here so let me know if I missed anything. |
Uh oh!
There was an error while loading. Please reload this page.
Bug Description
When using
PyArrayLikeDyn
withAllowTypeChange
, trailing singleton axes may be removed from inputs that arendarray
s but have the wrong dtype.Steps to Reproduce
Cargo.toml
main.rs
example.py
This results in the following error (plus a deprecation warning from numpy, seemingly for implicitly removing the singleton axis):
If no type change occurs, the axis is preserved, e.g.
succeeds. Non-array inputs also behave properly, e.g.
also succeeds.
Oddly enough, if I add a third axis, the trailing singleton dimension is no longer removed:
Relevant Info
Python Version
3.13.3
NumPy Version
2.2.5
PyO3 Version
0.24.2
rust-numpy Version
0.24.0
rustc Version
1.86.0
OS
(via WSL)
The text was updated successfully, but these errors were encountered: