Added support for fmod

This commit is contained in:
Benoit Steiner 2016-03-28 15:53:02 -07:00
parent 6772f653c3
commit c38295f0a0
2 changed files with 36 additions and 0 deletions

View File

@ -1053,6 +1053,28 @@ template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
double exp(const double &x) { return ::exp(x); } double exp(const double &x) { return ::exp(x); }
#endif #endif
template <typename T>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
T fmod(const T& a, const T& b) {
EIGEN_USING_STD_MATH(floor);
return fmod(a, b);
}
#ifdef __CUDACC__
template <>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
float fmod(const float& a, const float& b) {
return ::fmodf(a, b);
}
template <>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
double fmod(const double& a, const double& b) {
return ::fmod(a, b);
}
#endif
} // end namespace numext } // end namespace numext
namespace internal { namespace internal {

View File

@ -40,6 +40,20 @@ template <typename Scalar>
struct functor_traits<scalar_mod2_op<Scalar> > struct functor_traits<scalar_mod2_op<Scalar> >
{ enum { Cost = NumTraits<Scalar>::template Div<false>::Cost, PacketAccess = false }; }; { enum { Cost = NumTraits<Scalar>::template Div<false>::Cost, PacketAccess = false }; };
template <typename Scalar>
struct scalar_fmod_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_fmod_op);
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar
operator()(const Scalar& a, const Scalar& b) const {
return numext::fmod(a, b);
}
};
template <typename Scalar>
struct functor_traits<scalar_fmod_op<Scalar> > {
enum { Cost = 13, // Reciprocal throughput of FPREM on Haswell.
PacketAccess = false };
};
/** \internal /** \internal
* \brief Template functor to compute the sigmoid of a scalar * \brief Template functor to compute the sigmoid of a scalar