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