Re-add inf/sup.

This commit is contained in:
Sébastien Crozet 2020-03-24 19:05:47 +01:00
parent cdbc9da46c
commit 8ef46d62cb

View File

@ -4,6 +4,7 @@ use num::{Signed, Zero};
use std::ops::{Add, Mul}; use std::ops::{Add, Mul};
use simba::scalar::{ClosedDiv, ClosedMul}; use simba::scalar::{ClosedDiv, ClosedMul};
use simba::simd::SimdPartialOrd;
use crate::base::allocator::{Allocator, SameShapeAllocator}; use crate::base::allocator::{Allocator, SameShapeAllocator};
use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
@ -235,3 +236,31 @@ component_binop_impl!(
"; ";
// FIXME: add other operators like bitshift, etc. ? // FIXME: add other operators like bitshift, etc. ?
); );
/*
* inf/sup
*/
impl<N, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S>
where
N: Scalar + SimdPartialOrd,
DefaultAllocator: Allocator<N, R, C>,
{
/// Computes the infimum (aka. componentwise min) of two matrices/vectors.
#[inline]
pub fn inf(&self, other: &Self) -> MatrixMN<N, R, C> {
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<N, R, C> {
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<N, R, C>, MatrixMN<N, R, C>) {
// FIXME: can this be optimized?
(self.inf(other), self.sup(other))
}
}