Determinant.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_DETERMINANT_H
11 #define EIGEN_DETERMINANT_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 template<typename Derived>
19 inline const typename Derived::Scalar bruteforce_det3_helper
20 (const MatrixBase<Derived>& matrix, int a, int b, int c)
21 {
22  return matrix.coeff(0,a)
23  * (matrix.coeff(1,b) * matrix.coeff(2,c) - matrix.coeff(1,c) * matrix.coeff(2,b));
24 }
25 
26 template<typename Derived,
27  int DeterminantType = Derived::RowsAtCompileTime
29 {
30  static inline typename traits<Derived>::Scalar run(const Derived& m)
31  {
32  if(Derived::ColsAtCompileTime==Dynamic && m.rows()==0)
33  return typename traits<Derived>::Scalar(1);
34  return m.partialPivLu().determinant();
35  }
36 };
37 
38 template<typename Derived> struct determinant_impl<Derived, 1>
39 {
40  static inline EIGEN_DEVICE_FUNC
41  typename traits<Derived>::Scalar run(const Derived& m)
42  {
43  return m.coeff(0,0);
44  }
45 };
46 
47 template<typename Derived> struct determinant_impl<Derived, 2>
48 {
49  static inline EIGEN_DEVICE_FUNC
50  typename traits<Derived>::Scalar run(const Derived& m)
51  {
52  return m.coeff(0,0) * m.coeff(1,1) - m.coeff(1,0) * m.coeff(0,1);
53  }
54 };
55 
56 template<typename Derived> struct determinant_impl<Derived, 3>
57 {
58  static inline EIGEN_DEVICE_FUNC
59  typename traits<Derived>::Scalar run(const Derived& m)
60  {
61  return bruteforce_det3_helper(m,0,1,2)
62  - bruteforce_det3_helper(m,1,0,2)
63  + bruteforce_det3_helper(m,2,0,1);
64  }
65 };
66 
67 template<typename Derived> struct determinant_impl<Derived, 4>
68 {
69  typedef typename traits<Derived>::Scalar Scalar;
70  static EIGEN_DEVICE_FUNC
71  Scalar run(const Derived& m)
72  {
73  Scalar d2_01 = det2(m, 0, 1);
74  Scalar d2_02 = det2(m, 0, 2);
75  Scalar d2_03 = det2(m, 0, 3);
76  Scalar d2_12 = det2(m, 1, 2);
77  Scalar d2_13 = det2(m, 1, 3);
78  Scalar d2_23 = det2(m, 2, 3);
79  Scalar d3_0 = det3(m, 1,d2_23, 2,d2_13, 3,d2_12);
80  Scalar d3_1 = det3(m, 0,d2_23, 2,d2_03, 3,d2_02);
81  Scalar d3_2 = det3(m, 0,d2_13, 1,d2_03, 3,d2_01);
82  Scalar d3_3 = det3(m, 0,d2_12, 1,d2_02, 2,d2_01);
83  return internal::pmadd(-m(0,3),d3_0, m(1,3)*d3_1) +
84  internal::pmadd(-m(2,3),d3_2, m(3,3)*d3_3);
85  }
86 protected:
87  static EIGEN_DEVICE_FUNC
88  Scalar det2(const Derived& m, Index i0, Index i1)
89  {
90  return m(i0,0) * m(i1,1) - m(i1,0) * m(i0,1);
91  }
92 
93  static EIGEN_DEVICE_FUNC
94  Scalar det3(const Derived& m, Index i0, const Scalar& d0, Index i1, const Scalar& d1, Index i2, const Scalar& d2)
95  {
96  return internal::pmadd(m(i0,2), d0, internal::pmadd(-m(i1,2), d1, m(i2,2)*d2));
97  }
98 };
99 
100 } // end namespace internal
101 
106 template<typename Derived>
109 {
110  eigen_assert(rows() == cols());
113 }
114 
115 } // end namespace Eigen
116 
117 #endif // EIGEN_DETERMINANT_H
Eigen::internal::determinant_impl::run
static traits< Derived >::Scalar run(const Derived &m)
Definition: Determinant.h:30
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::bruteforce_det3_helper
const EIGEN_DEVICE_FUNC Derived::Scalar bruteforce_det3_helper(const MatrixBase< Derived > &matrix, int a, int b, int c)
Definition: Determinant.h:20
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::internal::determinant_impl< Derived, 4 >::det3
static EIGEN_DEVICE_FUNC Scalar det3(const Derived &m, Index i0, const Scalar &d0, Index i1, const Scalar &d1, Index i2, const Scalar &d2)
Definition: Determinant.h:94
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::internal::determinant_impl< Derived, 1 >::run
static EIGEN_DEVICE_FUNC traits< Derived >::Scalar run(const Derived &m)
Definition: Determinant.h:41
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::internal::determinant_impl< Derived, 4 >::Scalar
traits< Derived >::Scalar Scalar
Definition: Determinant.h:69
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::internal::determinant_impl< Derived, 3 >::run
static EIGEN_DEVICE_FUNC traits< Derived >::Scalar run(const Derived &m)
Definition: Determinant.h:59
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
Eigen::MatrixBase::determinant
EIGEN_DEVICE_FUNC Scalar determinant() const
Definition: Determinant.h:108
matrix
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: gtsam/3rdparty/Eigen/blas/common.h:110
test_docs.d2
d2
Definition: test_docs.py:29
i0
double i0(double x)
Definition: i0.c:149
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Eigen::internal::determinant_impl< Derived, 2 >::run
static EIGEN_DEVICE_FUNC traits< Derived >::Scalar run(const Derived &m)
Definition: Determinant.h:50
Eigen::internal::determinant_impl< Derived, 4 >::det2
static EIGEN_DEVICE_FUNC Scalar det2(const Derived &m, Index i0, Index i1)
Definition: Determinant.h:88
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
i1
double i1(double x)
Definition: i1.c:150
Eigen::internal::pmadd
EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Definition: AltiVec/PacketMath.h:827
Eigen::internal::determinant_impl
Definition: Determinant.h:28
Eigen::internal::determinant_impl< Derived, 4 >::run
static EIGEN_DEVICE_FUNC Scalar run(const Derived &m)
Definition: Determinant.h:71
internal
Definition: BandTriangularSolver.h:13
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:02