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