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
13/** \returns an expression of the Schur product (coefficient wise product) of *this and \a other
14 *
15 * Example: \include MatrixBase_cwiseProduct.cpp
16 * Output: \verbinclude MatrixBase_cwiseProduct.out
17 *
18 * \sa class CwiseBinaryOp, cwiseAbs2
19 */
20template<typename OtherDerived>
21EIGEN_DEVICE_FUNC
22EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)
23cwiseProduct(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/** \returns an expression of the coefficient-wise == operator of *this and \a other
29 *
30 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
31 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
32 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
33 * isMuchSmallerThan().
34 *
35 * Example: \include MatrixBase_cwiseEqual.cpp
36 * Output: \verbinclude MatrixBase_cwiseEqual.out
37 *
38 * \sa cwiseNotEqual(), isApprox(), isMuchSmallerThan()
39 */
40template<typename OtherDerived>
41EIGEN_DEVICE_FUNC
42inline const CwiseBinaryOp<std::equal_to<Scalar>, const Derived, const OtherDerived>
43cwiseEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
44{
45 return CwiseBinaryOp<std::equal_to<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
46}
47
48/** \returns an expression of the coefficient-wise != operator of *this and \a other
49 *
50 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
51 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
52 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
53 * isMuchSmallerThan().
54 *
55 * Example: \include MatrixBase_cwiseNotEqual.cpp
56 * Output: \verbinclude MatrixBase_cwiseNotEqual.out
57 *
58 * \sa cwiseEqual(), isApprox(), isMuchSmallerThan()
59 */
60template<typename OtherDerived>
61EIGEN_DEVICE_FUNC
62inline const CwiseBinaryOp<std::not_equal_to<Scalar>, const Derived, const OtherDerived>
63cwiseNotEqual(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
64{
65 return CwiseBinaryOp<std::not_equal_to<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
66}
67
68/** \returns an expression of the coefficient-wise min of *this and \a other
69 *
70 * Example: \include MatrixBase_cwiseMin.cpp
71 * Output: \verbinclude MatrixBase_cwiseMin.out
72 *
73 * \sa class CwiseBinaryOp, max()
74 */
75template<typename OtherDerived>
76EIGEN_DEVICE_FUNC
77EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const OtherDerived>
78cwiseMin(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
79{
80 return CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
81}
82
83/** \returns an expression of the coefficient-wise min of *this and scalar \a other
84 *
85 * \sa class CwiseBinaryOp, min()
86 */
87EIGEN_DEVICE_FUNC
88EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, const ConstantReturnType>
89cwiseMin(const Scalar &other) const
90{
91 return cwiseMin(Derived::Constant(rows(), cols(), other));
92}
93
94/** \returns an expression of the coefficient-wise max of *this and \a other
95 *
96 * Example: \include MatrixBase_cwiseMax.cpp
97 * Output: \verbinclude MatrixBase_cwiseMax.out
98 *
99 * \sa class CwiseBinaryOp, min()
100 */
101template<typename OtherDerived>
102EIGEN_DEVICE_FUNC
103EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const OtherDerived>
104cwiseMax(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
105{
106 return CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
107}
108
109/** \returns an expression of the coefficient-wise max of *this and scalar \a other
110 *
111 * \sa class CwiseBinaryOp, min()
112 */
113EIGEN_DEVICE_FUNC
114EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, const ConstantReturnType>
115cwiseMax(const Scalar &other) const
116{
117 return cwiseMax(Derived::Constant(rows(), cols(), other));
118}
119
120
121/** \returns an expression of the coefficient-wise quotient of *this and \a other
122 *
123 * Example: \include MatrixBase_cwiseQuotient.cpp
124 * Output: \verbinclude MatrixBase_cwiseQuotient.out
125 *
126 * \sa class CwiseBinaryOp, cwiseProduct(), cwiseInverse()
127 */
128template<typename OtherDerived>
129EIGEN_DEVICE_FUNC
130EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>
131cwiseQuotient(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
132{
133 return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived());
134}
135
136typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>, const Derived, const ConstantReturnType> CwiseScalarEqualReturnType;
137
138/** \returns an expression of the coefficient-wise == operator of \c *this and a scalar \a s
139 *
140 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types.
141 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is
142 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and
143 * isMuchSmallerThan().
144 *
145 * \sa cwiseEqual(const MatrixBase<OtherDerived> &) const
146 */
147EIGEN_DEVICE_FUNC
148inline const CwiseScalarEqualReturnType
149cwiseEqual(const Scalar& s) const
150{
151 return CwiseScalarEqualReturnType(derived(), Derived::Constant(rows(), cols(), s), internal::scalar_cmp_op<Scalar,Scalar,internal::cmp_EQ>());
152}
153