MCPcopy Create free account
hub / github.com/dask/dask / argtopk_aggregate

Function argtopk_aggregate

dask/array/chunk.py:246–265  ·  view source on GitHub ↗

Final aggregation function of argtopk Invoke argtopk one final time, sort the results internally, drop the data and return the index only.

(a_plus_idx, k, axis, keepdims)

Source from the content-addressed store, hash-verified

244
245
246def argtopk_aggregate(a_plus_idx, k, axis, keepdims):
247 """Final aggregation function of argtopk
248
249 Invoke argtopk one final time, sort the results internally, drop the data
250 and return the index only.
251 """
252 assert keepdims is True
253 a_plus_idx = a_plus_idx if len(a_plus_idx) > 1 else a_plus_idx[0]
254 a, idx = argtopk(a_plus_idx, k, axis, keepdims)
255 axis = axis[0]
256
257 idx2 = np.argsort(a, axis=axis)
258 idx = np.take_along_axis(idx, idx2, axis)
259 if k < 0:
260 return idx
261 return idx[
262 tuple(
263 slice(None, None, -1) if i == axis else slice(None) for i in range(idx.ndim)
264 )
265 ]
266
267
268def arange(start, stop, step, length, dtype, like=None):

Callers

nothing calls this directly

Calls 1

argtopkFunction · 0.70

Tested by

no test coverage detected