rydiqule.slicing.slicing.compute_grid

rydiqule.slicing.slicing.compute_grid(stack_shape: Tuple[int, ...], n_slices: int) List[ndarray][source]

Calculate the bin edges to break a given stack shape into at least a certain number of pieces

Works by iterating first over a number of slices per axis (N=1,2,3), then over each in the stack shape, splitting the axis into N slices, and comparing the total number of slices to the number specified. In a sense, the algorithm factors a number greater than or equal to n_slices, then breaks the stack along each axis according to this factorization. If the axis lengths do not break evenly into the appropriate number of pieces, the bin edges are truncated to an integer. This means that the slices are not guaranteed to be (1/n_slices), but they will be close enough for most cases.

Parameters:
  • stack_shape (tuple of int) – The shape of the stack to be sliced. Does not include Hamiltonian or matrix equation dimensions, so for a hamiltonain stack of shape (*l,n,n), stack_shape will be *l.

  • n_slices (int) – The number of slices into which to break the hamiltonian. Lower bound on the number of slices there will actually be.

Returns:

The list of bin edges axis by axis. Can be passed to matrix_slice() as the edges argument.

Return type:

list(np.ndarray)

Examples

>>> import rydiqule.slicing.slicing as slicing
>>> stack_shape=(10,10)
>>> print(slicing.compute_grid(stack_shape, 4))
[array([ 0,  5, 10]), array([ 0,  5, 10])]
>>> print(slicing.compute_grid(stack_shape, 6))
[array([ 0,  3,  6, 10]), array([ 0,  5, 10])]