MCPcopy
hub / github.com/dask/dask / normalize_chunks

Function normalize_chunks

dask/array/core.py:3058–3227  ·  view source on GitHub ↗

Normalize chunks to tuple of tuples This takes in a variety of input types and information and produces a full tuple-of-tuples result for chunks, suitable to be passed to Array or rechunk or any other operation that creates a Dask array. Parameters ---------- chunks: tuple,

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

Source from the content-addressed store, hash-verified

3056
3057
3058def normalize_chunks(chunks, shape=None, limit=None, dtype=None, previous_chunks=None):
3059 """Normalize chunks to tuple of tuples
3060
3061 This takes in a variety of input types and information and produces a full
3062 tuple-of-tuples result for chunks, suitable to be passed to Array or
3063 rechunk or any other operation that creates a Dask array.
3064
3065 Parameters
3066 ----------
3067 chunks: tuple, int, dict, or string
3068 The chunks to be normalized. See examples below for more details
3069 shape: Tuple[int]
3070 The shape of the array
3071 limit: int (optional)
3072 The maximum block size to target in bytes,
3073 if freedom is given to choose
3074 dtype: np.dtype
3075 previous_chunks: Tuple[Tuple[int]] optional
3076 Chunks from a previous array that we should use for inspiration when
3077 rechunking auto dimensions. If not provided but auto-chunking exists
3078 then auto-dimensions will prefer square-like chunk shapes.
3079
3080 Examples
3081 --------
3082 Fully explicit tuple-of-tuples
3083
3084 >>> from dask.array.core import normalize_chunks
3085 >>> normalize_chunks(((2, 2, 1), (2, 2, 2)), shape=(5, 6))
3086 ((2, 2, 1), (2, 2, 2))
3087
3088 Specify uniform chunk sizes
3089
3090 >>> normalize_chunks((2, 2), shape=(5, 6))
3091 ((2, 2, 1), (2, 2, 2))
3092
3093 Cleans up missing outer tuple
3094
3095 >>> normalize_chunks((3, 2), (5,))
3096 ((3, 2),)
3097
3098 Cleans up lists to tuples
3099
3100 >>> normalize_chunks([[2, 2], [3, 3]])
3101 ((2, 2), (3, 3))
3102
3103 Expands integer inputs 10 -> (10, 10)
3104
3105 >>> normalize_chunks(10, shape=(30, 5))
3106 ((10, 10, 10), (5,))
3107
3108 Expands dict inputs
3109
3110 >>> normalize_chunks({0: 2, 1: 3}, shape=(6, 6))
3111 ((2, 2, 2), (3, 3))
3112
3113 The values -1 and None get mapped to full size
3114
3115 >>> normalize_chunks((5, -1), shape=(10, 10))

Callers 15

_validate_chunksMethod · 0.90
_parse_wrap_argsFunction · 0.90
_choice_validate_paramsFunction · 0.90
_wrap_funcFunction · 0.90
rechunkFunction · 0.90
linspaceFunction · 0.90
arangeFunction · 0.90
indicesFunction · 0.90
eyeFunction · 0.90
triFunction · 0.90
fromfunctionFunction · 0.90
get_pad_shapes_chunksFunction · 0.90

Calls 8

allFunction · 0.90
parse_bytesFunction · 0.90
anyFunction · 0.90
sumFunction · 0.90
auto_chunksFunction · 0.85
dtypeMethod · 0.45
getMethod · 0.45

Tested by 14

test_nbytes_autoFunction · 0.72
test_auto_chunksFunction · 0.72
test_fftfreqFunction · 0.72
test_rfftfreqFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…