Chunker
- class PlasmaCalcs.dimensions.maindims_chunking.Chunker(chunks, maindims_sizes, init_slices=None, *, lenient=False)
Bases:
objectmanages choosing slices based on chunks.
— CAUTION —
derivative results different with/without chunks, unless deriv_before_slice=True.All other results should be the same with/without chunking.chunks: dictkeys should be maindim possibly with ‘_size’ or ‘_slices’ appended, e.g. ‘x’ or ‘y_size’.x –> break x into this many chunks total.x_size –> break x into chunks of this size.x_slices –> list of slices to use for x.maindims_sizes: dict{dim: full size} for dims in maindims.init_slices: None or dictdict of slices which already exist.un-chunked dims’ slices will be maintained when creating chunk slices.invalid chunking if any chunk dims appear inslices.None –> internally store as empty dict.lenient: boolwhether to allow any ChunkSlicer inputs, even if invalid.default False, i.e. self.check_valid() (which will raise ChunkError if not valid).Methods
__len__()the number of chunk slices which will be generated by self.iter_slicers().
checks that self is a valid ChunkSlicer.
return chunking info for dim x: (mode, value).
iterates through all chunk slices, yielding slices dict including any non-chunked slices.
slicers()list of all slices to use for chunking.
iterates through all chunk slices for dim x.
Attributes
the tuple of dims which are being chunked.
the maindims.
- __len__()
the number of chunk slices which will be generated by self.iter_slicers().
[EFF] perhaps should make this more efficient instead of generating all slices…
- _iter_slicers_x(x)
iterates through all chunk slices for dim x.
- check_valid()
checks that self is a valid ChunkSlicer. crash with ChunkError if not.
Valid must satisfy:- all chunk dims are maindims- no overlap between chunks and slices (e.g. ‘x’ in chunks and slices)
- property chunk_dims
the tuple of dims which are being chunked.
E.g., if chunks={‘x’:10, ‘y_size’:50}, then chunking_dims=’x’, ‘y’.Computed as set of self.chunks keys, with ‘_size’ or ‘_slices’ removed if present.
- dim_chunk_info(x)
return chunking info for dim x: (mode, value).
mode will be ‘n’, ‘size’, or ‘slices’,correspond to x, x_size, or x_slices appearing in self.chunks.value will be int, int, or iterable of slices, respectively.
- iter_slicers()
iterates through all chunk slices, yielding slices dict including any non-chunked slices.
E.g. chunks=dict(x_size=50), slices=dict(z=7) –> yield:
dict(x=slice(0,50), z=7),dict(x=slice(50,100), z=7),…
- property maindims
the maindims. Just the tuple of self.maindims_sizes keys.
- slicers()
list of all slices to use for chunking. Equivalent: list(self.iter_slicers()).