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
Move NumPy extra's strategies which are not dependent on NumPy into a seperate helper module #3067
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I'd like to share as much code as possible, which would include e.g. using an allow_newaxis
argument for the generic array_api
and documenting that newaxis is None
- it might be a little less natural, but making the new module a drop-in replacement as much as possible seems useful.
Just let me know when this is ready for another review 😄
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
232d22f
to
d3ce1cb
Compare
Just noting there's a force push because I accidentality started this PR branch a few commits behind master's HEAD 😅 |
Boundary checks were temporarily removed
Still need to work on this, namely commenting if @rsokl would like to take a look heh. I've moved all the independent strategies to Update: I'm trying out this factory thing for all the strategies, which is a bit jarring but meets the needs of both the NumPy and Array API extras. Not sure if it's a necessary evil or if there's a better solution—I'm sure I can make it more palatable at least, and possibly a revised |
It looks like the only difference here is that Numpy is limited to 32 dims, while the array API standard does not impose a limit. Is there any real downside to just enforcing the 32-dim limit for everyone? I suspect that it still applies to Mostly this is because the factory code looks complicated enough to cause headaches for both users and maintainers as soon as something unexpected happens, so I'd rather avoid it. |
Agreed, and in this current form the factory code prevents static type checkers and other tooling from seeing the signatures of the functions that are produced. I was going to recommend a more-complicated decorator that changes global state (the array-lib's) name within the context of the function's execution. This would enable transparency to tooling but would be even more complicated. Given that this is all in service of merely changing max-dim, I have to wonder if it is simply okay to go with Zac's recommendation of enforcing I think |
Ok, so I think these are the issues that make any refactor potentially problematic:
Assuming I'm on the right course, I need to work out the failing ghostwriter test case and sort out some more coverage issues (I didn't understand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all of your work on this! This should be pretty easy to wrap up. The remaining changes to be made are relatively simple; see below.
Regarding the ghostwriter test, hypothesis\hypothesis-python\tests\ghostwriter\recorded\magic_gufunc.txt
needs to be updated to reflect the fact that ghostwriter will ultimately import mutually_broadcastable_shapes
from _array_helpers
.
I am a little confused by the loss of coverage at 301 in _array_helpers
. @Zac-HD any idea how this might be happening?
ef1f29c
to
eb34163
Compare
Just incase folk missed the change—I removed |
Prior factory pattern obfuscates method signature
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Ryan Soklaski <ry26099@mit.edu>
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
4ec21a9
to
c24d940
Compare
c24d940
to
1151c09
Compare
This reverts commit 5ca1aff.
I can't figure out the existing coverage problem (mind I'm rather ignorant about the |
@Zac-HD I think we should at least include |
Fair - it is mentioned in the docs, too. Let's also add that to |
Ah I've possibly misread—I had just put all returned custom types (i.e. also |
0a71b76
to
3c082e2
Compare
@honno, regarding the coverage issue: Under this current branch this test case now raises a different error: >>> sig = "(" + ",".join(f"d{n}" for n in range(33)) + ")->()"
>>> mutually_broadcastable_shapes(signature=sig).example()
InvalidArgument: '(d0,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13,d14,d15,d16,d17,d18,d19,d20,d21,d22,d23,d24,d25,d26,d27,d28,d29,d30,d31,d32)->()'
is not a valid gufunc signature on master it raised the expected: It looks like the regex signature you pasted in has escaped backslashes. This is the correct signature (it restores coverage):
(I was surprised to find that Jupyter will automatically insert these additional slashes in its repr vs printing!) |
Co-authored-by: Ryan Soklaski <ry26099@mit.edu>
I see now, hopefully fixed.
Yeah I had evaluated |
Co-authored-by: Ryan Soklaski <ryan.soklaski@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With one tiny nitpick about an error message, I think this is ready to merge! Thanks again @honno for your contribution - and patience with us through the process 🥰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Awesome! Thank you Ryan & Zac for all your help :) |
As @Zac-HD suggested for #3065, this PR currently moves
BasicIndexStrategy
andMutuallyBroadcastableShapesStrategy
from the NumPy extra intohypothesis.extra.__array_helpers.py
. This change is useless on its own but should avoid duplicated code in the future. The public API remains unchanged.In anticipation for Array API support, I have removed NumPy-specific naming conventions and boundary checks in the private helper strategies, which is covered by the NumPy extra's methods anywho. I also replace
np.newaxis
withNone
in the (private) index strategy.See the honno/array-helpers-array-api branch for a working example of the Array API extra interfacing with
__array_helpers.py
too.TODO: I need to properly evaluate
array_shapes()
andvalid_tuple_axis()
, as well as the public broadcastable andbasic_indices()
strategies. I'm concerned about the NumPy-specific checks that are involved, as well as what helper methods will need to go into__array_helpers.py
, and how it could all effect #3065.