From deb261f64b9439f3a9a686b566c188b0d052e5b9 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 2 Oct 2015 10:33:25 +0200 Subject: Make abs2 compatible with custom complex types --- Eigen/src/Core/MathFunctions.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 45cff0c65..19b7954a9 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -241,8 +241,8 @@ struct conj_retval * Implementation of abs2 * ****************************************************************************/ -template -struct abs2_impl +template +struct abs2_impl_default { typedef typename NumTraits::Real RealScalar; EIGEN_DEVICE_FUNC @@ -252,16 +252,28 @@ struct abs2_impl } }; -template -struct abs2_impl > +template +struct abs2_impl_default // IsComplex { + typedef typename NumTraits::Real RealScalar; EIGEN_DEVICE_FUNC - static inline RealScalar run(const std::complex& x) + static inline RealScalar run(const Scalar& x) { return real(x)*real(x) + imag(x)*imag(x); } }; +template +struct abs2_impl +{ + typedef typename NumTraits::Real RealScalar; + EIGEN_DEVICE_FUNC + static inline RealScalar run(const Scalar& x) + { + return abs2_impl_default::IsComplex>::run(x); + } +}; + template struct abs2_retval { -- cgit v1.2.3