Main MRPT website > C++ reference
MRPT logo

Cwise.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 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 // Copyright (C) 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 #ifndef EIGEN_CWISE_H
00027 #define EIGEN_CWISE_H
00028 
00029 /** \internal
00030   * convenient macro to defined the return type of a cwise binary operation */
00031 #define EIGEN_CWISE_BINOP_RETURN_TYPE(OP) \
00032     CwiseBinaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
00033 
00034 /** \internal
00035   * convenient macro to defined the return type of a cwise unary operation */
00036 #define EIGEN_CWISE_UNOP_RETURN_TYPE(OP) \
00037     CwiseUnaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType>
00038 
00039 /** \internal
00040   * convenient macro to defined the return type of a cwise comparison to a scalar */
00041 #define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \
00042     CwiseBinaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType, \
00043         typename ExpressionType::ConstantReturnType >
00044 
00045 /** \class Cwise
00046   *
00047   * \brief Pseudo expression providing additional coefficient-wise operations
00048   *
00049   * \param ExpressionType the type of the object on which to do coefficient-wise operations
00050   *
00051   * This class represents an expression with additional coefficient-wise features.
00052   * It is the return type of MatrixBase::cwise()
00053   * and most of the time this is the only way it is used.
00054   *
00055   * Example: \include MatrixBase_cwise_const.cpp
00056   * Output: \verbinclude MatrixBase_cwise_const.out
00057   *
00058   * \sa MatrixBase::cwise() const, MatrixBase::cwise()
00059   */
00060 template<typename ExpressionType> class Cwise
00061 {
00062   public:
00063 
00064     typedef typename internal::traits<ExpressionType>::Scalar Scalar;
00065     typedef typename internal::conditional<internal::must_nest_by_value<ExpressionType>::ret,
00066         ExpressionType, const ExpressionType&>::type ExpressionTypeNested;
00067     typedef CwiseUnaryOp<internal::scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
00068 
00069     inline Cwise(const ExpressionType& matrix) : m_matrix(matrix) {}
00070 
00071     /** \internal */
00072     inline const ExpressionType& _expression() const { return m_matrix; }
00073 
00074     template<typename OtherDerived>
00075     const EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)
00076     operator*(const MatrixBase<OtherDerived> &other) const;
00077 
00078     template<typename OtherDerived>
00079     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_quotient_op)
00080     operator/(const MatrixBase<OtherDerived> &other) const;
00081 
00082     template<typename OtherDerived>
00083     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_min_op)
00084     min(const MatrixBase<OtherDerived> &other) const;
00085 
00086     template<typename OtherDerived>
00087     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_max_op)
00088     max(const MatrixBase<OtherDerived> &other) const;
00089 
00090     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)      abs() const;
00091     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)     abs2() const;
00092     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)   square() const;
00093     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)     cube() const;
00094     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)  inverse() const;
00095     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)     sqrt() const;
00096     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)      exp() const;
00097     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)      log() const;
00098     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)      cos() const;
00099     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)      sin() const;
00100     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)      pow(const Scalar& exponent) const;
00101 
00102     const ScalarAddReturnType
00103     operator+(const Scalar& scalar) const;
00104 
00105     /** \relates Cwise */
00106     friend const ScalarAddReturnType
00107     operator+(const Scalar& scalar, const Cwise& mat)
00108     { return mat + scalar; }
00109 
00110     ExpressionType& operator+=(const Scalar& scalar);
00111 
00112     const ScalarAddReturnType
00113     operator-(const Scalar& scalar) const;
00114 
00115     ExpressionType& operator-=(const Scalar& scalar);
00116 
00117     template<typename OtherDerived>
00118     inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
00119 
00120     template<typename OtherDerived>
00121     inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
00122 
00123     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
00124     operator<(const MatrixBase<OtherDerived>& other) const;
00125 
00126     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
00127     operator<=(const MatrixBase<OtherDerived>& other) const;
00128 
00129     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
00130     operator>(const MatrixBase<OtherDerived>& other) const;
00131 
00132     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
00133     operator>=(const MatrixBase<OtherDerived>& other) const;
00134 
00135     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
00136     operator==(const MatrixBase<OtherDerived>& other) const;
00137 
00138     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
00139     operator!=(const MatrixBase<OtherDerived>& other) const;
00140 
00141     // comparisons to a scalar value
00142     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
00143     operator<(Scalar s) const;
00144 
00145     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
00146     operator<=(Scalar s) const;
00147 
00148     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
00149     operator>(Scalar s) const;
00150 
00151     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
00152     operator>=(Scalar s) const;
00153 
00154     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
00155     operator==(Scalar s) const;
00156 
00157     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
00158     operator!=(Scalar s) const;
00159 
00160     // allow to extend Cwise outside Eigen
00161     #ifdef EIGEN_CWISE_PLUGIN
00162     #include EIGEN_CWISE_PLUGIN
00163     #endif
00164 
00165   protected:
00166     ExpressionTypeNested m_matrix;
00167 };
00168 
00169 
00170 /** \returns a Cwise wrapper of *this providing additional coefficient-wise operations
00171   *
00172   * Example: \include MatrixBase_cwise_const.cpp
00173   * Output: \verbinclude MatrixBase_cwise_const.out
00174   *
00175   * \sa class Cwise, cwise()
00176   */
00177 template<typename Derived>
00178 inline const Cwise<Derived> MatrixBase<Derived>::cwise() const
00179 {
00180   return derived();
00181 }
00182 
00183 /** \returns a Cwise wrapper of *this providing additional coefficient-wise operations
00184   *
00185   * Example: \include MatrixBase_cwise.cpp
00186   * Output: \verbinclude MatrixBase_cwise.out
00187   *
00188   * \sa class Cwise, cwise() const
00189   */
00190 template<typename Derived>
00191 inline Cwise<Derived> MatrixBase<Derived>::cwise()
00192 {
00193   return derived();
00194 }
00195 
00196 #endif // EIGEN_CWISE_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011