diff options
author | Gael Guennebaud <g.gael@free.fr> | 2015-10-02 10:33:25 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2015-10-02 10:33:25 +0200 |
commit | deb261f64b9439f3a9a686b566c188b0d052e5b9 (patch) | |
tree | dd01a4d93fcd6a9b4fd5fad4ca7dc3ab97cbe1fe /Eigen | |
parent | 75a60d3ac0ac10be7317b268911d0098acbbf472 (diff) |
Make abs2 compatible with custom complex types
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/Core/MathFunctions.h | 22 |
1 files changed, 17 insertions, 5 deletions
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<typename Scalar> -struct abs2_impl +template<typename Scalar,bool IsComplex> +struct abs2_impl_default { typedef typename NumTraits<Scalar>::Real RealScalar; EIGEN_DEVICE_FUNC @@ -252,17 +252,29 @@ struct abs2_impl } }; -template<typename RealScalar> -struct abs2_impl<std::complex<RealScalar> > +template<typename Scalar> +struct abs2_impl_default<Scalar, true> // IsComplex { + typedef typename NumTraits<Scalar>::Real RealScalar; EIGEN_DEVICE_FUNC - static inline RealScalar run(const std::complex<RealScalar>& x) + static inline RealScalar run(const Scalar& x) { return real(x)*real(x) + imag(x)*imag(x); } }; template<typename Scalar> +struct abs2_impl +{ + typedef typename NumTraits<Scalar>::Real RealScalar; + EIGEN_DEVICE_FUNC + static inline RealScalar run(const Scalar& x) + { + return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(x); + } +}; + +template<typename Scalar> struct abs2_retval { typedef typename NumTraits<Scalar>::Real type; |