From 8b6f53222b84d1e4f0f1e86b1d321777b58a28dc Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 2 Jun 2016 15:29:59 +0200 Subject: bug #1193: fix lpNorm for empty input. --- Eigen/src/Core/Dot.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Eigen/src/Core/Dot.h') diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 82d58fc0b..f3c869635 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -227,9 +227,12 @@ struct lpNorm_selector template struct lpNorm_selector { + typedef typename NumTraits::Scalar>::Real RealScalar; EIGEN_DEVICE_FUNC - static inline typename NumTraits::Scalar>::Real run(const MatrixBase& m) + static inline RealScalar run(const MatrixBase& m) { + if(Derived::SizeAtCompileTime==0 || (Derived::SizeAtCompileTime==Dynamic && m.size()==0)) + return RealScalar(0); return m.cwiseAbs().maxCoeff(); } }; @@ -240,6 +243,8 @@ struct lpNorm_selector * of the coefficients of \c *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^\infty \f$ * norm, that is the maximum of the absolute values of the coefficients of \c *this. * + * In all cases, if \c *this is empty, then the value 0 is returned. + * * \note For matrices, this function does not compute the operator-norm. That is, if \c *this is a matrix, then its coefficients are interpreted as a 1D vector. Nonetheless, you can easily compute the 1-norm and \f$\infty\f$-norm matrix operator norms using \link TutorialReductionsVisitorsBroadcastingReductionsNorm partial reductions \endlink. * * \sa norm() -- cgit v1.2.3