Main MRPT website > C++ reference
MRPT logo

ArrayWrapper.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) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_ARRAYWRAPPER_H
00026 #define EIGEN_ARRAYWRAPPER_H
00027 
00028 /** \class ArrayWrapper
00029   * \ingroup Core_Module
00030   *
00031   * \brief Expression of a mathematical vector or matrix as an array object
00032   *
00033   * This class is the return type of MatrixBase::array(), and most of the time
00034   * this is the only way it is use.
00035   *
00036   * \sa MatrixBase::array(), class MatrixWrapper
00037   */
00038 
00039 namespace internal {
00040 template<typename ExpressionType>
00041 struct traits<ArrayWrapper<ExpressionType> >
00042   : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00043 {
00044   typedef ArrayXpr XprKind;
00045 };
00046 }
00047 
00048 template<typename ExpressionType>
00049 class ArrayWrapper : public ArrayBase<ArrayWrapper<ExpressionType> >
00050 {
00051   public:
00052     typedef ArrayBase<ArrayWrapper> Base;
00053     EIGEN_DENSE_PUBLIC_INTERFACE(ArrayWrapper)
00054     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ArrayWrapper)
00055 
00056     typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
00057 
00058     inline ArrayWrapper(const ExpressionType& matrix) : m_expression(matrix) {}
00059 
00060     inline Index rows() const { return m_expression.rows(); }
00061     inline Index cols() const { return m_expression.cols(); }
00062     inline Index outerStride() const { return m_expression.outerStride(); }
00063     inline Index innerStride() const { return m_expression.innerStride(); }
00064 
00065     inline const CoeffReturnType coeff(Index row, Index col) const
00066     {
00067       return m_expression.coeff(row, col);
00068     }
00069 
00070     inline Scalar& coeffRef(Index row, Index col)
00071     {
00072       return m_expression.const_cast_derived().coeffRef(row, col);
00073     }
00074 
00075     inline const CoeffReturnType coeff(Index index) const
00076     {
00077       return m_expression.coeff(index);
00078     }
00079 
00080     inline Scalar& coeffRef(Index index)
00081     {
00082       return m_expression.const_cast_derived().coeffRef(index);
00083     }
00084 
00085     template<int LoadMode>
00086     inline const PacketScalar packet(Index row, Index col) const
00087     {
00088       return m_expression.template packet<LoadMode>(row, col);
00089     }
00090 
00091     template<int LoadMode>
00092     inline void writePacket(Index row, Index col, const PacketScalar& x)
00093     {
00094       m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
00095     }
00096 
00097     template<int LoadMode>
00098     inline const PacketScalar packet(Index index) const
00099     {
00100       return m_expression.template packet<LoadMode>(index);
00101     }
00102 
00103     template<int LoadMode>
00104     inline void writePacket(Index index, const PacketScalar& x)
00105     {
00106       m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
00107     }
00108 
00109     template<typename Dest>
00110     inline void evalTo(Dest& dst) const { dst = m_expression; }
00111 
00112   protected:
00113     const NestedExpressionType m_expression;
00114 };
00115 
00116 /** \class MatrixWrapper
00117   * \ingroup Core_Module
00118   *
00119   * \brief Expression of an array as a mathematical vector or matrix
00120   *
00121   * This class is the return type of ArrayBase::matrix(), and most of the time
00122   * this is the only way it is use.
00123   *
00124   * \sa MatrixBase::matrix(), class ArrayWrapper
00125   */
00126 
00127 namespace internal {
00128 template<typename ExpressionType>
00129 struct traits<MatrixWrapper<ExpressionType> >
00130  : public traits<typename remove_all<typename ExpressionType::Nested>::type >
00131 {
00132   typedef MatrixXpr XprKind;
00133 };
00134 }
00135 
00136 template<typename ExpressionType>
00137 class MatrixWrapper : public MatrixBase<MatrixWrapper<ExpressionType> >
00138 {
00139   public:
00140     typedef MatrixBase<MatrixWrapper<ExpressionType> > Base;
00141     EIGEN_DENSE_PUBLIC_INTERFACE(MatrixWrapper)
00142     EIGEN_INHERIT_ASSIGNMENT_OPERATORS(MatrixWrapper)
00143 
00144     typedef typename internal::nested<ExpressionType>::type NestedExpressionType;
00145 
00146     inline MatrixWrapper(const ExpressionType& matrix) : m_expression(matrix) {}
00147 
00148     inline Index rows() const { return m_expression.rows(); }
00149     inline Index cols() const { return m_expression.cols(); }
00150     inline Index outerStride() const { return m_expression.outerStride(); }
00151     inline Index innerStride() const { return m_expression.innerStride(); }
00152 
00153     inline const CoeffReturnType coeff(Index row, Index col) const
00154     {
00155       return m_expression.coeff(row, col);
00156     }
00157 
00158     inline Scalar& coeffRef(Index row, Index col)
00159     {
00160       return m_expression.const_cast_derived().coeffRef(row, col);
00161     }
00162 
00163     inline const Scalar& coeffRef(Index row, Index col) const
00164     {
00165       return m_expression.derived().coeffRef(row, col);
00166     }
00167 
00168     inline const CoeffReturnType coeff(Index index) const
00169     {
00170       return m_expression.coeff(index);
00171     }
00172 
00173     inline Scalar& coeffRef(Index index)
00174     {
00175       return m_expression.const_cast_derived().coeffRef(index);
00176     }
00177 
00178     template<int LoadMode>
00179     inline const PacketScalar packet(Index row, Index col) const
00180     {
00181       return m_expression.template packet<LoadMode>(row, col);
00182     }
00183 
00184     template<int LoadMode>
00185     inline void writePacket(Index row, Index col, const PacketScalar& x)
00186     {
00187       m_expression.const_cast_derived().template writePacket<LoadMode>(row, col, x);
00188     }
00189 
00190     template<int LoadMode>
00191     inline const PacketScalar packet(Index index) const
00192     {
00193       return m_expression.template packet<LoadMode>(index);
00194     }
00195 
00196     template<int LoadMode>
00197     inline void writePacket(Index index, const PacketScalar& x)
00198     {
00199       m_expression.const_cast_derived().template writePacket<LoadMode>(index, x);
00200     }
00201 
00202   protected:
00203     const NestedExpressionType m_expression;
00204 };
00205 
00206 #endif // EIGEN_ARRAYWRAPPER_H



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