xref: /aosp_15_r20/external/eigen/Eigen/src/misc/Kernel.h (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
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_KERNEL_H
11*bf2c3715SXin Li #define EIGEN_MISC_KERNEL_H
12*bf2c3715SXin Li 
13*bf2c3715SXin Li namespace Eigen {
14*bf2c3715SXin Li 
15*bf2c3715SXin Li namespace internal {
16*bf2c3715SXin Li 
17*bf2c3715SXin Li /** \class kernel_retval_base
18*bf2c3715SXin Li   *
19*bf2c3715SXin Li   */
20*bf2c3715SXin Li template<typename DecompositionType>
21*bf2c3715SXin Li struct traits<kernel_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::ColsAtCompileTime, // the number of rows in the "kernel matrix"
27*bf2c3715SXin Li                                    // is the number of cols of the original matrix
28*bf2c3715SXin Li                                    // so that the product "matrix * kernel = zero" makes sense
29*bf2c3715SXin Li     Dynamic,                       // we don't know at compile-time the dimension of the kernel
30*bf2c3715SXin Li     MatrixType::Options,
31*bf2c3715SXin Li     MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter
32*bf2c3715SXin Li     MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space,
33*bf2c3715SXin Li                                      // whose dimension is the number of columns of the original matrix
34*bf2c3715SXin Li   > ReturnType;
35*bf2c3715SXin Li };
36*bf2c3715SXin Li 
37*bf2c3715SXin Li template<typename _DecompositionType> struct kernel_retval_base
38*bf2c3715SXin Li  : public ReturnByValue<kernel_retval_base<_DecompositionType> >
39*bf2c3715SXin Li {
40*bf2c3715SXin Li   typedef _DecompositionType DecompositionType;
41*bf2c3715SXin Li   typedef ReturnByValue<kernel_retval_base> Base;
42*bf2c3715SXin Li 
43*bf2c3715SXin Li   explicit kernel_retval_base(const DecompositionType& dec)
44*bf2c3715SXin Li     : m_dec(dec),
45*bf2c3715SXin Li       m_rank(dec.rank()),
46*bf2c3715SXin Li       m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank)
47*bf2c3715SXin Li   {}
48*bf2c3715SXin Li 
49*bf2c3715SXin Li   inline Index rows() const { return m_dec.cols(); }
50*bf2c3715SXin Li   inline Index cols() const { return m_cols; }
51*bf2c3715SXin Li   inline Index rank() const { return m_rank; }
52*bf2c3715SXin Li   inline const DecompositionType& dec() const { return m_dec; }
53*bf2c3715SXin Li 
54*bf2c3715SXin Li   template<typename Dest> inline void evalTo(Dest& dst) const
55*bf2c3715SXin Li   {
56*bf2c3715SXin Li     static_cast<const kernel_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 };
63*bf2c3715SXin Li 
64*bf2c3715SXin Li } // end namespace internal
65*bf2c3715SXin Li 
66*bf2c3715SXin Li #define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \
67*bf2c3715SXin Li   typedef typename DecompositionType::MatrixType MatrixType; \
68*bf2c3715SXin Li   typedef typename MatrixType::Scalar Scalar; \
69*bf2c3715SXin Li   typedef typename MatrixType::RealScalar RealScalar; \
70*bf2c3715SXin Li   typedef Eigen::internal::kernel_retval_base<DecompositionType> Base; \
71*bf2c3715SXin Li   using Base::dec; \
72*bf2c3715SXin Li   using Base::rank; \
73*bf2c3715SXin Li   using Base::rows; \
74*bf2c3715SXin Li   using Base::cols; \
75*bf2c3715SXin Li   kernel_retval(const DecompositionType& dec) : Base(dec) {}
76*bf2c3715SXin Li 
77*bf2c3715SXin Li } // end namespace Eigen
78*bf2c3715SXin Li 
79*bf2c3715SXin Li #endif // EIGEN_MISC_KERNEL_H
80