Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/tensors/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ impl<F: Ring> Matrix<F> {
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<G: Ring>(&self, f: impl Fn(&F::Element) -> G::Element, field: G) -> Matrix<G> {
Matrix {
Expand Down Expand Up @@ -1023,6 +1029,24 @@ impl<F: Ring> Matrix<F> {
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<F>) {
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<F>) {
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<F::Element, MatrixError<F>> {
if self.nrows != self.ncols {
Expand Down
Loading