diff options
author | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-02-26 09:21:24 -0800 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-02-26 09:21:24 -0800 |
commit | fe19714f8094a2b6d6dab0cdd3c32874d0ad66b9 (patch) | |
tree | cbcbc577a8f7a7e2710e0cece87ea6a35d7c004d /Eigen | |
parent | e19829c3b0802c01c942fe9d095688f8ce2dcc7b (diff) | |
parent | e67672024d82ad4fb173d647842e0a8ad2448fa1 (diff) |
Merge branch 'rmlarsen1/eigen-nan_prop'
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/DenseBase.h | 14 | ||||
-rw-r--r-- | Eigen/src/Core/Redux.h | 18 |
2 files changed, 27 insertions, 5 deletions
diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 767a8e274..20cc4821a 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -449,9 +449,23 @@ template<typename Derived> class DenseBase EIGEN_DEVICE_FUNC Scalar prod() const; + template<int NaNPropagation> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const; + template<int NaNPropagation> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const; + + // By default, the fastest version with undefined NaN propagation semantics is + // used. + // TODO(rmlarsen): Replace with default template argument when we move to + // c++11 or beyond. + EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff() const { + return minCoeff<PropagateFast>(); + } + EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar maxCoeff() const { + return maxCoeff<PropagateFast>(); + } + template<typename IndexType> EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const; template<typename IndexType> EIGEN_DEVICE_FUNC diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 2eef5abc5..30598f415 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -419,25 +419,33 @@ DenseBase<Derived>::redux(const Func& func) const } /** \returns the minimum of all coefficients of \c *this. + * In case \c *this contains NaN, NaNPropagation determines the behavior: + * NaNPropagation == PropagateFast : undefined + * NaNPropagation == PropagateNaN : result is NaN + * NaNPropagation == PropagateNumbers : result is minimum of elements that are not NaN * \warning the matrix must be not empty, otherwise an assertion is triggered. - * \warning the result is undefined if \c *this contains NaN. */ template<typename Derived> +template<int NaNPropagation> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar DenseBase<Derived>::minCoeff() const { - return derived().redux(Eigen::internal::scalar_min_op<Scalar,Scalar>()); + return derived().redux(Eigen::internal::scalar_min_op<Scalar,Scalar, NaNPropagation>()); } -/** \returns the maximum of all coefficients of \c *this. +/** \returns the maximum of all coefficients of \c *this. + * In case \c *this contains NaN, NaNPropagation determines the behavior: + * NaNPropagation == PropagateFast : undefined + * NaNPropagation == PropagateNaN : result is NaN + * NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN * \warning the matrix must be not empty, otherwise an assertion is triggered. - * \warning the result is undefined if \c *this contains NaN. */ template<typename Derived> +template<int NaNPropagation> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar DenseBase<Derived>::maxCoeff() const { - return derived().redux(Eigen::internal::scalar_max_op<Scalar,Scalar>()); + return derived().redux(Eigen::internal::scalar_max_op<Scalar,Scalar, NaNPropagation>()); } /** \returns the sum of all coefficients of \c *this |