>>> 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)
| 1240 | |
| 1241 | |
| 1242 | def 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 | |
| 1270 | def finalize(results): |
searching dependent graphs…