array_split.split.ShapeSplitter¶
- class array_split.split.ShapeSplitter(array_shape, indices_or_sections=None, axis=None, array_start=None, array_itemsize=1, tile_shape=None, max_tile_bytes=None, max_tile_shape=None, sub_tile_shape=None, halo=None, tile_bounds_policy=<property object>)[source]¶
Implements array shape splitting. There are three main (top-level) methods:
__init__()Initialisation of parameters which define the split.
set_split_extents()Calculates the per-axis indices for the cuts. Sets the
split_shape,split_begsandsplit_endsattributes.calculate_split()Calls
set_split_extents()followed bycalculate_split_from_extents()to return thenumpy.ndarrayoftupleelements (slices).
Example:
>>> import numpy as np >>> ary = np.arange(0, 10) >>> splitter = ShapeSplitter(ary.shape, 3) >>> split = splitter.calculate_split() >>> split.shape (3,) >>> split array([(slice(0, 4, None),), (slice(4, 7, None),), (slice(7, 10, None),)], dtype=[('0', 'O')]) >>> [ary[slyce] for slyce in split.flatten().tolist()] [array([0, 1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])] >>> >>> splitter.split_shape # equivalent to split.shape above array([3]) >>> splitter.split_begs # start indices for tile extents [array([0, 4, 7])] >>> splitter.split_ends # stop indices for tile extents [array([ 4, 7, 10])]
Methods
__init__(array_shape[, indices_or_sections, ...])Initialises parameters which define a split.
calculate_axis_split_extents(num_sections, size)Divides
range(0, size)into (approximately) equal sized intervals.Computes the split.
Returns split calculated using extents obtained from
indices_per_axis.Returns split calculated using extents obtained from
split_sizeandsplit_num_slices_per_axis.Returns split calculated using extents obtained from
max_tile_bytes(andmax_tile_shape,sub_tile_shape,halo).Returns split calculated using extents obtained from
tile_shape.Returns split calculated using extents obtained from
split_begsandsplit_ends.Returns
(self.ndim, 2)shaped halo array elements indicating the halo for each split.Ensure that all parameter dimensions are consistent with the
array_shapedimension.Ensures this object does not have conflicting groups of parameters.
Ensures this object has a state consistent with evaluating a split.
Raises
ValueErroriftile_bounds_policyis not in[self.ARRAY_BOUNDS, self.NO_BOUNDS].Converts the
haloargument to a(self.array_shape.size, 2)shaped array.Sets split extents (
split_begsandsplit_ends) calculated using selected attributes set from__init__().Sets split shape
split_shapeand split extents (split_begsandsplit_ends) from values inindices_per_axis.Sets split shape
split_shapeand split extents (split_begsandsplit_ends) from values insplit_sizeandsplit_num_slices_per_axis.Sets split extents (
split_begsandsplit_ends) calculated using frommax_tile_bytes(andmax_tile_shape,sub_tile_shape,halo).Sets split shape
split_shapeand split extents (split_begsandsplit_ends) from value oftile_shape.Updates the
tile_beg_minandtile_end_maxdata members according totile_bounds_policy.Attributes
The number of bytes per array element, see
max_tile_bytes.The shape of the array which is to be split.
The start index.
Per-axis -ve and +ve halo sizes for extending tiles to overlap with neighbouring tiles.
The per-axis indices indicating the cuts for the split.
Class attribute for
logging.Loggerlogging.The maximum number of bytes for any tile (including
halo) in the returned split.Per-axis maximum sizes for calculated tiles.
The list of per-axis start indices for
sliceobjects.The list of per-axis stop indices for
sliceobjects.Number of slices per axis.
The shape of the calculated split array.
An
intindicating the number of tiles in the calculated split.Calculated tile shape will be an integer multiple of this sub-tile shape.
The per-axis minimum index for
slice.start.A string indicating whether tile halo extents can extend beyond the array domain.
The per-axis maximum index for
slice.stop.The shape of all tiles in the calculated split.
Class attribute indicating list of valid values for
tile_bound_policy.