mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
add fixed power unary operation
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
39fcc89798
commit
76a669fb45
@@ -134,26 +134,6 @@ absolute_difference
|
||||
*/
|
||||
EIGEN_MAKE_CWISE_BINARY_OP(pow,pow)
|
||||
|
||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||
EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(pow,pow)
|
||||
#else
|
||||
/** \returns an expression of the coefficients of \c *this rasied to the constant power \a exponent
|
||||
*
|
||||
* \tparam T is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression.
|
||||
*
|
||||
* This function computes the coefficient-wise power. The function MatrixBase::pow() in the
|
||||
* unsupported module MatrixFunctions computes the matrix power.
|
||||
*
|
||||
* Example: \include Cwise_pow.cpp
|
||||
* Output: \verbinclude Cwise_pow.out
|
||||
*
|
||||
* \sa ArrayBase::pow(ArrayBase), square(), cube(), exp(), log()
|
||||
*/
|
||||
template<typename T>
|
||||
const CwiseBinaryOp<internal::scalar_pow_op<Scalar,T>,Derived,Constant<T> > pow(const T& exponent) const;
|
||||
#endif
|
||||
|
||||
|
||||
// TODO code generating macros could be moved to Macros.h and could include generation of documentation
|
||||
#define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR) \
|
||||
template<typename OtherDerived> \
|
||||
|
||||
@@ -694,3 +694,32 @@ ndtri() const
|
||||
{
|
||||
return NdtriReturnType(derived());
|
||||
}
|
||||
|
||||
template <typename ScalarExponent>
|
||||
using UnaryPowReturnType =
|
||||
std::enable_if_t<internal::is_arithmetic<ScalarExponent>::value,
|
||||
CwiseUnaryOp<internal::scalar_unary_pow_op<Scalar, ScalarExponent>, const Derived>>;
|
||||
|
||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||
template <typename ScalarExponent>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryPowReturnType<ScalarExponent> pow(
|
||||
const ScalarExponent& exponent) const {
|
||||
return UnaryPowReturnType<ScalarExponent>(derived(), internal::scalar_unary_pow_op<Scalar, ScalarExponent>(exponent));
|
||||
#else
|
||||
/** \returns an expression of the coefficients of \c *this rasied to the constant power \a exponent
|
||||
*
|
||||
* \tparam T is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression.
|
||||
*
|
||||
* This function computes the coefficient-wise power. The function MatrixBase::pow() in the
|
||||
* unsupported module MatrixFunctions computes the matrix power.
|
||||
*
|
||||
* Example: \include Cwise_pow.cpp
|
||||
* Output: \verbinclude Cwise_pow.out
|
||||
*
|
||||
* \sa ArrayBase::pow(ArrayBase), square(), cube(), exp(), log()
|
||||
*/
|
||||
template <typename ScalarExponent>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryPowReturnType<ScalarExponent> pow(
|
||||
const ScalarExponent& exponent) const;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -93,3 +93,13 @@ EIGEN_DOC_UNARY_ADDONS(cwiseArg,arg)
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const CwiseArgReturnType
|
||||
cwiseArg() const { return CwiseArgReturnType(derived()); }
|
||||
|
||||
template <typename ScalarExponent>
|
||||
using CwisePowReturnType =
|
||||
std::enable_if_t<internal::is_arithmetic<ScalarExponent>::value,
|
||||
CwiseUnaryOp<internal::scalar_unary_pow_op<Scalar, ScalarExponent>, const Derived>>;
|
||||
|
||||
template <typename ScalarExponent>
|
||||
EIGEN_DEVICE_FUNC inline const CwisePowReturnType<ScalarExponent> cwisePow(const ScalarExponent& exponent) const {
|
||||
return CwisePowReturnType<ScalarExponent>(derived(), internal::scalar_unary_pow_op<Scalar, ScalarExponent>(exponent));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user