mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Avoid implicit scalar conversion with accuracy loss in pow(scalar,array)
This commit is contained in:
parent
50e09cca0f
commit
6dcf966558
@ -103,17 +103,18 @@ namespace Eigen
|
|||||||
inline const CwiseBinaryOp<internal::scalar_pow_op<Derived::Scalar,ScalarExponent>,Derived,Constant<ScalarExponent> >
|
inline const CwiseBinaryOp<internal::scalar_pow_op<Derived::Scalar,ScalarExponent>,Derived,Constant<ScalarExponent> >
|
||||||
pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent);
|
pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent);
|
||||||
#else
|
#else
|
||||||
template<typename Derived,typename ScalarExponent>
|
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),
|
EIGEN_DEVICE_FUNC inline
|
||||||
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,ScalarExponent,pow) >::type
|
EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(
|
||||||
pow(const Eigen::ArrayBase<Derived>& x, const ScalarExponent& exponent) {
|
const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename internal::promote_scalar_arg<typename Derived::Scalar
|
||||||
return x.derived().pow(exponent);
|
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)
|
||||||
template<typename Derived>
|
{
|
||||||
inline const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Derived,typename Derived::Scalar,pow)
|
typedef typename internal::promote_scalar_arg<typename Derived::Scalar,ScalarExponent,
|
||||||
pow(const Eigen::ArrayBase<Derived>& x, const typename Derived::Scalar& exponent) {
|
EIGEN_SCALAR_BINARY_SUPPORTED(pow,typename Derived::Scalar,ScalarExponent)>::type PromotedExponent;
|
||||||
return x.derived().pow(exponent);
|
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
|
#endif
|
||||||
|
|
||||||
@ -156,21 +157,17 @@ namespace Eigen
|
|||||||
inline const CwiseBinaryOp<internal::scalar_pow_op<Scalar,Derived::Scalar>,Constant<Scalar>,Derived>
|
inline const CwiseBinaryOp<internal::scalar_pow_op<Scalar,Derived::Scalar>,Constant<Scalar>,Derived>
|
||||||
pow(const Scalar& x,const Eigen::ArrayBase<Derived>& x);
|
pow(const Scalar& x,const Eigen::ArrayBase<Derived>& x);
|
||||||
#else
|
#else
|
||||||
template<typename Scalar, typename Derived>
|
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),
|
EIGEN_DEVICE_FUNC inline
|
||||||
const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,Derived,pow) >::type
|
EIGEN_MSVC10_WORKAROUND_BINARYOP_RETURN_TYPE(
|
||||||
pow(const Scalar& x, const Eigen::ArrayBase<Derived>& exponents)
|
const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename internal::promote_scalar_arg<typename Derived::Scalar
|
||||||
{
|
EIGEN_COMMA Scalar EIGEN_COMMA
|
||||||
return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar,Derived,pow)(
|
EIGEN_SCALAR_BINARY_SUPPORTED(pow,Scalar,typename Derived::Scalar)>::type,Derived,pow))
|
||||||
typename internal::plain_constant_type<Derived,Scalar>::type(exponents.rows(), exponents.cols(), x), exponents.derived() );
|
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;
|
||||||
template<typename Derived>
|
return EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(PromotedScalar,Derived,pow)(
|
||||||
inline const EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(typename Derived::Scalar,Derived,pow)
|
typename internal::plain_constant_type<Derived,PromotedScalar>::type(exponents.derived().rows(), exponents.derived().cols(), internal::scalar_constant_op<PromotedScalar>(x)), exponents.derived());
|
||||||
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() );
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user