You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.5 KiB

  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. #include "main.h"
  10. #include <Eigen/LU>
  11. #include <algorithm>
  12. template<typename MatrixType> void inverse_permutation_4x4()
  13. {
  14. typedef typename MatrixType::Scalar Scalar;
  15. typedef typename MatrixType::RealScalar RealScalar;
  16. Vector4i indices(0,1,2,3);
  17. for(int i = 0; i < 24; ++i)
  18. {
  19. MatrixType m = PermutationMatrix<4>(indices);
  20. MatrixType inv = m.inverse();
  21. double error = double( (m*inv-MatrixType::Identity()).norm() / NumTraits<Scalar>::epsilon() );
  22. EIGEN_DEBUG_VAR(error)
  23. VERIFY(error == 0.0);
  24. std::next_permutation(indices.data(),indices.data()+4);
  25. }
  26. }
  27. template<typename MatrixType> void inverse_general_4x4(int repeat)
  28. {
  29. typedef typename MatrixType::Scalar Scalar;
  30. typedef typename MatrixType::RealScalar RealScalar;
  31. double error_sum = 0., error_max = 0.;
  32. for(int i = 0; i < repeat; ++i)
  33. {
  34. MatrixType m;
  35. RealScalar absdet;
  36. do {
  37. m = MatrixType::Random();
  38. absdet = internal::abs(m.determinant());
  39. } while(absdet < NumTraits<Scalar>::epsilon());
  40. MatrixType inv = m.inverse();
  41. double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / NumTraits<Scalar>::epsilon() );
  42. error_sum += error;
  43. error_max = (std::max)(error_max, error);
  44. }
  45. std::cerr << "inverse_general_4x4, Scalar = " << type_name<Scalar>() << std::endl;
  46. double error_avg = error_sum / repeat;
  47. EIGEN_DEBUG_VAR(error_avg);
  48. EIGEN_DEBUG_VAR(error_max);
  49. // FIXME that 1.25 used to be a 1.0 until the NumTraits changes on 28 April 2010, what's going wrong??
  50. // FIXME that 1.25 used to be 1.2 until we tested gcc 4.1 on 30 June 2010 and got 1.21.
  51. VERIFY(error_avg < (NumTraits<Scalar>::IsComplex ? 8.0 : 1.25));
  52. VERIFY(error_max < (NumTraits<Scalar>::IsComplex ? 64.0 : 20.0));
  53. }
  54. void test_prec_inverse_4x4()
  55. {
  56. CALL_SUBTEST_1((inverse_permutation_4x4<Matrix4f>()));
  57. CALL_SUBTEST_1(( inverse_general_4x4<Matrix4f>(200000 * g_repeat) ));
  58. CALL_SUBTEST_2((inverse_permutation_4x4<Matrix<double,4,4,RowMajor> >()));
  59. CALL_SUBTEST_2(( inverse_general_4x4<Matrix<double,4,4,RowMajor> >(200000 * g_repeat) ));
  60. CALL_SUBTEST_3((inverse_permutation_4x4<Matrix4cf>()));
  61. CALL_SUBTEST_3((inverse_general_4x4<Matrix4cf>(50000 * g_repeat)));
  62. }