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 
00085     template<typename OtherDerived>
00086     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_min_op)
00087     min(const MatrixBase<OtherDerived> &other) const;
00088 
00089     template<typename OtherDerived>
00090     const EIGEN_CWISE_BINOP_RETURN_TYPE(internal::scalar_max_op)
00091     max(const MatrixBase<OtherDerived> &other) const;
00092 
00093     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs_op)      abs() const;
00094     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_abs2_op)     abs2() const;
00095     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_square_op)   square() const;
00096     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cube_op)     cube() const;
00097     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_inverse_op)  inverse() const;
00098     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sqrt_op)     sqrt() const;
00099     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_exp_op)      exp() const;
00100     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_log_op)      log() const;
00101     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_cos_op)      cos() const;
00102     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_sin_op)      sin() const;
00103     const EIGEN_CWISE_UNOP_RETURN_TYPE(internal::scalar_pow_op)      pow(const Scalar& exponent) const;
00104 
00105     const ScalarAddReturnType
00106     operator+(const Scalar& scalar) const;
00107 
00109     friend const ScalarAddReturnType
00110     operator+(const Scalar& scalar, const Cwise& mat)
00111     { return mat + scalar; }
00112 
00113     ExpressionType& operator+=(const Scalar& scalar);
00114 
00115     const ScalarAddReturnType
00116     operator-(const Scalar& scalar) const;
00117 
00118     ExpressionType& operator-=(const Scalar& scalar);
00119 
00120     template<typename OtherDerived>
00121     inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
00122 
00123     template<typename OtherDerived>
00124     inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
00125 
00126     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
00127     operator<(const MatrixBase<OtherDerived>& other) const;
00128 
00129     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
00130     operator<=(const MatrixBase<OtherDerived>& other) const;
00131 
00132     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
00133     operator>(const MatrixBase<OtherDerived>& other) const;
00134 
00135     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
00136     operator>=(const MatrixBase<OtherDerived>& other) const;
00137 
00138     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
00139     operator==(const MatrixBase<OtherDerived>& other) const;
00140 
00141     template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
00142     operator!=(const MatrixBase<OtherDerived>& other) const;
00143 
00144     // comparisons to a scalar value
00145     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
00146     operator<(Scalar s) const;
00147 
00148     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
00149     operator<=(Scalar s) const;
00150 
00151     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
00152     operator>(Scalar s) const;
00153 
00154     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
00155     operator>=(Scalar s) const;
00156 
00157     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
00158     operator==(Scalar s) const;
00159 
00160     const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
00161     operator!=(Scalar s) const;
00162 
00163     // allow to extend Cwise outside Eigen
00164     #ifdef EIGEN_CWISE_PLUGIN
00165     #include EIGEN_CWISE_PLUGIN
00166     #endif
00167 
00168   protected:
00169     ExpressionTypeNested m_matrix;
00170 };
00171 
00172 
00180 template<typename Derived>
00181 inline const Cwise<Derived> MatrixBase<Derived>::cwise() const
00182 {
00183   return derived();
00184 }
00185 
00193 template<typename Derived>
00194 inline Cwise<Derived> MatrixBase<Derived>::cwise()
00195 {
00196   return derived();
00197 }
00198 
00199 #endif // EIGEN_CWISE_H


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:00