Function Jet::Utilities::UnravelIndex

Function Documentation

inline std::vector<size_t> Jet::Utilities::UnravelIndex(unsigned long long index, const std::vector<size_t> &shape)

Converts a linear index into a multi-dimensional index.

The multi-dimensional index is written in row-major order.

Example: To compute the multi-index (i, j) of an element in a 2x2 matrix given a linear index of 2, shape would be {2, 2} and the result would be {1, 0}.

std::vector<size_t> multi_index = UnravelIndex(2, {2, 2});  // {1, 0}

Parameters
  • index – Linear index to be unraveled.

  • shape – Size of each index dimension.

Returns

Multi-index associated with the linear index.