unravel_index

Function unravel_index 

Source
pub fn unravel_index<T, S: Shape, L: Layout>(
    x: &Slice<T, S, L>,
    flat: usize,
) -> Vec<usize>
Expand description

Converts a flat index to multidimensional coordinates.

§Examples

use mdarray::DTensor;
use mdarray_linalg::unravel_index;

let x = DTensor::<usize, 2>::from_fn([2,3], |i| i[0] + i[1]);

assert_eq!(unravel_index(&x, 0), vec![0, 0]);
assert_eq!(unravel_index(&x, 4), vec![1, 1]);
assert_eq!(unravel_index(&x, 5), vec![1, 2]);

§Panics

Panics if flat is out of bounds (>= x.len()).