Eigen  3.2.91
CommonCwiseUnaryOps.h
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 common coefficient wise functions.
12 
13 #ifndef EIGEN_PARSED_BY_DOXYGEN
14 
16 typedef CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived> ScalarMultipleReturnType;
17 typedef CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived> ScalarComplexMultipleReturnType;
18 
20 typedef CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived> ScalarQuotient1ReturnType;
22 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
23  const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>,
24  const Derived&
25  >::type ConjugateReturnType;
27 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
28  const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>,
29  const Derived&
30  >::type RealReturnType;
32 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
33  CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>,
34  Derived&
35  >::type NonConstRealReturnType;
37 typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType;
39 typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType;
40 
41 typedef CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> NegativeReturnType;
42 //typedef CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived>
43 
44 #endif // not EIGEN_PARSED_BY_DOXYGEN
45 
48 EIGEN_DEVICE_FUNC
49 inline const NegativeReturnType
50 operator-() const { return NegativeReturnType(derived()); }
51 
52 
54 EIGEN_DEVICE_FUNC
55 inline const ScalarMultipleReturnType
56 operator*(const Scalar& scalar) const
57 {
58  return ScalarMultipleReturnType(derived(), internal::scalar_multiple_op<Scalar>(scalar));
59 }
60 
61 #ifdef EIGEN_PARSED_BY_DOXYGEN
62 const ScalarMultipleReturnType operator*(const RealScalar& scalar) const;
63 #endif
64 
66 EIGEN_DEVICE_FUNC
67 inline const ScalarQuotient1ReturnType
68 operator/(const Scalar& scalar) const
69 {
70  return ScalarQuotient1ReturnType(derived(), internal::scalar_quotient1_op<Scalar>(scalar));
71 }
72 
74 EIGEN_DEVICE_FUNC
75 inline const ScalarComplexMultipleReturnType
76 operator*(const std::complex<Scalar>& scalar) const
77 {
78  return ScalarComplexMultipleReturnType(derived(), internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >(scalar));
79 }
80 
81 EIGEN_DEVICE_FUNC
82 inline friend const ScalarMultipleReturnType
83 operator*(const Scalar& scalar, const StorageBaseType& matrix)
84 { return matrix*scalar; }
85 
86 EIGEN_DEVICE_FUNC
87 inline friend const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived>
88 operator*(const std::complex<Scalar>& scalar, const StorageBaseType& matrix)
89 { return matrix*scalar; }
90 
91 
92 template<class NewType> struct CastXpr { typedef typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<Scalar, NewType>, const Derived> >::type Type; };
93 
101 template<typename NewType>
102 EIGEN_DEVICE_FUNC
103 typename CastXpr<NewType>::Type
104 cast() const
105 {
106  return typename CastXpr<NewType>::Type(derived());
107 }
108 
112 EIGEN_DEVICE_FUNC
113 inline ConjugateReturnType
114 conjugate() const
115 {
116  return ConjugateReturnType(derived());
117 }
118 
122 EIGEN_DEVICE_FUNC
123 inline RealReturnType
124 real() const { return RealReturnType(derived()); }
125 
129 EIGEN_DEVICE_FUNC
130 inline const ImagReturnType
131 imag() const { return ImagReturnType(derived()); }
132 
152 template<typename CustomUnaryOp>
153 EIGEN_DEVICE_FUNC
154 inline const CwiseUnaryOp<CustomUnaryOp, const Derived>
155 unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
156 {
157  return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func);
158 }
159 
171 template<typename CustomViewOp>
172 EIGEN_DEVICE_FUNC
173 inline const CwiseUnaryView<CustomViewOp, const Derived>
174 unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
175 {
176  return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func);
177 }
178 
182 EIGEN_DEVICE_FUNC
183 inline NonConstRealReturnType
184 real() { return NonConstRealReturnType(derived()); }
185 
189 EIGEN_DEVICE_FUNC
190 inline NonConstImagReturnType
191 imag() { return NonConstImagReturnType(derived()); }