MatrixCwiseBinaryOps.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 // This file is a base class plugin containing matrix specifics coefficient wise functions.
12 
20 template<typename OtherDerived>
22 EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)
23 cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
24 {
25  return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)(derived(), other.derived());
26 }
27 
28 template<typename OtherDerived> using CwiseBinaryEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ>, const Derived, const OtherDerived>;
29 template<typename OtherDerived> using CwiseBinaryNotEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>, const Derived, const OtherDerived>;
30 template<typename OtherDerived> using CwiseBinaryLessReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>, const Derived, const OtherDerived>;
31 template<typename OtherDerived> using CwiseBinaryGreaterReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>, const Derived, const OtherDerived>;
32 template<typename OtherDerived> using CwiseBinaryLessOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>, const Derived, const OtherDerived>;
33 template<typename OtherDerived> using CwiseBinaryGreaterOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>, const Derived, const OtherDerived>;
34 
47 template<typename OtherDerived>
50 cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
51 {
52  return CwiseBinaryEqualReturnType<OtherDerived>(derived(), other.derived());
53 }
54 
67 template<typename OtherDerived>
70 cwiseNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
71 {
72  return CwiseBinaryNotEqualReturnType<OtherDerived>(derived(), other.derived());
73 }
74 
76 template<typename OtherDerived>
79 cwiseLess(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const
80 {
81  return CwiseBinaryLessReturnType<OtherDerived>(derived(), other.derived());
82 }
83 
85 template<typename OtherDerived>
88 cwiseGreater(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const
89 {
90  return CwiseBinaryGreaterReturnType<OtherDerived>(derived(), other.derived());
91 }
92 
94 template<typename OtherDerived>
97 cwiseLessOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const
98 {
99  return CwiseBinaryLessOrEqualReturnType<OtherDerived>(derived(), other.derived());
100 }
101 
103 template<typename OtherDerived>
106 cwiseGreaterOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const
107 {
108  return CwiseBinaryGreaterOrEqualReturnType<OtherDerived>(derived(), other.derived());
109 }
110 
118 template<int NaNPropagation=PropagateFast, typename OtherDerived>
120 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar,NaNPropagation>, const Derived, const OtherDerived>
121 cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
122 {
123  return CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar,NaNPropagation>, const Derived, const OtherDerived>(derived(), other.derived());
124 }
125 
130 template<int NaNPropagation=PropagateFast>
132 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar,NaNPropagation>, const Derived, const ConstantReturnType>
133 cwiseMin(const Scalar &other) const
134 {
135  return cwiseMin<NaNPropagation>(Derived::Constant(rows(), cols(), other));
136 }
137 
145 template<int NaNPropagation=PropagateFast, typename OtherDerived>
147 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar,NaNPropagation>, const Derived, const OtherDerived>
148 cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
149 {
150  return CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar,NaNPropagation>, const Derived, const OtherDerived>(derived(), other.derived());
151 }
152 
157 template<int NaNPropagation=PropagateFast>
159 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar,NaNPropagation>, const Derived, const ConstantReturnType>
160 cwiseMax(const Scalar &other) const
161 {
162  return cwiseMax<NaNPropagation>(Derived::Constant(rows(), cols(), other));
163 }
164 
165 
173 template<typename OtherDerived>
175 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>
176 cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
177 {
178  return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
179 }
180 
181 using CwiseScalarEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>, const Derived, const ConstantReturnType>;
182 using CwiseScalarNotEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>, const Derived, const ConstantReturnType>;
183 using CwiseScalarLessReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>, const Derived, const ConstantReturnType>;
184 using CwiseScalarGreaterReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>, const Derived, const ConstantReturnType>;
185 using CwiseScalarLessOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>, const Derived, const ConstantReturnType>;
186 using CwiseScalarGreaterOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>, const Derived, const ConstantReturnType>;
187 
198 inline const CwiseScalarEqualReturnType
199 cwiseEqual(const Scalar& s) const
200 {
201  return CwiseScalarEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
202 }
203 
204 
216 cwiseNotEqual(const Scalar& s) const
217 {
218  return CwiseScalarNotEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
219 }
220 
223 inline const CwiseScalarLessReturnType
224 cwiseLess(const Scalar& s) const
225 {
226  return CwiseScalarLessReturnType(derived(), Derived::Constant(rows(), cols(), s));
227 }
228 
231 inline const CwiseScalarGreaterReturnType
232 cwiseGreater(const Scalar& s) const
233 {
234  return CwiseScalarGreaterReturnType(derived(), Derived::Constant(rows(), cols(), s));
235 }
236 
240 cwiseLessOrEqual(const Scalar& s) const
241 {
242  return CwiseScalarLessOrEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
243 }
244 
248 cwiseGreaterOrEqual(const Scalar& s) const
249 {
250  return CwiseScalarGreaterOrEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
251 }
252 
253 template<typename OtherDerived> using CwiseBinaryTypedEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ, true>, const Derived, const OtherDerived>;
254 template<typename OtherDerived> using CwiseBinaryTypedNotEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ, true>, const Derived, const OtherDerived>;
255 template<typename OtherDerived> using CwiseBinaryTypedLessReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT, true>, const Derived, const OtherDerived>;
256 template<typename OtherDerived> using CwiseBinaryTypedGreaterReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT, true>, const Derived, const OtherDerived>;
257 template<typename OtherDerived> using CwiseBinaryTypedLessOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE, true>, const Derived, const OtherDerived>;
258 template<typename OtherDerived> using CwiseBinaryTypedGreaterOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE, true>, const Derived, const OtherDerived>;
259 
260 template <typename OtherDerived>
262 cwiseTypedEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { return CwiseBinaryTypedEqualReturnType<OtherDerived>(derived(), other.derived()); }
263 
264 template <typename OtherDerived>
266 cwiseTypedNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { return CwiseBinaryTypedNotEqualReturnType<OtherDerived>(derived(), other.derived()); }
267 
268 template <typename OtherDerived>
270 cwiseTypedLess(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { return CwiseBinaryTypedLessReturnType<OtherDerived>(derived(), other.derived()); }
271 
272 template <typename OtherDerived>
274 cwiseTypedGreater(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { return CwiseBinaryTypedGreaterReturnType<OtherDerived>(derived(), other.derived()); }
275 
276 template <typename OtherDerived>
278 cwiseTypedLessOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { return CwiseBinaryTypedLessOrEqualReturnType<OtherDerived>(derived(), other.derived()); }
279 
280 template <typename OtherDerived>
282 cwiseTypedGreaterOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { return CwiseBinaryTypedGreaterOrEqualReturnType<OtherDerived>(derived(), other.derived()); }
283 
284 using CwiseScalarTypedEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ, true>, const Derived, const ConstantReturnType>;
285 using CwiseScalarTypedNotEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ, true>, const Derived, const ConstantReturnType>;
286 using CwiseScalarTypedLessReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT, true>, const Derived, const ConstantReturnType>;
287 using CwiseScalarTypedGreaterReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT, true>, const Derived, const ConstantReturnType>;
288 using CwiseScalarTypedLessOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE, true>, const Derived, const ConstantReturnType>;
289 using CwiseScalarTypedGreaterOrEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE, true>, const Derived, const ConstantReturnType>;
290 
291 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseScalarTypedEqualReturnType
292 cwiseTypedEqual(const Scalar& s) const { return CwiseScalarTypedEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s)); }
293 
295 cwiseTypedNotEqual(const Scalar& s) const { return CwiseScalarTypedNotEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s)); }
296 
297 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseScalarTypedLessReturnType
298 cwiseTypedLess(const Scalar& s) const { return CwiseScalarTypedLessReturnType(derived(), ConstantReturnType(rows(), cols(), s)); }
299 
301 cwiseTypedGreater(const Scalar& s) const { return CwiseScalarTypedGreaterReturnType(derived(), ConstantReturnType(rows(), cols(), s)); }
302 
304 cwiseTypedLessOrEqual(const Scalar& s) const { return CwiseScalarTypedLessOrEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s)); }
305 
307 cwiseTypedGreaterOrEqual(const Scalar& s) const { return CwiseScalarTypedGreaterOrEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s)); }
#define EIGEN_CURRENT_STORAGE_BASE_CLASS
Definition: ArrayBase.h:92
#define EIGEN_CWISE_BINARY_RETURN_TYPE(LHS, RHS, OPNAME)
Definition: Macros.h:1182
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LE >, const Derived, const ConstantReturnType > CwiseScalarLessOrEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LE, true >, const Derived, const ConstantReturnType > CwiseScalarTypedLessOrEqualReturnType
const CwiseBinaryTypedLessReturnType< OtherDerived > cwiseTypedLess(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_EQ, true >, const Derived, const ConstantReturnType > CwiseScalarTypedEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_EQ >, const Derived, const ConstantReturnType > CwiseScalarEqualReturnType
const CwiseBinaryTypedGreaterOrEqualReturnType< OtherDerived > cwiseTypedGreaterOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
const CwiseBinaryEqualReturnType< OtherDerived > cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_NEQ, true >, const Derived, const ConstantReturnType > CwiseScalarTypedNotEqualReturnType
const CwiseBinaryOp< internal::scalar_min_op< Scalar, Scalar, NaNPropagation >, const Derived, const OtherDerived > cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
const CwiseBinaryTypedGreaterReturnType< OtherDerived > cwiseTypedGreater(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_NEQ, true >, const Derived, const OtherDerived > CwiseBinaryTypedNotEqualReturnType
const CwiseBinaryLessReturnType< OtherDerived > cwiseLess(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
const CwiseBinaryGreaterOrEqualReturnType< OtherDerived > cwiseGreaterOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GE, true >, const Derived, const ConstantReturnType > CwiseScalarTypedGreaterOrEqualReturnType
const CwiseBinaryTypedEqualReturnType< OtherDerived > cwiseTypedEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT, true >, const Derived, const OtherDerived > CwiseBinaryTypedGreaterReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_EQ, true >, const Derived, const OtherDerived > CwiseBinaryTypedEqualReturnType
const CwiseBinaryOp< internal::scalar_quotient_op< Scalar >, const Derived, const OtherDerived > cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT, true >, const Derived, const ConstantReturnType > CwiseScalarTypedGreaterReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_NEQ >, const Derived, const ConstantReturnType > CwiseScalarNotEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GE >, const Derived, const OtherDerived > CwiseBinaryGreaterOrEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_EQ >, const Derived, const OtherDerived > CwiseBinaryEqualReturnType
const CwiseBinaryGreaterReturnType< OtherDerived > cwiseGreater(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT >, const Derived, const OtherDerived > CwiseBinaryGreaterReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_NEQ >, const Derived, const OtherDerived > CwiseBinaryNotEqualReturnType
const CwiseBinaryTypedLessOrEqualReturnType< OtherDerived > cwiseTypedLessOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LT >, const Derived, const ConstantReturnType > CwiseScalarLessReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GE, true >, const Derived, const OtherDerived > CwiseBinaryTypedGreaterOrEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LE >, const Derived, const OtherDerived > CwiseBinaryLessOrEqualReturnType
const CwiseBinaryTypedNotEqualReturnType< OtherDerived > cwiseTypedNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
const CwiseBinaryOp< internal::scalar_max_op< Scalar, Scalar, NaNPropagation >, const Derived, const OtherDerived > cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
const CwiseBinaryLessOrEqualReturnType< OtherDerived > cwiseLessOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GT >, const Derived, const ConstantReturnType > CwiseScalarGreaterReturnType
const CwiseBinaryNotEqualReturnType< OtherDerived > cwiseNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LE, true >, const Derived, const OtherDerived > CwiseBinaryTypedLessOrEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LT >, const Derived, const OtherDerived > CwiseBinaryLessReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LT, true >, const Derived, const ConstantReturnType > CwiseScalarTypedLessReturnType
const CwiseBinaryOp< internal::scalar_product_op< Derived ::Scalar, OtherDerived ::Scalar >, const Derived, const OtherDerived > cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_GE >, const Derived, const ConstantReturnType > CwiseScalarGreaterOrEqualReturnType
CwiseBinaryOp< internal::scalar_cmp_op< Scalar, Scalar, internal::cmp_LT, true >, const Derived, const OtherDerived > CwiseBinaryTypedLessReturnType