Eigen  3.2.93
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 typename internal::conditional<NumTraits<Scalar>::IsComplex,
17  const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>,
18  const Derived&
19  >::type ConjugateReturnType;
21 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
22  const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>,
23  const Derived&
24  >::type RealReturnType;
26 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
27  CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>,
28  Derived&
29  >::type NonConstRealReturnType;
31 typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType;
33 typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType;
34 
35 typedef CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> NegativeReturnType;
36 
37 #endif // not EIGEN_PARSED_BY_DOXYGEN
38 
41 EIGEN_DEVICE_FUNC
42 inline const NegativeReturnType
43 operator-() const { return NegativeReturnType(derived()); }
44 
45 
46 template<class NewType> struct CastXpr { typedef typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<Scalar, NewType>, const Derived> >::type Type; };
47 
55 template<typename NewType>
56 EIGEN_DEVICE_FUNC
57 typename CastXpr<NewType>::Type
58 cast() const
59 {
60  return typename CastXpr<NewType>::Type(derived());
61 }
62 
66 EIGEN_DEVICE_FUNC
67 inline ConjugateReturnType
68 conjugate() const
69 {
70  return ConjugateReturnType(derived());
71 }
72 
76 EIGEN_DEVICE_FUNC
77 inline RealReturnType
78 real() const { return RealReturnType(derived()); }
79 
83 EIGEN_DEVICE_FUNC
84 inline const ImagReturnType
85 imag() const { return ImagReturnType(derived()); }
86 
106 template<typename CustomUnaryOp>
107 EIGEN_DEVICE_FUNC
108 inline const CwiseUnaryOp<CustomUnaryOp, const Derived>
109 unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
110 {
111  return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func);
112 }
113 
125 template<typename CustomViewOp>
126 EIGEN_DEVICE_FUNC
127 inline const CwiseUnaryView<CustomViewOp, const Derived>
128 unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
129 {
130  return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func);
131 }
132 
136 EIGEN_DEVICE_FUNC
137 inline NonConstRealReturnType
138 real() { return NonConstRealReturnType(derived()); }
139 
143 EIGEN_DEVICE_FUNC
144 inline NonConstImagReturnType
145 imag() { return NonConstImagReturnType(derived()); }
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_imag_op< typename Derived::Scalar >, const Derived > imag(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)