8000 PERF: Skip probing `__array_ufunc__` for NumPy builtin scalars by eendebakpt · Pull Request #21470 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

PERF: Skip probing __array_ufunc__ for NumPy builtin scalars #21470

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 5 commits into from
May 11, 2022
Merged
Changes from 1 commit
Commits
File filter

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
7 changes: 7 additions & 0 deletions numpy/core/src/common/ufunc_override.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "npy_import.h"
#include "ufunc_override.h"

#define PyObject_CheckExact_Type(op, checktype) (((PyObject*)(op))->ob_type == &checktype)

/*
* Check whether an object has __array_ufunc__ defined on its class and it
* is not the default, i.e., the object is not an ndarray, and its
Expand All @@ -30,6 +32,11 @@ PyUFuncOverride_GetNonDefaultArrayUfunc(PyObject *obj)
if (PyArray_CheckExact(obj)) {
return NULL;
}
/* Fast return for most common numpy scalar types */
if (PyObject_CheckExact_Type(obj, PyDoubleArrType_Type) || PyObject_CheckExact_Type(obj, PyIntArrType_Type)) {
return NULL;
}

/*
* Does the class define __array_ufunc__? (Note that LookupSpecial has fast
* return for basic python types, so no need to worry about those here)
Expand Down
0