diff --git a/src/tensors/matrix.rs b/src/tensors/matrix.rs index 9b762b0..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 { @@ -1023,6 +1029,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 {