MCPcopy
hub / github.com/dask/dask / blockdims_from_blockshape

Function blockdims_from_blockshape

dask/array/core.py:1242–1267  ·  view source on GitHub ↗

>>> blockdims_from_blockshape((10, 10), (4, 3)) ((4, 4, 2), (3, 3, 3, 1)) >>> blockdims_from_blockshape((10, 0), (4, 0)) ((4, 4, 2), (0,))

(shape, chunks)

Source from the content-addressed store, hash-verified

1240
1241
1242def blockdims_from_blockshape(shape, chunks):
1243 """
1244
1245 >>> blockdims_from_blockshape((10, 10), (4, 3))
1246 ((4, 4, 2), (3, 3, 3, 1))
1247 >>> blockdims_from_blockshape((10, 0), (4, 0))
1248 ((4, 4, 2), (0,))
1249 """
1250 if chunks is None:
1251 raise TypeError("Must supply chunks= keyword argument")
1252 if shape is None:
1253 raise TypeError("Must supply shape= keyword argument")
1254 if np.isnan(sum(shape)) or np.isnan(sum(chunks)):
1255 raise ValueError(
1256 f"Array chunk sizes are unknown. shape: {shape}, chunks: {chunks}{unknown_chunk_message}"
1257 )
1258 if not all(map(is_integer, chunks)):
1259 raise ValueError("chunks can only contain integers.")
1260 if not all(map(is_integer, shape)):
1261 raise ValueError("shape can only contain integers.")
1262 shape = tuple(map(int, shape))
1263 chunks = tuple(map(int, chunks))
1264 return tuple(
1265 ((bd,) * (d // bd) + ((d % bd,) if d % bd else ()) if d else (0,))
1266 for d, bd in zip(shape, chunks)
1267 )
1268
1269
1270def finalize(results):

Callers 2

Calls 2

sumFunction · 0.90
allFunction · 0.90

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…