Refactor Matrix implementation to require Clone trait and reorder methods for clarity

This commit is contained in:
Palash Tyagi 2025-04-26 00:22:08 +01:00
parent 56bb579530
commit cf5ae8550e

View File

@ -8,7 +8,7 @@ pub struct Matrix<T> {
data: Vec<T>,
}
impl<T> Matrix<T> {
impl<T: Clone> Matrix<T> {
/// Build from columns (each inner Vec is one column)
pub fn from_cols(cols_data: Vec<Vec<T>>) -> Self {
let cols = cols_data.len();
@ -38,13 +38,22 @@ impl<T> Matrix<T> {
Matrix { rows, cols, data }
}
pub fn rows(&self) -> usize {
self.rows
}
pub fn data(&self) -> &[T] {
&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 {
self.cols
}