8000 API: Allow comparisons with and between any python integers by seberg · Pull Request #24915 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Allow comparisons with and between any python integers #24915

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

Merged
merged 8 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter 10000

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
API: Make new resolve_dtypes_with_pyscalars private for now
Makign private by raising an error.  Maybe a bit odd, but OTOH,
it does advertise that we can make it public quite easily if we want
to.
  • Loading branch information
seberg committed Oct 18, 2023
commit cdbea5e2aafc29e5cda9e2668df052ddfd0e01ee
8 changes: 7 additions & 1 deletion numpy/_core/src/multiarray/array_method.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ fill_arraymethod_from_slots(
for (PyType_Slot *slot = &spec->slots[0]; slot->slot != 0; slot++) {
switch (slot->slot) {
case NPY_METH_resolve_descriptors_with_scalars:
if (!private) {
PyErr_SetString(PyExc_RuntimeError,
"the NPY_METH_resolve_descriptors_with_scalars "
"slot private due to uncertainty about the right "
"signature (see gh-24915)");
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with coming back to this when someone has a real need for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, fine to come back to this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adding, I can't see a comment that does more than repeat the error message. Added a leading underscore to the slot ID, though, so it is less awkward to keep it in a public header.

meth->resolve_descriptors_with_scalars = slot->pfunc;
continue;
case NPY_METH_resolve_descriptors:
Expand All @@ -269,7 +276,6 @@ fill_arraymethod_from_slots(
* (as in: we should not worry about changing it, but of
* course that would not break it immediately.)
*/
/* Only allow override for private functions initially */
meth->get_strided_loop = slot->pfunc;
continue;
/* "Typical" loops, supported used by the default `get_loop` */
Expand Down
9 changes: 8 additions & 1 deletion numpy/_core/src/umath/dispatching.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,21 @@ PyUFunc_AddLoop(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate)
*/
NPY_NO_EXPORT int
PyUFunc_AddLoopFromSpec(PyObject *ufunc, PyArrayMethod_Spec *spec)
{
return PyUFunc_AddLoopFromSpec_int(ufunc, spec, 0);
}


NPY_NO_EXPORT int
PyUFunc_AddLoopFromSpec_int(PyObject *ufunc, PyArrayMethod_Spec *spec, int priv)
{
if (!PyObject_TypeCheck(ufunc, &PyUFunc_Type)) {
PyErr_SetString(PyExc_TypeError,
"ufunc object passed is not a ufunc!");
return -1;
}
PyBoundArrayMethodObject *bmeth =
(PyBoundArrayMethodObject *)PyArrayMethod_FromSpec(spec);
(PyBoundArrayMethodObject *)PyArrayMethod_FromSpec_int(spec, priv);
if (bmeth == NULL) {
return -1;
}
Expand Down
3 changes: 3 additions & 0 deletions numpy/_core/src/umath/dispatching.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ PyUFunc_AddLoop(PyUFuncObject *ufunc, PyObject *info, int ignore_duplicate);
NPY_NO_EXPORT int
PyUFunc_AddLoopFromSpec(PyObject *ufunc, PyArrayMethod_Spec *spec);

NPY_NO_EXPORT int
PyUFunc_AddLoopFromSpec_int(PyObject *ufunc, PyArrayMethod_Spec *spec, int priv);

NPY_NO_EXPORT PyArrayMethodObject *
promote_and_get_ufuncimpl(PyUFuncObject *ufunc,
PyArrayObject *const ops[],
Expand Down
4 changes: 2 additions & 2 deletions numpy/_core/src/umath/special_integer_comparisons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,14 @@ add_dtype_loops(PyObject *umath, PyArrayMethod_Spec *spec, PyObject *info)
/* Register the spec/loop for both forward and backward direction */
spec->dtypes[0] = Int;
spec->dtypes[1] = PyInt;
int res = PyUFunc_AddLoopFromSpec((PyObject *)ufunc, spec);
int res = PyUFunc_AddLoopFromSpec_int((PyObject *)ufunc, spec, 1);
if (res < 0) {
Py_DECREF(Int);
goto fail;
}
spec->dtypes[0] = PyInt;
spec->dtypes[1] = Int;
res = PyUFunc_AddLoopFromSpec((PyObject *)ufunc, spec);
res = PyUFunc_AddLoopFromSpec_int((PyObject *)ufunc, spec, 1);
Py_DECREF(Int);
if (res < 0) {
goto fail;
Expand Down
0