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

Function topk

dask/array/chunk.py:173–188  ·  view source on GitHub ↗

Chunk and combine function of topk Extract the k largest elements from a on the given axis. If k is negative, extract the -k smallest elements instead. Note that, unlike in the parent function, the returned elements are not sorted internally.

(a, k, axis, keepdims)

Source from the content-addressed store, hash-verified

171
172
173def topk(a, k, axis, keepdims):
174 """Chunk and combine function of topk
175
176 Extract the k largest elements from a on the given axis.
177 If k is negative, extract the -k smallest elements instead.
178 Note that, unlike in the parent function, the returned elements
179 are not sorted internally.
180 """
181 assert keepdims is True
182 axis = axis[0]
183 if abs(k) >= a.shape[axis]:
184 return a
185
186 a = np.partition(a, -k, axis=axis)
187 k_slice = slice(-k, None) if k > 0 else slice(-k)
188 return a[tuple(k_slice if i == axis else slice(None) for i in range(a.ndim))]
189
190
191def topk_aggregate(a, k, axis, keepdims):

Callers 1

topk_aggregateFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected