11 #ifndef EIGEN_INVERSE_IMPL_H 12 #define EIGEN_INVERSE_IMPL_H 22 template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
28 result = matrix.partialPivLu().inverse();
32 template<
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
39 template<
typename MatrixType,
typename ResultType>
47 result.coeffRef(0,0) =
Scalar(1) / matrixEval.coeff(0,0);
51 template<
typename MatrixType,
typename ResultType>
55 static inline void run(
64 determinant = matrix.coeff(0,0);
65 invertible =
abs(determinant) > absDeterminantThreshold;
74 template<
typename MatrixType,
typename ResultType>
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;
86 template<
typename MatrixType,
typename ResultType>
98 template<
typename MatrixType,
typename ResultType>
112 determinant = matrix.determinant();
113 invertible =
abs(determinant) > absDeterminantThreshold;
114 if(!invertible)
return;
124 template<
typename MatrixType,
int i,
int j>
134 return m.coeff(i1, j1) * m.coeff(i2, j2)
135 - m.coeff(i1, j2) * m.coeff(i2, j1);
138 template<
typename MatrixType,
typename ResultType>
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;
155 template<
typename MatrixType,
typename ResultType>
163 cofactors_col0.
coeffRef(0) = cofactor_3x3<MatrixType,0,0>(
matrix);
164 cofactors_col0.
coeffRef(1) = cofactor_3x3<MatrixType,1,0>(
matrix);
165 cofactors_col0.
coeffRef(2) = cofactor_3x3<MatrixType,2,0>(
matrix);
166 const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
167 const Scalar invdet =
Scalar(1) / det;
172 template<
typename MatrixType,
typename ResultType>
187 cofactors_col0.
coeffRef(0) = cofactor_3x3<MatrixType,0,0>(
matrix);
188 cofactors_col0.
coeffRef(1) = cofactor_3x3<MatrixType,1,0>(
matrix);
189 cofactors_col0.
coeffRef(2) = cofactor_3x3<MatrixType,2,0>(
matrix);
190 determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
191 invertible =
abs(determinant) > absDeterminantThreshold;
192 if(!invertible)
return;
202 template<
typename Derived>
207 return matrix.coeff(i1,j1)
208 * (matrix.coeff(i2,j2) * matrix.coeff(i3,j3) - matrix.coeff(i2,j3) * matrix.coeff(i3,j2));
211 template<
typename MatrixType,
int i,
int j>
228 template<
int Arch,
typename Scalar,
typename MatrixType,
typename ResultType>
234 result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(
matrix);
235 result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(
matrix);
236 result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(
matrix);
237 result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(
matrix);
238 result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(
matrix);
239 result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(
matrix);
240 result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(
matrix);
241 result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(
matrix);
242 result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(
matrix);
243 result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(
matrix);
244 result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(
matrix);
245 result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(
matrix);
246 result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(
matrix);
247 result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(
matrix);
248 result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(
matrix);
249 result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(
matrix);
250 result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
254 template<
typename MatrixType,
typename ResultType>
257 MatrixType, ResultType>
261 template<
typename MatrixType,
typename ResultType>
274 determinant = matrix.determinant();
275 invertible =
abs(determinant) > absDeterminantThreshold;
289 template<
typename DstXprType,
typename XprType>
297 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
298 dst.resize(dstRows, dstCols);
300 const int Size =
EIGEN_PLAIN_ENUM_MIN(XprType::ColsAtCompileTime,DstXprType::ColsAtCompileTime);
303 &&
"Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
334 template<
typename Derived>
360 template<
typename Derived>
361 template<
typename ResultType>
374 RowsAtCompileTime == 2,
379 (derived(), absDeterminantThreshold, inverse, determinant, invertible);
399 template<
typename Derived>
400 template<
typename ResultType>
410 computeInverseAndDetWithCheck(inverse,determinant,invertible,absDeterminantThreshold);
415 #endif // EIGEN_INVERSE_IMPL_H
EIGEN_DEVICE_FUNC MatrixType::Scalar cofactor_4x4(const MatrixType &matrix)
internal::traits< Derived >::Scalar Scalar
EIGEN_DEVICE_FUNC Index rows() const
void determinant(const MatrixType &m)
Namespace containing all symbols from the Eigen library.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename XprType::Scalar > &)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Expression of the inverse of another expression.
EIGEN_DEVICE_FUNC void compute_inverse_size2_helper(const MatrixType &matrix, const typename ResultType::Scalar &invdet, ResultType &result)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &result, typename ResultType::Scalar &determinant, bool &invertible)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
Inverse< XprType > SrcXprType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
EIGEN_DEVICE_FUNC Index cols() const
void computeInverseAndDetWithCheck(ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible, const RealScalar &absDeterminantThreshold=NumTraits< Scalar >::dummy_precision()) const
EIGEN_DEVICE_FUNC MatrixType::Scalar cofactor_3x3(const MatrixType &m)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible)
NumTraits< Scalar >::Real RealScalar
NumTraits< Scalar >::Real RealScalar
void computeInverseWithCheck(ResultType &inverse, bool &invertible, const RealScalar &absDeterminantThreshold=NumTraits< Scalar >::dummy_precision()) const
#define EIGEN_PLAIN_ENUM_MIN(a, b)
const T::Scalar * extract_data(const T &m)
EIGEN_DEVICE_FUNC void compute_inverse_size3_helper(const MatrixType &matrix, const typename ResultType::Scalar &invdet, const Matrix< typename ResultType::Scalar, 3, 1 > &cofactors_col0, ResultType &result)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
The matrix class, also used for vectors and row-vectors.
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned & nestedExpression() const
void run(Expr &expr, Dev &dev)
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
const Inverse< Derived > inverse() const
Base class for all dense matrices, vectors, and expressions.
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
EIGEN_DEVICE_FUNC const Derived::Scalar general_det3_helper(const MatrixBase< Derived > &matrix, int i1, int i2, int i3, int j1, int j2, int j3)
#define EIGEN_ONLY_USED_FOR_DEBUG(x)