10 #ifndef EIGEN_DETERMINANT_H
11 #define EIGEN_DETERMINANT_H
17 template<
typename Derived>
18 inline const typename Derived::Scalar bruteforce_det3_helper
19 (
const MatrixBase<Derived>& matrix,
int a,
int b,
int c)
21 return matrix.coeff(0,a)
22 * (matrix.coeff(1,b) * matrix.coeff(2,c) - matrix.coeff(1,c) * matrix.coeff(2,b));
25 template<
typename Derived>
26 const typename Derived::Scalar bruteforce_det4_helper
27 (
const MatrixBase<Derived>& matrix,
int j,
int k,
int m,
int n)
29 return (matrix.coeff(j,0) * matrix.coeff(k,1) - matrix.coeff(k,0) * matrix.coeff(j,1))
30 * (matrix.coeff(m,2) * matrix.coeff(n,3) - matrix.coeff(n,2) * matrix.coeff(m,3));
33 template<
typename Derived,
34 int DeterminantType = Derived::RowsAtCompileTime
35 >
struct determinant_impl
37 static inline typename traits<Derived>::Scalar run(
const Derived& m)
39 if(Derived::ColsAtCompileTime==
Dynamic && m.rows()==0)
40 return typename traits<Derived>::Scalar(1);
41 return m.partialPivLu().determinant();
45 template<
typename Derived>
struct determinant_impl<Derived, 1>
47 static inline typename traits<Derived>::Scalar run(
const Derived& m)
53 template<
typename Derived>
struct determinant_impl<Derived, 2>
55 static inline typename traits<Derived>::Scalar run(
const Derived& m)
57 return m.coeff(0,0) * m.coeff(1,1) - m.coeff(1,0) * m.coeff(0,1);
61 template<
typename Derived>
struct determinant_impl<Derived, 3>
63 static inline typename traits<Derived>::Scalar run(
const Derived& m)
65 return bruteforce_det3_helper(m,0,1,2)
66 - bruteforce_det3_helper(m,1,0,2)
67 + bruteforce_det3_helper(m,2,0,1);
71 template<
typename Derived>
struct determinant_impl<Derived, 4>
73 static typename traits<Derived>::Scalar run(
const Derived& m)
76 return bruteforce_det4_helper(m,0,1,2,3)
77 - bruteforce_det4_helper(m,0,2,1,3)
78 + bruteforce_det4_helper(m,0,3,1,2)
79 + bruteforce_det4_helper(m,1,2,0,3)
80 - bruteforce_det4_helper(m,1,3,0,2)
81 + bruteforce_det4_helper(m,2,3,0,1);
91 template<
typename Derived>
94 eigen_assert(rows() == cols());
95 typedef typename internal::nested<Derived,Base::RowsAtCompileTime>::type Nested;
96 return internal::determinant_impl<typename internal::remove_all<Nested>::type>::run(derived());
101 #endif // EIGEN_DETERMINANT_H
const int Dynamic
Definition: Constants.h:21
Scalar determinant() const
Definition: Determinant.h:92