-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Poor ndarray.take performance on Fortran order arrays (Trac #2065) #2657
Comments
@mwiebe wrote on 2012-03-12 Confirmed. ndarray.take needs to be rewritten to be CPU cache-aware. In 1.6, element-wise ufuncs got this treatment. In 1.7, the ufunc reduce method has received this treatment. Making NumPy use more algorithms that respect the CPU cache should continue. |
Milestone changed to |
Good plan, but not a 1.8 blocker; removing milestone. |
A workaround is to use this numba with this @nb.njit(nogil=True)
def _take_2d_ixs0(rets, ixs, out):
T, N = rets.shape
M, = ixs.shape
assert out.shape == (T, M)
for t in range(T):
for m in range(M):
n = ixs[m]
assert -N < n < N, 'n'
out[t, m] = rets[t, n]
@nb.njit(nogil=True)
def _take_2d_ixs1(rets, ixs, out):
T, N = rets.shape
M, = ixs.shape
assert out.shape == (T, M)
for m in range(M):
n = ixs[m]
assert -N < n < N, 'n'
for t in range(T):
out[t, m] = rets[t, n]
def _take_2d(xs, ixs, axis):
if axis == 0:
return _take_2d(xs.T, ixs, 1).T
else:
assert axis == 1
T, N = xs.shape
M, = ixs.shape
order = 'C' if xs.flags.c_contiguous else 'F'
out = np.empty((T, M), dtype=xs.dtype, order=order)
(_take_2d_ixs0 if xs.flags.c_contiguous else _take_2d_ixs1)(xs, ixs, out)
return out Obviously not brilliant because it only works for the 2D case! |
I think this has been fixed in the last 7 years |
@wesm my benchmarks in #9450 still show very poor performance for |
I think the typical work around should normally be using advanced indexing anyway, even if there are a few cases advanced indexing is not super fast. And the 2D special cases where it is not quite optimal. |
Original ticket http://projects.scipy.org/numpy/ticket/2065 on 2012-02-26 by @wesm, assigned to unknown.
3000x slowdown observed:
The text was updated successfully, but these errors were encountered: