extendr_api::prelude::perm

Function swap_cols_idx

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

Swaps the two columns 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_cols_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_cols_idx(m.as_mut(), 0, 2);

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

assert_eq!(m, swapped);