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