flat_index_mapping

sofia_redux.toolkit.splines.spline_utils.flat_index_mapping(shape)[source]

Return index slices for Numba flattened arrays.

Given the shape of an array, return a variety of useful parameters for indexing a flattened (x.ravel()) version of that array.

For example, consider an array (x) of shape (3, 4):

x = [[ 0, 1, 2, 3],

[ 4, 5, 6, 7], [ 8, 9, 10, 11]]

which when flattened (x_flat) is equal to

x_flat = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

map_indices returns the indices of x_flat on x, and is a 2-D array of shape (n_dimensions, x.size). map_indices[:, 6] gives the N-D index of element 6 of x_flat in terms of x. i.e, map_indices[:, 6] = [1, 2].

transpose_indices contains the flat indices of an array that has been transposed. i.e. x.T.ravel()[transpose_indices] == x_flat

step_size contains indicates the flat index jump along the given dimension. i.e., the step size for the above example is [4, 1], indicating that for every increment along the first dimension, the flat index increments by 4. Likewise, for every increment along the second dimension, the flat index increments by 1.

Parameters:
shapenumpy.ndarray (int)
Returns:
map_indices, transpose_indices, step_size