CommonCwiseUnaryOps.h
Go to the documentation of this file.
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 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 // This file is a base class plugin containing common coefficient wise functions.
27 
28 #ifndef EIGEN_PARSED_BY_DOXYGEN
29 
31 typedef CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived> ScalarMultipleReturnType;
33 typedef CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived> ScalarQuotient1ReturnType;
36  const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>,
37  const Derived&
38  >::type ConjugateReturnType;
41  const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>,
42  const Derived&
43  >::type RealReturnType;
46  CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>,
47  Derived&
48  >::type NonConstRealReturnType;
50 typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType;
52 typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType;
53 
54 #endif // not EIGEN_PARSED_BY_DOXYGEN
55 
58 inline const CwiseUnaryOp<internal::scalar_opposite_op<typename internal::traits<Derived>::Scalar>, const Derived>
59 operator-() const { return derived(); }
60 
61 
63 inline const ScalarMultipleReturnType
64 operator*(const Scalar& scalar) const
65 {
66  return CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived>
67  (derived(), internal::scalar_multiple_op<Scalar>(scalar));
68 }
69 
70 #ifdef EIGEN_PARSED_BY_DOXYGEN
71 const ScalarMultipleReturnType operator*(const RealScalar& scalar) const;
72 #endif
73 
75 inline const CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>, const Derived>
76 operator/(const Scalar& scalar) const
77 {
78  return CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived>
79  (derived(), internal::scalar_quotient1_op<Scalar>(scalar));
80 }
81 
83 inline const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived>
84 operator*(const std::complex<Scalar>& scalar) const
85 {
86  return CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived>
87  (*static_cast<const Derived*>(this), internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >(scalar));
88 }
89 
90 inline friend const ScalarMultipleReturnType
91 operator*(const Scalar& scalar, const StorageBaseType& matrix)
92 { return matrix*scalar; }
93 
94 inline friend const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived>
95 operator*(const std::complex<Scalar>& scalar, const StorageBaseType& matrix)
96 { return matrix*scalar; }
97 
105 template<typename NewType>
106 typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, const Derived> >::type
107 cast() const
108 {
109  return derived();
110 }
111 
115 inline ConjugateReturnType
116 conjugate() const
117 {
118  return ConjugateReturnType(derived());
119 }
120 
124 inline RealReturnType
125 real() const { return derived(); }
126 
130 inline const ImagReturnType
131 imag() const { return derived(); }
132 
152 template<typename CustomUnaryOp>
153 inline const CwiseUnaryOp<CustomUnaryOp, const Derived>
154 unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
155 {
156  return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func);
157 }
158 
170 template<typename CustomViewOp>
171 inline const CwiseUnaryView<CustomViewOp, const Derived>
172 unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
173 {
174  return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func);
175 }
176 
180 inline NonConstRealReturnType
181 real() { return derived(); }
182 
186 inline NonConstImagReturnType
187 imag() { return derived(); }