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 <unsupported/Eigen/Polynomials>
00027 #include <iostream>
00028
00029 using namespace std;
00030
00031 namespace Eigen {
00032 namespace internal {
00033 template<int Size>
00034 struct increment_if_fixed_size
00035 {
00036 enum {
00037 ret = (Size == Dynamic) ? Dynamic : Size+1
00038 };
00039 };
00040 }
00041 }
00042
00043 template<typename _Scalar, int _Deg>
00044 void realRoots_to_monicPolynomial_test(int deg)
00045 {
00046 typedef internal::increment_if_fixed_size<_Deg> Dim;
00047 typedef Matrix<_Scalar,Dim::ret,1> PolynomialType;
00048 typedef Matrix<_Scalar,_Deg,1> EvalRootsType;
00049
00050 PolynomialType pols(deg+1);
00051 EvalRootsType roots = EvalRootsType::Random(deg);
00052 roots_to_monicPolynomial( roots, pols );
00053
00054 EvalRootsType evr( deg );
00055 for( int i=0; i<roots.size(); ++i ){
00056 evr[i] = std::abs( poly_eval( pols, roots[i] ) ); }
00057
00058 bool evalToZero = evr.isZero( test_precision<_Scalar>() );
00059 if( !evalToZero ){
00060 cerr << evr.transpose() << endl; }
00061 VERIFY( evalToZero );
00062 }
00063
00064 template<typename _Scalar> void realRoots_to_monicPolynomial_scalar()
00065 {
00066 CALL_SUBTEST_2( (realRoots_to_monicPolynomial_test<_Scalar,2>(2)) );
00067 CALL_SUBTEST_3( (realRoots_to_monicPolynomial_test<_Scalar,3>(3)) );
00068 CALL_SUBTEST_4( (realRoots_to_monicPolynomial_test<_Scalar,4>(4)) );
00069 CALL_SUBTEST_5( (realRoots_to_monicPolynomial_test<_Scalar,5>(5)) );
00070 CALL_SUBTEST_6( (realRoots_to_monicPolynomial_test<_Scalar,6>(6)) );
00071 CALL_SUBTEST_7( (realRoots_to_monicPolynomial_test<_Scalar,7>(7)) );
00072 CALL_SUBTEST_8( (realRoots_to_monicPolynomial_test<_Scalar,17>(17)) );
00073
00074 CALL_SUBTEST_9( (realRoots_to_monicPolynomial_test<_Scalar,Dynamic>(
00075 internal::random<int>(18,26) )) );
00076 }
00077
00078
00079
00080
00081 template<typename _Scalar, int _Deg>
00082 void CauchyBounds(int deg)
00083 {
00084 typedef internal::increment_if_fixed_size<_Deg> Dim;
00085 typedef Matrix<_Scalar,Dim::ret,1> PolynomialType;
00086 typedef Matrix<_Scalar,_Deg,1> EvalRootsType;
00087
00088 PolynomialType pols(deg+1);
00089 EvalRootsType roots = EvalRootsType::Random(deg);
00090 roots_to_monicPolynomial( roots, pols );
00091 _Scalar M = cauchy_max_bound( pols );
00092 _Scalar m = cauchy_min_bound( pols );
00093 _Scalar Max = roots.array().abs().maxCoeff();
00094 _Scalar min = roots.array().abs().minCoeff();
00095 bool eval = (M >= Max) && (m <= min);
00096 if( !eval )
00097 {
00098 cerr << "Roots: " << roots << endl;
00099 cerr << "Bounds: (" << m << ", " << M << ")" << endl;
00100 cerr << "Min,Max: (" << min << ", " << Max << ")" << endl;
00101 }
00102 VERIFY( eval );
00103 }
00104
00105 template<typename _Scalar> void CauchyBounds_scalar()
00106 {
00107 CALL_SUBTEST_2( (CauchyBounds<_Scalar,2>(2)) );
00108 CALL_SUBTEST_3( (CauchyBounds<_Scalar,3>(3)) );
00109 CALL_SUBTEST_4( (CauchyBounds<_Scalar,4>(4)) );
00110 CALL_SUBTEST_5( (CauchyBounds<_Scalar,5>(5)) );
00111 CALL_SUBTEST_6( (CauchyBounds<_Scalar,6>(6)) );
00112 CALL_SUBTEST_7( (CauchyBounds<_Scalar,7>(7)) );
00113 CALL_SUBTEST_8( (CauchyBounds<_Scalar,17>(17)) );
00114
00115 CALL_SUBTEST_9( (CauchyBounds<_Scalar,Dynamic>(
00116 internal::random<int>(18,26) )) );
00117 }
00118
00119 void test_polynomialutils()
00120 {
00121 for(int i = 0; i < g_repeat; i++)
00122 {
00123 realRoots_to_monicPolynomial_scalar<double>();
00124 realRoots_to_monicPolynomial_scalar<float>();
00125 CauchyBounds_scalar<double>();
00126 CauchyBounds_scalar<float>();
00127 }
00128 }