11 #ifndef EIGEN_INVERSE_IMPL_H
12 #define EIGEN_INVERSE_IMPL_H
25 template <
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
28 result =
matrix.partialPivLu().inverse();
32 template <
typename MatrixType,
typename ResultType,
int Size = MatrixType::RowsAtCompileTime>
40 template <
typename MatrixType,
typename ResultType>
45 result.coeffRef(0, 0) =
Scalar(1) / matrixEval.coeff(0, 0);
49 template <
typename MatrixType,
typename ResultType>
66 template <
typename MatrixType,
typename ResultType>
71 result.coeffRef(0, 0) =
matrix.coeff(1, 1) * invdet;
72 result.coeffRef(1, 0) = -
matrix.coeff(1, 0) * invdet;
73 result.coeffRef(0, 1) = -
matrix.coeff(0, 1) * invdet;
74 result.coeffRef(1, 1) = temp * invdet;
77 template <
typename MatrixType,
typename ResultType>
86 template <
typename MatrixType,
typename ResultType>
96 if (!invertible)
return;
106 template <
typename MatrixType,
int i,
int j>
108 enum { i1 = (
i + 1) % 3, i2 = (
i + 2) % 3, j1 = (
j + 1) % 3, j2 = (
j + 2) % 3 };
109 return m.coeff(i1, j1) *
m.coeff(i2, j2) -
m.coeff(i1, j2) *
m.coeff(i2, j1);
112 template <
typename MatrixType,
typename ResultType>
118 const Scalar c01 = cofactor_3x3<MatrixType, 0, 1>(
matrix) * invdet;
119 const Scalar c11 = cofactor_3x3<MatrixType, 1, 1>(
matrix) * invdet;
120 const Scalar c02 = cofactor_3x3<MatrixType, 0, 2>(
matrix) * invdet;
121 result.coeffRef(1, 2) = cofactor_3x3<MatrixType, 2, 1>(
matrix) * invdet;
122 result.coeffRef(2, 1) = cofactor_3x3<MatrixType, 1, 2>(
matrix) * invdet;
123 result.coeffRef(2, 2) = cofactor_3x3<MatrixType, 2, 2>(
matrix) * invdet;
124 result.coeffRef(1, 0) = c01;
125 result.coeffRef(1, 1) = c11;
126 result.coeffRef(2, 0) = c02;
127 result.row(0) = cofactors_col0 * invdet;
130 template <
typename MatrixType,
typename ResultType>
135 cofactors_col0.
coeffRef(0) = cofactor_3x3<MatrixType, 0, 0>(
matrix);
136 cofactors_col0.
coeffRef(1) = cofactor_3x3<MatrixType, 1, 0>(
matrix);
137 cofactors_col0.
coeffRef(2) = cofactor_3x3<MatrixType, 2, 0>(
matrix);
138 const Scalar det = (cofactors_col0.cwiseProduct(
matrix.col(0))).sum();
144 template <
typename MatrixType,
typename ResultType>
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);
157 if (!invertible)
return;
167 template <
typename Derived>
169 int i2,
int i3,
int j1,
int j2,
int j3) {
170 return matrix.coeff(i1, j1) *
174 template <
typename MatrixType,
int i,
int j>
176 enum { i1 = (
i + 1) % 4, i2 = (
i + 2) % 4, i3 = (
i + 3) % 4, j1 = (
j + 1) % 4, j2 = (
j + 2) % 4, j3 = (
j + 3) % 4 };
177 return general_det3_helper(
matrix, i1, i2, i3, j1, j2, j3) +
general_det3_helper(
matrix, i2, i3, i1, j1, j2, j3) +
181 template <
int Arch,
typename Scalar,
typename MatrixType,
typename ResultType>
184 result.coeffRef(0, 0) = cofactor_4x4<MatrixType, 0, 0>(
matrix);
185 result.coeffRef(1, 0) = -cofactor_4x4<MatrixType, 0, 1>(
matrix);
186 result.coeffRef(2, 0) = cofactor_4x4<MatrixType, 0, 2>(
matrix);
187 result.coeffRef(3, 0) = -cofactor_4x4<MatrixType, 0, 3>(
matrix);
188 result.coeffRef(0, 2) = cofactor_4x4<MatrixType, 2, 0>(
matrix);
189 result.coeffRef(1, 2) = -cofactor_4x4<MatrixType, 2, 1>(
matrix);
190 result.coeffRef(2, 2) = cofactor_4x4<MatrixType, 2, 2>(
matrix);
191 result.coeffRef(3, 2) = -cofactor_4x4<MatrixType, 2, 3>(
matrix);
192 result.coeffRef(0, 1) = -cofactor_4x4<MatrixType, 1, 0>(
matrix);
193 result.coeffRef(1, 1) = cofactor_4x4<MatrixType, 1, 1>(
matrix);
194 result.coeffRef(2, 1) = -cofactor_4x4<MatrixType, 1, 2>(
matrix);
195 result.coeffRef(3, 1) = cofactor_4x4<MatrixType, 1, 3>(
matrix);
196 result.coeffRef(0, 3) = -cofactor_4x4<MatrixType, 3, 0>(
matrix);
197 result.coeffRef(1, 3) = cofactor_4x4<MatrixType, 3, 1>(
matrix);
198 result.coeffRef(2, 3) = -cofactor_4x4<MatrixType, 3, 2>(
matrix);
199 result.coeffRef(3, 3) = cofactor_4x4<MatrixType, 3, 3>(
matrix);
200 result /= (
matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
204 template <
typename MatrixType,
typename ResultType>
206 :
compute_inverse_size4<Architecture::Target, typename MatrixType::Scalar, MatrixType, ResultType> {};
208 template <
typename MatrixType,
typename ResultType>
219 }
else if (invertible) {
235 template <
typename DstXprType,
typename XprType>
243 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
245 const int Size =
plain_enum_min(XprType::ColsAtCompileTime, DstXprType::ColsAtCompileTime);
248 "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
278 template <
typename Derived>
305 template <
typename Derived>
306 template <
typename ResultType>
310 const RealScalar& absDeterminantThreshold)
const {
315 typedef std::conditional_t<RowsAtCompileTime == 2,
341 template <
typename Derived>
342 template <
typename ResultType>
344 const RealScalar& absDeterminantThreshold)
const {
348 computeInverseAndDetWithCheck(
inverse,
determinant, invertible, absDeterminantThreshold);
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Definition: Macros.h:922
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:79
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:69
std::conditional_t< internal::is_same< typename internal::traits< Derived >::XprKind, MatrixXpr >::value, PlainMatrix, PlainArray > PlainObject
The plain matrix or array type corresponding to this expression.
Definition: DenseBase.h:204
internal::traits< Homogeneous< MatrixType, Direction_ > >::Scalar Scalar
Definition: DenseBase.h:62
Expression of the inverse of another expression.
Definition: Inverse.h:43
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Inverse.h:55
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Inverse.h:54
EIGEN_DEVICE_FUNC const XprTypeNestedCleaned & nestedExpression() const
Definition: Inverse.h:57
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
void computeInverseWithCheck(ResultType &inverse, bool &invertible, const RealScalar &absDeterminantThreshold=NumTraits< Scalar >::dummy_precision()) const
Definition: InverseImpl.h:343
void computeInverseAndDetWithCheck(ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible, const RealScalar &absDeterminantThreshold=NumTraits< Scalar >::dummy_precision()) const
Definition: InverseImpl.h:307
EIGEN_DEVICE_FUNC const Inverse< Derived > inverse() const
Definition: InverseImpl.h:279
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:217
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
void determinant(const MatrixType &m)
Definition: determinant.cpp:15
void inverse(const MatrixType &m)
Definition: inverse.cpp:64
int * m
Definition: level2_cplx_impl.h:294
constexpr int plain_enum_min(A a, B b)
Definition: Meta.h:649
EIGEN_DEVICE_FUNC void compute_inverse_size2_helper(const MatrixType &matrix, const typename ResultType::Scalar &invdet, ResultType &result)
Definition: InverseImpl.h:67
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)
Definition: InverseImpl.h:168
EIGEN_DEVICE_FUNC MatrixType::Scalar cofactor_4x4(const MatrixType &matrix)
Definition: InverseImpl.h:175
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
EIGEN_DEVICE_FUNC MatrixType::Scalar cofactor_3x3(const MatrixType &m)
Definition: InverseImpl.h:107
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)
Definition: InverseImpl.h:113
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T::Scalar * extract_data(const T &m)
Definition: BlasUtil.h:581
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
Definition: MathFunctions.h:1355
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: Eigen_Colamd.h:49
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
Inverse< XprType > SrcXprType
Definition: InverseImpl.h:238
static EIGEN_DEVICE_FUNC void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename XprType::Scalar > &)
Definition: InverseImpl.h:239
Definition: AssignEvaluator.h:773
Definition: AssignEvaluator.h:756
Template functor for scalar/packet assignment.
Definition: AssignmentFunctors.h:25
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
Definition: InverseImpl.h:42
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
Definition: InverseImpl.h:79
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
Definition: InverseImpl.h:132
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &result, typename ResultType::Scalar &determinant, bool &invertible)
Definition: InverseImpl.h:51
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible)
Definition: InverseImpl.h:88
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible)
Definition: InverseImpl.h:146
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, const typename MatrixType::RealScalar &absDeterminantThreshold, ResultType &inverse, typename ResultType::Scalar &determinant, bool &invertible)
Definition: InverseImpl.h:210
Definition: InverseImpl.h:33
Definition: InverseImpl.h:182
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
Definition: InverseImpl.h:183
Definition: InverseImpl.h:26
static EIGEN_DEVICE_FUNC void run(const MatrixType &matrix, ResultType &result)
Definition: InverseImpl.h:27
std::conditional_t< Evaluate, PlainObject, typename ref_selector< T >::type > type
Definition: XprHelper.h:549
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
void run(const string &dir_name, LinearSolver *linear_solver_pt, const unsigned nel_1d, bool mess_up_order)
Definition: two_d_poisson_compare_solvers.cc:317