From 44861dcbfeee041223c4aac1ee075e92fa4daa01 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Sep 2016 12:42:15 +0200 Subject: update --- eigen/test/eigen2/eigen2_prec_inverse_4x4.cpp | 84 +++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 eigen/test/eigen2/eigen2_prec_inverse_4x4.cpp (limited to 'eigen/test/eigen2/eigen2_prec_inverse_4x4.cpp') diff --git a/eigen/test/eigen2/eigen2_prec_inverse_4x4.cpp b/eigen/test/eigen2/eigen2_prec_inverse_4x4.cpp new file mode 100644 index 0000000..8bfa556 --- /dev/null +++ b/eigen/test/eigen2/eigen2_prec_inverse_4x4.cpp @@ -0,0 +1,84 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2009 Benoit Jacob +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "main.h" +#include +#include + +template std::string type_name() { return "other"; } +template<> std::string type_name() { return "float"; } +template<> std::string type_name() { return "double"; } +template<> std::string type_name() { return "int"; } +template<> std::string type_name >() { return "complex"; } +template<> std::string type_name >() { return "complex"; } +template<> std::string type_name >() { return "complex"; } + +#define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl; + +template inline typename NumTraits::Real epsilon() +{ + return std::numeric_limits::Real>::epsilon(); +} + +template void inverse_permutation_4x4() +{ + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + Vector4i indices(0,1,2,3); + for(int i = 0; i < 24; ++i) + { + MatrixType m = MatrixType::Zero(); + m(indices(0),0) = 1; + m(indices(1),1) = 1; + m(indices(2),2) = 1; + m(indices(3),3) = 1; + MatrixType inv = m.inverse(); + double error = double( (m*inv-MatrixType::Identity()).norm() / epsilon() ); + VERIFY(error == 0.0); + std::next_permutation(indices.data(),indices.data()+4); + } +} + +template void inverse_general_4x4(int repeat) +{ + typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; + double error_sum = 0., error_max = 0.; + for(int i = 0; i < repeat; ++i) + { + MatrixType m; + RealScalar absdet; + do { + m = MatrixType::Random(); + absdet = ei_abs(m.determinant()); + } while(absdet < 10 * epsilon()); + MatrixType inv = m.inverse(); + double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / epsilon() ); + error_sum += error; + error_max = std::max(error_max, error); + } + std::cerr << "inverse_general_4x4, Scalar = " << type_name() << std::endl; + double error_avg = error_sum / repeat; + EIGEN_DEBUG_VAR(error_avg); + EIGEN_DEBUG_VAR(error_max); + VERIFY(error_avg < (NumTraits::IsComplex ? 8.0 : 1.25)); + VERIFY(error_max < (NumTraits::IsComplex ? 64.0 : 20.0)); +} + +void test_eigen2_prec_inverse_4x4() +{ + CALL_SUBTEST_1((inverse_permutation_4x4())); + CALL_SUBTEST_1(( inverse_general_4x4(200000 * g_repeat) )); + + CALL_SUBTEST_2((inverse_permutation_4x4 >())); + CALL_SUBTEST_2(( inverse_general_4x4 >(200000 * g_repeat) )); + + CALL_SUBTEST_3((inverse_permutation_4x4())); + CALL_SUBTEST_3((inverse_general_4x4(50000 * g_repeat))); +} -- cgit v1.2.3