aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/GlobalFunctions.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-07-20 13:57:55 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-07-20 13:57:55 +0200
commit6544b49e59f6f43c9183bf0d15d74267f5070137 (patch)
tree140eff6e3e17fc7681dfefda759ec0a2f3591836 /Eigen/src/Core/GlobalFunctions.h
parent2d93060291f3373a3325413159062a3b4d1e95e8 (diff)
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.
Diffstat (limited to 'Eigen/src/Core/GlobalFunctions.h')
-rw-r--r--Eigen/src/Core/GlobalFunctions.h38
1 files changed, 34 insertions, 4 deletions
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<typename Derived>
- inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const Derived, const Derived>
- pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<Derived>& 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<typename Derived,typename ExponentDerived>
+ inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, const Derived, const ExponentDerived>
+ pow(const Eigen::ArrayBase<Derived>& x, const Eigen::ArrayBase<ExponentDerived>& exponents)
{
- return Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const Derived, const Derived>(
+ return Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename ExponentDerived::Scalar>, 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<typename Derived>
+ inline const Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>
+ pow(const typename Derived::Scalar& x, const Eigen::ArrayBase<Derived>& exponents)
+ {
+ typename Derived::ConstantReturnType constant_x(exponents.rows(), exponents.cols(), x);
+ return Eigen::CwiseBinaryOp<Eigen::internal::scalar_binary_pow_op<typename Derived::Scalar, typename Derived::Scalar>, const typename Derived::ConstantReturnType, const Derived>(
+ constant_x,
+ exponents.derived()
+ );
+ }
+
/**
* \brief Component-wise division of a scalar by array elements.
**/