pub struct Matrix<T: Send + Sync> { /* private fields */ }Expand description
A lightweight Matrix abstraction that does almost nothing.
Implementations§
Source§impl<T: Send + Sync> Matrix<T>
impl<T: Send + Sync> Matrix<T>
pub fn from_raw_parts(values: Vec<T>, n_rows: usize) -> Self
pub fn nelem(&self) -> usize
pub fn raw_values(&self) -> &Vec<T>
pub fn raw_values_mut(&mut self) -> &mut Vec<T>
Sourcepub fn rows_mut(&mut self) -> ChunksExactMut<'_, T>
pub fn rows_mut(&mut self) -> ChunksExactMut<'_, T>
Create a mutable iterator through rows
§Example
let vecs: Vec<Vec<u8>> = vec![
vec![0, 1, 2],
vec![3, 4, 5],
];
let mut mat = Matrix::from_vecs(vecs);
mat.rows_mut().for_each(|mut row| {
row.iter_mut().for_each(|mut x| *x += 1 );
});
assert_eq!(mat.raw_values(), &vec![1, 2, 3, 4, 5, 6])Sourcepub fn par_rows_mut(&mut self) -> ChunksExactMut<'_, T>
pub fn par_rows_mut(&mut self) -> ChunksExactMut<'_, T>
Parallel version of rows_mut
Sourcepub fn rows(&self) -> ChunksExact<'_, T>
pub fn rows(&self) -> ChunksExact<'_, T>
Create an iterator through rows
§Example
let vecs: Vec<Vec<u8>> = vec![
vec![0, 1, 2],
vec![3, 4, 5],
];
let mut mat = Matrix::from_vecs(vecs);
let rowsum: Vec<u8> = mat.rows().map(|row| {
row.iter().sum::<u8>()
})
.collect();
assert_eq!(rowsum, vec![3_u8, 12_u8])Sourcepub fn par_rows(&self) -> ChunksExact<'_, T>
pub fn par_rows(&self) -> ChunksExact<'_, T>
Parallel version of rows
Sourcepub fn implicit_transpose(self) -> ImplicitlyTransposedMatrix<T>
pub fn implicit_transpose(self) -> ImplicitlyTransposedMatrix<T>
Does an implicit transpose by inverting coordinates.
§Notes
The matrix is not rebuild, so if you are attempting to access the transposed matrix row-wise many times, there will be a lot of cache misses. This method is best used if you plan to traverse the transposed matrix a small number of times.
§Example
use lace_utils::Shape;
let vecs: Vec<Vec<u32>> = vec![
vec![0, 1, 2],
vec![3, 4, 5],
vec![6, 7, 8],
vec![9, 10, 11],
];
let mat = Matrix::from_vecs(vecs);
let mat_t = mat.clone().implicit_transpose();
assert_eq!(mat.n_rows(), mat_t.n_cols());
assert_eq!(mat.n_cols(), mat_t.n_rows());
for i in 0..3 {
for j in 0..3 {
assert_eq!(mat[(i, j)], mat_t[(j, i)]);
}
}
Source§impl<T: Send + Sync + Clone> Matrix<T>
impl<T: Send + Sync + Clone> Matrix<T>
Sourcepub fn vtile(col: Vec<T>, n_cols: usize) -> Self
pub fn vtile(col: Vec<T>, n_cols: usize) -> Self
Treat the input vector, col like a column vector and replicate it
n_cols times.
§Example
let col: Vec<u32> = vec![0, 1, 2];
let mat = Matrix::vtile(col, 12);
assert_eq!(mat[(0, 0)], 0);
assert_eq!(mat[(0, 11)], 0);
assert_eq!(mat[(1, 0)], 1);
assert_eq!(mat[(1, 11)], 1);
assert_eq!(mat[(2, 0)], 2);
assert_eq!(mat[(2, 11)], 2);Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Matrix<T>
impl<T> RefUnwindSafe for Matrix<T>where
T: RefUnwindSafe,
impl<T> Send for Matrix<T>
impl<T> Sync for Matrix<T>
impl<T> Unpin for Matrix<T>where
T: Unpin,
impl<T> UnwindSafe for Matrix<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more