mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-15 13:15:57 +08:00
bug #872: remove usage of deprecated bind1st/bind2nd functions (manually backported from devel branch)
This commit is contained in:
parent
0ebce69424
commit
51ab034f63
@ -259,6 +259,47 @@ template<> struct functor_traits<scalar_boolean_or_op> {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** \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<ComparisonName Cmp, typename Scalar>
|
||||||
|
struct result_of<scalar_cmp_op<Scalar, Cmp>(Scalar,Scalar)> {
|
||||||
|
typedef bool type;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_EQ> {
|
||||||
|
EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
|
||||||
|
EIGEN_STRONG_INLINE bool 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_STRONG_INLINE bool 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_STRONG_INLINE bool 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_STRONG_INLINE bool operator()(const Scalar& a, const Scalar& b) const {return !(a<=b || b<=a);}
|
||||||
|
};
|
||||||
|
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_NEQ> {
|
||||||
|
EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
|
||||||
|
EIGEN_STRONG_INLINE bool operator()(const Scalar& a, const Scalar& b) const {return a!=b;}
|
||||||
|
};
|
||||||
|
|
||||||
// unary functors:
|
// unary functors:
|
||||||
|
|
||||||
/** \internal
|
/** \internal
|
||||||
|
@ -433,6 +433,19 @@ struct MatrixXpr {};
|
|||||||
/** The type used to identify an array expression */
|
/** The type used to identify an array expression */
|
||||||
struct ArrayXpr {};
|
struct ArrayXpr {};
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
|
/** \internal
|
||||||
|
* Constants for comparison functors
|
||||||
|
*/
|
||||||
|
enum ComparisonName {
|
||||||
|
cmp_EQ = 0,
|
||||||
|
cmp_LT = 1,
|
||||||
|
cmp_LE = 2,
|
||||||
|
cmp_UNORD = 3,
|
||||||
|
cmp_NEQ = 4
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
|
||||||
#endif // EIGEN_CONSTANTS_H
|
#endif // EIGEN_CONSTANTS_H
|
||||||
|
@ -70,6 +70,43 @@ max
|
|||||||
return (max)(Derived::PlainObject::Constant(rows(), cols(), other));
|
return (max)(Derived::PlainObject::Constant(rows(), cols(), other));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR) \
|
||||||
|
template<typename OtherDerived> \
|
||||||
|
EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived> \
|
||||||
|
OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
|
||||||
|
{ \
|
||||||
|
return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived>(derived(), other.derived()); \
|
||||||
|
}\
|
||||||
|
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_STRONG_INLINE const Cmp ## COMPARATOR ## ReturnType \
|
||||||
|
OP(const Scalar& s) const { \
|
||||||
|
return this->OP(Derived::PlainObject::Constant(rows(), cols(), s)); \
|
||||||
|
} \
|
||||||
|
friend EIGEN_STRONG_INLINE const RCmp ## COMPARATOR ## ReturnType \
|
||||||
|
OP(const Scalar& s, const Derived& d) { \
|
||||||
|
return Derived::PlainObject::Constant(d.rows(), d.cols(), s).OP(d); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define EIGEN_MAKE_CWISE_COMP_R_OP(OP, R_OP, RCOMPARATOR) \
|
||||||
|
template<typename OtherDerived> \
|
||||||
|
EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived> \
|
||||||
|
OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
|
||||||
|
{ \
|
||||||
|
return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived>(other.derived(), derived()); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
inline const RCmp ## RCOMPARATOR ## ReturnType \
|
||||||
|
OP(const Scalar& s) const { \
|
||||||
|
return Derived::PlainObject::Constant(rows(), cols(), s).R_OP(*this); \
|
||||||
|
} \
|
||||||
|
friend inline const Cmp ## RCOMPARATOR ## ReturnType \
|
||||||
|
OP(const Scalar& s, const Derived& d) { \
|
||||||
|
return d.R_OP(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise \< operator of *this and \a other
|
/** \returns an expression of the coefficient-wise \< operator of *this and \a other
|
||||||
*
|
*
|
||||||
* Example: \include Cwise_less.cpp
|
* Example: \include Cwise_less.cpp
|
||||||
@ -77,7 +114,7 @@ max
|
|||||||
*
|
*
|
||||||
* \sa all(), any(), operator>(), operator<=()
|
* \sa all(), any(), operator>(), operator<=()
|
||||||
*/
|
*/
|
||||||
EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less)
|
EIGEN_MAKE_CWISE_COMP_OP(operator<, LT)
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
|
/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
|
||||||
*
|
*
|
||||||
@ -86,7 +123,7 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less)
|
|||||||
*
|
*
|
||||||
* \sa all(), any(), operator>=(), operator<()
|
* \sa all(), any(), operator>=(), operator<()
|
||||||
*/
|
*/
|
||||||
EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal)
|
EIGEN_MAKE_CWISE_COMP_OP(operator<=, LE)
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise \> operator of *this and \a other
|
/** \returns an expression of the coefficient-wise \> operator of *this and \a other
|
||||||
*
|
*
|
||||||
@ -95,7 +132,7 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal)
|
|||||||
*
|
*
|
||||||
* \sa all(), any(), operator>=(), operator<()
|
* \sa all(), any(), operator>=(), operator<()
|
||||||
*/
|
*/
|
||||||
EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater)
|
EIGEN_MAKE_CWISE_COMP_R_OP(operator>, operator<, LT)
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
|
/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
|
||||||
*
|
*
|
||||||
@ -104,7 +141,7 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater)
|
|||||||
*
|
*
|
||||||
* \sa all(), any(), operator>(), operator<=()
|
* \sa all(), any(), operator>(), operator<=()
|
||||||
*/
|
*/
|
||||||
EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal)
|
EIGEN_MAKE_CWISE_COMP_R_OP(operator>=, operator<=, LE)
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise == operator of *this and \a other
|
/** \returns an expression of the coefficient-wise == operator of *this and \a other
|
||||||
*
|
*
|
||||||
@ -118,7 +155,7 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal)
|
|||||||
*
|
*
|
||||||
* \sa all(), any(), isApprox(), isMuchSmallerThan()
|
* \sa all(), any(), isApprox(), isMuchSmallerThan()
|
||||||
*/
|
*/
|
||||||
EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to)
|
EIGEN_MAKE_CWISE_COMP_OP(operator==, EQ)
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise != operator of *this and \a other
|
/** \returns an expression of the coefficient-wise != operator of *this and \a other
|
||||||
*
|
*
|
||||||
@ -132,7 +169,10 @@ EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to)
|
|||||||
*
|
*
|
||||||
* \sa all(), any(), isApprox(), isMuchSmallerThan()
|
* \sa all(), any(), isApprox(), isMuchSmallerThan()
|
||||||
*/
|
*/
|
||||||
EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to)
|
EIGEN_MAKE_CWISE_COMP_OP(operator!=, NEQ)
|
||||||
|
|
||||||
|
#undef EIGEN_MAKE_CWISE_COMP_OP
|
||||||
|
#undef EIGEN_MAKE_CWISE_COMP_R_OP
|
||||||
|
|
||||||
// scalar addition
|
// scalar addition
|
||||||
|
|
||||||
@ -209,3 +249,5 @@ operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
|
|||||||
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
|
THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL);
|
||||||
return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived());
|
return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,19 +185,3 @@ cube() const
|
|||||||
{
|
{
|
||||||
return derived();
|
return derived();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(METHOD_NAME,FUNCTOR) \
|
|
||||||
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)); \
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,3 +124,20 @@ cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
|
|||||||
{
|
{
|
||||||
return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
|
return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,internal::cmp_EQ>, const Derived, const ConstantReturnType> CwiseScalarEqualReturnType;
|
||||||
|
|
||||||
|
/** \returns an expression of the coefficient-wise == operator of \c *this and a scalar \a s
|
||||||
|
*
|
||||||
|
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
|
||||||
|
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is
|
||||||
|
* generally a far better idea to use a fuzzy comparison as provided by isApprox() and
|
||||||
|
* isMuchSmallerThan().
|
||||||
|
*
|
||||||
|
* \sa cwiseEqual(const MatrixBase<OtherDerived> &) const
|
||||||
|
*/
|
||||||
|
inline const CwiseScalarEqualReturnType
|
||||||
|
cwiseEqual(const Scalar& s) const
|
||||||
|
{
|
||||||
|
return CwiseScalarEqualReturnType(derived(), Derived::Constant(rows(), cols(), s), internal::scalar_cmp_op<Scalar,internal::cmp_EQ>());
|
||||||
|
}
|
||||||
|
@ -50,18 +50,3 @@ cwiseSqrt() const { return derived(); }
|
|||||||
inline const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived>
|
inline const CwiseUnaryOp<internal::scalar_inverse_op<Scalar>, const Derived>
|
||||||
cwiseInverse() const { return derived(); }
|
cwiseInverse() const { return derived(); }
|
||||||
|
|
||||||
/** \returns an expression of the coefficient-wise == operator of \c *this and a scalar \a s
|
|
||||||
*
|
|
||||||
* \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
|
|
||||||
* In order to check for equality between two vectors or matrices with floating-point coefficients, it is
|
|
||||||
* generally a far better idea to use a fuzzy comparison as provided by isApprox() and
|
|
||||||
* isMuchSmallerThan().
|
|
||||||
*
|
|
||||||
* \sa cwiseEqual(const MatrixBase<OtherDerived> &) const
|
|
||||||
*/
|
|
||||||
inline const CwiseUnaryOp<std::binder1st<std::equal_to<Scalar> >, const Derived>
|
|
||||||
cwiseEqual(const Scalar& s) const
|
|
||||||
{
|
|
||||||
return CwiseUnaryOp<std::binder1st<std::equal_to<Scalar> >,const Derived>
|
|
||||||
(derived(), std::bind1st(std::equal_to<Scalar>(), s));
|
|
||||||
}
|
|
||||||
|
@ -109,6 +109,8 @@ template<typename ArrayType> void comparisons(const ArrayType& m)
|
|||||||
VERIFY(! (m1 < m3).all() );
|
VERIFY(! (m1 < m3).all() );
|
||||||
VERIFY(! (m1 > m3).all() );
|
VERIFY(! (m1 > m3).all() );
|
||||||
}
|
}
|
||||||
|
VERIFY(!(m1 > m2 && m1 < m2).any());
|
||||||
|
VERIFY((m1 <= m2 || m1 >= m2).all());
|
||||||
|
|
||||||
// comparisons to scalar
|
// comparisons to scalar
|
||||||
VERIFY( (m1 != (m1(r,c)+1) ).any() );
|
VERIFY( (m1 != (m1(r,c)+1) ).any() );
|
||||||
|
@ -102,6 +102,7 @@ template<typename MatrixType> void comparisons(const MatrixType& m)
|
|||||||
VERIFY( (m1.array() > (m1(r,c)-1) ).any() );
|
VERIFY( (m1.array() > (m1(r,c)-1) ).any() );
|
||||||
VERIFY( (m1.array() < (m1(r,c)+1) ).any() );
|
VERIFY( (m1.array() < (m1(r,c)+1) ).any() );
|
||||||
VERIFY( (m1.array() == m1(r,c) ).any() );
|
VERIFY( (m1.array() == m1(r,c) ).any() );
|
||||||
|
VERIFY( m1.cwiseEqual(m1(r,c)).any() );
|
||||||
|
|
||||||
// test Select
|
// test Select
|
||||||
VERIFY_IS_APPROX( (m1.array()<m2.array()).select(m1,m2), m1.cwiseMin(m2) );
|
VERIFY_IS_APPROX( (m1.array()<m2.array()).select(m1,m2), m1.cwiseMin(m2) );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user