/src/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.inc
Line | Count | Source |
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 | | |
15 | | /** \internal the return type of conjugate() */ |
16 | | typedef std::conditional_t<NumTraits<Scalar>::IsComplex, |
17 | | const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>, const Derived&> |
18 | | ConjugateReturnType; |
19 | | /** \internal the return type of real() const */ |
20 | | typedef std::conditional_t<NumTraits<Scalar>::IsComplex, |
21 | | const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>, const Derived&> |
22 | | RealReturnType; |
23 | | /** \internal the return type of real() */ |
24 | | typedef std::conditional_t<NumTraits<Scalar>::IsComplex, CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>, |
25 | | Derived&> |
26 | | NonConstRealReturnType; |
27 | | /** \internal the return type of imag() const */ |
28 | | typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType; |
29 | | /** \internal the return type of imag() */ |
30 | | typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType; |
31 | | |
32 | | typedef CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> NegativeReturnType; |
33 | | |
34 | | #endif // not EIGEN_PARSED_BY_DOXYGEN |
35 | | |
36 | | /// \returns an expression of the opposite of \c *this |
37 | | /// |
38 | | EIGEN_DOC_UNARY_ADDONS(operator-, opposite) |
39 | | /// |
40 | | EIGEN_DEVICE_FUNC inline const NegativeReturnType operator-() const { return NegativeReturnType(derived()); } |
41 | | |
42 | | template <class NewType> |
43 | | struct CastXpr { |
44 | | typedef typename internal::cast_return_type< |
45 | | Derived, const CwiseUnaryOp<internal::core_cast_op<Scalar, NewType>, const Derived> >::type Type; |
46 | | }; |
47 | | |
48 | | /// \returns an expression of \c *this with the \a Scalar type casted to |
49 | | /// \a NewScalar. |
50 | | /// |
51 | | /// The template parameter \a NewScalar is the type we are casting the scalars to. |
52 | | /// |
53 | | EIGEN_DOC_UNARY_ADDONS(cast, conversion function) |
54 | | /// |
55 | | /// \sa class CwiseUnaryOp |
56 | | /// |
57 | | template <typename NewType> |
58 | | EIGEN_DEVICE_FUNC typename CastXpr<NewType>::Type cast() const { |
59 | | return typename CastXpr<NewType>::Type(derived()); |
60 | | } |
61 | | |
62 | | /// \returns an expression of the complex conjugate of \c *this. |
63 | | /// |
64 | | EIGEN_DOC_UNARY_ADDONS(conjugate, complex conjugate) |
65 | | /// |
66 | | /// \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_conj">Math functions</a>, MatrixBase::adjoint() |
67 | 296 | EIGEN_DEVICE_FUNC inline ConjugateReturnType conjugate() const { return ConjugateReturnType(derived()); } |
68 | | |
69 | | /// \returns an expression of the complex conjugate of \c *this if Cond==true, returns derived() otherwise. |
70 | | /// |
71 | | EIGEN_DOC_UNARY_ADDONS(conjugate, complex conjugate) |
72 | | /// |
73 | | /// \sa conjugate() |
74 | | template <bool Cond> |
75 | | EIGEN_DEVICE_FUNC inline std::conditional_t<Cond, ConjugateReturnType, const Derived&> conjugateIf() const { |
76 | | typedef std::conditional_t<Cond, ConjugateReturnType, const Derived&> ReturnType; |
77 | | return ReturnType(derived()); |
78 | | } |
79 | | |
80 | | /// \returns a read-only expression of the real part of \c *this. |
81 | | /// |
82 | | EIGEN_DOC_UNARY_ADDONS(real, real part function) |
83 | | /// |
84 | | /// \sa imag() |
85 | | EIGEN_DEVICE_FUNC inline RealReturnType real() const { return RealReturnType(derived()); } |
86 | | |
87 | | /// \returns an read-only expression of the imaginary part of \c *this. |
88 | | /// |
89 | | EIGEN_DOC_UNARY_ADDONS(imag, imaginary part function) |
90 | | /// |
91 | | /// \sa real() |
92 | | EIGEN_DEVICE_FUNC inline const ImagReturnType imag() const { return ImagReturnType(derived()); } |
93 | | |
94 | | /// \brief Apply a unary operator coefficient-wise |
95 | | /// \param[in] func Functor implementing the unary operator |
96 | | /// \tparam CustomUnaryOp Type of \a func |
97 | | /// \returns An expression of a custom coefficient-wise unary operator \a func of *this |
98 | | /// |
99 | | /// The function \c ptr_fun() from the C++ standard library can be used to make functors out of normal functions. |
100 | | /// |
101 | | /// Example: |
102 | | /// \include class_CwiseUnaryOp_ptrfun.cpp |
103 | | /// Output: \verbinclude class_CwiseUnaryOp_ptrfun.out |
104 | | /// |
105 | | /// Genuine functors allow for more possibilities, for instance it may contain a state. |
106 | | /// |
107 | | /// Example: |
108 | | /// \include class_CwiseUnaryOp.cpp |
109 | | /// Output: \verbinclude class_CwiseUnaryOp.out |
110 | | /// |
111 | | EIGEN_DOC_UNARY_ADDONS(unaryExpr, unary function) |
112 | | /// |
113 | | /// \sa unaryViewExpr, binaryExpr, class CwiseUnaryOp |
114 | | /// |
115 | | template <typename CustomUnaryOp> |
116 | | EIGEN_DEVICE_FUNC inline const CwiseUnaryOp<CustomUnaryOp, const Derived> unaryExpr( |
117 | | const CustomUnaryOp& func = CustomUnaryOp()) const { |
118 | | return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func); |
119 | | } |
120 | | |
121 | | /// \returns a const expression of a custom coefficient-wise unary operator \a func of *this |
122 | | /// |
123 | | /// The template parameter \a CustomUnaryOp is the type of the functor |
124 | | /// of the custom unary operator. |
125 | | /// |
126 | | /// Example: |
127 | | /// \include class_CwiseUnaryOp.cpp |
128 | | /// Output: \verbinclude class_CwiseUnaryOp.out |
129 | | /// |
130 | | EIGEN_DOC_UNARY_ADDONS(unaryViewExpr, unary function) |
131 | | /// |
132 | | /// \sa unaryExpr, binaryExpr class CwiseUnaryOp |
133 | | /// |
134 | | template <typename CustomViewOp> |
135 | | EIGEN_DEVICE_FUNC inline const CwiseUnaryView<CustomViewOp, const Derived> unaryViewExpr( |
136 | | const CustomViewOp& func = CustomViewOp()) const { |
137 | | return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func); |
138 | | } |
139 | | |
140 | | /// \returns a non-const expression of a custom coefficient-wise unary view \a func of *this |
141 | | /// |
142 | | /// The template parameter \a CustomUnaryOp is the type of the functor |
143 | | /// of the custom unary operator. |
144 | | /// |
145 | | EIGEN_DOC_UNARY_ADDONS(unaryViewExpr, unary function) |
146 | | /// |
147 | | /// \sa unaryExpr, binaryExpr class CwiseUnaryOp |
148 | | /// |
149 | | template <typename CustomViewOp> |
150 | | EIGEN_DEVICE_FUNC inline CwiseUnaryView<CustomViewOp, Derived> unaryViewExpr( |
151 | | const CustomViewOp& func = CustomViewOp()) { |
152 | | return CwiseUnaryView<CustomViewOp, Derived>(derived(), func); |
153 | | } |
154 | | |
155 | | /// \returns a non const expression of the real part of \c *this. |
156 | | /// |
157 | | EIGEN_DOC_UNARY_ADDONS(real, real part function) |
158 | | /// |
159 | | /// \sa imag() |
160 | | EIGEN_DEVICE_FUNC inline NonConstRealReturnType real() { return NonConstRealReturnType(derived()); } |
161 | | |
162 | | /// \returns a non const expression of the imaginary part of \c *this. |
163 | | /// |
164 | | EIGEN_DOC_UNARY_ADDONS(imag, imaginary part function) |
165 | | /// |
166 | | /// \sa real() |
167 | | EIGEN_DEVICE_FUNC inline NonConstImagReturnType imag() { return NonConstImagReturnType(derived()); } |