Main MRPT website > C++ reference
MRPT logo

CommonCwiseUnaryOps.h

Go to the documentation of this file.
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 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 // This file is a base class plugin containing common coefficient wise functions.
00027 
00028 #ifndef EIGEN_PARSED_BY_DOXYGEN
00029 
00030 /** \internal Represents a scalar multiple of an expression */
00031 typedef CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, Derived> ScalarMultipleReturnType;
00032 /** \internal Represents a quotient of an expression by a scalar*/
00033 typedef CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, Derived> ScalarQuotient1ReturnType;
00034 /** \internal the return type of conjugate() */
00035 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
00036                     const CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, Derived>,
00037                     const Derived&
00038                   >::type ConjugateReturnType;
00039 /** \internal the return type of real() const */
00040 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
00041                     const CwiseUnaryOp<internal::scalar_real_op<Scalar>, Derived>,
00042                     const Derived&
00043                   >::type RealReturnType;
00044 /** \internal the return type of real() */
00045 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
00046                     CwiseUnaryView<internal::scalar_real_ref_op<Scalar>, Derived>,
00047                     Derived&
00048                   >::type NonConstRealReturnType;
00049 /** \internal the return type of imag() const */
00050 typedef CwiseUnaryOp<internal::scalar_imag_op<Scalar>, Derived> ImagReturnType;
00051 /** \internal the return type of imag() */
00052 typedef CwiseUnaryView<internal::scalar_imag_ref_op<Scalar>, Derived> NonConstImagReturnType;
00053 
00054 #endif // not EIGEN_PARSED_BY_DOXYGEN
00055 
00056 /** \returns an expression of the opposite of \c *this
00057   */
00058 inline const CwiseUnaryOp<internal::scalar_opposite_op<typename internal::traits<Derived>::Scalar>,Derived>
00059 operator-() const { return derived(); }
00060 
00061 
00062 /** \returns an expression of \c *this scaled by the scalar factor \a scalar */
00063 inline const ScalarMultipleReturnType
00064 operator*(const Scalar& scalar) const
00065 {
00066   return CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, Derived>
00067     (derived(), internal::scalar_multiple_op<Scalar>(scalar));
00068 }
00069 
00070 #ifdef EIGEN_PARSED_BY_DOXYGEN
00071 const ScalarMultipleReturnType operator*(const RealScalar& scalar) const;
00072 #endif
00073 
00074 /** \returns an expression of \c *this divided by the scalar value \a scalar */
00075 inline const CwiseUnaryOp<internal::scalar_quotient1_op<typename internal::traits<Derived>::Scalar>, Derived>
00076 operator/(const Scalar& scalar) const
00077 {
00078   return CwiseUnaryOp<internal::scalar_quotient1_op<Scalar>, Derived>
00079     (derived(), internal::scalar_quotient1_op<Scalar>(scalar));
00080 }
00081 
00082 /** Overloaded for efficient real matrix times complex scalar value */
00083 inline const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
00084 operator*(const std::complex<Scalar>& scalar) const
00085 {
00086   return CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
00087     (*static_cast<const Derived*>(this), internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >(scalar));
00088 }
00089 
00090 inline friend const ScalarMultipleReturnType
00091 operator*(const Scalar& scalar, const StorageBaseType& matrix)
00092 { return matrix*scalar; }
00093 
00094 inline friend const CwiseUnaryOp<internal::scalar_multiple2_op<Scalar,std::complex<Scalar> >, Derived>
00095 operator*(const std::complex<Scalar>& scalar, const StorageBaseType& matrix)
00096 { return matrix*scalar; }
00097 
00098 /** \returns an expression of *this with the \a Scalar type casted to
00099   * \a NewScalar.
00100   *
00101   * The template parameter \a NewScalar is the type we are casting the scalars to.
00102   *
00103   * \sa class CwiseUnaryOp
00104   */
00105 template<typename NewType>
00106 typename internal::cast_return_type<Derived,const CwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, Derived> >::type
00107 cast() const
00108 {
00109   return derived();
00110 }
00111 
00112 /** \returns an expression of the complex conjugate of \c *this.
00113   *
00114   * \sa adjoint() */
00115 inline ConjugateReturnType
00116 conjugate() const
00117 {
00118   return ConjugateReturnType(derived());
00119 }
00120 
00121 /** \returns a read-only expression of the real part of \c *this.
00122   *
00123   * \sa imag() */
00124 inline RealReturnType
00125 real() const { return derived(); }
00126 
00127 /** \returns an read-only expression of the imaginary part of \c *this.
00128   *
00129   * \sa real() */
00130 inline const ImagReturnType
00131 imag() const { return derived(); }
00132 
00133 /** \brief Apply a unary operator coefficient-wise
00134   * \param[in]  func  Functor implementing the unary operator
00135   * \tparam  CustomUnaryOp Type of \a func  
00136   * \returns An expression of a custom coefficient-wise unary operator \a func of *this
00137   *
00138   * The function \c ptr_fun() from the C++ standard library can be used to make functors out of normal functions.
00139   *
00140   * Example:
00141   * \include class_CwiseUnaryOp_ptrfun.cpp
00142   * Output: \verbinclude class_CwiseUnaryOp_ptrfun.out
00143   *
00144   * Genuine functors allow for more possibilities, for instance it may contain a state.
00145   *
00146   * Example:
00147   * \include class_CwiseUnaryOp.cpp
00148   * Output: \verbinclude class_CwiseUnaryOp.out
00149   *
00150   * \sa class CwiseUnaryOp, class CwiseBinaryOp
00151   */
00152 template<typename CustomUnaryOp>
00153 inline const CwiseUnaryOp<CustomUnaryOp, Derived>
00154 unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const
00155 {
00156   return CwiseUnaryOp<CustomUnaryOp, Derived>(derived(), func);
00157 }
00158 
00159 /** \returns an expression of a custom coefficient-wise unary operator \a func of *this
00160   *
00161   * The template parameter \a CustomUnaryOp is the type of the functor
00162   * of the custom unary operator.
00163   *
00164   * Example:
00165   * \include class_CwiseUnaryOp.cpp
00166   * Output: \verbinclude class_CwiseUnaryOp.out
00167   *
00168   * \sa class CwiseUnaryOp, class CwiseBinaryOp
00169   */
00170 template<typename CustomViewOp>
00171 inline const CwiseUnaryView<CustomViewOp, Derived>
00172 unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const
00173 {
00174   return CwiseUnaryView<CustomViewOp, Derived>(derived(), func);
00175 }
00176 
00177 /** \returns a non const expression of the real part of \c *this.
00178   *
00179   * \sa imag() */
00180 inline NonConstRealReturnType
00181 real() { return derived(); }
00182 
00183 /** \returns a non const expression of the imaginary part of \c *this.
00184   *
00185   * \sa real() */
00186 inline NonConstImagReturnType
00187 imag() { return derived(); }



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011