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 // 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 #ifndef EIGEN_CWISE_H
00012 #define EIGEN_CWISE_H
00013 
00014 namespace Eigen { 
00015 
00018 #define EIGEN_CWISE_BINOP_RETURN_TYPE(OP) \
00019     CwiseBinaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
00020 
00023 #define EIGEN_CWISE_UNOP_RETURN_TYPE(OP) \
00024     CwiseUnaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType>
00025 
00028 #define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \
00029     CwiseBinaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType, \
00030         typename ExpressionType::ConstantReturnType >
00031 
00050 template<typename ExpressionType> class Cwise
00051 {
00052   public:
00053 
00054     typedef typename internal::traits<ExpressionType>::Scalar Scalar;
00055     typedef typename internal::conditional<internal::must_nest_by_value<ExpressionType>::ret,
00056         ExpressionType, const ExpressionType&>::type ExpressionTypeNested;
00057     typedef CwiseUnaryOp<internal::scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
00058 
00059     inline Cwise(const ExpressionType& matrix) : m_matrix(matrix) {}
00060 
00062     inline const ExpressionType& _expression() const { return m_matrix; }
00063 
00064     template<typename OtherDerived>
00065     const EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)
00066     operator*(const MatrixBase<OtherDerived> &other) const;
00067 
00068     template<typename OtherDerived>
00069     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_quotient_op)
00070     operator/(const MatrixBase<OtherDerived> &other) const;
00071 
00073     template<typename OtherDerived>
00074     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_min_op)
00075     (min)(const MatrixBase<OtherDerived> &other) const
00076     { return EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_min_op)(_expression(), other.derived()); }
00077 
00079     template<typename OtherDerived>
00080     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_max_op)
00081     (max)(const MatrixBase<OtherDerived> &other) const
00082     { return EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_max_op)(_expression(), other.derived()); }
00083 
00084     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)      abs() const;
00085     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)     abs2() const;
00086     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)   square() const;
00087     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)     cube() const;
00088     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)  inverse() const;
00089     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)     sqrt() const;
00090     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)      exp() const;
00091     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)      log() const;
00092     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)      cos() const;
00093     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)      sin() const;
00094     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)      pow(const Scalar& exponent) const;
00095 
00096     const ScalarAddReturnType
00097     operator+(const Scalar& scalar) const;
00098 
00100     friend const ScalarAddReturnType
00101     operator+(const Scalar& scalar, const Cwise& mat)
00102     { return mat + scalar; }
00103 
00104     ExpressionType& operator+=(const Scalar& scalar);
00105 
00106     const ScalarAddReturnType
00107     operator-(const Scalar& scalar) const;
00108 
00109     ExpressionType& operator-=(const Scalar& scalar);
00110 
00111     template<typename OtherDerived>
00112     inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
00113 
00114     template<typename OtherDerived>
00115     inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
00116 
00117     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
00118     operator<(const MatrixBase<OtherDerived>& other) const;
00119 
00120     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
00121     operator<=(const MatrixBase<OtherDerived>& other) const;
00122 
00123     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
00124     operator>(const MatrixBase<OtherDerived>& other) const;
00125 
00126     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
00127     operator>=(const MatrixBase<OtherDerived>& other) const;
00128 
00129     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
00130     operator==(const MatrixBase<OtherDerived>& other) const;
00131 
00132     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
00133     operator!=(const MatrixBase<OtherDerived>& other) const;
00134 
00135     // comparisons to a scalar value
00136     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
00137     operator<(Scalar s) const;
00138 
00139     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
00140     operator<=(Scalar s) const;
00141 
00142     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
00143     operator>(Scalar s) const;
00144 
00145     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
00146     operator>=(Scalar s) const;
00147 
00148     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
00149     operator==(Scalar s) const;
00150 
00151     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
00152     operator!=(Scalar s) const;
00153 
00154     // allow to extend Cwise outside Eigen
00155     #ifdef EIGEN_CWISE_PLUGIN
00156     #include EIGEN_CWISE_PLUGIN
00157     #endif
00158 
00159   protected:
00160     ExpressionTypeNested m_matrix;
00161 };
00162 
00163 
00171 template<typename Derived>
00172 inline const Cwise<Derived> MatrixBase<Derived>::cwise() const
00173 {
00174   return derived();
00175 }
00176 
00184 template<typename Derived>
00185 inline Cwise<Derived> MatrixBase<Derived>::cwise()
00186 {
00187   return derived();
00188 }
00189 
00190 } // end namespace Eigen
00191 
00192 #endif // EIGEN_CWISE_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:36:56