MCPcopy
hub / github.com/dask/dask / take

Function take

dask/array/_array_expr/_slicing.py:342–366  ·  view source on GitHub ↗
(x, index, axis=0)

Source from the content-addressed store, hash-verified

340
341
342def take(x, index, axis=0):
343 if not np.isnan(x.chunks[axis]).any():
344 from dask.array._array_expr._shuffle import _shuffle
345 from dask.array.utils import arange_safe, asarray_safe
346
347 arange = arange_safe(np.sum(x.chunks[axis]), like=index)
348 if len(index) == len(arange) and np.abs(index - arange).sum() == 0:
349 # no-op
350 return x
351
352 average_chunk_size = int(sum(x.chunks[axis]) / len(x.chunks[axis]))
353
354 indexer = []
355 index = asarray_safe(index, like=index)
356 for i in range(0, len(index), average_chunk_size):
357 indexer.append(index[i : i + average_chunk_size].tolist())
358 return _shuffle(x, indexer, axis, "getitem-")
359 elif len(x.chunks[axis]) == 1:
360 return TakeUnknownOneChunk(x, index, axis)
361 else:
362 from dask.array.core import unknown_chunk_message
363
364 raise ValueError(
365 f"Array chunk size or shape is unknown. {unknown_chunk_message}"
366 )
367
368
369class Slice(ArrayExpr):

Callers 4

test_takeFunction · 0.90
test_take_sortedFunction · 0.90
slice_wrap_listsFunction · 0.70

Calls 8

arange_safeFunction · 0.90
asarray_safeFunction · 0.90
_shuffleFunction · 0.90
TakeUnknownOneChunkClass · 0.85
sumFunction · 0.50
anyMethod · 0.45
sumMethod · 0.45
absMethod · 0.45

Tested by 3

test_takeFunction · 0.72
test_take_sortedFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…