mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 07:09: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> {
|
impl<T: PartialOrd + Clone> Matrix<T> {
|
||||||
$(
|
$(
|
||||||
#[doc = concat!("Element-wise comparison `self ", stringify!($op), " rhs`,\n\
|
#[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
|
pub fn $method<Rhs>(&self, rhs: Rhs) -> BoolMatrix
|
||||||
where
|
where
|
||||||
Rhs: Broadcastable<T>,
|
Rhs: Broadcastable<T>,
|
||||||
{
|
{
|
||||||
// Prepare broadcasted rhs-data
|
// Prepare broadcasted rhs-data using the trait
|
||||||
let rhs_data = rhs.to_vec(self.rows, self.cols);
|
let rhs_data = rhs.to_vec(self.rows, self.cols);
|
||||||
|
|
||||||
// Pairwise compare
|
// Pairwise compare using iterators
|
||||||
let data = self
|
let data = self
|
||||||
.data
|
.data
|
||||||
.iter()
|
.iter() // Borrow self's data
|
||||||
.cloned()
|
.zip(rhs_data.iter()) // Borrow rhs's broadcasted data
|
||||||
.zip(rhs_data.into_iter())
|
.map(|(a, b)| a $op b) // Perform comparison op
|
||||||
.map(|(a, b)| a $op b)
|
|
||||||
.collect();
|
.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