mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
Add support for inverse hyperbolic functions.
Fix cost of division.
This commit is contained in:
parent
a49d01edba
commit
28ba1b2c32
@ -66,6 +66,11 @@ namespace Eigen
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh)
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asinh,scalar_asinh_op,inverse hyperbolic sine,\sa ArrayBase::asinh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acosh,scalar_acosh_op,inverse hyperbolic cosine,\sa ArrayBase::acosh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atanh,scalar_atanh_op,inverse hyperbolic tangent,\sa ArrayBase::atanh)
|
||||
#endif
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic,scalar_logistic_op,logistic function,\sa ArrayBase::logistic)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma)
|
||||
|
@ -468,6 +468,11 @@ template<typename Derived> class MatrixBase
|
||||
const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine)
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine)
|
||||
#endif
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root)
|
||||
|
@ -548,6 +548,23 @@ struct functor_traits<scalar_tanh_op<Scalar> > {
|
||||
};
|
||||
};
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \internal
|
||||
* \brief Template functor to compute the atanh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::atanh()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_atanh_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_atanh_op)
|
||||
EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::atanh(a); }
|
||||
};
|
||||
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_atanh_op<Scalar> > {
|
||||
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
|
||||
};
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the sinh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::sinh()
|
||||
@ -567,6 +584,23 @@ struct functor_traits<scalar_sinh_op<Scalar> >
|
||||
};
|
||||
};
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \internal
|
||||
* \brief Template functor to compute the asinh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::asinh()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_asinh_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_asinh_op)
|
||||
EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::asinh(a); }
|
||||
};
|
||||
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_asinh_op<Scalar> > {
|
||||
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
|
||||
};
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the cosh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::cosh()
|
||||
@ -586,6 +620,23 @@ struct functor_traits<scalar_cosh_op<Scalar> >
|
||||
};
|
||||
};
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \internal
|
||||
* \brief Template functor to compute the acosh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::acosh()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_acosh_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_acosh_op)
|
||||
EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::acosh(a); }
|
||||
};
|
||||
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_acosh_op<Scalar> > {
|
||||
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
|
||||
};
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the inverse of a scalar
|
||||
* \sa class CwiseUnaryOp, Cwise::inverse()
|
||||
@ -598,9 +649,13 @@ struct scalar_inverse_op {
|
||||
EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
|
||||
{ return internal::pdiv(pset1<Packet>(Scalar(1)),a); }
|
||||
};
|
||||
template<typename Scalar>
|
||||
struct functor_traits<scalar_inverse_op<Scalar> >
|
||||
{ enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasDiv }; };
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_inverse_op<Scalar> > {
|
||||
enum {
|
||||
PacketAccess = packet_traits<Scalar>::HasDiv,
|
||||
Cost = scalar_div_cost<Scalar, PacketAccess>::value
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the square of a scalar
|
||||
|
@ -23,6 +23,11 @@ typedef CwiseUnaryOp<internal::scalar_atan_op<Scalar>, const Derived> AtanReturn
|
||||
typedef CwiseUnaryOp<internal::scalar_tanh_op<Scalar>, const Derived> TanhReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_logistic_op<Scalar>, const Derived> LogisticReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_sinh_op<Scalar>, const Derived> SinhReturnType;
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
typedef CwiseUnaryOp<internal::scalar_atanh_op<Scalar>, const Derived> AtanhReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_asinh_op<Scalar>, const Derived> AsinhReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_acosh_op<Scalar>, const Derived> AcoshReturnType;
|
||||
#endif
|
||||
typedef CwiseUnaryOp<internal::scalar_cosh_op<Scalar>, const Derived> CoshReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_square_op<Scalar>, const Derived> SquareReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_cube_op<Scalar>, const Derived> CubeReturnType;
|
||||
@ -327,7 +332,7 @@ sinh() const
|
||||
* Example: \include Cwise_cosh.cpp
|
||||
* Output: \verbinclude Cwise_cosh.out
|
||||
*
|
||||
* \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cosh">Math functions</a>, tan(), sinh(), cosh()
|
||||
* \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_cosh">Math functions</a>, tanh(), sinh(), cosh()
|
||||
*/
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const CoshReturnType
|
||||
@ -336,6 +341,41 @@ cosh() const
|
||||
return CoshReturnType(derived());
|
||||
}
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \returns an expression of the coefficient-wise inverse hyperbolic tan of *this.
|
||||
*
|
||||
* \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atanh">Math functions</a>, atanh(), asinh(), acosh()
|
||||
*/
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const AtanhReturnType
|
||||
atanh() const
|
||||
{
|
||||
return AtanhReturnType(derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise inverse hyperbolic sin of *this.
|
||||
*
|
||||
* \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_asinh">Math functions</a>, atanh(), asinh(), acosh()
|
||||
*/
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const AsinhReturnType
|
||||
asinh() const
|
||||
{
|
||||
return AsinhReturnType(derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise inverse hyperbolic cos of *this.
|
||||
*
|
||||
* \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_acosh">Math functions</a>, atanh(), asinh(), acosh()
|
||||
*/
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const AcoshReturnType
|
||||
acosh() const
|
||||
{
|
||||
return AcoshReturnType(derived());
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \returns an expression of the coefficient-wise logistic of *this.
|
||||
*/
|
||||
EIGEN_DEVICE_FUNC
|
||||
|
@ -231,6 +231,11 @@ template<typename ArrayType> void array_real(const ArrayType& m)
|
||||
VERIFY_IS_APPROX(m1.sinh(), sinh(m1));
|
||||
VERIFY_IS_APPROX(m1.cosh(), cosh(m1));
|
||||
VERIFY_IS_APPROX(m1.tanh(), tanh(m1));
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
VERIFY_IS_APPROX(m1.tanh().atanh(), atanh(tanh(m1)));
|
||||
VERIFY_IS_APPROX(m1.sinh().asinh(), asinh(sinh(m1)));
|
||||
VERIFY_IS_APPROX(m1.cosh().acosh(), acosh(cosh(m1)));
|
||||
#endif
|
||||
VERIFY_IS_APPROX(m1.logistic(), logistic(m1));
|
||||
|
||||
VERIFY_IS_APPROX(m1.arg(), arg(m1));
|
||||
|
Loading…
Reference in New Issue
Block a user