1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10 #ifndef EIGEN_ARRAY_CWISE_OPERATORS_H
11 #define EIGEN_ARRAY_CWISE_OPERATORS_H
12
13 namespace Eigen {
14
15 /***************************************************************************
16 * The following functions were defined in Core
17 ***************************************************************************/
18
19
20 /** \deprecated ArrayBase::abs() */
21 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)22 EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)
23 Cwise<ExpressionType>::abs() const
24 {
25 return _expression();
26 }
27
28 /** \deprecated ArrayBase::abs2() */
29 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)30 EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)
31 Cwise<ExpressionType>::abs2() const
32 {
33 return _expression();
34 }
35
36 /** \deprecated ArrayBase::exp() */
37 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)38 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)
39 Cwise<ExpressionType>::exp() const
40 {
41 return _expression();
42 }
43
44 /** \deprecated ArrayBase::log() */
45 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)46 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)
47 Cwise<ExpressionType>::log() const
48 {
49 return _expression();
50 }
51
52 /** \deprecated ArrayBase::operator*() */
53 template<typename ExpressionType>
54 template<typename OtherDerived>
EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)55 EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)
56 Cwise<ExpressionType>::operator*(const MatrixBase<OtherDerived> &other) const
57 {
58 return EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)(_expression(), other.derived());
59 }
60
61 /** \deprecated ArrayBase::operator/() */
62 template<typename ExpressionType>
63 template<typename OtherDerived>
64 EIGEN_STRONG_INLINE const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_quotient_op)
65 Cwise<ExpressionType>::operator/(const MatrixBase<OtherDerived> &other) const
66 {
67 return EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_quotient_op)(_expression(), other.derived());
68 }
69
70 /** \deprecated ArrayBase::operator*=() */
71 template<typename ExpressionType>
72 template<typename OtherDerived>
73 inline ExpressionType& Cwise<ExpressionType>::operator*=(const MatrixBase<OtherDerived> &other)
74 {
75 return m_matrix.const_cast_derived() = *this * other;
76 }
77
78 /** \deprecated ArrayBase::operator/=() */
79 template<typename ExpressionType>
80 template<typename OtherDerived>
81 inline ExpressionType& Cwise<ExpressionType>::operator/=(const MatrixBase<OtherDerived> &other)
82 {
83 return m_matrix.const_cast_derived() = *this / other;
84 }
85
86 /***************************************************************************
87 * The following functions were defined in Array
88 ***************************************************************************/
89
90 // -- unary operators --
91
92 /** \deprecated ArrayBase::sqrt() */
93 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)94 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)
95 Cwise<ExpressionType>::sqrt() const
96 {
97 return _expression();
98 }
99
100 /** \deprecated ArrayBase::cos() */
101 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)102 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)
103 Cwise<ExpressionType>::cos() const
104 {
105 return _expression();
106 }
107
108
109 /** \deprecated ArrayBase::sin() */
110 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)111 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)
112 Cwise<ExpressionType>::sin() const
113 {
114 return _expression();
115 }
116
117
118 /** \deprecated ArrayBase::log() */
119 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)120 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)
121 Cwise<ExpressionType>::pow(const Scalar& exponent) const
122 {
123 return EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)(_expression(), internal::scalar_pow_op<Scalar>(exponent));
124 }
125
126
127 /** \deprecated ArrayBase::inverse() */
128 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)129 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)
130 Cwise<ExpressionType>::inverse() const
131 {
132 return _expression();
133 }
134
135 /** \deprecated ArrayBase::square() */
136 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)137 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)
138 Cwise<ExpressionType>::square() const
139 {
140 return _expression();
141 }
142
143 /** \deprecated ArrayBase::cube() */
144 template<typename ExpressionType>
EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)145 inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)
146 Cwise<ExpressionType>::cube() const
147 {
148 return _expression();
149 }
150
151
152 // -- binary operators --
153
154 /** \deprecated ArrayBase::operator<() */
155 template<typename ExpressionType>
156 template<typename OtherDerived>
157 inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
158 Cwise<ExpressionType>::operator<(const MatrixBase<OtherDerived> &other) const
159 {
160 return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)(_expression(), other.derived());
161 }
162
163 /** \deprecated ArrayBase::<=() */
164 template<typename ExpressionType>
165 template<typename OtherDerived>
166 inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
167 Cwise<ExpressionType>::operator<=(const MatrixBase<OtherDerived> &other) const
168 {
169 return EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)(_expression(), other.derived());
170 }
171
172 /** \deprecated ArrayBase::operator>() */
173 template<typename ExpressionType>
174 template<typename OtherDerived>
EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)175 inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
176 Cwise<ExpressionType>::operator>(const MatrixBase<OtherDerived> &other) const
177 {
178 return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)(_expression(), other.derived());
179 }
180
181 /** \deprecated ArrayBase::operator>=() */
182 template<typename ExpressionType>
183 template<typename OtherDerived>
EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)184 inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
185 Cwise<ExpressionType>::operator>=(const MatrixBase<OtherDerived> &other) const
186 {
187 return EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)(_expression(), other.derived());
188 }
189
190 /** \deprecated ArrayBase::operator==() */
191 template<typename ExpressionType>
192 template<typename OtherDerived>
193 inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
194 Cwise<ExpressionType>::operator==(const MatrixBase<OtherDerived> &other) const
195 {
196 return EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)(_expression(), other.derived());
197 }
198
199 /** \deprecated ArrayBase::operator!=() */
200 template<typename ExpressionType>
201 template<typename OtherDerived>
202 inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
203 Cwise<ExpressionType>::operator!=(const MatrixBase<OtherDerived> &other) const
204 {
205 return EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)(_expression(), other.derived());
206 }
207
208 // comparisons to scalar value
209
210 /** \deprecated ArrayBase::operator<(Scalar) */
211 template<typename ExpressionType>
212 inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
213 Cwise<ExpressionType>::operator<(Scalar s) const
214 {
215 return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)(_expression(),
216 typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
217 }
218
219 /** \deprecated ArrayBase::operator<=(Scalar) */
220 template<typename ExpressionType>
221 inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
222 Cwise<ExpressionType>::operator<=(Scalar s) const
223 {
224 return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)(_expression(),
225 typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
226 }
227
228 /** \deprecated ArrayBase::operator>(Scalar) */
229 template<typename ExpressionType>
EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)230 inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
231 Cwise<ExpressionType>::operator>(Scalar s) const
232 {
233 return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)(_expression(),
234 typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
235 }
236
237 /** \deprecated ArrayBase::operator>=(Scalar) */
238 template<typename ExpressionType>
EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)239 inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
240 Cwise<ExpressionType>::operator>=(Scalar s) const
241 {
242 return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)(_expression(),
243 typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
244 }
245
246 /** \deprecated ArrayBase::operator==(Scalar) */
247 template<typename ExpressionType>
248 inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
249 Cwise<ExpressionType>::operator==(Scalar s) const
250 {
251 return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)(_expression(),
252 typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
253 }
254
255 /** \deprecated ArrayBase::operator!=(Scalar) */
256 template<typename ExpressionType>
257 inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
258 Cwise<ExpressionType>::operator!=(Scalar s) const
259 {
260 return EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)(_expression(),
261 typename ExpressionType::ConstantReturnType(_expression().rows(), _expression().cols(), s));
262 }
263
264 // scalar addition
265
266 /** \deprecated ArrayBase::operator+(Scalar) */
267 template<typename ExpressionType>
268 inline const typename Cwise<ExpressionType>::ScalarAddReturnType
269 Cwise<ExpressionType>::operator+(const Scalar& scalar) const
270 {
271 return typename Cwise<ExpressionType>::ScalarAddReturnType(m_matrix, internal::scalar_add_op<Scalar>(scalar));
272 }
273
274 /** \deprecated ArrayBase::operator+=(Scalar) */
275 template<typename ExpressionType>
276 inline ExpressionType& Cwise<ExpressionType>::operator+=(const Scalar& scalar)
277 {
278 return m_matrix.const_cast_derived() = *this + scalar;
279 }
280
281 /** \deprecated ArrayBase::operator-(Scalar) */
282 template<typename ExpressionType>
283 inline const typename Cwise<ExpressionType>::ScalarAddReturnType
284 Cwise<ExpressionType>::operator-(const Scalar& scalar) const
285 {
286 return *this + (-scalar);
287 }
288
289 /** \deprecated ArrayBase::operator-=(Scalar) */
290 template<typename ExpressionType>
291 inline ExpressionType& Cwise<ExpressionType>::operator-=(const Scalar& scalar)
292 {
293 return m_matrix.const_cast_derived() = *this - scalar;
294 }
295
296 } // end namespace Eigen
297
298 #endif // EIGEN_ARRAY_CWISE_OPERATORS_H
299