From 69c821539a5b0036a80a8f1eaf22033095a2b4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20K=C3=A4lin?= Date: Wed, 1 Jul 2026 15:05:59 +0200 Subject: [PATCH 1/2] Implement append_row and concatenate for Matrix --- src/tensors/matrix.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tensors/matrix.rs b/src/tensors/matrix.rs index 9b762b0..a0bbb15 100644 --- a/src/tensors/matrix.rs +++ b/src/tensors/matrix.rs @@ -1023,6 +1023,24 @@ impl Matrix { Ok((m1, m2)) } + /// Appends a row to the matrix. + /// + /// The number of columns of the matrix and the length of the vector need to agree. + pub fn append_row(&mut self, row: Vector) { + assert_eq!(self.ncols as usize, row.len()); + self.nrows += 1; + self.data.extend(row.data); + } + + /// Concatenates two matrices, i.e. appends the rows of the `other` matrix to `self`. + /// + /// The number of columns of the two matrices need to agree. + pub fn concatenate(&mut self, other: Matrix) { + assert_eq!(self.ncols, other.ncols); + self.nrows += other.nrows; + self.data.extend(other.data); + } + /// Compute the determinant of the matrix. pub fn det(&self) -> Result> { if self.nrows != self.ncols { From 1d2abecfb1fb7897ad9eb0a2d53458921da8cc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20K=C3=A4lin?= Date: Wed, 1 Jul 2026 15:15:21 +0200 Subject: [PATCH 2/2] Adding iter_mut for Matrix --- src/tensors/matrix.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tensors/matrix.rs b/src/tensors/matrix.rs index a0bbb15..968b33b 100644 --- a/src/tensors/matrix.rs +++ b/src/tensors/matrix.rs @@ -922,6 +922,12 @@ impl Matrix { self.data.iter() } + /// Return a row-first iterator over the mutable entries of the matrix. + pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, F::Element> { + self.data.iter_mut() + } + + /// Apply a function `f` to each entry of the matrix. pub fn map(&self, f: impl Fn(&F::Element) -> G::Element, field: G) -> Matrix { Matrix {