8000 more small-array performance improvements by juliantaylor · Pull Request #4904 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

more small-array performance improvements #4904

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

Closed
wants to merge 4 commits into from
Closed
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
Prev Previous commit
Next Next commit
ENH: skip the slower type tuple code path for common reductions
The creation and parsing of the type tuple is slower than the array
result path used by binary ufuncs. For the most common reductions add a
fast path skipping the type tuple creation and sending it through the
array result path.
Improves small reduction performance of these types by 5%-10%.
  • Loading branch information
juliantaylor committed Oct 9, 2015
commit 74bc91946212616532721ea3a195ba4971eac4df
15 changes: 11 additions & 4 deletions numpy/core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2774,17 +2774,24 @@ reduce_type_resolver(PyUFuncObject *ufunc, PyArrayObject *arr,
* resolution.
*/
if (odtype != NULL) {
type_tup = PyTuple_Pack(3, odtype, odtype, Py_None);
if (type_tup == NULL) {
return -1;
if (!(PyTypeNum_ISBOOL(odtype->type_num) &&
PyArray_TYPE(arr) == odtype->type_num) &&
!(PyTypeNum_ISFLOAT(odtype->type_num) &&
PyArray_TYPE(arr) == odtype->type_num &&
PyArray_DESCR(arr)->byteorder == odtype->byteorder &&
odtype->byteorder == NPY_NATIVE)) {
type_tup = PyTuple_Pack(3, odtype, odtype, Py_None);
if (type_tup == NULL) {
return -1;
}
}
}

/* Use the type resolution function to find our loop */
retcode = ufunc->type_resolver(
ufunc, NPY_UNSAFE_CASTING,
op, type_tup, dtypes);
Py_DECREF(type_tup);
Py_XDECREF(type_tup);
if (retcode == -1) {
return -1;
}
Expand Down
0