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 
00031 #define EIGEN_CWISE_BINOP_RETURN_TYPE(OP) \
00032     CwiseBinaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
00033 
00036 #define EIGEN_CWISE_UNOP_RETURN_TYPE(OP) \
00037     CwiseUnaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType>
00038 
00041 #define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \
00042     CwiseBinaryOp<OP<typename internal::traits<ExpressionType>::Scalar>, ExpressionType, \
00043         typename ExpressionType::ConstantReturnType >
00044 
00063 template<typename ExpressionType> class Cwise
00064 {
00065   public:
00066 
00067     typedef typename internal::traits<ExpressionType>::Scalar Scalar;
00068     typedef typename internal::conditional<internal::must_nest_by_value<ExpressionType>::ret,
00069         ExpressionType, const ExpressionType&>::type ExpressionTypeNested;
00070     typedef CwiseUnaryOp<internal::scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
00071 
00072     inline Cwise(const ExpressionType& matrix) : m_matrix(matrix) {}
00073 
00075     inline const ExpressionType& _expression() const { return m_matrix; }
00076 
00077     template<typename OtherDerived>
00078     const EIGEN_CWISE_PRODUCT_RETURN_TYPE(ExpressionType,OtherDerived)
00079     operator*(const MatrixBase<OtherDerived> &other) const;
00080 
00081     template<typename OtherDerived>
00082     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_quotient_op)
00083     operator/(const MatrixBase<OtherDerived> &other) const;
00084 
00086     template<typename OtherDerived>
00087     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_min_op)
00088     (min)(const MatrixBase<OtherDerived> &other) const
00089     { return EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_min_op)(_expression(), other.derived()); }
00090 
00092     template<typename OtherDerived>
00093     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_max_op)
00094     (max)(const MatrixBase<OtherDerived> &other) const
00095     { return EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_max_op)(_expression(), other.derived()); }
00096 
00097     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)      abs() const;
00098     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)     abs2() const;
00099     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)   square() const;
00100     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)     cube() const;
00101     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)  inverse() const;
00102     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)     sqrt() const;
00103     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)      exp() const;
00104     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)      log() const;
00105     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)      cos() const;
00106     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)      sin() const;
00107     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)      pow(const Scalar& exponent) const;
00108 
00109     const ScalarAddReturnType
00110     operator+(const Scalar& scalar) const;
00111 
00113     friend const ScalarAddReturnType
00114     operator+(const Scalar& scalar, const Cwise& mat)
00115     { return mat + scalar; }
00116 
00117     ExpressionType& operator+=(const Scalar& scalar);
00118 
00119     const ScalarAddReturnType
00120     operator-(const Scalar& scalar) const;
00121 
00122     ExpressionType& operator-=(const Scalar& scalar);
00123 
00124     template<typename OtherDerived>
00125     inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
00126 
00127     template<typename OtherDerived>
00128     inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
00129 
00130     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
00131     operator<(const MatrixBase<OtherDerived>& other) const;
00132 
00133     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
00134     operator<=(const MatrixBase<OtherDerived>& other) const;
00135 
00136     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
00137     operator>(const MatrixBase<OtherDerived>& other) const;
00138 
00139     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
00140     operator>=(const MatrixBase<OtherDerived>& other) const;
00141 
00142     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
00143     operator==(const MatrixBase<OtherDerived>& other) const;
00144 
00145     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
00146     operator!=(const MatrixBase<OtherDerived>& other) const;
00147 
00148     // comparisons to a scalar value
00149     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
00150     operator<(Scalar s) const;
00151 
00152     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
00153     operator<=(Scalar s) const;
00154 
00155     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
00156     operator>(Scalar s) const;
00157 
00158     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
00159     operator>=(Scalar s) const;
00160 
00161     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
00162     operator==(Scalar s) const;
00163 
00164     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
00165     operator!=(Scalar s) const;
00166 
00167     // allow to extend Cwise outside Eigen
00168     #ifdef EIGEN_CWISE_PLUGIN
00169     #include EIGEN_CWISE_PLUGIN
00170     #endif
00171 
00172   protected:
00173     ExpressionTypeNested m_matrix;
00174 };
00175 
00176 
00184 template<typename Derived>
00185 inline const Cwise<Derived> MatrixBase<Derived>::cwise() const
00186 {
00187   return derived();
00188 }
00189 
00197 template<typename Derived>
00198 inline Cwise<Derived> MatrixBase<Derived>::cwise()
00199 {
00200   return derived();
00201 }
00202 
00203 #endif // EIGEN_CWISE_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:36