From cf5ae8550eaa9632f215c902313e9a3125212e5e Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 26 Apr 2025 00:22:08 +0100 Subject: [PATCH] Refactor Matrix implementation to require Clone trait and reorder methods for clarity --- src/matrix/mat.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/matrix/mat.rs b/src/matrix/mat.rs index 400facc..6378172 100644 --- a/src/matrix/mat.rs +++ b/src/matrix/mat.rs @@ -8,7 +8,7 @@ pub struct Matrix { data: Vec, } -impl Matrix { +impl Matrix { /// Build from columns (each inner Vec is one column) pub fn from_cols(cols_data: Vec>) -> Self { let cols = cols_data.len(); @@ -38,13 +38,22 @@ impl Matrix { 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 { + self.data.clone() + } + + pub fn rows(&self) -> usize { + self.rows + } + pub fn cols(&self) -> usize { self.cols }