MCPcopy
hub / github.com/dask/dask / chunks_from_arrays

Function chunks_from_arrays

dask/array/core.py:5428–5461  ·  view source on GitHub ↗

Chunks tuple from nested list of arrays >>> x = np.array([1, 2]) >>> chunks_from_arrays([x, x]) ((2, 2),) >>> x = np.array([[1, 2]]) >>> chunks_from_arrays([[x], [x]]) ((1, 1), (2,)) >>> x = np.array([[1, 2]]) >>> chunks_from_arrays([[x, x]]) ((1,), (2, 2))

(arrays)

Source from the content-addressed store, hash-verified

5426
5427
5428def chunks_from_arrays(arrays):
5429 """Chunks tuple from nested list of arrays
5430
5431 >>> x = np.array([1, 2])
5432 >>> chunks_from_arrays([x, x])
5433 ((2, 2),)
5434
5435 >>> x = np.array([[1, 2]])
5436 >>> chunks_from_arrays([[x], [x]])
5437 ((1, 1), (2,))
5438
5439 >>> x = np.array([[1, 2]])
5440 >>> chunks_from_arrays([[x, x]])
5441 ((1,), (2, 2))
5442
5443 >>> chunks_from_arrays([1, 1])
5444 ((1, 1),)
5445 """
5446 if not arrays:
5447 return ()
5448 result = []
5449 dim = 0
5450
5451 def shape(x):
5452 try:
5453 return x.shape or (1,)
5454 except AttributeError:
5455 return (1,)
5456
5457 while isinstance(arrays, (list, tuple)):
5458 result.append(tuple(shape(deepfirst(a))[dim] for a in arrays))
5459 arrays = arrays[0]
5460 dim += 1
5461 return tuple(result)
5462
5463
5464def deepfirst(seq):

Callers 1

concatenate3Function · 0.85

Calls 2

deepfirstFunction · 0.85
shapeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…