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

Function unify_chunks

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

4129
4130
4131def unify_chunks(*args, **kwargs):
4132 """
4133 Unify chunks across a sequence of arrays
4134
4135 This utility function is used within other common operations like
4136 :func:`dask.array.core.map_blocks` and :func:`dask.array.core.blockwise`.
4137 It is not commonly used by end-users directly.
4138
4139 Parameters
4140 ----------
4141 *args: sequence of Array, index pairs
4142 Sequence like (x, 'ij', y, 'jk', z, 'i')
4143
4144 Examples
4145 --------
4146 >>> import dask.array as da
4147 >>> x = da.ones(10, chunks=((5, 2, 3),))
4148 >>> y = da.ones(10, chunks=((2, 3, 5),))
4149 >>> chunkss, arrays = unify_chunks(x, 'i', y, 'i')
4150 >>> chunkss
4151 {'i': (2, 3, 2, 3)}
4152
4153 >>> x = da.ones((100, 10), chunks=(20, 5))
4154 >>> y = da.ones((10, 100), chunks=(4, 50))
4155 >>> chunkss, arrays = unify_chunks(x, 'ij', y, 'jk', 'constant', None)
4156 >>> chunkss # doctest: +SKIP
4157 {'k': (50, 50), 'i': (20, 20, 20, 20, 20), 'j': (4, 1, 3, 2)}
4158
4159 >>> unify_chunks(0, None)
4160 ({}, [0])
4161
4162 Returns
4163 -------
4164 chunkss : dict
4165 Map like {index: chunks}.
4166 arrays : list
4167 List of rechunked arrays.
4168
4169 See Also
4170 --------
4171 common_blockdim
4172 """
4173 if not args:
4174 return {}, []
4175
4176 arginds = [
4177 (asanyarray(a) if ind is not None else a, ind) for a, ind in partition(2, args)
4178 ] # [x, ij, y, jk]
4179 warn = kwargs.get("warn", True)
4180
4181 arrays, inds = zip(*arginds)
4182 if all(ind is None for ind in inds):
4183 return {}, list(arrays)
4184 if all(ind == inds[0] for ind in inds) and all(
4185 a.chunks == arrays[0].chunks for a in arrays
4186 ):
4187 return dict(zip(inds[0], arrays[0].chunks)), arrays
4188

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