aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/LU/Inverse.h
diff options
context:
space:
mode:
Diffstat (limited to 'Eigen/src/LU/Inverse.h')
-rw-r--r--Eigen/src/LU/Inverse.h148
1 files changed, 76 insertions, 72 deletions
diff --git a/Eigen/src/LU/Inverse.h b/Eigen/src/LU/Inverse.h
index b587e3309..99286523a 100644
--- a/Eigen/src/LU/Inverse.h
+++ b/Eigen/src/LU/Inverse.h
@@ -25,12 +25,14 @@
#ifndef EIGEN_INVERSE_H
#define EIGEN_INVERSE_H
+namespace internal {
+
/**********************************
*** General case implementation ***
**********************************/
template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime>
-struct ei_compute_inverse
+struct compute_inverse
{
static inline void run(const MatrixType& matrix, ResultType& result)
{
@@ -39,14 +41,14 @@ struct ei_compute_inverse
};
template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime>
-struct ei_compute_inverse_and_det_with_check { /* nothing! general case not supported. */ };
+struct compute_inverse_and_det_with_check { /* nothing! general case not supported. */ };
/****************************
*** Size 1 implementation ***
****************************/
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse<MatrixType, ResultType, 1>
+struct compute_inverse<MatrixType, ResultType, 1>
{
static inline void run(const MatrixType& matrix, ResultType& result)
{
@@ -56,7 +58,7 @@ struct ei_compute_inverse<MatrixType, ResultType, 1>
};
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 1>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 1>
{
static inline void run(
const MatrixType& matrix,
@@ -67,7 +69,7 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 1>
)
{
determinant = matrix.coeff(0,0);
- invertible = ei_abs(determinant) > absDeterminantThreshold;
+ invertible = abs(determinant) > absDeterminantThreshold;
if(invertible) result.coeffRef(0,0) = typename ResultType::Scalar(1) / determinant;
}
};
@@ -77,7 +79,7 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 1>
****************************/
template<typename MatrixType, typename ResultType>
-inline void ei_compute_inverse_size2_helper(
+inline void compute_inverse_size2_helper(
const MatrixType& matrix, const typename ResultType::Scalar& invdet,
ResultType& result)
{
@@ -88,18 +90,18 @@ inline void ei_compute_inverse_size2_helper(
}
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse<MatrixType, ResultType, 2>
+struct compute_inverse<MatrixType, ResultType, 2>
{
static inline void run(const MatrixType& matrix, ResultType& result)
{
typedef typename ResultType::Scalar Scalar;
const Scalar invdet = typename MatrixType::Scalar(1) / matrix.determinant();
- ei_compute_inverse_size2_helper(matrix, invdet, result);
+ compute_inverse_size2_helper(matrix, invdet, result);
}
};
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 2>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 2>
{
static inline void run(
const MatrixType& matrix,
@@ -111,10 +113,10 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 2>
{
typedef typename ResultType::Scalar Scalar;
determinant = matrix.determinant();
- invertible = ei_abs(determinant) > absDeterminantThreshold;
+ invertible = abs(determinant) > absDeterminantThreshold;
if(!invertible) return;
const Scalar invdet = Scalar(1) / determinant;
- ei_compute_inverse_size2_helper(matrix, invdet, inverse);
+ compute_inverse_size2_helper(matrix, invdet, inverse);
}
};
@@ -123,7 +125,7 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 2>
****************************/
template<typename MatrixType, int i, int j>
-inline typename MatrixType::Scalar ei_3x3_cofactor(const MatrixType& m)
+inline typename MatrixType::Scalar cofactor_3x3(const MatrixType& m)
{
enum {
i1 = (i+1) % 3,
@@ -136,39 +138,39 @@ inline typename MatrixType::Scalar ei_3x3_cofactor(const MatrixType& m)
}
template<typename MatrixType, typename ResultType>
-inline void ei_compute_inverse_size3_helper(
+inline void compute_inverse_size3_helper(
const MatrixType& matrix,
const typename ResultType::Scalar& invdet,
const Matrix<typename ResultType::Scalar,3,1>& cofactors_col0,
ResultType& result)
{
result.row(0) = cofactors_col0 * invdet;
- result.coeffRef(1,0) = ei_3x3_cofactor<MatrixType,0,1>(matrix) * invdet;
- result.coeffRef(1,1) = ei_3x3_cofactor<MatrixType,1,1>(matrix) * invdet;
- result.coeffRef(1,2) = ei_3x3_cofactor<MatrixType,2,1>(matrix) * invdet;
- result.coeffRef(2,0) = ei_3x3_cofactor<MatrixType,0,2>(matrix) * invdet;
- result.coeffRef(2,1) = ei_3x3_cofactor<MatrixType,1,2>(matrix) * invdet;
- result.coeffRef(2,2) = ei_3x3_cofactor<MatrixType,2,2>(matrix) * invdet;
+ result.coeffRef(1,0) = cofactor_3x3<MatrixType,0,1>(matrix) * invdet;
+ result.coeffRef(1,1) = cofactor_3x3<MatrixType,1,1>(matrix) * invdet;
+ result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix) * invdet;
+ result.coeffRef(2,0) = cofactor_3x3<MatrixType,0,2>(matrix) * invdet;
+ result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix) * invdet;
+ result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix) * invdet;
}
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse<MatrixType, ResultType, 3>
+struct compute_inverse<MatrixType, ResultType, 3>
{
static inline void run(const MatrixType& matrix, ResultType& result)
{
typedef typename ResultType::Scalar Scalar;
Matrix<Scalar,3,1> cofactors_col0;
- cofactors_col0.coeffRef(0) = ei_3x3_cofactor<MatrixType,0,0>(matrix);
- cofactors_col0.coeffRef(1) = ei_3x3_cofactor<MatrixType,1,0>(matrix);
- cofactors_col0.coeffRef(2) = ei_3x3_cofactor<MatrixType,2,0>(matrix);
+ cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
+ cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
+ cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
const Scalar invdet = Scalar(1) / det;
- ei_compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result);
+ compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result);
}
};
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
{
static inline void run(
const MatrixType& matrix,
@@ -180,14 +182,14 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
{
typedef typename ResultType::Scalar Scalar;
Matrix<Scalar,3,1> cofactors_col0;
- cofactors_col0.coeffRef(0) = ei_3x3_cofactor<MatrixType,0,0>(matrix);
- cofactors_col0.coeffRef(1) = ei_3x3_cofactor<MatrixType,1,0>(matrix);
- cofactors_col0.coeffRef(2) = ei_3x3_cofactor<MatrixType,2,0>(matrix);
+ cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
+ cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
+ cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
- invertible = ei_abs(determinant) > absDeterminantThreshold;
+ invertible = abs(determinant) > absDeterminantThreshold;
if(!invertible) return;
const Scalar invdet = Scalar(1) / determinant;
- ei_compute_inverse_size3_helper(matrix, invdet, cofactors_col0, inverse);
+ compute_inverse_size3_helper(matrix, invdet, cofactors_col0, inverse);
}
};
@@ -196,7 +198,7 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
****************************/
template<typename Derived>
-inline const typename Derived::Scalar ei_general_det3_helper
+inline const typename Derived::Scalar general_det3_helper
(const MatrixBase<Derived>& matrix, int i1, int i2, int i3, int j1, int j2, int j3)
{
return matrix.coeff(i1,j1)
@@ -204,7 +206,7 @@ inline const typename Derived::Scalar ei_general_det3_helper
}
template<typename MatrixType, int i, int j>
-inline typename MatrixType::Scalar ei_4x4_cofactor(const MatrixType& matrix)
+inline typename MatrixType::Scalar cofactor_4x4(const MatrixType& matrix)
{
enum {
i1 = (i+1) % 4,
@@ -214,45 +216,45 @@ inline typename MatrixType::Scalar ei_4x4_cofactor(const MatrixType& matrix)
j2 = (j+2) % 4,
j3 = (j+3) % 4
};
- return ei_general_det3_helper(matrix, i1, i2, i3, j1, j2, j3)
- + ei_general_det3_helper(matrix, i2, i3, i1, j1, j2, j3)
- + ei_general_det3_helper(matrix, i3, i1, i2, j1, j2, j3);
+ return general_det3_helper(matrix, i1, i2, i3, j1, j2, j3)
+ + general_det3_helper(matrix, i2, i3, i1, j1, j2, j3)
+ + general_det3_helper(matrix, i3, i1, i2, j1, j2, j3);
}
template<int Arch, typename Scalar, typename MatrixType, typename ResultType>
-struct ei_compute_inverse_size4
+struct compute_inverse_size4
{
static void run(const MatrixType& matrix, ResultType& result)
{
- result.coeffRef(0,0) = ei_4x4_cofactor<MatrixType,0,0>(matrix);
- result.coeffRef(1,0) = -ei_4x4_cofactor<MatrixType,0,1>(matrix);
- result.coeffRef(2,0) = ei_4x4_cofactor<MatrixType,0,2>(matrix);
- result.coeffRef(3,0) = -ei_4x4_cofactor<MatrixType,0,3>(matrix);
- result.coeffRef(0,2) = ei_4x4_cofactor<MatrixType,2,0>(matrix);
- result.coeffRef(1,2) = -ei_4x4_cofactor<MatrixType,2,1>(matrix);
- result.coeffRef(2,2) = ei_4x4_cofactor<MatrixType,2,2>(matrix);
- result.coeffRef(3,2) = -ei_4x4_cofactor<MatrixType,2,3>(matrix);
- result.coeffRef(0,1) = -ei_4x4_cofactor<MatrixType,1,0>(matrix);
- result.coeffRef(1,1) = ei_4x4_cofactor<MatrixType,1,1>(matrix);
- result.coeffRef(2,1) = -ei_4x4_cofactor<MatrixType,1,2>(matrix);
- result.coeffRef(3,1) = ei_4x4_cofactor<MatrixType,1,3>(matrix);
- result.coeffRef(0,3) = -ei_4x4_cofactor<MatrixType,3,0>(matrix);
- result.coeffRef(1,3) = ei_4x4_cofactor<MatrixType,3,1>(matrix);
- result.coeffRef(2,3) = -ei_4x4_cofactor<MatrixType,3,2>(matrix);
- result.coeffRef(3,3) = ei_4x4_cofactor<MatrixType,3,3>(matrix);
+ result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(matrix);
+ result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(matrix);
+ result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(matrix);
+ result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(matrix);
+ result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(matrix);
+ result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(matrix);
+ result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(matrix);
+ result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(matrix);
+ result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(matrix);
+ result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(matrix);
+ result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(matrix);
+ result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(matrix);
+ result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(matrix);
+ result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(matrix);
+ result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(matrix);
+ result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(matrix);
result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
}
};
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse<MatrixType, ResultType, 4>
- : ei_compute_inverse_size4<Architecture::Target, typename MatrixType::Scalar,
+struct compute_inverse<MatrixType, ResultType, 4>
+ : compute_inverse_size4<Architecture::Target, typename MatrixType::Scalar,
MatrixType, ResultType>
{
};
template<typename MatrixType, typename ResultType>
-struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 4>
+struct compute_inverse_and_det_with_check<MatrixType, ResultType, 4>
{
static inline void run(
const MatrixType& matrix,
@@ -263,8 +265,8 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 4>
)
{
determinant = matrix.determinant();
- invertible = ei_abs(determinant) > absDeterminantThreshold;
- if(invertible) ei_compute_inverse<MatrixType, ResultType>::run(matrix, inverse);
+ invertible = abs(determinant) > absDeterminantThreshold;
+ if(invertible) compute_inverse<MatrixType, ResultType>::run(matrix, inverse);
}
};
@@ -273,20 +275,20 @@ struct ei_compute_inverse_and_det_with_check<MatrixType, ResultType, 4>
*************************/
template<typename MatrixType>
-struct ei_traits<ei_inverse_impl<MatrixType> >
+struct traits<inverse_impl<MatrixType> >
{
typedef typename MatrixType::PlainObject ReturnType;
};
template<typename MatrixType>
-struct ei_inverse_impl : public ReturnByValue<ei_inverse_impl<MatrixType> >
+struct inverse_impl : public ReturnByValue<inverse_impl<MatrixType> >
{
typedef typename MatrixType::Index Index;
- typedef typename ei_eval<MatrixType>::type MatrixTypeNested;
- typedef typename ei_cleantype<MatrixTypeNested>::type MatrixTypeNestedCleaned;
+ typedef typename eval<MatrixType>::type MatrixTypeNested;
+ typedef typename cleantype<MatrixTypeNested>::type MatrixTypeNestedCleaned;
const MatrixTypeNested m_matrix;
- ei_inverse_impl(const MatrixType& matrix)
+ inverse_impl(const MatrixType& matrix)
: m_matrix(matrix)
{}
@@ -297,13 +299,15 @@ struct ei_inverse_impl : public ReturnByValue<ei_inverse_impl<MatrixType> >
{
const int Size = EIGEN_PLAIN_ENUM_MIN(MatrixType::ColsAtCompileTime,Dest::ColsAtCompileTime);
EIGEN_ONLY_USED_FOR_DEBUG(Size);
- ei_assert(( (Size<=1) || (Size>4) || (ei_extract_data(m_matrix)!=ei_extract_data(dst)))
+ eigen_assert(( (Size<=1) || (Size>4) || (extract_data(m_matrix)!=extract_data(dst)))
&& "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
- ei_compute_inverse<MatrixTypeNestedCleaned, Dest>::run(m_matrix, dst);
+ compute_inverse<MatrixTypeNestedCleaned, Dest>::run(m_matrix, dst);
}
};
+} // end namespace internal
+
/** \lu_module
*
* \returns the matrix inverse of this matrix.
@@ -322,11 +326,11 @@ struct ei_inverse_impl : public ReturnByValue<ei_inverse_impl<MatrixType> >
* \sa computeInverseAndDetWithCheck()
*/
template<typename Derived>
-inline const ei_inverse_impl<Derived> MatrixBase<Derived>::inverse() const
+inline const internal::inverse_impl<Derived> MatrixBase<Derived>::inverse() const
{
EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsInteger,THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
- ei_assert(rows() == cols());
- return ei_inverse_impl<Derived>(derived());
+ eigen_assert(rows() == cols());
+ return internal::inverse_impl<Derived>(derived());
}
/** \lu_module
@@ -357,15 +361,15 @@ inline void MatrixBase<Derived>::computeInverseAndDetWithCheck(
) const
{
// i'd love to put some static assertions there, but SFINAE means that they have no effect...
- ei_assert(rows() == cols());
+ eigen_assert(rows() == cols());
// for 2x2, it's worth giving a chance to avoid evaluating.
// for larger sizes, evaluating has negligible cost and limits code size.
- typedef typename ei_meta_if<
+ typedef typename internal::meta_if<
RowsAtCompileTime == 2,
- typename ei_cleantype<typename ei_nested<Derived, 2>::type>::type,
+ typename internal::cleantype<typename internal::nested<Derived, 2>::type>::type,
PlainObject
>::ret MatrixType;
- ei_compute_inverse_and_det_with_check<MatrixType, ResultType>::run
+ internal::compute_inverse_and_det_with_check<MatrixType, ResultType>::run
(derived(), absDeterminantThreshold, inverse, determinant, invertible);
}
@@ -396,7 +400,7 @@ inline void MatrixBase<Derived>::computeInverseWithCheck(
{
RealScalar determinant;
// i'd love to put some static assertions there, but SFINAE means that they have no effect...
- ei_assert(rows() == cols());
+ eigen_assert(rows() == cols());
computeInverseAndDetWithCheck(inverse,determinant,invertible,absDeterminantThreshold);
}