10 #ifndef EIGEN_INVERSE_H 11 #define EIGEN_INVERSE_H 21 template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
24 static inline void run(
const MatrixType& matrix, ResultType& result)
26 result = matrix.partialPivLu().inverse();
30 template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
37 template<
typename MatrixType,
typename ResultType>
40 static inline void run(
const MatrixType& matrix, ResultType& result)
43 result.coeffRef(0,0) =
Scalar(1) / matrix.coeff(0,0);
47 template<
typename MatrixType,
typename ResultType>
50 static inline void run(
52 const typename MatrixType::RealScalar& absDeterminantThreshold,
59 determinant = matrix.coeff(0,0);
60 invertible = abs(determinant) > absDeterminantThreshold;
69 template<
typename MatrixType,
typename ResultType>
70 inline void compute_inverse_size2_helper(
74 result.coeffRef(0,0) = matrix.coeff(1,1) * invdet;
75 result.coeffRef(1,0) = -matrix.coeff(1,0) * invdet;
76 result.coeffRef(0,1) = -matrix.coeff(0,1) * invdet;
77 result.coeffRef(1,1) = matrix.coeff(0,0) * invdet;
80 template<
typename MatrixType,
typename ResultType>
83 static inline void run(
const MatrixType& matrix, ResultType& result)
87 compute_inverse_size2_helper(matrix, invdet, result);
91 template<
typename MatrixType,
typename ResultType>
94 static inline void run(
96 const typename MatrixType::RealScalar& absDeterminantThreshold,
104 determinant = matrix.determinant();
105 invertible = abs(determinant) > absDeterminantThreshold;
106 if(!invertible)
return;
107 const Scalar invdet =
Scalar(1) / determinant;
108 compute_inverse_size2_helper(matrix, invdet, inverse);
116 template<
typename MatrixType,
int i,
int j>
125 return m.coeff(i1, j1) * m.coeff(i2, j2)
126 - m.coeff(i1, j2) * m.coeff(i2, j1);
129 template<
typename MatrixType,
typename ResultType>
130 inline void compute_inverse_size3_helper(
136 result.row(0) = cofactors_col0 * invdet;
137 result.coeffRef(1,0) = cofactor_3x3<MatrixType,0,1>(matrix) * invdet;
138 result.coeffRef(1,1) = cofactor_3x3<MatrixType,1,1>(matrix) * invdet;
139 result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix) * invdet;
140 result.coeffRef(2,0) = cofactor_3x3<MatrixType,0,2>(matrix) * invdet;
141 result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix) * invdet;
142 result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix) * invdet;
145 template<
typename MatrixType,
typename ResultType>
148 static inline void run(
const MatrixType& matrix, ResultType& result)
152 cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
153 cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
154 cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
155 const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
156 const Scalar invdet =
Scalar(1) / det;
157 compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result);
161 template<
typename MatrixType,
typename ResultType>
164 static inline void run(
166 const typename MatrixType::RealScalar& absDeterminantThreshold,
175 cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
176 cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
177 cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
178 determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
179 invertible = abs(determinant) > absDeterminantThreshold;
180 if(!invertible)
return;
181 const Scalar invdet =
Scalar(1) / determinant;
182 compute_inverse_size3_helper(matrix, invdet, cofactors_col0, inverse);
190 template<
typename Derived>
194 return matrix.coeff(i1,j1)
195 * (matrix.coeff(i2,j2) * matrix.coeff(i3,j3) - matrix.coeff(i2,j3) * matrix.coeff(i3,j2));
198 template<
typename MatrixType,
int i,
int j>
209 return general_det3_helper(matrix, i1, i2, i3, j1, j2, j3)
210 + general_det3_helper(matrix, i2, i3, i1, j1, j2, j3)
211 + general_det3_helper(matrix, i3, i1, i2, j1, j2, j3);
214 template<
int Arch,
typename Scalar,
typename MatrixType,
typename ResultType>
217 static void run(
const MatrixType& matrix, ResultType& result)
219 result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(matrix);
220 result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(matrix);
221 result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(matrix);
222 result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(matrix);
223 result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(matrix);
224 result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(matrix);
225 result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(matrix);
226 result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(matrix);
227 result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(matrix);
228 result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(matrix);
229 result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(matrix);
230 result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(matrix);
231 result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(matrix);
232 result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(matrix);
233 result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(matrix);
234 result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(matrix);
235 result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
239 template<
typename MatrixType,
typename ResultType>
242 MatrixType, ResultType>
246 template<
typename MatrixType,
typename ResultType>
249 static inline void run(
251 const typename MatrixType::RealScalar& absDeterminantThreshold,
258 determinant = matrix.determinant();
259 invertible = abs(determinant) > absDeterminantThreshold;
268 template<
typename MatrixType>
271 typedef typename MatrixType::PlainObject ReturnType;
274 template<
typename MatrixType>
277 typedef typename MatrixType::Index Index;
280 MatrixTypeNested m_matrix;
286 inline Index rows()
const {
return m_matrix.rows(); }
287 inline Index cols()
const {
return m_matrix.cols(); }
289 template<
typename Dest>
inline void evalTo(Dest& dst)
const 291 const int Size = EIGEN_PLAIN_ENUM_MIN(MatrixType::ColsAtCompileTime,Dest::ColsAtCompileTime);
292 EIGEN_ONLY_USED_FOR_DEBUG(Size);
293 eigen_assert(( (Size<=1) || (Size>4) || (extract_data(m_matrix)!=extract_data(dst)))
294 &&
"Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
319 template<
typename Derived>
323 eigen_assert(rows() == cols());
345 template<
typename Derived>
346 template<
typename ResultType>
351 const RealScalar& absDeterminantThreshold
355 eigen_assert(rows() == cols());
359 RowsAtCompileTime == 2,
364 (derived(), absDeterminantThreshold, inverse, determinant, invertible);
384 template<
typename Derived>
385 template<
typename ResultType>
389 const RealScalar& absDeterminantThreshold
392 RealScalar determinant;
394 eigen_assert(rows() == cols());
395 computeInverseAndDetWithCheck(inverse,determinant,invertible,absDeterminantThreshold);
400 #endif // EIGEN_INVERSE_H
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Definition: ReturnByValue.h:50
void computeInverseAndDetWithCheck(ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible, const RealScalar &absDeterminantThreshold=NumTraits< Scalar >::dummy_precision()) const
Definition: Inverse.h:347
const internal::inverse_impl< Derived > inverse() const
Definition: Inverse.h:320
Definition: Inverse.h:215
Definition: ForwardDeclarations.h:219
Definition: BandTriangularSolver.h:13
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
void computeInverseWithCheck(ResultType &inverse, bool &invertible, const RealScalar &absDeterminantThreshold=NumTraits< Scalar >::dummy_precision()) const
Definition: Inverse.h:386
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: ForwardDeclarations.h:17
Definition: XprHelper.h:203
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48