Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "main.h"
00011 #include <unsupported/Eigen/Polynomials>
00012 #include <iostream>
00013
00014 using namespace std;
00015
00016 namespace Eigen {
00017 namespace internal {
00018 template<int Size>
00019 struct increment_if_fixed_size
00020 {
00021 enum {
00022 ret = (Size == Dynamic) ? Dynamic : Size+1
00023 };
00024 };
00025 }
00026 }
00027
00028 template<typename _Scalar, int _Deg>
00029 void realRoots_to_monicPolynomial_test(int deg)
00030 {
00031 typedef internal::increment_if_fixed_size<_Deg> Dim;
00032 typedef Matrix<_Scalar,Dim::ret,1> PolynomialType;
00033 typedef Matrix<_Scalar,_Deg,1> EvalRootsType;
00034
00035 PolynomialType pols(deg+1);
00036 EvalRootsType roots = EvalRootsType::Random(deg);
00037 roots_to_monicPolynomial( roots, pols );
00038
00039 EvalRootsType evr( deg );
00040 for( int i=0; i<roots.size(); ++i ){
00041 evr[i] = std::abs( poly_eval( pols, roots[i] ) ); }
00042
00043 bool evalToZero = evr.isZero( test_precision<_Scalar>() );
00044 if( !evalToZero ){
00045 cerr << evr.transpose() << endl; }
00046 VERIFY( evalToZero );
00047 }
00048
00049 template<typename _Scalar> void realRoots_to_monicPolynomial_scalar()
00050 {
00051 CALL_SUBTEST_2( (realRoots_to_monicPolynomial_test<_Scalar,2>(2)) );
00052 CALL_SUBTEST_3( (realRoots_to_monicPolynomial_test<_Scalar,3>(3)) );
00053 CALL_SUBTEST_4( (realRoots_to_monicPolynomial_test<_Scalar,4>(4)) );
00054 CALL_SUBTEST_5( (realRoots_to_monicPolynomial_test<_Scalar,5>(5)) );
00055 CALL_SUBTEST_6( (realRoots_to_monicPolynomial_test<_Scalar,6>(6)) );
00056 CALL_SUBTEST_7( (realRoots_to_monicPolynomial_test<_Scalar,7>(7)) );
00057 CALL_SUBTEST_8( (realRoots_to_monicPolynomial_test<_Scalar,17>(17)) );
00058
00059 CALL_SUBTEST_9( (realRoots_to_monicPolynomial_test<_Scalar,Dynamic>(
00060 internal::random<int>(18,26) )) );
00061 }
00062
00063
00064
00065
00066 template<typename _Scalar, int _Deg>
00067 void CauchyBounds(int deg)
00068 {
00069 typedef internal::increment_if_fixed_size<_Deg> Dim;
00070 typedef Matrix<_Scalar,Dim::ret,1> PolynomialType;
00071 typedef Matrix<_Scalar,_Deg,1> EvalRootsType;
00072
00073 PolynomialType pols(deg+1);
00074 EvalRootsType roots = EvalRootsType::Random(deg);
00075 roots_to_monicPolynomial( roots, pols );
00076 _Scalar M = cauchy_max_bound( pols );
00077 _Scalar m = cauchy_min_bound( pols );
00078 _Scalar Max = roots.array().abs().maxCoeff();
00079 _Scalar min = roots.array().abs().minCoeff();
00080 bool eval = (M >= Max) && (m <= min);
00081 if( !eval )
00082 {
00083 cerr << "Roots: " << roots << endl;
00084 cerr << "Bounds: (" << m << ", " << M << ")" << endl;
00085 cerr << "Min,Max: (" << min << ", " << Max << ")" << endl;
00086 }
00087 VERIFY( eval );
00088 }
00089
00090 template<typename _Scalar> void CauchyBounds_scalar()
00091 {
00092 CALL_SUBTEST_2( (CauchyBounds<_Scalar,2>(2)) );
00093 CALL_SUBTEST_3( (CauchyBounds<_Scalar,3>(3)) );
00094 CALL_SUBTEST_4( (CauchyBounds<_Scalar,4>(4)) );
00095 CALL_SUBTEST_5( (CauchyBounds<_Scalar,5>(5)) );
00096 CALL_SUBTEST_6( (CauchyBounds<_Scalar,6>(6)) );
00097 CALL_SUBTEST_7( (CauchyBounds<_Scalar,7>(7)) );
00098 CALL_SUBTEST_8( (CauchyBounds<_Scalar,17>(17)) );
00099
00100 CALL_SUBTEST_9( (CauchyBounds<_Scalar,Dynamic>(
00101 internal::random<int>(18,26) )) );
00102 }
00103
00104 void test_polynomialutils()
00105 {
00106 for(int i = 0; i < g_repeat; i++)
00107 {
00108 realRoots_to_monicPolynomial_scalar<double>();
00109 realRoots_to_monicPolynomial_scalar<float>();
00110 CauchyBounds_scalar<double>();
00111 CauchyBounds_scalar<float>();
00112 }
00113 }