mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-27 07:29:52 +08:00
Added support for modulo operation
This commit is contained in:
parent
fbcf8cc8c1
commit
29038b982d
@ -172,6 +172,13 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
||||
return unaryExpr(internal::scalar_quotient1_op<Scalar>(rhs));
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_mod_op<Scalar>, const Derived>
|
||||
operator% (Scalar rhs) const {
|
||||
EIGEN_STATIC_ASSERT(std::numeric_limits<Scalar>::is_integer, YOU_MADE_A_PROGRAMMING_MISTAKE_TRY_MOD);
|
||||
return unaryExpr(internal::scalar_mod_op<Scalar>(rhs));
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseBinaryOp<internal::scalar_max_op<Scalar>, const Derived, const TensorCwiseNullaryOp<internal::scalar_constant_op<Scalar>, const Derived> >
|
||||
cwiseMax(Scalar threshold) const {
|
||||
|
@ -14,6 +14,20 @@ namespace Eigen {
|
||||
namespace internal {
|
||||
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the modulo between an array and a scalar.
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_mod_op {
|
||||
EIGEN_DEVICE_FUNC scalar_mod_op(const Scalar& divisor) : m_divisor(divisor) {}
|
||||
EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a % m_divisor; }
|
||||
const Scalar m_divisor;
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_mod_op<Scalar> >
|
||||
{ enum { Cost = 2 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
|
||||
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the sigmoid of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::sigmoid()
|
||||
|
Loading…
Reference in New Issue
Block a user