# HG changeset patch # User Christoph Hertzberg # Date 1430737100 -7200 # Mon May 04 12:58:20 2015 +0200 # Node ID 72f8bc53df9d44555e8ad272b32641a4f9db0758 # Parent 0368cddffb0034075c249ef6eec1c290ee5725ed Bug 872: Avoid deprecated binder1st/binder2nd usage by providing custom functors for comparison operators diff -r 0368cddffb00 -r 72f8bc53df9d Eigen/src/Core/functors/BinaryFunctors.h --- a/Eigen/src/Core/functors/BinaryFunctors.h Fri May 01 22:10:41 2015 +0200 +++ b/Eigen/src/Core/functors/BinaryFunctors.h Mon May 04 12:58:20 2015 +0200 @@ -155,6 +155,48 @@ }; /** \internal + * \brief Template functors for comparison of two scalars + * \todo Implement packet-comparisons + */ +template struct scalar_cmp_op; + +template +struct functor_traits > { + enum { + Cost = NumTraits::AddCost, + PacketAccess = false + }; +}; + + +template struct scalar_cmp_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a==b;} +}; +template struct scalar_cmp_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a struct scalar_cmp_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a<=b;} +}; +template struct scalar_cmp_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return !(a<=b || b<=a);} +}; +template struct scalar_cmp_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a!=b;} +}; + +template +struct result_of(Scalar,Scalar)> { + typedef bool type; +}; + + +/** \internal * \brief Template functor to compute the hypot of two scalars * * \sa MatrixBase::stableNorm(), class Redux diff -r 0368cddffb00 -r 72f8bc53df9d Eigen/src/Core/util/Constants.h --- a/Eigen/src/Core/util/Constants.h Fri May 01 22:10:41 2015 +0200 +++ b/Eigen/src/Core/util/Constants.h Mon May 04 12:58:20 2015 +0200 @@ -492,6 +492,16 @@ // evaluator based on iterators to access coefficients. struct IteratorBased {}; +/** \internal + * Constants for comparison functors + */ +enum ComparisonName { + cmp_EQ = 0, + cmp_LT = 1, + cmp_LE = 2, + cmp_UNORD = 3, + cmp_NE = 4 +}; } // end namespace internal } // end namespace Eigen diff -r 0368cddffb00 -r 72f8bc53df9d Eigen/src/plugins/ArrayCwiseBinaryOps.h --- a/Eigen/src/plugins/ArrayCwiseBinaryOps.h Fri May 01 22:10:41 2015 +0200 +++ b/Eigen/src/plugins/ArrayCwiseBinaryOps.h Mon May 04 12:58:20 2015 +0200 @@ -81,7 +81,15 @@ * * \sa all(), any(), operator>(), operator<=() */ -EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less) +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const OtherDerived> +operator<(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const +{ + return CwiseBinaryOp, const Derived, const OtherDerived>(derived(), other.derived()); +} + + + /** \returns an expression of the coefficient-wise \<= operator of *this and \a other * @@ -90,7 +98,12 @@ * * \sa all(), any(), operator>=(), operator<() */ -EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal) +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const OtherDerived> +operator<=(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const +{ + return CwiseBinaryOp, const Derived, const OtherDerived>(derived(), other.derived()); +} /** \returns an expression of the coefficient-wise \> operator of *this and \a other * @@ -99,7 +112,12 @@ * * \sa all(), any(), operator>=(), operator<() */ -EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater) +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const OtherDerived, const Derived> +operator>(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const +{ + return CwiseBinaryOp, const OtherDerived, const Derived>(other.derived(), derived()); +} /** \returns an expression of the coefficient-wise \>= operator of *this and \a other * @@ -108,7 +126,12 @@ * * \sa all(), any(), operator>(), operator<=() */ -EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal) +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const OtherDerived, const Derived> +operator>=(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const +{ + return CwiseBinaryOp, const OtherDerived, const Derived>(other.derived(), derived()); +} /** \returns an expression of the coefficient-wise == operator of *this and \a other * @@ -122,7 +145,12 @@ * * \sa all(), any(), isApprox(), isMuchSmallerThan() */ -EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to) +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const OtherDerived> +operator==(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const +{ + return CwiseBinaryOp, const Derived, const OtherDerived>(derived(), other.derived()); +} /** \returns an expression of the coefficient-wise != operator of *this and \a other * @@ -136,7 +164,46 @@ * * \sa all(), any(), isApprox(), isMuchSmallerThan() */ -EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to) +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp, const Derived, const OtherDerived> +operator!=(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const +{ + return CwiseBinaryOp, const Derived, const OtherDerived>(derived(), other.derived()); +} + + + +#define EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(METHOD_NAME,COMPARATOR) \ + typedef CwiseBinaryOp, const Derived, const CwiseNullaryOp, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \ + typedef CwiseBinaryOp, const CwiseNullaryOp, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \ + EIGEN_DEVICE_FUNC \ + inline const Cmp ## COMPARATOR ## ReturnType \ + METHOD_NAME(const Scalar& s) const { \ + return METHOD_NAME(Derived::PlainObject::Constant(rows(), cols(), s)); \ + } \ + friend inline const RCmp ## COMPARATOR ## ReturnType \ + METHOD_NAME(const Scalar& s, const Derived& d) { \ + return Derived::PlainObject::Constant(d.rows(), d.cols(), s).METHOD_NAME(d); \ + } + +#define EIGEN_MAKE_SCALAR_CWISE_RCMP_UNARY_OP(METHOD_NAME, R_METHOD_NAME, RCOMPARATOR) \ + EIGEN_DEVICE_FUNC \ + inline const RCmp ## RCOMPARATOR ## ReturnType \ + METHOD_NAME(const Scalar& s) const { \ + return Derived::PlainObject::Constant(rows(), cols(), s).R_METHOD_NAME(*this); \ + } \ + friend inline const Cmp ## RCOMPARATOR ## ReturnType \ + METHOD_NAME(const Scalar& s, const Derived& d) { \ + return d.R_METHOD_NAME(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \ + } + +EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator==, EQ) +EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator!=, NE) +EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator<, LT) +EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator<=, LE) +EIGEN_MAKE_SCALAR_CWISE_RCMP_UNARY_OP(operator>,operator<, LT) +EIGEN_MAKE_SCALAR_CWISE_RCMP_UNARY_OP(operator>=,operator<=, LE) + // scalar addition diff -r 0368cddffb00 -r 72f8bc53df9d Eigen/src/plugins/ArrayCwiseUnaryOps.h --- a/Eigen/src/plugins/ArrayCwiseUnaryOps.h Fri May 01 22:10:41 2015 +0200 +++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h Mon May 04 12:58:20 2015 +0200 @@ -246,24 +246,5 @@ return CubeReturnType(derived()); } -#define EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(METHOD_NAME,FUNCTOR) \ - EIGEN_DEVICE_FUNC \ - inline const CwiseUnaryOp >, const Derived> \ - METHOD_NAME(const Scalar& s) const { \ - return CwiseUnaryOp >, const Derived> \ - (derived(), std::bind2nd(FUNCTOR(), s)); \ - } \ - friend inline const CwiseUnaryOp >, const Derived> \ - METHOD_NAME(const Scalar& s, const Derived& d) { \ - return CwiseUnaryOp >, const Derived> \ - (d, std::bind1st(FUNCTOR(), s)); \ - } -EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator==, std::equal_to) -EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator!=, std::not_equal_to) -EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<, std::less) -EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<=, std::less_equal) -EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>, std::greater) -EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>=, std::greater_equal) - diff -r 0368cddffb00 -r 72f8bc53df9d test/array.cpp --- a/test/array.cpp Fri May 01 22:10:41 2015 +0200 +++ b/test/array.cpp Mon May 04 12:58:20 2015 +0200 @@ -136,6 +136,8 @@ VERIFY(! (m1 < m3).all() ); VERIFY(! (m1 > m3).all() ); } + VERIFY(!(m1 > m2 && m1 < m2).any()); + VERIFY((m1 <= m2 || m1 >= m2).all()); // comparisons array to scalar VERIFY( (m1 != (m1(r,c)+1) ).any() );