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

Function normalize_chunks

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

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