Merge pull request #31 from Magnus167/bugfix/not_operator

Implement logical NOT for references to boolean matrices
This commit is contained in:
Palash Tyagi 2025-05-02 23:40:12 +01:00 committed by GitHub
commit d2d4764c17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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>;