From 8ef46d62cbd52f44b76065fde931374a0f18a2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 24 Mar 2020 19:05:47 +0100 Subject: [PATCH] Re-add inf/sup. --- src/base/componentwise.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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)) + } +}