Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026 #include <Eigen/LU>
00027 #include <algorithm>
00028
00029 template<typename T> std::string type_name() { return "other"; }
00030 template<> std::string type_name<float>() { return "float"; }
00031 template<> std::string type_name<double>() { return "double"; }
00032 template<> std::string type_name<int>() { return "int"; }
00033 template<> std::string type_name<std::complex<float> >() { return "complex<float>"; }
00034 template<> std::string type_name<std::complex<double> >() { return "complex<double>"; }
00035 template<> std::string type_name<std::complex<int> >() { return "complex<int>"; }
00036
00037 #define EIGEN_DEBUG_VAR(x) std::cerr << #x << " = " << x << std::endl;
00038
00039 template<typename T> inline typename NumTraits<T>::Real epsilon()
00040 {
00041 return std::numeric_limits<typename NumTraits<T>::Real>::epsilon();
00042 }
00043
00044 template<typename MatrixType> void inverse_permutation_4x4()
00045 {
00046 typedef typename MatrixType::Scalar Scalar;
00047 typedef typename MatrixType::RealScalar RealScalar;
00048 Vector4i indices(0,1,2,3);
00049 for(int i = 0; i < 24; ++i)
00050 {
00051 MatrixType m = MatrixType::Zero();
00052 m(indices(0),0) = 1;
00053 m(indices(1),1) = 1;
00054 m(indices(2),2) = 1;
00055 m(indices(3),3) = 1;
00056 MatrixType inv = m.inverse();
00057 double error = double( (m*inv-MatrixType::Identity()).norm() / epsilon<Scalar>() );
00058 VERIFY(error == 0.0);
00059 std::next_permutation(indices.data(),indices.data()+4);
00060 }
00061 }
00062
00063 template<typename MatrixType> void inverse_general_4x4(int repeat)
00064 {
00065 typedef typename MatrixType::Scalar Scalar;
00066 typedef typename MatrixType::RealScalar RealScalar;
00067 double error_sum = 0., error_max = 0.;
00068 for(int i = 0; i < repeat; ++i)
00069 {
00070 MatrixType m;
00071 RealScalar absdet;
00072 do {
00073 m = MatrixType::Random();
00074 absdet = ei_abs(m.determinant());
00075 } while(absdet < 10 * epsilon<Scalar>());
00076 MatrixType inv = m.inverse();
00077 double error = double( (m*inv-MatrixType::Identity()).norm() * absdet / epsilon<Scalar>() );
00078 error_sum += error;
00079 error_max = std::max(error_max, error);
00080 }
00081 std::cerr << "inverse_general_4x4, Scalar = " << type_name<Scalar>() << std::endl;
00082 double error_avg = error_sum / repeat;
00083 EIGEN_DEBUG_VAR(error_avg);
00084 EIGEN_DEBUG_VAR(error_max);
00085 VERIFY(error_avg < (NumTraits<Scalar>::IsComplex ? 8.0 : 1.25));
00086 VERIFY(error_max < (NumTraits<Scalar>::IsComplex ? 64.0 : 20.0));
00087 }
00088
00089 void test_eigen2_prec_inverse_4x4()
00090 {
00091 CALL_SUBTEST_1((inverse_permutation_4x4<Matrix4f>()));
00092 CALL_SUBTEST_1(( inverse_general_4x4<Matrix4f>(200000 * g_repeat) ));
00093
00094 CALL_SUBTEST_2((inverse_permutation_4x4<Matrix<double,4,4,RowMajor> >()));
00095 CALL_SUBTEST_2(( inverse_general_4x4<Matrix<double,4,4,RowMajor> >(200000 * g_repeat) ));
00096
00097 CALL_SUBTEST_3((inverse_permutation_4x4<Matrix4cf>()));
00098 CALL_SUBTEST_3((inverse_general_4x4<Matrix4cf>(50000 * g_repeat)));
00099 }