From f845a8bb1a8bb560d4a4cbad71c2d559aeceb9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Sat, 16 Apr 2022 05:07:44 +0000 Subject: [PATCH] Fix cwise NaN propagation for scalar input. --- Eigen/src/plugins/MatrixCwiseBinaryOps.h | 6 +++--- test/array_for_matrix.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Eigen/src/plugins/MatrixCwiseBinaryOps.h b/Eigen/src/plugins/MatrixCwiseBinaryOps.h index fa84c3cfc..46fe08ce8 100644 --- a/Eigen/src/plugins/MatrixCwiseBinaryOps.h +++ b/Eigen/src/plugins/MatrixCwiseBinaryOps.h @@ -86,10 +86,10 @@ cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const */ template EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const ConstantReturnType> +EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const ConstantReturnType> cwiseMin(const Scalar &other) const { - return cwiseMin(Derived::Constant(rows(), cols(), other)); + return cwiseMin(Derived::Constant(rows(), cols(), other)); } /** \returns an expression of the coefficient-wise max of *this and \a other @@ -116,7 +116,7 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const ConstantReturnType> cwiseMax(const Scalar &other) const { - return cwiseMax(Derived::Constant(rows(), cols(), other)); + return cwiseMax(Derived::Constant(rows(), cols(), other)); } diff --git a/test/array_for_matrix.cpp b/test/array_for_matrix.cpp index 8086b3432..06e04a2fa 100644 --- a/test/array_for_matrix.cpp +++ b/test/array_for_matrix.cpp @@ -219,11 +219,20 @@ template void cwise_min_max(const MatrixType& m) VERIFY((numext::isnan)(m1.template cwiseMin(MatrixType::Constant(rows,cols, Scalar(1)))(0,0))); VERIFY(!(numext::isnan)(m1.template cwiseMax(MatrixType::Constant(rows,cols, Scalar(1)))(0,0))); VERIFY(!(numext::isnan)(m1.template cwiseMin(MatrixType::Constant(rows,cols, Scalar(1)))(0,0))); + VERIFY((numext::isnan)(m1.template cwiseMax(Scalar(1))(0,0))); + VERIFY((numext::isnan)(m1.template cwiseMin(Scalar(1))(0,0))); + VERIFY(!(numext::isnan)(m1.template cwiseMax(Scalar(1))(0,0))); + VERIFY(!(numext::isnan)(m1.template cwiseMin(Scalar(1))(0,0))); + VERIFY((numext::isnan)(m1.array().template max(MatrixType::Constant(rows,cols, Scalar(1)).array())(0,0))); VERIFY((numext::isnan)(m1.array().template min(MatrixType::Constant(rows,cols, Scalar(1)).array())(0,0))); VERIFY(!(numext::isnan)(m1.array().template max(MatrixType::Constant(rows,cols, Scalar(1)).array())(0,0))); VERIFY(!(numext::isnan)(m1.array().template min(MatrixType::Constant(rows,cols, Scalar(1)).array())(0,0))); + VERIFY((numext::isnan)(m1.array().template max(Scalar(1))(0,0))); + VERIFY((numext::isnan)(m1.array().template min(Scalar(1))(0,0))); + VERIFY(!(numext::isnan)(m1.array().template max(Scalar(1))(0,0))); + VERIFY(!(numext::isnan)(m1.array().template min(Scalar(1))(0,0))); // Reductions. VERIFY((numext::isnan)(m1.template maxCoeff()));