From f41b1f1666e91dc674a42fed9c444c91f483133f Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 26 Feb 2015 09:42:41 -0800 Subject: Added support for fast reciprocal square root computation. --- Eigen/src/Core/functors/UnaryFunctors.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Eigen/src/Core/functors') diff --git a/Eigen/src/Core/functors/UnaryFunctors.h b/Eigen/src/Core/functors/UnaryFunctors.h index ec42e6850..a3b5f50b1 100644 --- a/Eigen/src/Core/functors/UnaryFunctors.h +++ b/Eigen/src/Core/functors/UnaryFunctors.h @@ -224,6 +224,25 @@ struct functor_traits > }; }; +/** \internal + * \brief Template functor to compute the reciprocal square root of a scalar + * \sa class CwiseUnaryOp, Cwise::rsqrt() + */ +template struct scalar_rsqrt_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_rsqrt_op) + EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { using std::sqrt; return Scalar(1)/sqrt(a); } + typedef typename packet_traits::type Packet; + inline Packet packetOp(const Packet& a) const { return internal::prsqrt(a); } +}; + +template +struct functor_traits > +{ enum { + Cost = 5 * NumTraits::MulCost, + PacketAccess = packet_traits::HasRsqrt + }; +}; + /** \internal * \brief Template functor to compute the cosine of a scalar * \sa class CwiseUnaryOp, ArrayBase::cos() -- cgit v1.2.3