prec_inverse_4x4.cpp
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) 2009 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 #include "main.h"
11 #include <Eigen/LU>
12 #include <algorithm>
13 
14 template<typename MatrixType> void inverse_permutation_4x4()
15 {
16  typedef typename MatrixType::Scalar Scalar;
17  Vector4i indices(0,1,2,3);
18  for(int i = 0; i < 24; ++i)
19  {
21  MatrixType inv = m.inverse();
22  double error = double( (m*inv-MatrixType::Identity()).norm() / NumTraits<Scalar>::epsilon() );
24  VERIFY(error == 0.0);
25  std::next_permutation(indices.data(),indices.data()+4);
26  }
27 }
28 
29 template<typename MatrixType> void inverse_general_4x4(int repeat)
30 {
31  using std::abs;
32  typedef typename MatrixType::Scalar Scalar;
33  double error_sum = 0., error_max = 0.;
34  for(int i = 0; i < repeat; ++i)
35  {
36  MatrixType m;
37  bool is_invertible;
38  do {
39  m = MatrixType::Random();
40  is_invertible = Eigen::FullPivLU<MatrixType>(m).isInvertible();
41  } while(!is_invertible);
42  MatrixType inv = m.inverse();
43  double error = double( (m*inv-MatrixType::Identity()).norm());
44  error_sum += error;
45  error_max = (std::max)(error_max, error);
46  }
47  std::cerr << "inverse_general_4x4, Scalar = " << type_name<Scalar>() << std::endl;
48  double error_avg = error_sum / repeat;
49  EIGEN_DEBUG_VAR(error_avg);
50  EIGEN_DEBUG_VAR(error_max);
51  // FIXME that 1.25 used to be a 1.0 until the NumTraits changes on 28 April 2010, what's going wrong??
52  // FIXME that 1.25 used to be 1.2 until we tested gcc 4.1 on 30 June 2010 and got 1.21.
53  VERIFY(error_avg < (NumTraits<Scalar>::IsComplex ? 8.0 : 1.25));
54  VERIFY(error_max < (NumTraits<Scalar>::IsComplex ? 64.0 : 20.0));
55 
56  {
57  int s = 5;//internal::random<int>(4,10);
58  int i = 0;//internal::random<int>(0,s-4);
59  int j = 0;//internal::random<int>(0,s-4);
61  mat.setRandom();
62  MatrixType submat = mat.template block<4,4>(i,j);
63  MatrixType mat_inv = mat.template block<4,4>(i,j).inverse();
64  VERIFY_IS_APPROX(mat_inv, submat.inverse());
65  mat.template block<4,4>(i,j) = submat.inverse();
66  VERIFY_IS_APPROX(mat_inv, (mat.template block<4,4>(i,j)));
67  }
68 }
69 
70 EIGEN_DECLARE_TEST(prec_inverse_4x4)
71 {
72  CALL_SUBTEST_1((inverse_permutation_4x4<Matrix4f>()));
73  CALL_SUBTEST_1(( inverse_general_4x4<Matrix4f>(200000 * g_repeat) ));
75 
79 
80  CALL_SUBTEST_3((inverse_permutation_4x4<Matrix4cf>()));
81  CALL_SUBTEST_3((inverse_general_4x4<Matrix4cf>(50000 * g_repeat)));
82 }
s
RealScalar s
Definition: level1_cplx_impl.h:126
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Eigen::FullPivLU::isInvertible
bool isInvertible() const
Definition: FullPivLU.h:385
mat
MatrixXf mat
Definition: Tutorial_AdvancedInitialization_CommaTemporary.cpp:1
Eigen::FullPivLU
LU decomposition of a matrix with complete pivoting, and related features.
Definition: ForwardDeclarations.h:268
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(prec_inverse_4x4)
Definition: prec_inverse_4x4.cpp:70
test_eigen_tensor.indices
indices
Definition: test_eigen_tensor.py:33
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::internal::repeat
constexpr array< t, n > repeat(t v)
Definition: CXX11Meta.h:483
Eigen::g_repeat
static int g_repeat
Definition: main.h:169
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
EIGEN_DEBUG_VAR
#define EIGEN_DEBUG_VAR(x)
Definition: Macros.h:898
error
static double error
Definition: testRot3.cpp:37
main.h
Eigen::PermutationMatrix
Permutation matrix.
Definition: PermutationMatrix.h:297
inverse_general_4x4
void inverse_general_4x4(int repeat)
Definition: prec_inverse_4x4.cpp:29
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
abs
#define abs(x)
Definition: datatypes.h:17
max
#define max(a, b)
Definition: datatypes.h:20
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
inverse_permutation_4x4
void inverse_permutation_4x4()
Definition: prec_inverse_4x4.cpp:14
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
VERIFY
#define VERIFY(a)
Definition: main.h:380


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:46