10 #ifndef EIGEN_DETERMINANT_H
11 #define EIGEN_DETERMINANT_H
19 template<
typename Derived>
28 template<
typename Derived,
29 int DeterminantType = Derived::RowsAtCompileTime
30 >
struct determinant_impl
32 static inline typename traits<Derived>::Scalar run(
const Derived&
m)
34 if(Derived::ColsAtCompileTime==
Dynamic &&
m.rows()==0)
35 return typename traits<Derived>::Scalar(1);
36 return m.partialPivLu().determinant();
40 template<
typename Derived>
struct determinant_impl<Derived, 1>
43 typename traits<Derived>::Scalar run(
const Derived&
m)
49 template<
typename Derived>
struct determinant_impl<Derived, 2>
52 typename traits<Derived>::Scalar run(
const Derived&
m)
54 return m.coeff(0,0) *
m.coeff(1,1) -
m.coeff(1,0) *
m.coeff(0,1);
58 template<
typename Derived>
struct determinant_impl<Derived, 3>
61 typename traits<Derived>::Scalar run(
const Derived&
m)
69 template<
typename Derived>
struct determinant_impl<Derived, 4>
71 typedef typename traits<Derived>::Scalar Scalar;
73 Scalar run(
const Derived&
m)
75 Scalar d2_01 = det2(
m, 0, 1);
76 Scalar d2_02 = det2(
m, 0, 2);
77 Scalar d2_03 = det2(
m, 0, 3);
78 Scalar d2_12 = det2(
m, 1, 2);
79 Scalar d2_13 = det2(
m, 1, 3);
80 Scalar d2_23 = det2(
m, 2, 3);
81 Scalar d3_0 = det3(
m, 1,d2_23, 2,d2_13, 3,d2_12);
82 Scalar d3_1 = det3(
m, 0,d2_23, 2,d2_03, 3,d2_02);
83 Scalar d3_2 = det3(
m, 0,d2_13, 1,d2_03, 3,d2_01);
84 Scalar d3_3 = det3(
m, 0,d2_12, 1,d2_02, 2,d2_01);
85 return internal::pmadd(
static_cast<Scalar
>(-
m(0,3)),d3_0,
static_cast<Scalar
>(
m(1,3)*d3_1)) +
86 internal::pmadd(
static_cast<Scalar
>(-
m(2,3)),d3_2,
static_cast<Scalar
>(
m(3,3)*d3_3));
92 return m(i0,0) *
m(i1,1) -
m(i1,0) *
m(i0,1);
96 Scalar det3(
const Derived&
m,
Index i0,
const Scalar& d0,
Index i1,
const Scalar& d1,
Index i2,
const Scalar& d2)
108 template<
typename Derived>
113 typedef typename internal::nested_eval<Derived,Base::RowsAtCompileTime>::type Nested;
114 return internal::determinant_impl<internal::remove_all_t<Nested>>::run(derived());
#define EIGEN_DEVICE_FUNC
CoeffReturnType coeff(Index row, Index col) const
Base class for all dense matrices, vectors, and expressions.
Scalar determinant() const
const Derived::Scalar bruteforce_det3_helper(const MatrixBase< Derived > &matrix, int a, int b, int c)
Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.