From 85fb517eaf8225a607328d67ab573596b81015f1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 6 Sep 2016 17:23:15 +0200 Subject: [PATCH] Generalize ScalarBinaryOpTraits to any complex-real combination as defined by NumTraits (instead of supporting std::complex only). --- Eigen/src/Core/NumTraits.h | 3 +++ Eigen/src/Core/util/XprHelper.h | 33 ++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Eigen/src/Core/NumTraits.h b/Eigen/src/Core/NumTraits.h index 42cffbd3b..899dc672a 100644 --- a/Eigen/src/Core/NumTraits.h +++ b/Eigen/src/Core/NumTraits.h @@ -255,6 +255,9 @@ private: static inline std::string quiet_NaN(); }; +// Empty specialization for void to allow template specialization based on NumTraits::Real with T==void and SFINAE. +template<> struct NumTraits {}; + } // end namespace Eigen #endif // EIGEN_NUMTRAITS_H diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 7e43f4fea..e26a92022 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -707,7 +707,7 @@ std::string demangle_flags(int f) * This class permits to control the scalar return type of any binary operation performed on two different scalar types through (partial) template specializations. * * For instance, let \c U1, \c U2 and \c U3 be three user defined scalar types for which most operations between instances of \c U1 and \c U2 returns an \c U3. - * You can let Eigen knows that by defining: + * You can let %Eigen knows that by defining: \code template struct ScalarBinaryOpTraits { typedef U3 ReturnType; }; @@ -725,6 +725,14 @@ std::string demangle_flags(int f) struct ScalarBinaryOpTraits > { typedef U1 ReturnType; }; \endcode * + * By default, the following generic combinations are supported: + + + + + +
ScalarAScalarBBinaryOpReturnTypeNote
\c T \c T \c * \c T
\c NumTraits::Real \c T \c * \c T Only if \c NumTraits::IsComplex
\c T \c NumTraits::Real \c * \c T Only if \c NumTraits::IsComplex
+ * * \sa CwiseBinaryOp */ template > @@ -741,6 +749,17 @@ struct ScalarBinaryOpTraits typedef T ReturnType; }; +template +struct ScalarBinaryOpTraits::IsComplex,T>::type>::Real, BinaryOp> +{ + typedef T ReturnType; +}; +template +struct ScalarBinaryOpTraits::IsComplex,T>::type>::Real, T, BinaryOp> +{ + typedef T ReturnType; +}; + // For Matrix * Permutation template struct ScalarBinaryOpTraits @@ -762,18 +781,6 @@ struct ScalarBinaryOpTraits typedef void ReturnType; }; -template -struct ScalarBinaryOpTraits,BinaryOp> -{ - typedef std::complex ReturnType; -}; - -template -struct ScalarBinaryOpTraits, T,BinaryOp> -{ - typedef std::complex ReturnType; -}; - // We require Lhs and Rhs to have "compatible" scalar types. // It is tempting to always allow mixing different types but remember that this is often impossible in the vectorized paths. // So allowing mixing different types gives very unexpected errors when enabling vectorization, when the user tries to