mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
Add boolean not operator (!) array support
This commit is contained in:
parent
85da0c2281
commit
1c78d6f2a6
@ -626,6 +626,24 @@ struct functor_traits<scalar_isFinite_op<Scalar> >
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the logical not of a boolean
|
||||
*
|
||||
* \sa class CwiseUnaryOp, ArrayBase::operator!
|
||||
*/
|
||||
template<typename Scalar> struct scalar_boolean_not_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_not_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a) const { return !a; }
|
||||
};
|
||||
template<typename Scalar>
|
||||
struct functor_traits<scalar_boolean_not_op<Scalar> > {
|
||||
enum {
|
||||
Cost = NumTraits<bool>::AddCost,
|
||||
PacketAccess = false
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
@ -5,6 +5,7 @@ typedef CwiseUnaryOp<internal::scalar_arg_op<Scalar>, const Derived> ArgReturnTy
|
||||
typedef CwiseUnaryOp<internal::scalar_abs2_op<Scalar>, const Derived> Abs2ReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_sqrt_op<Scalar>, const Derived> SqrtReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived> InverseReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_boolean_not_op<Scalar>, const Derived> BooleanNotReturnType;
|
||||
|
||||
typedef CwiseUnaryOp<internal::scalar_exp_op<Scalar>, const Derived> ExpReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_log_op<Scalar>, const Derived> LogReturnType;
|
||||
@ -404,6 +405,25 @@ isFinite() const
|
||||
return IsFiniteReturnType(derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise ! operator of *this
|
||||
*
|
||||
* \warning this operator is for expression of bool only.
|
||||
*
|
||||
* Example: \include Cwise_boolean_not.cpp
|
||||
* Output: \verbinclude Cwise_boolean_not.out
|
||||
*
|
||||
* \sa operator!=()
|
||||
*/
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline const BooleanNotReturnType
|
||||
operator!() const
|
||||
{
|
||||
EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value),
|
||||
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
|
||||
return BooleanNotReturnType(derived());
|
||||
}
|
||||
|
||||
|
||||
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(METHOD_NAME,FUNCTOR) \
|
||||
EIGEN_DEVICE_FUNC \
|
||||
inline const CwiseUnaryOp<std::binder2nd<FUNCTOR<Scalar> >, const Derived> \
|
||||
|
5
doc/snippets/Cwise_boolean_not.cpp
Normal file
5
doc/snippets/Cwise_boolean_not.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
Array3d v(1,2,3);
|
||||
v(1) *= 0.0/0.0;
|
||||
v(2) /= 0.0;
|
||||
cout << v << endl << endl;
|
||||
cout << !isFinite(v) << endl;
|
@ -221,6 +221,8 @@ template<typename ArrayType> void array_real(const ArrayType& m)
|
||||
VERIFY_IS_APPROX(m1.square().sqrt(), sqrt(square(m1)));
|
||||
VERIFY_IS_APPROX(cube(m1.cube()), pow((m1),3*3));
|
||||
|
||||
VERIFY(!(m1>m2),(m1<=m2));
|
||||
|
||||
VERIFY_IS_APPROX(cos(m1+RealScalar(3)*m2), cos((m1+RealScalar(3)*m2).eval()));
|
||||
|
||||
VERIFY_IS_APPROX(m1.abs().sqrt(), sqrt(abs(m1)));
|
||||
|
Loading…
Reference in New Issue
Block a user