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

Function normalize_chunks

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

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