20 template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
21 struct compute_adjugate
23 static inline void run(
const MatrixType& matrix, ResultType& result)
25 eigen_assert( matrix.rows() == matrix.cols() &&
"Matrix is not square.");
27 switch( matrix.rows() )
30 compute_adjugate<MatrixType, ResultType, 1>::run(matrix,result);
33 compute_adjugate<MatrixType, ResultType, 2>::run(matrix,result);
36 compute_adjugate<MatrixType, ResultType, 3>::run(matrix,result);
39 compute_adjugate<MatrixType, ResultType, 4>::run(matrix,result);
42 eigen_assert(
false &&
"Not implemented.");
51 template<
typename MatrixType,
typename ResultType>
52 struct compute_adjugate<MatrixType, ResultType, 1>
54 static inline void run(
const MatrixType& , ResultType& result)
56 result.coeffRef(0,0) =
typename ResultType::Scalar(1);
62 template<
typename MatrixType,
typename ResultType>
63 struct compute_adjugate<MatrixType, ResultType, 2>
65 static inline void run(
const MatrixType& matrix, ResultType& result)
67 result.coeffRef(0,0) = matrix.coeff(1,1);
68 result.coeffRef(1,0) = -matrix.coeff(1,0);
69 result.coeffRef(0,1) = -matrix.coeff(0,1);
70 result.coeffRef(1,1) = matrix.coeff(0,0);
76 template<
typename MatrixType,
typename ResultType>
77 struct compute_adjugate<MatrixType, ResultType, 3>
79 static inline void run(
const MatrixType& matrix, ResultType& result)
81 result.coeffRef(0,0) = cofactor_3x3<MatrixType,0,0>(matrix);
82 result.coeffRef(0,1) = cofactor_3x3<MatrixType,1,0>(matrix);
83 result.coeffRef(0,2) = cofactor_3x3<MatrixType,2,0>(matrix);
84 result.coeffRef(1,0) = cofactor_3x3<MatrixType,0,1>(matrix);
85 result.coeffRef(1,1) = cofactor_3x3<MatrixType,1,1>(matrix);
86 result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix);
87 result.coeffRef(2,0) = cofactor_3x3<MatrixType,0,2>(matrix);
88 result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix);
89 result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix);
95 template<
typename MatrixType,
typename ResultType>
96 struct compute_adjugate<MatrixType, ResultType, 4>
98 static inline void run(
const MatrixType& matrix, ResultType& result)
100 result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(matrix);
101 result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(matrix);
102 result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(matrix);
103 result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(matrix);
104 result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(matrix);
105 result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(matrix);
106 result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(matrix);
107 result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(matrix);
108 result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(matrix);
109 result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(matrix);
110 result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(matrix);
111 result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(matrix);
112 result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(matrix);
113 result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(matrix);
114 result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(matrix);
115 result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(matrix);
121 template<
typename MatrixType>
122 struct adjugate_impl :
public ReturnByValue<adjugate_impl<MatrixType> >
124 typedef typename MatrixType::Index Index;
125 typedef typename internal::eval<MatrixType>::type MatrixTypeNested;
126 typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
127 MatrixTypeNested m_matrix;
129 adjugate_impl(
const MatrixType& matrix)
133 inline Index rows()
const {
return m_matrix.rows(); }
134 inline Index cols()
const {
return m_matrix.cols(); }
136 template<
typename Dest>
inline void evalTo(Dest& dst)
const
138 static const int Size = EIGEN_PLAIN_ENUM_MIN(MatrixType::ColsAtCompileTime,Dest::ColsAtCompileTime);
139 EIGEN_ONLY_USED_FOR_DEBUG(Size);
140 eigen_assert(( (Size<=1) || (Size>4) || (extract_data(m_matrix)!=extract_data(dst)))
141 &&
"Aliasing problem detected in adjugate(), you need to do adjugate().eval() here.");
143 compute_adjugate<MatrixTypeNestedCleaned, Dest>::run(m_matrix, dst);
147 template<
typename MatrixType>
148 struct traits<adjugate_impl<MatrixType> >
150 typedef typename MatrixType::PlainObject ReturnType;
159 template<
typename Derived>
160 inline const internal::adjugate_impl<Derived>
161 MatrixBase<Derived>::adjugate()
const
163 eigen_assert(rows() == cols());
164 return internal::adjugate_impl<Derived>(derived());
168 template<
typename Derived>
169 inline void MatrixBase<Derived>::adjugateInPlace()
171 derived() = adjugate().eval();