From 6544b49e59f6f43c9183bf0d15d74267f5070137 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 20 Jul 2015 13:57:55 +0200 Subject: Generalize pow(x,e) such that x and e can be a different expression type or a scalar for either x or e. Add x.pow(e) with e an array expression. --- Eigen/src/Core/GlobalFunctions.h | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'Eigen/src/Core/GlobalFunctions.h') diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 15d92b862..90d6b6e28 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -71,16 +71,46 @@ namespace Eigen return x.derived().pow(exponent); } - template - inline const Eigen::CwiseBinaryOp, const Derived, const Derived> - pow(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) + /** \returns an expression of the coefficient-wise power of \a x to the given array of \a exponents. + * + * This function computes the coefficient-wise power. + * + * Example: \include Cwise_array_power_array.cpp + * Output: \verbinclude Cwise_array_power_array.out + * + * \sa ArrayBase::pow() + */ + template + inline const Eigen::CwiseBinaryOp, const Derived, const ExponentDerived> + pow(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) { - return Eigen::CwiseBinaryOp, const Derived, const Derived>( + return Eigen::CwiseBinaryOp, const Derived, const ExponentDerived>( x.derived(), exponents.derived() ); } + /** \returns an expression of the coefficient-wise power of the scalar \a x to the given array of \a exponents. + * + * This function computes the coefficient-wise power between a scalar and an array of exponents. + * Beaware that the scalar type of the input scalar \a x and the exponents \a exponents must be the same. + * + * Example: \include Cwise_scalar_power_array.cpp + * Output: \verbinclude Cwise_scalar_power_array.out + * + * \sa ArrayBase::pow() + */ + template + inline const Eigen::CwiseBinaryOp, const typename Derived::ConstantReturnType, const Derived> + pow(const typename Derived::Scalar& x, const Eigen::ArrayBase& exponents) + { + typename Derived::ConstantReturnType constant_x(exponents.rows(), exponents.cols(), x); + return Eigen::CwiseBinaryOp, const typename Derived::ConstantReturnType, const Derived>( + constant_x, + exponents.derived() + ); + } + /** * \brief Component-wise division of a scalar by array elements. **/ -- cgit v1.2.3