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

Function blockdims_from_blockshape

dask/array/core.py:1237–1262  ·  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

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

Callers 2

Calls 2

sumFunction · 0.90
allFunction · 0.90

Tested by 1