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_begs and split_ends attributes.

calculate_split()

Calls set_split_extents() followed by calculate_split_from_extents() to return the numpy.ndarray of tuple elements (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.

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_size and split_num_slices_per_axis.

calculate_split_by_tile_max_bytes()

Returns split calculated using extents obtained from max_tile_bytes (and max_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_begs and split_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_shape dimension.

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 ValueError if tile_bounds_policy is not in [self.ARRAY_BOUNDS, self.NO_BOUNDS].

convert_halo_to_array_form(halo)

Converts the halo argument to a (self.array_shape.size, 2) shaped array.

set_split_extents()

Sets split extents (split_begs and split_ends) calculated using selected attributes set from __init__().

set_split_extents_by_indices_per_axis()

Sets split shape split_shape and split extents (split_begs and split_ends) from values in indices_per_axis.

set_split_extents_by_split_size()

Sets split shape split_shape and split extents (split_begs and split_ends) from values in split_size and split_num_slices_per_axis.

set_split_extents_by_tile_max_bytes()

Sets split extents (split_begs and split_ends) calculated using from max_tile_bytes (and max_tile_shape, sub_tile_shape, halo).

set_split_extents_by_tile_shape()

Sets split shape split_shape and split extents (split_begs and split_ends) from value of tile_shape.

update_tile_extent_bounds()

Updates the tile_beg_min and tile_end_max data members according to tile_bounds_policy.

Attributes

array_itemsize

The number of bytes per array element, see max_tile_bytes.

array_shape

The shape of the array which is to be split.

array_start

The start index.

halo

Per-axis -ve and +ve halo sizes for extending tiles to overlap with neighbouring tiles.

indices_per_axis

The per-axis indices indicating the cuts for the split.

logger

Class attribute for logging.Logger logging.

max_tile_bytes

The maximum number of bytes for any tile (including halo) in the returned split.

max_tile_shape

Per-axis maximum sizes for calculated tiles.

split_begs

The list of per-axis start indices for slice objects.

split_ends

The list of per-axis stop indices for slice objects.

split_num_slices_per_axis

Number of slices per axis.

split_shape

The shape of the calculated split array.

split_size

An int indicating the number of tiles in the calculated split.

sub_tile_shape

Calculated tile shape will be an integer multiple of this sub-tile shape.

tile_beg_min

The per-axis minimum index for slice.start.

tile_bounds_policy

A string indicating whether tile halo extents can extend beyond the array domain.

tile_end_max

The per-axis maximum index for slice.stop.

tile_shape

The shape of all tiles in the calculated split.

valid_tile_bounds_policies

Class attribute indicating list of valid values for tile_bound_policy.