mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 07:09:59 +00:00
Refactor Matrix implementation to require Clone trait and reorder methods for clarity
This commit is contained in:
parent
56bb579530
commit
cf5ae8550e
@ -8,7 +8,7 @@ pub struct Matrix<T> {
|
|||||||
data: Vec<T>,
|
data: Vec<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Matrix<T> {
|
impl<T: Clone> Matrix<T> {
|
||||||
/// Build from columns (each inner Vec is one column)
|
/// Build from columns (each inner Vec is one column)
|
||||||
pub fn from_cols(cols_data: Vec<Vec<T>>) -> Self {
|
pub fn from_cols(cols_data: Vec<Vec<T>>) -> Self {
|
||||||
let cols = cols_data.len();
|
let cols = cols_data.len();
|
||||||
@ -38,13 +38,22 @@ impl<T> Matrix<T> {
|
|||||||
Matrix { rows, cols, data }
|
Matrix { rows, cols, data }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rows(&self) -> usize {
|
|
||||||
self.rows
|
|
||||||
}
|
|
||||||
pub fn data(&self) -> &[T] {
|
pub fn data(&self) -> &[T] {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn data_mut(&mut self) -> &mut [T] {
|
||||||
|
&mut self.data
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_vec(&self) -> Vec<T> {
|
||||||
|
self.data.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rows(&self) -> usize {
|
||||||
|
self.rows
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cols(&self) -> usize {
|
pub fn cols(&self) -> usize {
|
||||||
self.cols
|
self.cols
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user