diff --git a/src/base/componentwise.rs b/src/base/componentwise.rs index 9f6d68eb..d5a57b6c 100644 --- a/src/base/componentwise.rs +++ b/src/base/componentwise.rs @@ -4,6 +4,7 @@ use num::{Signed, Zero}; use std::ops::{Add, Mul}; use simba::scalar::{ClosedDiv, ClosedMul}; +use simba::simd::SimdPartialOrd; use crate::base::allocator::{Allocator, SameShapeAllocator}; use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; @@ -235,3 +236,31 @@ component_binop_impl!( "; // FIXME: add other operators like bitshift, etc. ? ); + +/* + * inf/sup + */ +impl> Matrix +where + N: Scalar + SimdPartialOrd, + DefaultAllocator: Allocator, +{ + /// Computes the infimum (aka. componentwise min) of two matrices/vectors. + #[inline] + pub fn inf(&self, other: &Self) -> MatrixMN { + self.zip_map(other, |a, b| a.simd_min(b)) + } + + /// Computes the supremum (aka. componentwise max) of two matrices/vectors. + #[inline] + pub fn sup(&self, other: &Self) -> MatrixMN { + self.zip_map(other, |a, b| a.simd_max(b)) + } + + /// Computes the (infimum, supremum) of two matrices/vectors. + #[inline] + pub fn inf_sup(&self, other: &Self) -> (MatrixMN, MatrixMN) { + // FIXME: can this be optimized? + (self.inf(other), self.sup(other)) + } +}