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)
| 3056 | |
| 3057 | |
| 3058 | def 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)) |
searching dependent graphs…