Eigne Matrix Class Library
Dependents: Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more
CommonCwiseUnaryOps.h
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> 00006 // 00007 // This Source Code Form is subject to the terms of the Mozilla 00008 // Public License v. 2.0. If a copy of the MPL was not distributed 00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00010 00011 // This file is a base class plugin containing common coefficient wise functions. 00012 00013 #ifndef EIGEN_PARSED_BY_DOXYGEN 00014 00015 /** \internal Represents a scalar multiple of an expression */ 00016 typedef CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived> ScalarMultipleReturnType; 00017 /** \internal Represents a quotient of an expression by a scalar*/ 00018 typedef CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived> ScalarQuotient1ReturnType; 00019 /** \internal the return type of conjugate() */ 00020 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, 00021 const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const Derived>, 00022 const Derived& 00023 >::type ConjugateReturnType; 00024 /** \internal the return type of real() const */ 00025 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, 00026 const CwiseUnaryOp<internal::scalar_real_op<Scalar>, const Derived>, 00027 const Derived& 00028 >::type RealReturnType; 00029 /** \internal the return type of real() */ 00030 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex, 00031 CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>, 00032 Derived& 00033 >::type NonConstRealReturnType; 00034 /** \internal the return type of imag() const */ 00035 typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, const Derived> ImagReturnType; 00036 /** \internal the return type of imag() */ 00037 typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType; 00038 00039 #endif // not EIGEN_PARSED_BY_DOXYGEN 00040 00041 /** \returns an expression of the opposite of \c *this 00042 */ 00043 inline const CwiseUnaryOp<internal::scalar_opposite_op<typename internal::traits<Derived>::Scalar>, const Derived> 00044 operator-() const { return derived(); } 00045 00046 00047 /** \returns an expression of \c *this scaled by the scalar factor \a scalar */ 00048 inline const ScalarMultipleReturnType 00049 operator* (const Scalar& scalar) const 00050 { 00051 return CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Derived> 00052 (derived(), internal::scalar_multiple_op<Scalar>(scalar)); 00053 } 00054 00055 #ifdef EIGEN_PARSED_BY_DOXYGEN 00056 const ScalarMultipleReturnType operator* (const RealScalar& scalar) const; 00057 #endif 00058 00059 /** \returns an expression of \c *this divided by the scalar value \a scalar */ 00060 inline const CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>, const Derived> 00061 operator/(const Scalar& scalar) const 00062 { 00063 return CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, const Derived> 00064 (derived(), internal::scalar_quotient1_op<Scalar>(scalar)); 00065 } 00066 00067 /** Overloaded for efficient real matrix times complex scalar value */ 00068 inline const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived> 00069 operator* (const std::complex<Scalar>& scalar) const 00070 { 00071 return CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived> 00072 (*static_cast<const Derived*>(this), internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >(scalar)); 00073 } 00074 00075 inline friend const ScalarMultipleReturnType 00076 operator* (const Scalar& scalar, const StorageBaseType& matrix) 00077 { return matrix*scalar; } 00078 00079 inline friend const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, const Derived> 00080 operator* (const std::complex<Scalar>& scalar, const StorageBaseType& matrix) 00081 { return matrix*scalar; } 00082 00083 /** \returns an expression of *this with the \a Scalar type casted to 00084 * \a NewScalar. 00085 * 00086 * The template parameter \a NewScalar is the type we are casting the scalars to. 00087 * 00088 * \sa class CwiseUnaryOp 00089 */ 00090 template<typename NewType> 00091 typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, const Derived> >::type 00092 cast() const 00093 { 00094 return derived(); 00095 } 00096 00097 /** \returns an expression of the complex conjugate of \c *this. 00098 * 00099 * \sa adjoint() */ 00100 inline ConjugateReturnType 00101 conjugate() const 00102 { 00103 return ConjugateReturnType(derived()); 00104 } 00105 00106 /** \returns a read-only expression of the real part of \c *this. 00107 * 00108 * \sa imag() */ 00109 inline RealReturnType 00110 real() const { return derived(); } 00111 00112 /** \returns an read-only expression of the imaginary part of \c *this. 00113 * 00114 * \sa real() */ 00115 inline const ImagReturnType 00116 imag() const { return derived(); } 00117 00118 /** \brief Apply a unary operator coefficient-wise 00119 * \param[in] func Functor implementing the unary operator 00120 * \tparam CustomUnaryOp Type of \a func 00121 * \returns An expression of a custom coefficient-wise unary operator \a func of *this 00122 * 00123 * The function \c ptr_fun() from the C++ standard library can be used to make functors out of normal functions. 00124 * 00125 * Example: 00126 * \include class_CwiseUnaryOp_ptrfun.cpp 00127 * Output: \verbinclude class_CwiseUnaryOp_ptrfun.out 00128 * 00129 * Genuine functors allow for more possibilities, for instance it may contain a state. 00130 * 00131 * Example: 00132 * \include class_CwiseUnaryOp.cpp 00133 * Output: \verbinclude class_CwiseUnaryOp.out 00134 * 00135 * \sa class CwiseUnaryOp, class CwiseBinaryOp 00136 */ 00137 template<typename CustomUnaryOp> 00138 inline const CwiseUnaryOp<CustomUnaryOp, const Derived> 00139 unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const 00140 { 00141 return CwiseUnaryOp<CustomUnaryOp, const Derived>(derived(), func); 00142 } 00143 00144 /** \returns an expression of a custom coefficient-wise unary operator \a func of *this 00145 * 00146 * The template parameter \a CustomUnaryOp is the type of the functor 00147 * of the custom unary operator. 00148 * 00149 * Example: 00150 * \include class_CwiseUnaryOp.cpp 00151 * Output: \verbinclude class_CwiseUnaryOp.out 00152 * 00153 * \sa class CwiseUnaryOp, class CwiseBinaryOp 00154 */ 00155 template<typename CustomViewOp> 00156 inline const CwiseUnaryView<CustomViewOp, const Derived> 00157 unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const 00158 { 00159 return CwiseUnaryView<CustomViewOp, const Derived>(derived(), func); 00160 } 00161 00162 /** \returns a non const expression of the real part of \c *this. 00163 * 00164 * \sa imag() */ 00165 inline NonConstRealReturnType 00166 real() { return derived(); } 00167 00168 /** \returns a non const expression of the imaginary part of \c *this. 00169 * 00170 * \sa real() */ 00171 inline NonConstImagReturnType 00172 imag() { return derived(); }
Generated on Tue Jul 12 2022 17:46:50 by 1.7.2