diff options
author | Gael Guennebaud <g.gael@free.fr> | 2017-06-12 16:47:22 +0200 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2017-06-12 16:47:22 +0200 |
commit | 6dcf966558ff9782f34c5df897c15eb37f1e95e3 (patch) | |
tree | 1796b681c65abe674bdd14d636406c9461c1f114 /Eigen/src/Core/GlobalFunctions.h | |
parent | 50e09cca0f2312d89ced431b3a6cd7ff7c925d09 (diff) |
Avoid implicit scalar conversion with accuracy loss in pow(scalar,array)
Diffstat (limited to 'Eigen/src/Core/GlobalFunctions.h')
-rw-r--r-- | Eigen/src/Core/GlobalFunctions.h | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 12828a7c3..50406400b 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -103,17 +103,18 @@ namespace Eigen inline const CwiseBinaryOp<internal::scalar_pow_op<Derived::Scalar,ScalarExponent>,Derived,Constant<ScalarExponent> > pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent); #else - template<typename Derived,typename ScalarExponent> - inline typename internal::enable_if< !(internal::is_same<typename Derived::Scalar,ScalarExponent>::value) && EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent), - const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,ScalarExponent,pow) >::type - pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent) { - return x.derived().pow(exponent); - } - - template<typename Derived> - inline const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename Derived::Scalar,pow) - pow(const Eigen::ArrayBase<Derived>& x, const typename Derived::Scalar& exponent) { - return x.derived().pow(exponent); + template <typename Derived,typename ScalarExponent> + EIGEN_DEVICE_FUNC inline + EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE( + const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<typename Derived::Scalar + EIGEN_COMMA ScalarExponent EIGEN_COMMA + EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type,pow)) + pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent) + { + typedef typename internal::promote_scalar_arg<typename Derived::Scalar,ScalarExponent, + EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type PromotedExponent; + return EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,PromotedExponent,pow)(x.derived(), + typename internal::plain_constant_type<Derived,PromotedExponent>::type(x.derived().rows(), x.derived().cols(), internal::scalar_constant_op<PromotedExponent>(exponent))); } #endif @@ -156,21 +157,17 @@ namespace Eigen inline const CwiseBinaryOp<internal::scalar_pow_op<Scalar,Derived::Scalar>,Constant<Scalar>,Derived> pow(const Scalar& x,const Eigen::ArrayBase<Derived>& x); #else - template<typename Scalar, typename Derived> - inline typename internal::enable_if< !(internal::is_same<typename Derived::Scalar,Scalar>::value) && EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar), - const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,Derived,pow) >::type - pow(const Scalar& x, const Eigen::ArrayBase<Derived>& exponents) - { - return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,Derived,pow)( - typename internal::plain_constant_type<Derived,Scalar>::type(exponents.rows(), exponents.cols(), x), exponents.derived() ); - } - - template<typename Derived> - inline const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename Derived::Scalar,Derived,pow) - pow(const typename Derived::Scalar& x, const Eigen::ArrayBase<Derived>& exponents) - { - return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename Derived::Scalar,Derived,pow)( - typename internal::plain_constant_type<Derived,typename Derived::Scalar>::type(exponents.rows(), exponents.cols(), x), exponents.derived() ); + template <typename Scalar, typename Derived> + EIGEN_DEVICE_FUNC inline + EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE( + const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<typename Derived::Scalar + EIGEN_COMMA Scalar EIGEN_COMMA + EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type,Derived,pow)) + pow(const Scalar& x, const Eigen::ArrayBase<Derived>& exponents) { + typedef typename internal::promote_scalar_arg<typename Derived::Scalar,Scalar, + EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type PromotedScalar; + return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedScalar,Derived,pow)( + typename internal::plain_constant_type<Derived,PromotedScalar>::type(exponents.derived().rows(), exponents.derived().cols(), internal::scalar_constant_op<PromotedScalar>(x)), exponents.derived()); } #endif |