MCPcopy
hub / github.com/dask/dask / unify_chunks

Function unify_chunks

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

4335
4336
4337def 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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…