Unify chunks across a sequence of arrays This utility function is used within other common operations like :func:`dask.array.core.map_blocks` and :func:`dask.array.core.blockwise`. It is not commonly used by end-users directly. Parameters ---------- *args: sequence of
(*args, **kwargs)
| 4335 | |
| 4336 | |
| 4337 | def unify_chunks(*args, **kwargs): |
| 4338 | """ |
| 4339 | Unify chunks across a sequence of arrays |
| 4340 | |
| 4341 | This utility function is used within other common operations like |
| 4342 | :func:`dask.array.core.map_blocks` and :func:`dask.array.core.blockwise`. |
| 4343 | It is not commonly used by end-users directly. |
| 4344 | |
| 4345 | Parameters |
| 4346 | ---------- |
| 4347 | *args: sequence of Array, index pairs |
| 4348 | Sequence like (x, 'ij', y, 'jk', z, 'i') |
| 4349 | |
| 4350 | Examples |
| 4351 | -------- |
| 4352 | >>> import dask.array as da |
| 4353 | >>> x = da.ones(10, chunks=((5, 2, 3),)) |
| 4354 | >>> y = da.ones(10, chunks=((2, 3, 5),)) |
| 4355 | >>> chunkss, arrays = unify_chunks(x, 'i', y, 'i') |
| 4356 | >>> chunkss |
| 4357 | {'i': (2, 3, 2, 3)} |
| 4358 | |
| 4359 | >>> x = da.ones((100, 10), chunks=(20, 5)) |
| 4360 | >>> y = da.ones((10, 100), chunks=(4, 50)) |
| 4361 | >>> chunkss, arrays = unify_chunks(x, 'ij', y, 'jk', 'constant', None) |
| 4362 | >>> chunkss # doctest: +SKIP |
| 4363 | {'k': (50, 50), 'i': (20, 20, 20, 20, 20), 'j': (4, 1, 3, 2)} |
| 4364 | |
| 4365 | >>> unify_chunks(0, None) |
| 4366 | ({}, [0]) |
| 4367 | |
| 4368 | Returns |
| 4369 | ------- |
| 4370 | chunkss : dict |
| 4371 | Map like {index: chunks}. |
| 4372 | arrays : list |
| 4373 | List of rechunked arrays. |
| 4374 | |
| 4375 | See Also |
| 4376 | -------- |
| 4377 | common_blockdim |
| 4378 | """ |
| 4379 | if not args: |
| 4380 | return {}, [] |
| 4381 | |
| 4382 | arginds = [ |
| 4383 | (asanyarray(a) if ind is not None else a, ind) for a, ind in partition(2, args) |
| 4384 | ] # [x, ij, y, jk] |
| 4385 | warn = kwargs.get("warn", True) |
| 4386 | |
| 4387 | arrays, inds = zip(*arginds) |
| 4388 | if all(ind is None for ind in inds): |
| 4389 | return {}, list(arrays) |
| 4390 | if all(ind == inds[0] for ind in inds) and all( |
| 4391 | a.chunks == arrays[0].chunks for a in arrays |
| 4392 | ): |
| 4393 | return dict(zip(inds[0], arrays[0].chunks)), arrays |
| 4394 |
no test coverage detected
searching dependent graphs…