1 | // This file is part of Eigen, a lightweight C++ template library
|
---|
2 | // for linear algebra.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2006-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_MINOR_H
|
---|
11 | #define EIGEN_MINOR_H
|
---|
12 |
|
---|
13 | namespace Eigen {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * \class Minor
|
---|
17 | *
|
---|
18 | * \brief Expression of a minor
|
---|
19 | *
|
---|
20 | * \param MatrixType the type of the object in which we are taking a minor
|
---|
21 | *
|
---|
22 | * This class represents an expression of a minor. It is the return
|
---|
23 | * type of MatrixBase::minor() and most of the time this is the only way it
|
---|
24 | * is used.
|
---|
25 | *
|
---|
26 | * \sa MatrixBase::minor()
|
---|
27 | */
|
---|
28 |
|
---|
29 | namespace internal {
|
---|
30 | template<typename MatrixType>
|
---|
31 | struct traits<Minor<MatrixType> >
|
---|
32 | : traits<MatrixType>
|
---|
33 | {
|
---|
34 | typedef typename nested<MatrixType>::type MatrixTypeNested;
|
---|
35 | typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
|
---|
36 | typedef typename MatrixType::StorageKind StorageKind;
|
---|
37 | enum {
|
---|
38 | RowsAtCompileTime = (MatrixType::RowsAtCompileTime != Dynamic) ?
|
---|
39 | int(MatrixType::RowsAtCompileTime) - 1 : Dynamic,
|
---|
40 | ColsAtCompileTime = (MatrixType::ColsAtCompileTime != Dynamic) ?
|
---|
41 | int(MatrixType::ColsAtCompileTime) - 1 : Dynamic,
|
---|
42 | MaxRowsAtCompileTime = (MatrixType::MaxRowsAtCompileTime != Dynamic) ?
|
---|
43 | int(MatrixType::MaxRowsAtCompileTime) - 1 : Dynamic,
|
---|
44 | MaxColsAtCompileTime = (MatrixType::MaxColsAtCompileTime != Dynamic) ?
|
---|
45 | int(MatrixType::MaxColsAtCompileTime) - 1 : Dynamic,
|
---|
46 | Flags = _MatrixTypeNested::Flags & (HereditaryBits | LvalueBit),
|
---|
47 | CoeffReadCost = _MatrixTypeNested::CoeffReadCost // minor is used typically on tiny matrices,
|
---|
48 | // where loops are unrolled and the 'if' evaluates at compile time
|
---|
49 | };
|
---|
50 | };
|
---|
51 | }
|
---|
52 |
|
---|
53 | template<typename MatrixType> class Minor
|
---|
54 | : public MatrixBase<Minor<MatrixType> >
|
---|
55 | {
|
---|
56 | public:
|
---|
57 |
|
---|
58 | typedef MatrixBase<Minor> Base;
|
---|
59 | EIGEN_DENSE_PUBLIC_INTERFACE(Minor)
|
---|
60 |
|
---|
61 | inline Minor(const MatrixType& matrix,
|
---|
62 | Index row, Index col)
|
---|
63 | : m_matrix(matrix), m_row(row), m_col(col)
|
---|
64 | {
|
---|
65 | eigen_assert(row >= 0 && row < matrix.rows()
|
---|
66 | && col >= 0 && col < matrix.cols());
|
---|
67 | }
|
---|
68 |
|
---|
69 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Minor)
|
---|
70 |
|
---|
71 | inline Index rows() const { return m_matrix.rows() - 1; }
|
---|
72 | inline Index cols() const { return m_matrix.cols() - 1; }
|
---|
73 |
|
---|
74 | inline Scalar& coeffRef(Index row, Index col)
|
---|
75 | {
|
---|
76 | return m_matrix.const_cast_derived().coeffRef(row + (row >= m_row), col + (col >= m_col));
|
---|
77 | }
|
---|
78 |
|
---|
79 | inline const Scalar coeff(Index row, Index col) const
|
---|
80 | {
|
---|
81 | return m_matrix.coeff(row + (row >= m_row), col + (col >= m_col));
|
---|
82 | }
|
---|
83 |
|
---|
84 | protected:
|
---|
85 | const typename MatrixType::Nested m_matrix;
|
---|
86 | const Index m_row, m_col;
|
---|
87 | };
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * \return an expression of the (\a row, \a col)-minor of *this,
|
---|
91 | * i.e. an expression constructed from *this by removing the specified
|
---|
92 | * row and column.
|
---|
93 | *
|
---|
94 | * Example: \include MatrixBase_minor.cpp
|
---|
95 | * Output: \verbinclude MatrixBase_minor.out
|
---|
96 | *
|
---|
97 | * \sa class Minor
|
---|
98 | */
|
---|
99 | template<typename Derived>
|
---|
100 | inline Minor<Derived>
|
---|
101 | MatrixBase<Derived>::minor(Index row, Index col)
|
---|
102 | {
|
---|
103 | return Minor<Derived>(derived(), row, col);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * This is the const version of minor(). */
|
---|
108 | template<typename Derived>
|
---|
109 | inline const Minor<Derived>
|
---|
110 | MatrixBase<Derived>::minor(Index row, Index col) const
|
---|
111 | {
|
---|
112 | return Minor<Derived>(derived(), row, col);
|
---|
113 | }
|
---|
114 |
|
---|
115 | } // end namespace Eigen
|
---|
116 |
|
---|
117 | #endif // EIGEN_MINOR_H
|
---|