extendr_api::prelude::perm

Function swap_rows_idx

pub fn swap_rows_idx<E>(mat: MatMut<'_, E>, a: usize, b: usize)
where E: ComplexField,
Expand description

Swaps the two rows at indices a and b in the given matrix.

§Panics

Panics if either a or b is out of bounds.

§Example

use faer::{mat, perm::swap_rows_idx};

let mut m = mat![
    [1.0, 2.0, 3.0],
    [4.0, 5.0, 6.0],
    [7.0, 8.0, 9.0],
    [10.0, 14.0, 12.0],
];

swap_rows_idx(m.as_mut(), 0, 2);

let swapped = mat![
    [7.0, 8.0, 9.0],
    [4.0, 5.0, 6.0],
    [1.0, 2.0, 3.0],
    [10.0, 14.0, 12.0],
];

assert_eq!(m, swapped);