You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: overridable functions from NEP 35 do not show up in ARRAY_FUNCTIONS #27451
List all numpy functions overridable via __array_function__
Since there's an API to check NEP 18 support, there should probably be one for NEP 35 too. I'm not sure wether the best route would be to extend the existing API to cover NEP 35 functions too, or if another set of functions should be added to np.testing.overrides.
We started discussing supporting a subset of these functions in astropy.units (astropy/astropy#17001), but I haven't found an easy systematic way to discover the whole set (in particular because we're already testing for implementation completeness of NEP 18 functions).
Thanks for the note. This should not be very hard, I think. The like= argument for (most, I think not all) is handled in C.
They are thus slightly different (not wrapped, e.g. also don't have _implementation).
The solution may just be to add them manually (maybe with a decorator), and I suppose also add a test for that. Where the test may be the more interesting part even.
This may not be quite trivial, but should be possible to fiugre out with some pointers, I suspect.
Good news, it seems that many such functions are already decorated with @set_array_function_like_doc (ref gh-16935).
Here are all 9 functions with this decorator
require
ones
full
fromfunction
identity
loadtxt
genfromtxt
eye
tri
And here are every other NEP 35 function I could find (reading through gh-16935), which I'm guessing are all C-implemented
array
asarray
asanyarray
ascontiguousarray
asfortranarray
empty
zeros
fromstring
fromiter
fromfile
frombuffer
arange
conveniently, this second subset still has their docstrings defined in Python and can be discovered by grepping for
(which is essentially an inlining of @set_array_function_like_doc)
I think it's possible to resolve the problem with just some plumbing in that decorator... at least for the Python-implemented part. For the C-implemented part, I'm not sure what to do. Manually writing down the list of 12 functions somewhere is clearly the easy way out, but it's also not easily discoverable or maintainable. Adding a dedicated flag to numpy.lib.add_newdoc would provide a systematic way to do it but I generally don't like stacking argument to existing functions, even semi-private ones. How about tweaking add_newdoc so it automatically performs the str.replaceand registers the function upon dedecting the substring "${ARRAY_FUNCTION_LIKE}" ?
Activity
seberg commentedon Sep 30, 2024
Thanks for the note. This should not be very hard, I think. The
like=argument for (most, I think not all) is handled in C.They are thus slightly different (not wrapped, e.g. also don't have
_implementation).The solution may just be to add them manually (maybe with a decorator), and I suppose also add a test for that. Where the test may be the more interesting part even.
This may not be quite trivial, but should be possible to fiugre out with some pointers, I suspect.
neutrinoceros commentedon Sep 30, 2024
I can give it a try later this week.
neutrinoceros commentedon Oct 2, 2024
Good news, it seems that many such functions are already decorated with
@set_array_function_like_doc(ref gh-16935).Here are all 9 functions with this decorator
requireonesfullfromfunctionidentityloadtxtgenfromtxteyetriAnd here are every other NEP 35 function I could find (reading through gh-16935), which I'm guessing are all C-implemented
arrayasarrayasanyarrayascontiguousarrayasfortranarrayemptyzerosfromstringfromiterfromfilefrombufferarangeconveniently, this second subset still has their docstrings defined in Python and can be discovered by grepping for
(which is essentially an inlining of
@set_array_function_like_doc)I think it's possible to resolve the problem with just some plumbing in that decorator... at least for the Python-implemented part. For the C-implemented part, I'm not sure what to do. Manually writing down the list of 12 functions somewhere is clearly the easy way out, but it's also not easily discoverable or maintainable. Adding a dedicated flag to
numpy.lib.add_newdocwould provide a systematic way to do it but I generally don't like stacking argument to existing functions, even semi-private ones. How about tweakingadd_newdocso it automatically performs thestr.replaceand registers the function upon dedecting the substring"${ARRAY_FUNCTION_LIKE}"?seberg commentedon Oct 2, 2024
Not sure that modifying
add_newdocis worth it, maybe we just add it as another line in the same place? But if you think it is, also fine.neutrinoceros commentedon Oct 3, 2024
@seberg I opened gh-27490 with my initial approach. Let me know what you think !
API: register NEP 35 functions as array_functions (numpy#27490)