11#ifndef EIGEN_INVERSE_IMPL_H
12#define EIGEN_INVERSE_IMPL_H
22template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
26 static inline void run(
const MatrixType& matrix, ResultType& result)
28 result = matrix.partialPivLu().inverse();
32template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
39template<
typename MatrixType,
typename ResultType>
43 static inline void run(
const MatrixType& matrix, ResultType& result)
45 typedef typename MatrixType::Scalar Scalar;
47 result.coeffRef(0,0) = Scalar(1) /
matrixEval.coeff(0,0);
51template<
typename MatrixType,
typename ResultType>
55 static inline void run(
56 const MatrixType& matrix,
59 typename ResultType::Scalar& determinant,
64 determinant = matrix.coeff(0,0);
66 if(
invertible) result.coeffRef(0,0) =
typename ResultType::Scalar(1) / determinant;
74template<
typename MatrixType,
typename ResultType>
76inline void compute_inverse_size2_helper(
77 const MatrixType& matrix,
const typename ResultType::Scalar&
invdet,
80 result.coeffRef(0,0) = matrix.coeff(1,1) *
invdet;
81 result.coeffRef(1,0) = -matrix.coeff(1,0) *
invdet;
82 result.coeffRef(0,1) = -matrix.coeff(0,1) *
invdet;
83 result.coeffRef(1,1) = matrix.coeff(0,0) *
invdet;
86template<
typename MatrixType,
typename ResultType>
90 static inline void run(
const MatrixType& matrix, ResultType& result)
92 typedef typename ResultType::Scalar Scalar;
93 const Scalar
invdet =
typename MatrixType::Scalar(1) / matrix.determinant();
94 compute_inverse_size2_helper(matrix,
invdet, result);
98template<
typename MatrixType,
typename ResultType>
102 static inline void run(
103 const MatrixType& matrix,
106 typename ResultType::Scalar& determinant,
111 typedef typename ResultType::Scalar Scalar;
112 determinant = matrix.determinant();
115 const Scalar
invdet = Scalar(1) / determinant;
116 compute_inverse_size2_helper(matrix,
invdet, inverse);
124template<
typename MatrixType,
int i,
int j>
126inline typename MatrixType::Scalar cofactor_3x3(
const MatrixType& m)
134 return m.coeff(
i1,
j1) * m.coeff(
i2,
j2)
135 - m.coeff(
i1,
j2) * m.coeff(
i2,
j1);
138template<
typename MatrixType,
typename ResultType>
140inline void compute_inverse_size3_helper(
141 const MatrixType& matrix,
142 const typename ResultType::Scalar& invdet,
146 result.row(0) = cofactors_col0 * invdet;
147 result.coeffRef(1,0) = cofactor_3x3<MatrixType,0,1>(matrix) * invdet;
148 result.coeffRef(1,1) = cofactor_3x3<MatrixType,1,1>(matrix) * invdet;
149 result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix) * invdet;
150 result.coeffRef(2,0) = cofactor_3x3<MatrixType,0,2>(matrix) * invdet;
151 result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix) * invdet;
152 result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix) * invdet;
155template<
typename MatrixType,
typename ResultType>
159 static inline void run(
const MatrixType& matrix, ResultType& result)
161 typedef typename ResultType::Scalar Scalar;
172template<
typename MatrixType,
typename ResultType>
176 static inline void run(
177 const MatrixType& matrix,
180 typename ResultType::Scalar& determinant,
185 typedef typename ResultType::Scalar Scalar;
193 const Scalar
invdet = Scalar(1) / determinant;
202template<
typename Derived>
204inline const typename Derived::Scalar general_det3_helper
207 return matrix.coeff(
i1,
j1)
208 * (matrix.coeff(
i2,
j2) * matrix.coeff(
i3,
j3) - matrix.coeff(
i2,
j3) * matrix.coeff(
i3,
j2));
211template<
typename MatrixType,
int i,
int j>
213inline typename MatrixType::Scalar cofactor_4x4(
const MatrixType& matrix)
223 return general_det3_helper(matrix, i1, i2, i3, j1, j2, j3)
224 + general_det3_helper(matrix, i2, i3, i1, j1, j2, j3)
225 + general_det3_helper(matrix, i3, i1, i2, j1, j2, j3);
228template<
int Arch,
typename Scalar,
typename MatrixType,
typename ResultType>
232 static void run(
const MatrixType& matrix, ResultType& result)
250 result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
254template<
typename MatrixType,
typename ResultType>
257 MatrixType, ResultType>
261template<
typename MatrixType,
typename ResultType>
265 static inline void run(
266 const MatrixType& matrix,
269 typename ResultType::Scalar& determinant,
274 determinant = matrix.determinant();
289template<
typename DstXprType,
typename XprType,
typename Scalar>
296 const int Size = EIGEN_PLAIN_ENUM_MIN(XprType::ColsAtCompileTime,DstXprType::ColsAtCompileTime);
297 EIGEN_ONLY_USED_FOR_DEBUG(Size);
298 eigen_assert(( (Size<=1) || (Size>4) || (extract_data(
src.nestedExpression())!=extract_data(
dst)))
299 &&
"Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
330template<
typename Derived>
334 eigen_assert(rows() == cols());
356template<
typename Derived>
357template<
typename ResultType>
360 typename ResultType::Scalar& determinant,
366 eigen_assert(rows() == cols());
370 RowsAtCompileTime == 2,
395template<
typename Derived>
396template<
typename ResultType>
403 RealScalar determinant;
405 eigen_assert(rows() == cols());
Expression of the inverse of another expression.
Definition Inverse.h:44
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Pseudo expression representing a solving operation.
Definition Solve.h:63
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition AssignEvaluator.h:684
Definition AssignEvaluator.h:674
Definition AssignmentFunctors.h:21
Definition InverseImpl.h:33
Definition InverseImpl.h:230
Definition InverseImpl.h:24
Definition CoreEvaluators.h:82
Definition inference.c:32