array_split.split.calculate_tile_shape_for_max_bytes

array_split.split.calculate_tile_shape_for_max_bytes(array_shape, array_itemsize, max_tile_bytes, max_tile_shape=None, sub_tile_shape=None, halo=None)[source]

Returns a tile shape tile_shape such that numpy.product(tile_shape)*numpy.sum(array_itemsize) <= max_tile_bytes. Also, if max_tile_shape is not None then numpy.all(tile_shape <= max_tile_shape) is True and if sub_tile_shape is not None the numpy.all((tile_shape % sub_tile_shape) == 0) is True.

Parameters:
  • array_shape (sequence of int) – Shape of the array which is to be split into tiles.
  • array_itemsize (int) – The number of bytes per element of the array to be tiled.
  • max_tile_bytes (int) – The maximum number of bytes for the returned tile_shape.
  • max_tile_shape (sequence of int) – Per axis maximum shapes for the returned tile_shape.
  • sub_tile_shape (sequence of int) – The returned tile_shape will be an even multiple of this sub-tile shape.
  • halo (int, sequence of int, or (len(array_shape), 2) shaped numpy.ndarray) – How tiles are extended in each axis direction with halo elements. See The halo parameter for meaning of halo values.
Return type:

numpy.ndarray

Returns:

A 1D array of shape (len(array_shape),) indicating a tile shape which will (approximately) uniformly divide the given array_shape into tiles (sub-arrays).

Examples:

>>> from array_split.split import calculate_tile_shape_for_max_bytes
>>> calculate_tile_shape_for_max_bytes(
... array_shape=[512,],
... array_itemsize=1,
... max_tile_bytes=512
... )
array([512])
>>> calculate_tile_shape_for_max_bytes(
... array_shape=[512,],
... array_itemsize=2,  # Doubling the itemsize halves the tile size.
... max_tile_bytes=512
... )
array([256])
>>> calculate_tile_shape_for_max_bytes(
... array_shape=[512,],
... array_itemsize=1,
... max_tile_bytes=512-1  # tile shape will now be halved
... )
array([256])