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

Function unify_chunks

dask/array/core.py:4336–4432  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

map_overlapFunction · 0.90
blockwiseFunction · 0.90
concatenateFunction · 0.85
broadcast_arraysFunction · 0.85
stackFunction · 0.85

Calls 10

allFunction · 0.90
maxFunction · 0.90
broadcast_dimensionsFunction · 0.90
sumFunction · 0.90
partitionFunction · 0.85
asanyarrayFunction · 0.70
getMethod · 0.45
prodMethod · 0.45
valuesMethod · 0.45
rechunkMethod · 0.45

Tested by

no test coverage detected