MCPcopy
hub / github.com/dask/dask / auto_chunks

Function auto_chunks

dask/array/core.py:3257–3424  ·  view source on GitHub ↗

Determine automatic chunks This takes in a chunks value that contains ``"auto"`` values in certain dimensions and replaces those values with concrete dimension sizes that try to get chunks to be of a certain size in bytes, provided by the ``limit=`` keyword. If multiple dimensions

(chunks, shape, limit, dtype, previous_chunks=None)

Source from the content-addressed store, hash-verified

3255
3256
3257def auto_chunks(chunks, shape, limit, dtype, previous_chunks=None):
3258 """Determine automatic chunks
3259
3260 This takes in a chunks value that contains ``"auto"`` values in certain
3261 dimensions and replaces those values with concrete dimension sizes that try
3262 to get chunks to be of a certain size in bytes, provided by the ``limit=``
3263 keyword. If multiple dimensions are marked as ``"auto"`` then they will
3264 all respond to meet the desired byte limit, trying to respect the aspect
3265 ratio of their dimensions in ``previous_chunks=``, if given.
3266
3267 Parameters
3268 ----------
3269 chunks: Tuple
3270 A tuple of either dimensions or tuples of explicit chunk dimensions
3271 Some entries should be "auto"
3272 shape: Tuple[int]
3273 limit: int, str
3274 The maximum allowable size of a chunk in bytes
3275 previous_chunks: Tuple[Tuple[int]]
3276
3277 See also
3278 --------
3279 normalize_chunks: for full docstring and parameters
3280 """
3281 if previous_chunks is not None:
3282 # rioxarray is passing ((1, ), (x,)) for shapes like (100, 5x),
3283 # so add this compat code for now
3284 # https://github.com/corteva/rioxarray/pull/820
3285 previous_chunks = (
3286 c[0] if isinstance(c, tuple) and len(c) == 1 else c for c in previous_chunks
3287 )
3288 previous_chunks = _convert_int_chunk_to_tuple(shape, previous_chunks)
3289 chunks = list(chunks)
3290
3291 autos = {i for i, c in enumerate(chunks) if c == "auto"}
3292 if not autos:
3293 return tuple(chunks)
3294
3295 if limit is None:
3296 limit = config.get("array.chunk-size")
3297 if isinstance(limit, str):
3298 limit = parse_bytes(limit)
3299
3300 if dtype is None:
3301 raise TypeError("dtype must be known for auto-chunking")
3302
3303 if dtype.hasobject:
3304 raise NotImplementedError(
3305 "Can not use auto rechunking with object dtype. "
3306 "We are unable to estimate the size in bytes of object data"
3307 )
3308
3309 for x in tuple(chunks) + tuple(shape):
3310 if (
3311 isinstance(x, Number)
3312 and np.isnan(x)
3313 or isinstance(x, tuple)
3314 and np.isnan(x).any()

Callers 1

normalize_chunksFunction · 0.85

Calls 12

parse_bytesFunction · 0.90
maxFunction · 0.90
_compute_multiplierFunction · 0.85
setClass · 0.85
_trivial_aggregateFunction · 0.85
round_toFunction · 0.85
getMethod · 0.45
anyMethod · 0.45
prodMethod · 0.45
medianMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…