array_split.ShapeSplitter¶
-
class
array_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()] [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.calculate_split()Computes the split. calculate_split_by_indices_per_axis()Returns split calculated using extents obtained from indices_per_axis.calculate_split_by_split_size()Returns split calculated using extents obtained from split_sizeandsplit_num_slices_per_axis.calculate_split_by_tile_max_bytes()Returns split calculated using extents obtained from max_tile_bytes(andmax_tile_shape,sub_tile_shape,halo).calculate_split_by_tile_shape()Returns split calculated using extents obtained from tile_shape.calculate_split_from_extents()Returns split calculated using extents obtained from split_begsandsplit_ends.calculate_split_halos_from_extents()Returns (self.ndim, 2)shaped halo array elements indicating the halo for each split.check_consistent_parameter_dimensions()Ensure that all parameter dimensions are consistent with the array_shapedimension.check_consistent_parameter_grouping()Ensures this object does not have conflicting groups of parameters. check_split_parameters()Ensures this object has a state consistent with evaluating a split. check_tile_bounds_policy()Raises ValueErroriftile_bounds_policyis not in[self.ARRAY_BOUNDS, self.NO_BOUNDS].convert_halo_to_array_form(halo)Converts the haloargument to a(self.array_shape.size, 2)shaped array.set_split_extents()Sets split extents ( split_begsandsplit_ends) calculated using selected attributes set from__init__().set_split_extents_by_indices_per_axis()Sets split shape split_shapeand split extents (split_begsandsplit_ends) from values inindices_per_axis.set_split_extents_by_split_size()Sets split shape split_shapeand split extents (split_begsandsplit_ends) from values insplit_sizeandsplit_num_slices_per_axis.set_split_extents_by_tile_max_bytes()Sets split extents ( split_begsandsplit_ends) calculated using frommax_tile_bytes(andmax_tile_shape,sub_tile_shape,halo).set_split_extents_by_tile_shape()Sets split shape split_shapeand split extents (split_begsandsplit_ends) from value oftile_shape.update_tile_extent_bounds()Updates the tile_beg_minandtile_end_maxdata members according totile_bounds_policy.Attributes
array_itemsizeThe number of bytes per array element, see max_tile_bytes.array_shapeThe shape of the array which is to be split. array_startThe start index. haloPer-axis -ve and +ve halo sizes for extending tiles to overlap with neighbouring tiles. indices_per_axisThe per-axis indices indicating the cuts for the split. loggerClass attribute for logging.Loggerlogging.max_tile_bytesThe maximum number of bytes for any tile (including halo) in the returned split.max_tile_shapePer-axis maximum sizes for calculated tiles. split_begsThe list of per-axis start indices for sliceobjects.split_endsThe list of per-axis stop indices for sliceobjects.split_num_slices_per_axisNumber of slices per axis. split_shapeThe shape of the calculated split array. split_sizeAn intindicating the number of tiles in the calculated split.sub_tile_shapeCalculated tile shape will be an integer multiple of this sub-tile shape. tile_beg_minThe per-axis minimum index for slice.start.tile_bounds_policyA string indicating whether tile halo extents can extend beyond the array domain. tile_end_maxThe per-axis maximum index for slice.stop.tile_shapeThe shape of all tiles in the calculated split. valid_tile_bounds_policiesClass attribute indicating list of valid values for tile_bound_policy.