mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:19:59 +00:00
Enhance element-wise comparison methods to optimize data handling
This commit is contained in:
parent
ecb1939ec2
commit
10c6116f8f
@ -372,24 +372,25 @@ macro_rules! impl_elementwise_cmp {
|
||||
impl<T: PartialOrd + Clone> Matrix<T> {
|
||||
$(
|
||||
#[doc = concat!("Element-wise comparison `self ", stringify!($op), " rhs`,\n\
|
||||
where `rhs` may be a `Matrix<T>` or a scalar T.")]
|
||||
where `rhs` may be a `Matrix<T>` or a scalar T.\n\
|
||||
Returns a `BoolMatrix`.")]
|
||||
pub fn $method<Rhs>(&self, rhs: Rhs) -> BoolMatrix
|
||||
where
|
||||
Rhs: Broadcastable<T>,
|
||||
{
|
||||
// Prepare broadcasted rhs-data
|
||||
// Prepare broadcasted rhs-data using the trait
|
||||
let rhs_data = rhs.to_vec(self.rows, self.cols);
|
||||
|
||||
// Pairwise compare
|
||||
// Pairwise compare using iterators
|
||||
let data = self
|
||||
.data
|
||||
.iter()
|
||||
.cloned()
|
||||
.zip(rhs_data.into_iter())
|
||||
.map(|(a, b)| a $op b)
|
||||
.iter() // Borrow self's data
|
||||
.zip(rhs_data.iter()) // Borrow rhs's broadcasted data
|
||||
.map(|(a, b)| a $op b) // Perform comparison op
|
||||
.collect();
|
||||
|
||||
BoolMatrix::from_vec(data, self.rows, self.cols)
|
||||
// Create BoolMatrix from result
|
||||
Matrix::<bool>::from_vec(data, self.rows, self.cols)
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user