Skip to content
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

BUG: Fix numba DUFuncs added loops getting picked up #21139

Merged
merged 1 commit into from Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions numpy/core/src/umath/dispatching.c
Expand Up @@ -746,6 +746,40 @@ promote_and_get_info_and_ufuncimpl(PyUFuncObject *ufunc,
}
info = promote_and_get_info_and_ufuncimpl(ufunc,
ops, signature, new_op_dtypes, NPY_FALSE);
if (info == NULL) {
/*
* NOTE: This block exists solely to support numba's DUFuncs which add
* new loops dynamically, so our list may get outdated. Thus, we
* have to make sure that the loop exists.
*
* Before adding a new loop, ensure that it actually exists. There
* is a tiny chance that this would not work, but it would require an
* extension additionally have a custom loop getter.
* This check should ensure a the right error message, but in principle
* we could try to call the loop getter here.
*/
char *types = ufunc->types;
npy_bool loop_exists = NPY_FALSE;
for (int i = 0; i < ufunc->ntypes; ++i) {
loop_exists = NPY_TRUE; /* assume it exists, break if not */
for (int j = 0; j < ufunc->nargs; ++j) {
if (types[j] != new_op_dtypes[j]->type_num) {
loop_exists = NPY_FALSE;
break;
}
}
if (loop_exists) {
break;
}
types += ufunc->nargs;
}

if (loop_exists) {
info = add_and_return_legacy_wrapping_ufunc_loop(
ufunc, new_op_dtypes, 0);
}
}

for (int i = 0; i < ufunc->nargs; i++) {
Py_XDECREF(new_op_dtypes[i]);
}
Expand Down