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
13namespace Eigen {
14
15/***************************************************************************
16* The following functions were defined in Core
17***************************************************************************/
18
19
20/** \deprecated ArrayBase::abs() */
21template<typename ExpressionType>
22EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)
23Cwise<ExpressionType>::abs() const
24{
25  return _expression();
26}
27
28/** \deprecated ArrayBase::abs2() */
29template<typename ExpressionType>
30EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)
31Cwise<ExpressionType>::abs2() const
32{
33  return _expression();
34}
35
36/** \deprecated ArrayBase::exp() */
37template<typename ExpressionType>
38inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)
39Cwise<ExpressionType>::exp() const
40{
41  return _expression();
42}
43
44/** \deprecated ArrayBase::log() */
45template<typename ExpressionType>
46inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)
47Cwise<ExpressionType>::log() const
48{
49  return _expression();
50}
51
52/** \deprecated ArrayBase::operator*() */
53template<typename ExpressionType>
54template<typename OtherDerived>
55EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)
56Cwise<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/() */
62template<typename ExpressionType>
63template<typename OtherDerived>
64EIGEN_STRONG_INLINE const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_quotient_op)
65Cwise<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*=() */
71template<typename ExpressionType>
72template<typename OtherDerived>
73inline ExpressionType& Cwise<ExpressionType>::operator*=(const MatrixBase<OtherDerived> &other)
74{
75  return m_matrix.const_cast_derived() = *this * other;
76}
77
78/** \deprecated ArrayBase::operator/=() */
79template<typename ExpressionType>
80template<typename OtherDerived>
81inline 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() */
93template<typename ExpressionType>
94inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)
95Cwise<ExpressionType>::sqrt() const
96{
97  return _expression();
98}
99
100/** \deprecated ArrayBase::cos() */
101template<typename ExpressionType>
102inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)
103Cwise<ExpressionType>::cos() const
104{
105  return _expression();
106}
107
108
109/** \deprecated ArrayBase::sin() */
110template<typename ExpressionType>
111inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)
112Cwise<ExpressionType>::sin() const
113{
114  return _expression();
115}
116
117
118/** \deprecated ArrayBase::log() */
119template<typename ExpressionType>
120inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)
121Cwise<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() */
128template<typename ExpressionType>
129inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)
130Cwise<ExpressionType>::inverse() const
131{
132  return _expression();
133}
134
135/** \deprecated ArrayBase::square() */
136template<typename ExpressionType>
137inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)
138Cwise<ExpressionType>::square() const
139{
140  return _expression();
141}
142
143/** \deprecated ArrayBase::cube() */
144template<typename ExpressionType>
145inline const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)
146Cwise<ExpressionType>::cube() const
147{
148  return _expression();
149}
150
151
152// -- binary operators --
153
154/** \deprecated ArrayBase::operator<() */
155template<typename ExpressionType>
156template<typename OtherDerived>
157inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
158Cwise<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::<=() */
164template<typename ExpressionType>
165template<typename OtherDerived>
166inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
167Cwise<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>() */
173template<typename ExpressionType>
174template<typename OtherDerived>
175inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
176Cwise<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>=() */
182template<typename ExpressionType>
183template<typename OtherDerived>
184inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
185Cwise<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==() */
191template<typename ExpressionType>
192template<typename OtherDerived>
193inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
194Cwise<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!=() */
200template<typename ExpressionType>
201template<typename OtherDerived>
202inline const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
203Cwise<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) */
211template<typename ExpressionType>
212inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
213Cwise<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) */
220template<typename ExpressionType>
221inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
222Cwise<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) */
229template<typename ExpressionType>
230inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
231Cwise<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) */
238template<typename ExpressionType>
239inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
240Cwise<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) */
247template<typename ExpressionType>
248inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
249Cwise<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) */
256template<typename ExpressionType>
257inline const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
258Cwise<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) */
267template<typename ExpressionType>
268inline const typename Cwise<ExpressionType>::ScalarAddReturnType
269Cwise<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) */
275template<typename ExpressionType>
276inline ExpressionType& Cwise<ExpressionType>::operator+=(const Scalar& scalar)
277{
278  return m_matrix.const_cast_derived() = *this + scalar;
279}
280
281/** \deprecated ArrayBase::operator-(Scalar) */
282template<typename ExpressionType>
283inline const typename Cwise<ExpressionType>::ScalarAddReturnType
284Cwise<ExpressionType>::operator-(const Scalar& scalar) const
285{
286  return *this + (-scalar);
287}
288
289/** \deprecated ArrayBase::operator-=(Scalar) */
290template<typename ExpressionType>
291inline 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