-
-
Notifications
You must be signed in to change notification settings - Fork 11k
DEP: deprecate np.set_numeric_ops and friends #11916
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
Conversation
Codecov failures since newly deprecated |
I think codecov is comparing this pr to some other base changeset. The diff is showing changes I did not make to |
Your link is for "changes," not the actual diff, which correctly shows which lines in this PR are not covered. I tend to ignore the "changes" tab, as previously discussed elsewhere. |
53613cf
to
e6b3911
Compare
rebased and deprecation test added to help code coverage |
Closed/reopened to restart crashed appveyor tests |
Should squash before merging |
dae5b0e
to
823ed3e
Compare
squashed to a single commit |
numpy/core/_add_newdocs.py
Outdated
@@ -1537,6 +1537,10 @@ def luf(lamdaexpr, *args, **kwargs): | |||
|
|||
Set numerical operators for array objects. | |||
|
|||
.. deprecated:: 1.16 | |||
|
|||
Use :c:func:`PyUFunc_ReplaceLoopBySignature` to change ufunc behaviour. |
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.
Perhaps we should also suggest creating a subclass with an overloaded __array_ufunc__
here, for python-only users who were replacing operators.
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.
done
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.
This reads badly. Maybe
For the general case, use :c:func:`PyUFunc_ReplaceLoopBySignature`.
For ndarray subclasses, define the ``__array_ufunc__`` method and
override the relevant ufunc.
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.
Ping.
823ed3e
to
e20fd11
Compare
This closes #10141, right? |
It doesn't look like you added a deprecation notice to the C api docs |
e20fd11
to
11fa5ca
Compare
C API deprecation added. Also added a commit to remove mention of the deprecated |
ping |
94723cb
to
0a21fa2
Compare
rebased to fix release note merge confilicts |
ping |
@eric-wieser indeed I did not increment the NPY_API_VERSION for the deprecation. Fixed. |
Get dictionary showing number functions that all arrays will use | ||
*/ | ||
NPY_NO_EXPORT PyObject * | ||
PyArray_GetNumericOps(void) |
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.
Should be wrapped in
#if !defined(NPY_NO_DEPRECATED_API) || \
(NPY_NO_DEPRECATED_API < NPY_1_16_API_VERSION)
#endif
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.
That is only for headers, to allow access to old API macros. The C files always start with this define, which will defeat the check you suggest
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
. NPY_API_VERSION
is hard-coded from C_API_VERSION
in core/setup_common.py
, see core/setup.py
where the magic happens.
We don't really have a way to actually remove or disable deprecated API functions, since the convention is that the PyArray_API structure built in __multiarray_api.h
by core/code_generators/generate_array_api.py
from the list in core.code_generators/numpy_api.py
can only grow, never shrink, to allow backward compatibility.
This is somewhat talked about in the documentation from the user's perspective and in the 'VERSIONING SUPPORT' docstring in setup_common.py
, but if you think of hook where I can hang more documentation let me know.
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.
Oops, good point.
Can we move PyArray_GetNumericOps
to a macro that hides the C api macro?
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.
We could eventually turn the warning into an exception. Not sure if I understand which "C api macro" you mean, there are so many.
At some point we could remove things from the PyArray_API
structure by changing our major version, which would infer no backward API compatibility.
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.
I mean this macro:
#define PyArray_GetNumericOps \
(*(PyObject * (*)(void)) \
PyArray_API[41])
Perhaps we should leave this as an open question, and just take this PR as it currently stands
Not sure that we should increment the API version, the API hash remains the same and nothing has been added or removed, nor do we remove deprecated API functions -- there are a couple. So the API hasn't changed, we just recommend that some interface functions should not be used. If we want to disable the function, I don't think we have a policy for that. |
If that's the case, why does |
Those who wish to access |
Yep, there was a move to hide the structure internals behind functions so that we would be freed up to change the structures in the future, but that is incomplete and has been stalled for some time. |
Note PR #11175 changed the size of |
But that change is not backwards compatible, i.e., code that uses the new attributes will not run on older NumPy. Is that the case for code compiled against 1.16? |
07e9486
to
73c5a5a
Compare
The only difference in this PR is the deprecation warning that will be emitted on 1.16 if the deprecated C functions are used. Does that not justify incrementing the |
Conversely, I think that users should be able to opt into no longer having |
Honestly, as far as I've ever been able to figure out, there is no good reason for it to exist.
It was also done incorrectly... the internals were moved from macros/direct access to inline functions, but inline functions are just like macros: they both expose the structure internals as part of the ABI. And we never had a plan for how to actually remove the old APIs. And I'm not even sure what the point is... I don't think anything on our roadmap actually benefits from hiding the internals of Also, I'm pretty sure that all of the C compilers we support have native support for issuing deprecation warnings, so I'm not sure why we need to invent our own system? |
Are you sure the inline functions aren't inline only when used within multiarray? I thought I saw something like that somewhere, but perhaps I'm imagining it. |
I see code in |
The code currently uses functions in the headers which will probably be inlined to be identical to the macros.
This would incur a performance penalty since the call could no longer be inlined, and would cross a shared-object border. Whether that penalty is significant or not depends on the use case. We could adopt a policy where the first call caches a C-compatible representation of the hidden, possibly non-C-representable field, and functions like Besides the 1.7 attribute hiding API changes, we used NPY_API_VERSION for the Also, PR #12235 fixes the definition of the NPY_1_XX_API_VERSION macros, and is waiting for review Perhaps we could merge this, and if a change to the API versioning policy is needed open a new issue for that. |
This is probably good to go? It looks fairly uncontroversial. |
reworded documentation |
Thanks Matti. |
The third part of NEP 15. Deprecate
np.set_numeric_ops
,PyArray_SetNumericOps
,PyArray_GetNumericOps
.The second part, "we should use some new, private API to set up
ndarray.__add__
and friends" is still TBD.