Eigen  5.0.1
 
Loading...
Searching...
No Matches
MatrixCwiseBinaryOps.inc
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// SPDX-License-Identifier: MPL-2.0
11
12// This file is a base class plugin containing matrix specific coefficient wise functions.
13
21template <typename OtherDerived>
22EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived, OtherDerived,
23 internal::scalar_product_op)
24 cwiseProduct(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
25 return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived, OtherDerived, internal::scalar_product_op)(derived(), other.derived());
26}
27
28template <typename OtherDerived>
29using CwiseBinaryEqualReturnType =
30 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ>, const Derived, const OtherDerived>;
31template <typename OtherDerived>
32using CwiseBinaryNotEqualReturnType =
33 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>, const Derived, const OtherDerived>;
34template <typename OtherDerived>
35using CwiseBinaryLessReturnType =
36 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>, const Derived, const OtherDerived>;
37template <typename OtherDerived>
38using CwiseBinaryGreaterReturnType =
39 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>, const Derived, const OtherDerived>;
40template <typename OtherDerived>
41using CwiseBinaryLessOrEqualReturnType =
42 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>, const Derived, const OtherDerived>;
43template <typename OtherDerived>
44using CwiseBinaryGreaterOrEqualReturnType =
45 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>, const Derived, const OtherDerived>;
46
59template <typename OtherDerived>
60EIGEN_DEVICE_FUNC constexpr inline const CwiseBinaryEqualReturnType<OtherDerived> cwiseEqual(
61 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
62 return CwiseBinaryEqualReturnType<OtherDerived>(derived(), other.derived());
63}
64
77template <typename OtherDerived>
78EIGEN_DEVICE_FUNC constexpr inline const CwiseBinaryNotEqualReturnType<OtherDerived> cwiseNotEqual(
79 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
80 return CwiseBinaryNotEqualReturnType<OtherDerived>(derived(), other.derived());
81}
82
84template <typename OtherDerived>
85EIGEN_DEVICE_FUNC constexpr inline const CwiseBinaryLessReturnType<OtherDerived> cwiseLess(
86 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
87 return CwiseBinaryLessReturnType<OtherDerived>(derived(), other.derived());
88}
89
91template <typename OtherDerived>
92EIGEN_DEVICE_FUNC constexpr inline const CwiseBinaryGreaterReturnType<OtherDerived> cwiseGreater(
93 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
94 return CwiseBinaryGreaterReturnType<OtherDerived>(derived(), other.derived());
95}
96
98template <typename OtherDerived>
99EIGEN_DEVICE_FUNC constexpr inline const CwiseBinaryLessOrEqualReturnType<OtherDerived> cwiseLessOrEqual(
100 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
101 return CwiseBinaryLessOrEqualReturnType<OtherDerived>(derived(), other.derived());
102}
103
105template <typename OtherDerived>
106EIGEN_DEVICE_FUNC constexpr inline const CwiseBinaryGreaterOrEqualReturnType<OtherDerived> cwiseGreaterOrEqual(
107 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
108 return CwiseBinaryGreaterOrEqualReturnType<OtherDerived>(derived(), other.derived());
109}
110
118template <int NaNPropagation = PropagateFast, typename OtherDerived>
119EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const
120 CwiseBinaryOp<internal::scalar_min_op<Scalar, Scalar, NaNPropagation>, const Derived, const OtherDerived>
121 cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
122 return CwiseBinaryOp<internal::scalar_min_op<Scalar, Scalar, NaNPropagation>, const Derived, const OtherDerived>(
123 derived(), other.derived());
124}
125
130template <int NaNPropagation = PropagateFast>
131EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const
132 CwiseBinaryOp<internal::scalar_min_op<Scalar, Scalar, NaNPropagation>, const Derived, const ConstantReturnType>
133 cwiseMin(const Scalar& other) const {
134 return cwiseMin<NaNPropagation>(Derived::Constant(rows(), cols(), other));
135}
136
144template <int NaNPropagation = PropagateFast, typename OtherDerived>
145EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const
146 CwiseBinaryOp<internal::scalar_max_op<Scalar, Scalar, NaNPropagation>, const Derived, const OtherDerived>
147 cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
148 return CwiseBinaryOp<internal::scalar_max_op<Scalar, Scalar, NaNPropagation>, const Derived, const OtherDerived>(
149 derived(), other.derived());
150}
151
156template <int NaNPropagation = PropagateFast>
157EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const
158 CwiseBinaryOp<internal::scalar_max_op<Scalar, Scalar, NaNPropagation>, const Derived, const ConstantReturnType>
159 cwiseMax(const Scalar& other) const {
160 return cwiseMax<NaNPropagation>(Derived::Constant(rows(), cols(), other));
161}
162
170template <typename OtherDerived>
171EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const
172 CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>
173 cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
174 return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(),
175 other.derived());
176}
177
178using CwiseScalarEqualReturnType =
179 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ>, const Derived, const ConstantReturnType>;
180using CwiseScalarNotEqualReturnType =
181 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ>, const Derived, const ConstantReturnType>;
182using CwiseScalarLessReturnType =
183 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT>, const Derived, const ConstantReturnType>;
184using CwiseScalarGreaterReturnType =
185 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT>, const Derived, const ConstantReturnType>;
186using CwiseScalarLessOrEqualReturnType =
187 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE>, const Derived, const ConstantReturnType>;
188using CwiseScalarGreaterOrEqualReturnType =
189 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE>, const Derived, const ConstantReturnType>;
190
200EIGEN_DEVICE_FUNC constexpr inline const CwiseScalarEqualReturnType cwiseEqual(const Scalar& s) const {
201 return CwiseScalarEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
202}
203
213EIGEN_DEVICE_FUNC constexpr inline const CwiseScalarNotEqualReturnType cwiseNotEqual(const Scalar& s) const {
214 return CwiseScalarNotEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
215}
216
218EIGEN_DEVICE_FUNC constexpr inline const CwiseScalarLessReturnType cwiseLess(const Scalar& s) const {
219 return CwiseScalarLessReturnType(derived(), Derived::Constant(rows(), cols(), s));
220}
221
223EIGEN_DEVICE_FUNC constexpr inline const CwiseScalarGreaterReturnType cwiseGreater(const Scalar& s) const {
224 return CwiseScalarGreaterReturnType(derived(), Derived::Constant(rows(), cols(), s));
225}
226
228EIGEN_DEVICE_FUNC constexpr inline const CwiseScalarLessOrEqualReturnType cwiseLessOrEqual(const Scalar& s) const {
229 return CwiseScalarLessOrEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
230}
231
233EIGEN_DEVICE_FUNC constexpr inline const CwiseScalarGreaterOrEqualReturnType cwiseGreaterOrEqual(
234 const Scalar& s) const {
235 return CwiseScalarGreaterOrEqualReturnType(derived(), Derived::Constant(rows(), cols(), s));
236}
237
238template <typename OtherDerived>
239using CwiseBinaryTypedEqualReturnType =
240 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ, true>, const Derived, const OtherDerived>;
241template <typename OtherDerived>
242using CwiseBinaryTypedNotEqualReturnType =
243 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ, true>, const Derived, const OtherDerived>;
244template <typename OtherDerived>
245using CwiseBinaryTypedLessReturnType =
246 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT, true>, const Derived, const OtherDerived>;
247template <typename OtherDerived>
248using CwiseBinaryTypedGreaterReturnType =
249 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT, true>, const Derived, const OtherDerived>;
250template <typename OtherDerived>
251using CwiseBinaryTypedLessOrEqualReturnType =
252 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE, true>, const Derived, const OtherDerived>;
253template <typename OtherDerived>
254using CwiseBinaryTypedGreaterOrEqualReturnType =
255 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE, true>, const Derived, const OtherDerived>;
256
257template <typename OtherDerived>
258EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseBinaryTypedEqualReturnType<OtherDerived> cwiseTypedEqual(
259 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
260 return CwiseBinaryTypedEqualReturnType<OtherDerived>(derived(), other.derived());
261}
262
263template <typename OtherDerived>
264EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseBinaryTypedNotEqualReturnType<OtherDerived>
265cwiseTypedNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
266 return CwiseBinaryTypedNotEqualReturnType<OtherDerived>(derived(), other.derived());
267}
268
269template <typename OtherDerived>
270EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseBinaryTypedLessReturnType<OtherDerived> cwiseTypedLess(
271 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
272 return CwiseBinaryTypedLessReturnType<OtherDerived>(derived(), other.derived());
273}
274
275template <typename OtherDerived>
276EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseBinaryTypedGreaterReturnType<OtherDerived> cwiseTypedGreater(
277 const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
278 return CwiseBinaryTypedGreaterReturnType<OtherDerived>(derived(), other.derived());
279}
280
281template <typename OtherDerived>
282EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseBinaryTypedLessOrEqualReturnType<OtherDerived>
283cwiseTypedLessOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
284 return CwiseBinaryTypedLessOrEqualReturnType<OtherDerived>(derived(), other.derived());
285}
286
287template <typename OtherDerived>
288EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseBinaryTypedGreaterOrEqualReturnType<OtherDerived>
289cwiseTypedGreaterOrEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const {
290 return CwiseBinaryTypedGreaterOrEqualReturnType<OtherDerived>(derived(), other.derived());
291}
292
293using CwiseScalarTypedEqualReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_EQ, true>,
294 const Derived, const ConstantReturnType>;
295using CwiseScalarTypedNotEqualReturnType =
296 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_NEQ, true>, const Derived,
297 const ConstantReturnType>;
298using CwiseScalarTypedLessReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LT, true>,
299 const Derived, const ConstantReturnType>;
300using CwiseScalarTypedGreaterReturnType = CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GT, true>,
301 const Derived, const ConstantReturnType>;
302using CwiseScalarTypedLessOrEqualReturnType =
303 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_LE, true>, const Derived,
304 const ConstantReturnType>;
305using CwiseScalarTypedGreaterOrEqualReturnType =
306 CwiseBinaryOp<internal::scalar_cmp_op<Scalar, Scalar, internal::cmp_GE, true>, const Derived,
307 const ConstantReturnType>;
308
309EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseScalarTypedEqualReturnType
310cwiseTypedEqual(const Scalar& s) const {
311 return CwiseScalarTypedEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s));
312}
313
314EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseScalarTypedNotEqualReturnType
315cwiseTypedNotEqual(const Scalar& s) const {
316 return CwiseScalarTypedNotEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s));
317}
318
319EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseScalarTypedLessReturnType
320cwiseTypedLess(const Scalar& s) const {
321 return CwiseScalarTypedLessReturnType(derived(), ConstantReturnType(rows(), cols(), s));
322}
323
324EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseScalarTypedGreaterReturnType
325cwiseTypedGreater(const Scalar& s) const {
326 return CwiseScalarTypedGreaterReturnType(derived(), ConstantReturnType(rows(), cols(), s));
327}
328
329EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseScalarTypedLessOrEqualReturnType
330cwiseTypedLessOrEqual(const Scalar& s) const {
331 return CwiseScalarTypedLessOrEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s));
332}
333
334EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const CwiseScalarTypedGreaterOrEqualReturnType
335cwiseTypedGreaterOrEqual(const Scalar& s) const {
336 return CwiseScalarTypedGreaterOrEqualReturnType(derived(), ConstantReturnType(rows(), cols(), s));
337}