// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2010 Manuel Yguel // // 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 using namespace std; namespace Eigen { namespace internal { template struct increment_if_fixed_size { enum { ret = (Size == Dynamic) ? Dynamic : Size+1 }; }; } } template void realRoots_to_monicPolynomial_test(int deg) { typedef internal::increment_if_fixed_size<_Deg> Dim; typedef Matrix PolynomialType; typedef Matrix EvalRootsType; PolynomialType pols(deg+1); EvalRootsType roots = EvalRootsType::Random(deg); roots_to_monicPolynomial( roots, pols ); EvalRootsType evr( deg ); for( int i=0; i() ); if( !evalToZero ){ cerr << evr.transpose() << endl; } VERIFY( evalToZero ); } template void realRoots_to_monicPolynomial_scalar() { CALL_SUBTEST_2( (realRoots_to_monicPolynomial_test(2)) ); CALL_SUBTEST_3( (realRoots_to_monicPolynomial_test(3)) ); CALL_SUBTEST_4( (realRoots_to_monicPolynomial_test(4)) ); CALL_SUBTEST_5( (realRoots_to_monicPolynomial_test(5)) ); CALL_SUBTEST_6( (realRoots_to_monicPolynomial_test(6)) ); CALL_SUBTEST_7( (realRoots_to_monicPolynomial_test(7)) ); CALL_SUBTEST_8( (realRoots_to_monicPolynomial_test(17)) ); CALL_SUBTEST_9( (realRoots_to_monicPolynomial_test( internal::random(18,26) )) ); } template void CauchyBounds(int deg) { typedef internal::increment_if_fixed_size<_Deg> Dim; typedef Matrix PolynomialType; typedef Matrix EvalRootsType; PolynomialType pols(deg+1); EvalRootsType roots = EvalRootsType::Random(deg); roots_to_monicPolynomial( roots, pols ); Scalar_ M = cauchy_max_bound( pols ); Scalar_ m = cauchy_min_bound( pols ); Scalar_ Max = roots.array().abs().maxCoeff(); Scalar_ min = roots.array().abs().minCoeff(); bool eval = (M >= Max) && (m <= min); if( !eval ) { cerr << "Roots: " << roots << endl; cerr << "Bounds: (" << m << ", " << M << ")" << endl; cerr << "Min,Max: (" << min << ", " << Max << ")" << endl; } VERIFY( eval ); } template void CauchyBounds_scalar() { CALL_SUBTEST_2( (CauchyBounds(2)) ); CALL_SUBTEST_3( (CauchyBounds(3)) ); CALL_SUBTEST_4( (CauchyBounds(4)) ); CALL_SUBTEST_5( (CauchyBounds(5)) ); CALL_SUBTEST_6( (CauchyBounds(6)) ); CALL_SUBTEST_7( (CauchyBounds(7)) ); CALL_SUBTEST_8( (CauchyBounds(17)) ); CALL_SUBTEST_9( (CauchyBounds( internal::random(18,26) )) ); } EIGEN_DECLARE_TEST(polynomialutils) { for(int i = 0; i < g_repeat; i++) { realRoots_to_monicPolynomial_scalar(); realRoots_to_monicPolynomial_scalar(); CauchyBounds_scalar(); CauchyBounds_scalar(); } }