Skip to main content

swap_rows

Function swap_rows 

Source
pub fn swap_rows<T>(
    m: &mut Matrix<T>,
    a: usize,
    b: usize,
) -> Result<(), MatrixShapeError>
Expand description

Swap two rows in a matrix in-place.

No-op if a == b, after validating that the index exists.

§Errors

Returns MatrixShapeError::RowIndexOutOfBounds if either index is not less than m.nrows().

§Examples

use tensor4all_tensorbackend::{from_vec2d, swap_rows};

let mut m = from_vec2d(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
swap_rows(&mut m, 0, 1).unwrap();
assert_eq!(m[[0, 0]], 3.0);
assert_eq!(m[[1, 0]], 1.0);