Skip to main content

perm_from_forward

Function perm_from_forward 

Source
pub fn perm_from_forward(fwd: Vec<usize>) -> Result<Perm<usize>, SparseError>
Expand description

Construct a Perm<usize> from a forward permutation array, computing the inverse automatically.

Takes ownership of the forward array to avoid an extra allocation when converting to Box<[usize]> for faer’s Perm::new_checked.

§Errors

Returns SparseError::InvalidInput if the array contains duplicate indices or out-of-bounds values.

§Examples

use rivrs_sparse::ordering::perm_from_forward;

let fwd = vec![2, 0, 1];
let perm = perm_from_forward(fwd).unwrap();
let (fwd_arr, inv_arr) = perm.as_ref().arrays();
assert_eq!(fwd_arr, &[2, 0, 1]);
assert_eq!(inv_arr, &[1, 2, 0]);