Home | History | Annotate | Download | only in misc
      1 // This file is part of Eigen, a lightweight C++ template library
      2 // for linear algebra.
      3 //
      4 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1 (at) gmail.com>
      5 //
      6 // This Source Code Form is subject to the terms of the Mozilla
      7 // Public License v. 2.0. If a copy of the MPL was not distributed
      8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
      9 
     10 #ifndef EIGEN_MISC_IMAGE_H
     11 #define EIGEN_MISC_IMAGE_H
     12 
     13 namespace Eigen {
     14 
     15 namespace internal {
     16 
     17 /** \class image_retval_base
     18   *
     19   */
     20 template<typename DecompositionType>
     21 struct traits<image_retval_base<DecompositionType> >
     22 {
     23   typedef typename DecompositionType::MatrixType MatrixType;
     24   typedef Matrix<
     25     typename MatrixType::Scalar,
     26     MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose
     27                                    // dimension is the number of rows of the original matrix
     28     Dynamic,                       // we don't know at compile time the dimension of the image (the rank)
     29     MatrixType::Options,
     30     MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix,
     31     MatrixType::MaxColsAtCompileTime  // so it has the same number of rows and at most as many columns.
     32   > ReturnType;
     33 };
     34 
     35 template<typename _DecompositionType> struct image_retval_base
     36  : public ReturnByValue<image_retval_base<_DecompositionType> >
     37 {
     38   typedef _DecompositionType DecompositionType;
     39   typedef typename DecompositionType::MatrixType MatrixType;
     40   typedef ReturnByValue<image_retval_base> Base;
     41   typedef typename Base::Index Index;
     42 
     43   image_retval_base(const DecompositionType& dec, const MatrixType& originalMatrix)
     44     : m_dec(dec), m_rank(dec.rank()),
     45       m_cols(m_rank == 0 ? 1 : m_rank),
     46       m_originalMatrix(originalMatrix)
     47   {}
     48 
     49   inline Index rows() const { return m_dec.rows(); }
     50   inline Index cols() const { return m_cols; }
     51   inline Index rank() const { return m_rank; }
     52   inline const DecompositionType& dec() const { return m_dec; }
     53   inline const MatrixType& originalMatrix() const { return m_originalMatrix; }
     54 
     55   template<typename Dest> inline void evalTo(Dest& dst) const
     56   {
     57     static_cast<const image_retval<DecompositionType>*>(this)->evalTo(dst);
     58   }
     59 
     60   protected:
     61     const DecompositionType& m_dec;
     62     Index m_rank, m_cols;
     63     const MatrixType& m_originalMatrix;
     64 };
     65 
     66 } // end namespace internal
     67 
     68 #define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) \
     69   typedef typename DecompositionType::MatrixType MatrixType; \
     70   typedef typename MatrixType::Scalar Scalar; \
     71   typedef typename MatrixType::RealScalar RealScalar; \
     72   typedef typename MatrixType::Index Index; \
     73   typedef Eigen::internal::image_retval_base<DecompositionType> Base; \
     74   using Base::dec; \
     75   using Base::originalMatrix; \
     76   using Base::rank; \
     77   using Base::rows; \
     78   using Base::cols; \
     79   image_retval(const DecompositionType& dec, const MatrixType& originalMatrix) \
     80     : Base(dec, originalMatrix) {}
     81 
     82 } // end namespace Eigen
     83 
     84 #endif // EIGEN_MISC_IMAGE_H
     85