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 // 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_KERNEL_H
11 #define EIGEN_MISC_KERNEL_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
22 template<typename DecompositionType>
23 struct traits<kernel_retval_base<DecompositionType> >
24 {
26  typedef Matrix<
27  typename MatrixType::Scalar,
28  MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix"
29  // is the number of cols of the original matrix
30  // so that the product "matrix * kernel = zero" makes sense
31  Dynamic, // we don't know at compile-time the dimension of the kernel
32  MatrixType::Options,
33  MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter
34  MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space,
35  // whose dimension is the number of columns of the original matrix
36  > ReturnType;
37 };
38 
39 template<typename DecompositionType_> struct kernel_retval_base
40  : public ReturnByValue<kernel_retval_base<DecompositionType_> >
41 {
42  typedef DecompositionType_ DecompositionType;
43  typedef ReturnByValue<kernel_retval_base> Base;
44 
45  explicit kernel_retval_base(const DecompositionType& dec)
46  : m_dec(dec),
47  m_rank(dec.rank()),
48  m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank)
49  {}
50 
51  inline Index rows() const { return m_dec.cols(); }
52  inline Index cols() const { return m_cols; }
53  inline Index rank() const { return m_rank; }
54  inline const DecompositionType& dec() const { return m_dec; }
55 
56  template<typename Dest> inline void evalTo(Dest& dst) const
57  {
58  static_cast<const kernel_retval<DecompositionType>*>(this)->evalTo(dst);
59  }
60 
61  protected:
62  const DecompositionType& m_dec;
63  Index m_rank, m_cols;
64 };
65 
66 } // end namespace internal
67 
68 #define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \
69  typedef typename DecompositionType::MatrixType MatrixType; \
70  typedef typename MatrixType::Scalar Scalar; \
71  typedef typename MatrixType::RealScalar RealScalar; \
72  typedef Eigen::internal::kernel_retval_base<DecompositionType> Base; \
73  using Base::dec; \
74  using Base::rank; \
75  using Base::rows; \
76  using Base::cols; \
77  kernel_retval(const DecompositionType& dec) : Base(dec) {}
78 
79 } // end namespace Eigen
80 
81 #endif // EIGEN_MISC_KERNEL_H
Matrix< float, 1, Dynamic > MatrixType
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
internal::dense_xpr_base< ReturnByValue >::type Base
Definition: ReturnByValue.h:58
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const int Dynamic
Definition: Constants.h:24