Bugzilla – Attachment 572 Details for
Bug 872
std::binder2nd deprecated warnings with C++11
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
[patch]
Replacing binder1st/binder2nd usage by custom functors
bug872.patch (text/plain), 10.10 KB, created by
Christoph Hertzberg
on 2015-05-04 12:53:46 UTC
(
hide
)
Description:
Replacing binder1st/binder2nd usage by custom functors
Filename:
MIME Type:
Creator:
Christoph Hertzberg
Created:
2015-05-04 12:53:46 UTC
Size:
10.10 KB
patch
obsolete
># HG changeset patch ># User Christoph Hertzberg <chtz@informatik.uni-bremen.de> ># 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<typename Scalar, ComparisonName cmp> struct scalar_cmp_op; >+ >+template<typename Scalar, ComparisonName cmp> >+struct functor_traits<scalar_cmp_op<Scalar, cmp> > { >+ enum { >+ Cost = NumTraits<Scalar>::AddCost, >+ PacketAccess = false >+ }; >+}; >+ >+ >+template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_EQ> { >+ 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<typename Scalar> struct scalar_cmp_op<Scalar, cmp_LT> { >+ 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<typename Scalar> struct scalar_cmp_op<Scalar, cmp_LE> { >+ 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<typename Scalar> struct scalar_cmp_op<Scalar, cmp_UNORD> { >+ 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<typename Scalar> struct scalar_cmp_op<Scalar, cmp_NE> { >+ 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<ComparisonName Cmp, typename Scalar> >+struct result_of<scalar_cmp_op<Scalar, Cmp>(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<typename OtherDerived> >+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, const Derived, const OtherDerived> >+operator<(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const >+{ >+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, 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<typename OtherDerived> >+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, const Derived, const OtherDerived> >+operator<=(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const >+{ >+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, 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<typename OtherDerived> >+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, const OtherDerived, const Derived> >+operator>(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const >+{ >+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, 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<typename OtherDerived> >+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, const OtherDerived, const Derived> >+operator>=(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const >+{ >+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, 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<typename OtherDerived> >+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_EQ>, const Derived, const OtherDerived> >+operator==(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const >+{ >+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_EQ>, 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<typename OtherDerived> >+EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_NE>, const Derived, const OtherDerived> >+operator!=(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const >+{ >+ return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_NE>, const Derived, const OtherDerived>(derived(), other.derived()); >+} >+ >+ >+ >+#define EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(METHOD_NAME,COMPARATOR) \ >+ typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \ >+ typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, 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<std::binder2nd<FUNCTOR<Scalar> >, const Derived> \ >- METHOD_NAME(const Scalar& s) const { \ >- return CwiseUnaryOp<std::binder2nd<FUNCTOR<Scalar> >, const Derived> \ >- (derived(), std::bind2nd(FUNCTOR<Scalar>(), s)); \ >- } \ >- friend inline const CwiseUnaryOp<std::binder1st<FUNCTOR<Scalar> >, const Derived> \ >- METHOD_NAME(const Scalar& s, const Derived& d) { \ >- return CwiseUnaryOp<std::binder1st<FUNCTOR<Scalar> >, const Derived> \ >- (d, std::bind1st(FUNCTOR<Scalar>(), 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() );
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 872
: 572