Template Function Indexer::indexer

Function Documentation

template<typename T = size_t, typename D = std::vector<T>, typename L = D>
T Indexer::indexer(const D &dims, const L &loc)

Produces a one-dimensional index of an array given a multi-dimensional location.

Given the dimensions of a mulit-dimensional array and a vector of positions across those dimensions, this function returns the corresponding index of that location within the flattened, one-dimensional representation of the array, as it would typically be stored in memory, or when a multi-dimensional spatial array is flattened into a single logical dimension.

Parameters:
  • dims – An ordered container holding the sequence of dimension sizes.

  • loc – An ordered container holding the position in each dimension.

Returns:

The flattened one-dimensional index corresponding to the two input arguments.