Kernel.h
Go to the documentation of this file.
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@gmail.com>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_MISC_KERNEL_H
26 #define EIGEN_MISC_KERNEL_H
27 
28 namespace Eigen {
29 
30 namespace internal {
31 
35 template<typename DecompositionType>
36 struct traits<kernel_retval_base<DecompositionType> >
37 {
38  typedef typename DecompositionType::MatrixType MatrixType;
39  typedef Matrix<
40  typename MatrixType::Scalar,
41  MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix"
42  // is the number of cols of the original matrix
43  // so that the product "matrix * kernel = zero" makes sense
44  Dynamic, // we don't know at compile-time the dimension of the kernel
45  MatrixType::Options,
46  MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter
47  MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space,
48  // whose dimension is the number of columns of the original matrix
49  > ReturnType;
50 };
51 
52 template<typename _DecompositionType> struct kernel_retval_base
53  : public ReturnByValue<kernel_retval_base<_DecompositionType> >
54 {
55  typedef _DecompositionType DecompositionType;
56  typedef ReturnByValue<kernel_retval_base> Base;
57  typedef typename Base::Index Index;
58 
59  kernel_retval_base(const DecompositionType& dec)
60  : m_dec(dec),
61  m_rank(dec.rank()),
62  m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank)
63  {}
64 
65  inline Index rows() const { return m_dec.cols(); }
66  inline Index cols() const { return m_cols; }
67  inline Index rank() const { return m_rank; }
68  inline const DecompositionType& dec() const { return m_dec; }
69 
70  template<typename Dest> inline void evalTo(Dest& dst) const
71  {
72  static_cast<const kernel_retval<DecompositionType>*>(this)->evalTo(dst);
73  }
74 
75  protected:
76  const DecompositionType& m_dec;
77  Index m_rank, m_cols;
78 };
79 
80 } // end namespace internal
81 
82 #define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \
83  typedef typename DecompositionType::MatrixType MatrixType; \
84  typedef typename MatrixType::Scalar Scalar; \
85  typedef typename MatrixType::RealScalar RealScalar; \
86  typedef typename MatrixType::Index Index; \
87  typedef Eigen::internal::kernel_retval_base<DecompositionType> Base; \
88  using Base::dec; \
89  using Base::rank; \
90  using Base::rows; \
91  using Base::cols; \
92  kernel_retval(const DecompositionType& dec) : Base(dec) {}
93 
94 } // end namespace Eigen
95 
96 #endif // EIGEN_MISC_KERNEL_H