prec_inverse_4x4.cpp File Reference
#include "main.h"
#include <Eigen/LU>
#include <algorithm>

Functions

template<typename MatrixType >
void inverse_permutation_4x4 ()
 
template<typename MatrixType >
void inverse_general_4x4 (int repeat)
 
 EIGEN_DECLARE_TEST (prec_inverse_4x4)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( prec_inverse_4x4  )
65  {
66  CALL_SUBTEST_1((inverse_permutation_4x4<Matrix4f>()));
67  CALL_SUBTEST_1((inverse_general_4x4<Matrix4f>(200000 * g_repeat)));
69 
73 
74  CALL_SUBTEST_3((inverse_permutation_4x4<Matrix4cf>()));
75  CALL_SUBTEST_3((inverse_general_4x4<Matrix4cf>(50000 * g_repeat)));
76 }
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
static int g_repeat
Definition: main.h:191
void inverse_general_4x4(int repeat)
Definition: prec_inverse_4x4.cpp:26
void inverse_permutation_4x4()
Definition: prec_inverse_4x4.cpp:15
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, Eigen::g_repeat, inverse_general_4x4(), and inverse_permutation_4x4().

◆ inverse_general_4x4()

template<typename MatrixType >
void inverse_general_4x4 ( int  repeat)
26  {
27  using std::abs;
28  typedef typename MatrixType::Scalar Scalar;
29  double error_sum = 0., error_max = 0.;
30  for (int i = 0; i < repeat; ++i) {
31  MatrixType m;
32  bool is_invertible;
33  do {
34  m = MatrixType::Random();
35  is_invertible = Eigen::FullPivLU<MatrixType>(m).isInvertible();
36  } while (!is_invertible);
37  MatrixType inv = m.inverse();
38  double error = double((m * inv - MatrixType::Identity()).norm());
39  error_sum += error;
40  error_max = (std::max)(error_max, error);
41  }
42  std::cerr << "inverse_general_4x4, Scalar = " << type_name<Scalar>() << std::endl;
43  double error_avg = error_sum / repeat;
44  EIGEN_DEBUG_VAR(error_avg);
45  EIGEN_DEBUG_VAR(error_max);
46  // FIXME that 1.25 used to be a 1.0 until the NumTraits changes on 28 April 2010, what's going wrong??
47  // FIXME that 1.25 used to be 1.2 until we tested gcc 4.1 on 30 June 2010 and got 1.21.
48  VERIFY(error_avg < (NumTraits<Scalar>::IsComplex ? 8.0 : 1.25));
49  VERIFY(error_max < (NumTraits<Scalar>::IsComplex ? 64.0 : 20.0));
50 
51  {
52  int s = 5; // internal::random<int>(4,10);
53  int i = 0; // internal::random<int>(0,s-4);
54  int j = 0; // internal::random<int>(0,s-4);
56  mat.setRandom();
57  MatrixType submat = mat.template block<4, 4>(i, j);
58  MatrixType mat_inv = mat.template block<4, 4>(i, j).inverse();
59  VERIFY_IS_APPROX(mat_inv, submat.inverse());
60  mat.template block<4, 4>(i, j) = submat.inverse();
61  VERIFY_IS_APPROX(mat_inv, (mat.template block<4, 4>(i, j)));
62  }
63 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
#define EIGEN_DEBUG_VAR(x)
Definition: Macros.h:815
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
LU decomposition of a matrix with complete pivoting, and related features.
Definition: FullPivLU.h:63
bool isInvertible() const
Definition: FullPivLU.h:371
#define max(a, b)
Definition: datatypes.h:23
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
RealScalar s
Definition: level1_cplx_impl.h:130
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY(a)
Definition: main.h:362
constexpr array< t, n > repeat(t v)
Definition: MoreMeta.h:583
int error
Definition: calibrate.py:297
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References abs(), EIGEN_DEBUG_VAR, calibrate::error, i, Eigen::FullPivLU< MatrixType_, PermutationIndex_ >::isInvertible(), j, m, max, Eigen::internal::repeat(), s, VERIFY, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ inverse_permutation_4x4()

template<typename MatrixType >
void inverse_permutation_4x4 ( )
15  {
16  Vector4i indices(0, 1, 2, 3);
17  for (int i = 0; i < 24; ++i) {
19  MatrixType inv = m.inverse();
20  VERIFY_IS_APPROX(m * inv, MatrixType::Identity());
21  std::next_permutation(indices.data(), indices.data() + 4);
22  }
23 }
Permutation matrix.
Definition: PermutationMatrix.h:280

References i, m, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().