pub type RMatrix<T> = RArray<T, 2>;Aliased Type§
pub struct RMatrix<T> {
robj: Robj,
_data: PhantomData<T>,
}Fields§
§robj: RobjOwning Robj (probably should be a Pin).
_data: PhantomData<T>Data type of the n-array
Implementations§
Source§impl<T> RMatrix<T>
impl<T> RMatrix<T>
pub fn get_colnames(&self) -> Option<Strings>
pub fn get_rownames(&self) -> Option<Strings>
Source§impl<T> RMatrix<T>
impl<T> RMatrix<T>
Sourcepub fn new_matrix<F: Clone + FnMut(usize, usize) -> T>(
nrows: usize,
ncols: usize,
f: F,
) -> Self
pub fn new_matrix<F: Clone + FnMut(usize, usize) -> T>( nrows: usize, ncols: usize, f: F, ) -> Self
Create a new matrix wrapper.
§Arguments
nrows- the number of rows the returned matrix will havencols- the number of columns the returned matrix will havef- a function that will be called for each entry of the matrix in order to populate it with values. It must return a scalar value that can be converted to an R scalar, such asi32,u32, orf64, i.e. see ToVectorValue. It accepts two arguments:r- the current row of the entry we are creatingc- the current column of the entry we are creating
Sourcepub fn row_iter(&self) -> RowIter<'_, T> ⓘ
pub fn row_iter(&self) -> RowIter<'_, T> ⓘ
Returns an iterator over the rows of the matrix.
This method is experimental and likely to be unstable for a while.
Each row is returned as an RColumn<T> containing a copy of the
row’s values in row-major order.
use extendr_api::prelude::*;
test! {
let matrix = RMatrix::new_matrix(3, 2, |r, c| [
[1., 2., 3.],
[4., 5., 6.]][c][r]);
let rows: Vec<_> = matrix.row_iter().collect();
assert_eq!(rows.len(), 3);
assert_eq!(rows[0].data(), &[1., 4.]);
assert_eq!(rows[1].data(), &[2., 5.]);
assert_eq!(rows[2].data(), &[3., 6.]);
}Sourcepub fn col_iter(&self) -> ColIter<'_, T> ⓘ
pub fn col_iter(&self) -> ColIter<'_, T> ⓘ
Returns an iterator over the columns of the matrix.
This method is experimental and likely to be unstable for a while.
Each column is returned as an RColumn<T> containing a copy of the
column’s values.
use extendr_api::prelude::*;
test! {
let matrix = RMatrix::new_matrix(3, 2, |r, c| [
[1., 2., 3.],
[4., 5., 6.]][c][r]);
let cols: Vec<_> = matrix.col_iter().collect();
assert_eq!(cols.len(), 2);
assert_eq!(cols[0].data(), &[1., 2., 3.]);
assert_eq!(cols[1].data(), &[4., 5., 6.]);
}Trait Implementations§
Source§impl From<Mat<f64>> for RMatrix<f64>
Convert a faer::Mat<f64> into an RMatrix<f64> which is not NA aware.
impl From<Mat<f64>> for RMatrix<f64>
Convert a faer::Mat<f64> into an RMatrix<f64> which is not NA aware.
Source§impl From<MatRef<'_, f64>> for RMatrix<f64>
Convert a faer::Mat<f64> into an RMatrix<f64> which is not NA aware.
impl From<MatRef<'_, f64>> for RMatrix<f64>
Convert a faer::Mat<f64> into an RMatrix<f64> which is not NA aware.