extendr_api::prelude::mat

Function from_row_major_slice_generic

pub fn from_row_major_slice_generic<E>(
    slice: <<E as Entity>::Group as ForType>::FaerOf<&[<E as Entity>::Unit]>,
    nrows: usize,
    ncols: usize,
) -> MatRef<'_, E>
where E: Entity,
Expand description

Creates a MatRef from slice views over the matrix data, and the matrix dimensions. The data is interpreted in a row-major format, so that the first chunk of ncols values from the slices goes in the first column of the matrix, the second chunk of ncols values goes in the second column, and so on.

§Panics

The function panics if any of the following conditions are violated:

  • nrows * ncols == slice.len()

§Example

use faer::mat;

let slice = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0_f64];
let view = mat::from_row_major_slice::<f64>(&slice, 3, 2);

let expected = mat![[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];
assert_eq!(expected, view);