Merge pull request #31 from Magnus167/bugfix/not_operator

Implement logical NOT for references to boolean matrices
This commit is contained in:
2025-05-02 23:40:12 +01:00
committed by GitHub

View File

@@ -364,6 +364,21 @@ impl Not for Matrix<bool> {
}
}
// implement for &Matrix<bool>
impl<'a> Not for &'a Matrix<bool> {
type Output = Matrix<bool>;
fn not(self) -> Matrix<bool> {
// Invert each boolean element in the matrix
let data = self.data.iter().map(|&v| !v).collect();
Matrix {
rows: self.rows,
cols: self.cols,
data,
}
}
}
pub type FloatMatrix = Matrix<f64>;
pub type BoolMatrix = Matrix<bool>;
pub type IntMatrix = Matrix<i32>;