pub fn swap_cols<T>(
m: &mut Matrix<T>,
a: usize,
b: usize,
) -> Result<(), MatrixShapeError>Expand description
Swap two columns in a matrix in-place.
No-op if a == b, after validating that the index exists.
§Errors
Returns MatrixShapeError::ColumnIndexOutOfBounds if either index is not
less than m.ncols().
§Examples
use tensor4all_tensorbackend::{from_vec2d, swap_cols};
let mut m = from_vec2d(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
swap_cols(&mut m, 0, 1).unwrap();
assert_eq!(m[[0, 0]], 2.0);
assert_eq!(m[[0, 1]], 1.0);