This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
View | Details | Raw Unified | Return to bug 872
Collapse All | Expand All

(-)a/Eigen/src/Core/functors/BinaryFunctors.h (+42 lines)
Lines 155-160 Link Here
155
};
155
};
156
156
157
/** \internal
157
/** \internal
158
  * \brief Template functors for comparison of two scalars
159
  * \todo Implement packet-comparisons
160
  */
161
template<typename Scalar, ComparisonName cmp> struct scalar_cmp_op;
162
163
template<typename Scalar, ComparisonName cmp>
164
struct functor_traits<scalar_cmp_op<Scalar, cmp> > {
165
  enum {
166
    Cost = NumTraits<Scalar>::AddCost,
167
    PacketAccess = false
168
  };
169
};
170
171
172
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_EQ> {
173
  EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
174
  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a==b;}
175
};
176
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_LT> {
177
  EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
178
  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a<b;}
179
};
180
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_LE> {
181
  EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
182
  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a<=b;}
183
};
184
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_UNORD> {
185
  EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
186
  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return !(a<=b || b<=a);}
187
};
188
template<typename Scalar> struct scalar_cmp_op<Scalar, cmp_NE> {
189
  EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
190
  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE operator()(const Scalar& a, const Scalar& b) const {return a!=b;}
191
};
192
193
template<ComparisonName Cmp, typename Scalar>
194
struct result_of<scalar_cmp_op<Scalar, Cmp>(Scalar,Scalar)> {
195
  typedef bool type;
196
};
197
198
199
/** \internal
158
  * \brief Template functor to compute the hypot of two scalars
200
  * \brief Template functor to compute the hypot of two scalars
159
  *
201
  *
160
  * \sa MatrixBase::stableNorm(), class Redux
202
  * \sa MatrixBase::stableNorm(), class Redux
(-)a/Eigen/src/Core/util/Constants.h (+10 lines)
Lines 492-497 Link Here
492
// evaluator based on iterators to access coefficients. 
492
// evaluator based on iterators to access coefficients. 
493
struct IteratorBased {};
493
struct IteratorBased {};
494
494
495
/** \internal
496
 * Constants for comparison functors
497
 */
498
enum ComparisonName {
499
  cmp_EQ = 0,
500
  cmp_LT = 1,
501
  cmp_LE = 2,
502
  cmp_UNORD = 3,
503
  cmp_NE = 4
504
};
495
} // end namespace internal
505
} // end namespace internal
496
506
497
} // end namespace Eigen
507
} // end namespace Eigen
(-)a/Eigen/src/plugins/ArrayCwiseBinaryOps.h (-6 / +73 lines)
Lines 81-87 Link Here
81
  *
81
  *
82
  * \sa all(), any(), operator>(), operator<=()
82
  * \sa all(), any(), operator>(), operator<=()
83
  */
83
  */
84
EIGEN_MAKE_CWISE_BINARY_OP(operator<,std::less)
84
template<typename OtherDerived>
85
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, const Derived, const OtherDerived>
86
operator<(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
87
{
88
  return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, const Derived, const OtherDerived>(derived(), other.derived());
89
}
90
91
92
85
93
86
/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
94
/** \returns an expression of the coefficient-wise \<= operator of *this and \a other
87
  *
95
  *
Lines 90-96 Link Here
90
  *
98
  *
91
  * \sa all(), any(), operator>=(), operator<()
99
  * \sa all(), any(), operator>=(), operator<()
92
  */
100
  */
93
EIGEN_MAKE_CWISE_BINARY_OP(operator<=,std::less_equal)
101
template<typename OtherDerived>
102
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, const Derived, const OtherDerived>
103
operator<=(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
104
{
105
  return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, const Derived, const OtherDerived>(derived(), other.derived());
106
}
94
107
95
/** \returns an expression of the coefficient-wise \> operator of *this and \a other
108
/** \returns an expression of the coefficient-wise \> operator of *this and \a other
96
  *
109
  *
Lines 99-105 Link Here
99
  *
112
  *
100
  * \sa all(), any(), operator>=(), operator<()
113
  * \sa all(), any(), operator>=(), operator<()
101
  */
114
  */
102
EIGEN_MAKE_CWISE_BINARY_OP(operator>,std::greater)
115
template<typename OtherDerived>
116
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, const OtherDerived, const Derived>
117
operator>(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
118
{
119
  return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LT>, const OtherDerived, const Derived>(other.derived(), derived());
120
}
103
121
104
/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
122
/** \returns an expression of the coefficient-wise \>= operator of *this and \a other
105
  *
123
  *
Lines 108-114 Link Here
108
  *
126
  *
109
  * \sa all(), any(), operator>(), operator<=()
127
  * \sa all(), any(), operator>(), operator<=()
110
  */
128
  */
111
EIGEN_MAKE_CWISE_BINARY_OP(operator>=,std::greater_equal)
129
template<typename OtherDerived>
130
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, const OtherDerived, const Derived>
131
operator>=(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
132
{
133
  return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_LE>, const OtherDerived, const Derived>(other.derived(), derived());
134
}
112
135
113
/** \returns an expression of the coefficient-wise == operator of *this and \a other
136
/** \returns an expression of the coefficient-wise == operator of *this and \a other
114
  *
137
  *
Lines 122-128 Link Here
122
  *
145
  *
123
  * \sa all(), any(), isApprox(), isMuchSmallerThan()
146
  * \sa all(), any(), isApprox(), isMuchSmallerThan()
124
  */
147
  */
125
EIGEN_MAKE_CWISE_BINARY_OP(operator==,std::equal_to)
148
template<typename OtherDerived>
149
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_EQ>, const Derived, const OtherDerived>
150
operator==(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
151
{
152
  return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_EQ>, const Derived, const OtherDerived>(derived(), other.derived());
153
}
126
154
127
/** \returns an expression of the coefficient-wise != operator of *this and \a other
155
/** \returns an expression of the coefficient-wise != operator of *this and \a other
128
  *
156
  *
Lines 136-142 Link Here
136
  *
164
  *
137
  * \sa all(), any(), isApprox(), isMuchSmallerThan()
165
  * \sa all(), any(), isApprox(), isMuchSmallerThan()
138
  */
166
  */
139
EIGEN_MAKE_CWISE_BINARY_OP(operator!=,std::not_equal_to)
167
template<typename OtherDerived>
168
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_NE>, const Derived, const OtherDerived>
169
operator!=(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
170
{
171
  return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_NE>, const Derived, const OtherDerived>(derived(), other.derived());
172
}
173
174
175
176
#define EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(METHOD_NAME,COMPARATOR) \
177
  typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \
178
  typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \
179
  EIGEN_DEVICE_FUNC \
180
  inline const Cmp ## COMPARATOR ## ReturnType \
181
  METHOD_NAME(const Scalar& s) const { \
182
    return METHOD_NAME(Derived::PlainObject::Constant(rows(), cols(), s)); \
183
  } \
184
  friend inline const RCmp ## COMPARATOR ## ReturnType \
185
  METHOD_NAME(const Scalar& s, const Derived& d) { \
186
    return Derived::PlainObject::Constant(d.rows(), d.cols(), s).METHOD_NAME(d); \
187
  }
188
189
#define EIGEN_MAKE_SCALAR_CWISE_RCMP_UNARY_OP(METHOD_NAME, R_METHOD_NAME, RCOMPARATOR) \
190
  EIGEN_DEVICE_FUNC \
191
  inline const RCmp ## RCOMPARATOR ## ReturnType \
192
  METHOD_NAME(const Scalar& s) const { \
193
    return Derived::PlainObject::Constant(rows(), cols(), s).R_METHOD_NAME(*this); \
194
  } \
195
  friend inline const Cmp ## RCOMPARATOR ## ReturnType \
196
  METHOD_NAME(const Scalar& s, const Derived& d) { \
197
    return d.R_METHOD_NAME(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \
198
  }
199
200
EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator==,  EQ)
201
EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator!=,  NE)
202
EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator<,  LT)
203
EIGEN_MAKE_SCALAR_CWISE_CMP_UNARY_OP(operator<=,  LE)
204
EIGEN_MAKE_SCALAR_CWISE_RCMP_UNARY_OP(operator>,operator<,  LT)
205
EIGEN_MAKE_SCALAR_CWISE_RCMP_UNARY_OP(operator>=,operator<=,  LE)
206
140
207
141
// scalar addition
208
// scalar addition
142
209
(-)a/Eigen/src/plugins/ArrayCwiseUnaryOps.h (-19 lines)
Lines 246-269 Link Here
246
  return CubeReturnType(derived());
246
  return CubeReturnType(derived());
247
}
247
}
248
248
249
#define EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(METHOD_NAME,FUNCTOR) \
250
  EIGEN_DEVICE_FUNC \
251
  inline const CwiseUnaryOp<std::binder2nd<FUNCTOR<Scalar> >, const Derived> \
252
  METHOD_NAME(const Scalar& s) const { \
253
    return CwiseUnaryOp<std::binder2nd<FUNCTOR<Scalar> >, const Derived> \
254
            (derived(), std::bind2nd(FUNCTOR<Scalar>(), s)); \
255
  } \
256
  friend inline const CwiseUnaryOp<std::binder1st<FUNCTOR<Scalar> >, const Derived> \
257
  METHOD_NAME(const Scalar& s, const Derived& d) { \
258
	  return CwiseUnaryOp<std::binder1st<FUNCTOR<Scalar> >, const Derived> \
259
			  (d, std::bind1st(FUNCTOR<Scalar>(), s)); \
260
  }
261
249
262
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator==,  std::equal_to)
263
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator!=,  std::not_equal_to)
264
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<,   std::less)
265
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator<=,  std::less_equal)
266
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>,   std::greater)
267
EIGEN_MAKE_SCALAR_CWISE_UNARY_OP(operator>=,  std::greater_equal)
268
250
269
(-)a/test/array.cpp (+2 lines)
Lines 136-141 Link Here
136
    VERIFY(! (m1 < m3).all() );
136
    VERIFY(! (m1 < m3).all() );
137
    VERIFY(! (m1 > m3).all() );
137
    VERIFY(! (m1 > m3).all() );
138
  }
138
  }
139
  VERIFY(!(m1 > m2 && m1 < m2).any());
140
  VERIFY((m1 <= m2 || m1 >= m2).all());
139
141
140
  // comparisons array to scalar
142
  // comparisons array to scalar
141
  VERIFY( (m1 != (m1(r,c)+1) ).any() );
143
  VERIFY( (m1 != (m1(r,c)+1) ).any() );

Return to bug 872