-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Constant slices are deduplicated too aggressively #126298
Comments
This comment was marked as outdated.
This comment was marked as outdated.
What build options are you using (e.g. JIT, free-threading)? Wonder if this could be #126222. |
JIT is built but not enabled ( |
No-NumPy reproducer: class GetItemPrinter:
def __getitem__(self, key):
print(key)
a = GetItemPrinter()
a[0.0:]
a[0:, 0.0:2]
a[0.0::2, :0]
a[0.0:1:2,:]
a[:, 0.0:]
a[:0.0] Output:
I believe this is due to GH-125063 (CC @mdboom). In the bytecode compiler, we deduplicate constants. However, it's not enough to deduplicate them by equality; we also need to disambiguate based on type, signed zero, etc. so that It looks like slices are only being compared by equality, which means that |
Thanks for finding this. I'll have a look. |
One observation we had while discussing this is that, in general |
Yeah, that's a good idea. I think we can merge this PR (assuming it's correct), and then investigate the marshal approach. I'm happy to take that on if no one else wants to. |
There's also |
…ython#126398) * pythongh-126298: Don't deduplicated slice constants based on equality * NULL check for PySlice_New * Fix refcounting * Fix refcounting some more * Fix refcounting * Make tests more complete * Fix tests
Bug report
Bug description:
I try to build numpy with Python 3.14.0a1 and encounter very strange test failures regarding array slicing. The offending tests source code can be found here and here.
I compiled both numpy 1.26.4 and 2.1.2 for Fedora Linux and installed it into an environment with Python 3.14. This happens for both versions of numpy. It doesn't happen with Python 3.13 and numpy 1.26.4.
In both tests, it's either TypeError expected and not raised (
test_slicing_no_floats
), or the other way around (test_valid_slicing
). Let's take a look attest_slicing_no_floats
.assert_raises
is numpy's wrapper over unittest, but that's irrelevant for the problem - let's replace it with a minimal viable function and run the offending piece of code:What if I switch the 1st and last line of the test? A completely different row stops raising TypeError:
When I arbitrarily remove the 3rd row from the function, suddenly TypeError is correctly raised:
Other modifications are somewhat unpredictable:
I tried also direct slicing, in all cases TypeError was correctly raised:
And calling lambdas with the same result:
The original test failure from our build system
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: