11 #include <unsupported/Eigen/Polynomials> 30 template<
int Deg,
typename POLYNOMIAL,
typename SOLVER>
35 typedef typename SOLVER::RootsType RootsType;
38 const Index deg = pols.size()-1;
41 SOLVER solve_constr (pols);
43 psolve.compute( pols );
44 const RootsType& roots( psolve.roots() );
45 EvalRootsType evr( deg );
46 for(
int i=0;
i<roots.size(); ++
i ){
49 bool evalToZero = evr.isZero( test_precision<Scalar>() );
52 cerr <<
"WRONG root: " << endl;
53 cerr <<
"Polynomial: " << pols.transpose() << endl;
54 cerr <<
"Roots found: " << roots.transpose() << endl;
55 cerr <<
"Abs value of the polynomial at the roots: " << evr.transpose() << endl;
59 std::vector<Scalar> rootModuli( roots.size() );
61 aux = roots.array().abs();
62 std::sort( rootModuli.begin(), rootModuli.end() );
63 bool distinctModuli=
true;
64 for(
size_t i=1;
i<rootModuli.size() && distinctModuli; ++
i )
67 distinctModuli =
false; }
69 VERIFY( evalToZero || !distinctModuli );
71 return distinctModuli;
80 template<
int Deg,
typename POLYNOMIAL>
87 PolynomialSolverType psolve;
88 aux_evalSolver<Deg, POLYNOMIAL, PolynomialSolverType>( pols, psolve );
94 template<
int Deg,
typename POLYNOMIAL,
typename ROOTS,
typename REAL_ROOTS >
102 PolynomialSolverType psolve;
103 if( aux_evalSolver<Deg, POLYNOMIAL, PolynomialSolverType>( pols, psolve ) )
112 std::vector< Real > calc_realRoots;
113 psolve.realRoots( calc_realRoots );
114 VERIFY( calc_realRoots.size() == (
size_t)real_roots.size() );
116 const Scalar psPrec =
sqrt( test_precision<Scalar>() );
118 for(
size_t i=0;
i<calc_realRoots.size(); ++
i )
121 for(
size_t j=0;
j<calc_realRoots.size()&& !found; ++
j )
131 abs( psolve.greatestRoot() ), psPrec ) );
135 abs( psolve.smallestRoot() ), psPrec ) );
139 Real r = psolve.absGreatestRealRoot( hasRealRoot );
140 VERIFY( hasRealRoot == (real_roots.size() > 0 ) );
145 r = psolve.absSmallestRealRoot( hasRealRoot );
146 VERIFY( hasRealRoot == (real_roots.size() > 0 ) );
151 r = psolve.greatestRealRoot( hasRealRoot );
152 VERIFY( hasRealRoot == (real_roots.size() > 0 ) );
157 r = psolve.smallestRealRoot( hasRealRoot );
158 VERIFY( hasRealRoot == (real_roots.size() > 0 ) );
165 template<
typename _Scalar,
int _Deg>
168 typedef internal::increment_if_fixed_size<_Deg> Dim;
172 cout <<
"Standard cases" << endl;
173 PolynomialType pols = PolynomialType::Random(deg+1);
174 evalSolver<_Deg,PolynomialType>( pols );
176 cout <<
"Hard cases" << endl;
177 _Scalar multipleRoot = internal::random<_Scalar>();
178 EvalRootsType allRoots = EvalRootsType::Constant(deg,multipleRoot);
180 evalSolver<_Deg,PolynomialType>( pols );
182 cout <<
"Test sugar" << endl;
183 EvalRootsType realRoots = EvalRootsType::Random(deg);
185 evalSolverSugarFunction<_Deg>(
187 realRoots.template
cast <
199 CALL_SUBTEST_1( (polynomialsolver<float,1>(1)) );
200 CALL_SUBTEST_2( (polynomialsolver<double,2>(2)) );
201 CALL_SUBTEST_3( (polynomialsolver<double,3>(3)) );
202 CALL_SUBTEST_4( (polynomialsolver<float,4>(4)) );
203 CALL_SUBTEST_5( (polynomialsolver<double,5>(5)) );
204 CALL_SUBTEST_6( (polynomialsolver<float,6>(6)) );
205 CALL_SUBTEST_7( (polynomialsolver<float,7>(7)) );
206 CALL_SUBTEST_8( (polynomialsolver<double,8>(8)) );
208 CALL_SUBTEST_9( (polynomialsolver<float,Dynamic>(
209 internal::random<int>(9,13)
211 CALL_SUBTEST_10((polynomialsolver<double,Dynamic>(
212 internal::random<int>(9,13)
214 CALL_SUBTEST_11((polynomialsolver<float,Dynamic>(1)) );
void evalSolver(const POLYNOMIAL &pols)
void test_polynomialsolver()
T poly_eval(const Polynomials &poly, const T &x)
A matrix or vector expression mapping an existing array of data.
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Namespace containing all symbols from the Eigen library.
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
void roots_to_monicPolynomial(const RootVector &rv, Polynomial &poly)
void evalSolverSugarFunction(const POLYNOMIAL &pols, const ROOTS &roots, const REAL_ROOTS &real_roots)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC NewType cast(const OldType &x)
bool aux_evalSolver(const POLYNOMIAL &pols, SOLVER &psolve)
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
void polynomialsolver(int deg)
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())