Eigen  3.3.3
Kernel.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_MISC_KERNEL_H
00011 #define EIGEN_MISC_KERNEL_H
00012 
00013 namespace Eigen { 
00014 
00015 namespace internal {
00016 
00020 template<typename DecompositionType>
00021 struct traits<kernel_retval_base<DecompositionType> >
00022 {
00023   typedef typename DecompositionType::MatrixType MatrixType;
00024   typedef Matrix<
00025     typename MatrixType::Scalar,
00026     MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix"
00027                                    // is the number of cols of the original matrix
00028                                    // so that the product "matrix * kernel = zero" makes sense
00029     Dynamic,                       // we don't know at compile-time the dimension of the kernel
00030     MatrixType::Options,
00031     MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter
00032     MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space,
00033                                      // whose dimension is the number of columns of the original matrix
00034   > ReturnType;
00035 };
00036 
00037 template<typename _DecompositionType> struct kernel_retval_base
00038  : public ReturnByValue<kernel_retval_base<_DecompositionType> >
00039 {
00040   typedef _DecompositionType DecompositionType;
00041   typedef ReturnByValue<kernel_retval_base> Base;
00042 
00043   explicit kernel_retval_base(const DecompositionType& dec)
00044     : m_dec(dec),
00045       m_rank(dec.rank()),
00046       m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank)
00047   {}
00048 
00049   inline Index rows() const { return m_dec.cols(); }
00050   inline Index cols() const { return m_cols; }
00051   inline Index rank() const { return m_rank; }
00052   inline const DecompositionType& dec() const { return m_dec; }
00053 
00054   template<typename Dest> inline void evalTo(Dest& dst) const
00055   {
00056     static_cast<const kernel_retval<DecompositionType>*>(this)->evalTo(dst);
00057   }
00058 
00059   protected:
00060     const DecompositionType& m_dec;
00061     Index m_rank, m_cols;
00062 };
00063 
00064 } // end namespace internal
00065 
00066 #define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \
00067   typedef typename DecompositionType::MatrixType MatrixType; \
00068   typedef typename MatrixType::Scalar Scalar; \
00069   typedef typename MatrixType::RealScalar RealScalar; \
00070   typedef Eigen::internal::kernel_retval_base<DecompositionType> Base; \
00071   using Base::dec; \
00072   using Base::rank; \
00073   using Base::rows; \
00074   using Base::cols; \
00075   kernel_retval(const DecompositionType& dec) : Base(dec) {}
00076 
00077 } // end namespace Eigen
00078 
00079 #endif // EIGEN_MISC_KERNEL_H
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends