pub type RMatrix<T> = RArray<T, 2>;
Aliased Type§
struct RMatrix<T> {
robj: Robj,
_data: PhantomData<T>,
}
Fields§
§robj: Robj
Owning 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
Source§impl<T, const NDIM: usize> RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
impl<T, const NDIM: usize> RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
Source§impl<T, const NDIM: usize> RArray<T, NDIM>
impl<T, const NDIM: usize> RArray<T, NDIM>
pub fn get_dimnames(&self) -> List
Sourcepub fn get_dim(&self) -> Vec<usize>
pub fn get_dim(&self) -> Vec<usize>
Get the dimension vector of the array.
Equivalent to dim()
in R
Sourcepub fn set_names(&mut self, names: Strings)
pub fn set_names(&mut self, names: Strings)
Set the names of the elements of an array.
Equivalent to names<-
in R
Sourcepub fn set_dimnames(&mut self, dimnames: List)
pub fn set_dimnames(&mut self, dimnames: List)
Set the dimension names of an array.
For RMatrix
a list of length 2 is required, as that would entail
column-names and row-names. If you only wish to set one, but not the other,
then the unset element must be R NULL
Equivalent to dimnames<-
in R
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.
Source§impl<T, const NDIM: usize> Index<[usize; NDIM]> for RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
impl<T, const NDIM: usize> Index<[usize; NDIM]> for RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
Source§fn index(&self, index: [usize; NDIM]) -> &Self::Output
fn index(&self, index: [usize; NDIM]) -> &Self::Output
Zero-based indexing for DIM-dimensional arrays.
Panics if out of bounds. Zero-based indexing in row, column order.
Panics if out of bounds.
use extendr_api::prelude::*;
test! {
let matrix = RArray::new_matrix(3, 2, |r, c| [
[1., 2., 3.],
[4., 5., 6.]][c][r]);
assert_eq!(matrix[[0, 0]], 1.);
assert_eq!(matrix[[1, 0]], 2.);
assert_eq!(matrix[[2, 1]], 6.);
let matrix = RArray::new_matrix3d(3, 2, 2, |r, c, d| (r + c + d) as f64);
assert_eq!(matrix[[0, 0, 0]], 0.);
assert_eq!(matrix[[1, 0, 1]], 2.);
assert_eq!(matrix[[2, 1, 1]], 4.);
}
Source§impl<T, const NDIM: usize> IndexMut<[usize; NDIM]> for RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
impl<T, const NDIM: usize> IndexMut<[usize; NDIM]> for RArray<T, NDIM>where
Robj: for<'a> AsTypedSlice<'a, T>,
Source§fn index_mut(&mut self, index: [usize; NDIM]) -> &mut Self::Output
fn index_mut(&mut self, index: [usize; NDIM]) -> &mut Self::Output
Zero-based mutable indexing for DIM-dimensional arrays.
Panics if out of bounds.
use extendr_api::prelude::*;
test! {
let mut matrix = RMatrix::new_matrix(3, 2, |_, _| 0.);
matrix[[0, 0]] = 1.;
matrix[[1, 0]] = 2.;
matrix[[2, 0]] = 3.;
matrix[[0, 1]] = 4.;
assert_eq!(matrix.as_real_slice().unwrap(), &[1., 2., 3., 4., 0., 0.]);
let mut matrix = RMatrix3D::new_matrix3d(3, 2, 2, |_, _, _| 0.);
matrix[[0, 0, 0]] = 1.;
matrix[[1, 0, 0]] = 2.;
matrix[[2, 0, 0]] = 3.;
matrix[[0, 1, 0]] = 4.;
assert_eq!(matrix.as_real_slice().unwrap(),
&[1., 2., 3., 4., 0., 0., 0., 0., 0., 0., 0., 0.]);
}