@@ -32,9 +32,10 @@ bool aux_evalSolver( const POLYNOMIAL& pols, SOLVER& psolve )
3232{
3333 typedef typename POLYNOMIAL::Index Index;
3434 typedef typename POLYNOMIAL::Scalar Scalar;
35+ typedef typename POLYNOMIAL::RealScalar RealScalar;
3536
3637 typedef typename SOLVER::RootsType RootsType;
37- typedef Matrix<Scalar ,Deg,1 > EvalRootsType;
38+ typedef Matrix<RealScalar ,Deg,1 > EvalRootsType;
3839
3940 const Index deg = pols.size ()-1 ;
4041
@@ -57,7 +58,7 @@ bool aux_evalSolver( const POLYNOMIAL& pols, SOLVER& psolve )
5758 cerr << endl;
5859 }
5960
60- std::vector<Scalar > rootModuli ( roots.size () );
61+ std::vector<RealScalar > rootModuli ( roots.size () );
6162 Map< EvalRootsType > aux ( &rootModuli[0 ], roots.size () );
6263 aux = roots.array ().abs ();
6364 std::sort ( rootModuli.begin (), rootModuli.end () );
@@ -83,7 +84,7 @@ void evalSolver( const POLYNOMIAL& pols )
8384{
8485 typedef typename POLYNOMIAL::Scalar Scalar;
8586
86- typedef PolynomialSolver<Scalar, Deg > PolynomialSolverType;
87+ typedef PolynomialSolver<Scalar, Deg > PolynomialSolverType;
8788
8889 PolynomialSolverType psolve;
8990 aux_evalSolver<Deg, POLYNOMIAL, PolynomialSolverType>( pols, psolve );
@@ -97,6 +98,7 @@ void evalSolverSugarFunction( const POLYNOMIAL& pols, const ROOTS& roots, const
9798{
9899 using std::sqrt;
99100 typedef typename POLYNOMIAL::Scalar Scalar;
101+ typedef typename POLYNOMIAL::RealScalar RealScalar;
100102
101103 typedef PolynomialSolver<Scalar, Deg > PolynomialSolverType;
102104
@@ -107,15 +109,12 @@ void evalSolverSugarFunction( const POLYNOMIAL& pols, const ROOTS& roots, const
107109 // 1) the roots found are correct
108110 // 2) the roots have distinct moduli
109111
110- typedef typename POLYNOMIAL::Scalar Scalar;
111- typedef typename REAL_ROOTS::Scalar Real;
112-
113112 // Test realRoots
114- std::vector< Real > calc_realRoots;
115- psolve.realRoots ( calc_realRoots );
116- VERIFY ( calc_realRoots.size () == (size_t )real_roots.size () );
113+ std::vector< RealScalar > calc_realRoots;
114+ psolve.realRoots ( calc_realRoots, test_precision<RealScalar>() );
115+ VERIFY_IS_EQUAL ( calc_realRoots.size () , (size_t )real_roots.size () );
117116
118- const Scalar psPrec = sqrt ( test_precision<Scalar >() );
117+ const RealScalar psPrec = sqrt ( test_precision<RealScalar >() );
119118
120119 for ( size_t i=0 ; i<calc_realRoots.size (); ++i )
121120 {
@@ -138,7 +137,7 @@ void evalSolverSugarFunction( const POLYNOMIAL& pols, const ROOTS& roots, const
138137
139138 bool hasRealRoot;
140139 // Test absGreatestRealRoot
141- Real r = psolve.absGreatestRealRoot ( hasRealRoot );
140+ RealScalar r = psolve.absGreatestRealRoot ( hasRealRoot );
142141 VERIFY ( hasRealRoot == (real_roots.size () > 0 ) );
143142 if ( hasRealRoot ){
144143 VERIFY ( internal::isApprox ( real_roots.array ().abs ().maxCoeff (), abs (r), psPrec ) ); }
@@ -167,9 +166,11 @@ void evalSolverSugarFunction( const POLYNOMIAL& pols, const ROOTS& roots, const
167166template <typename _Scalar, int _Deg>
168167void polynomialsolver (int deg)
169168{
170- typedef internal::increment_if_fixed_size<_Deg> Dim;
169+ typedef typename NumTraits<_Scalar>::Real RealScalar;
170+ typedef internal::increment_if_fixed_size<_Deg> Dim;
171171 typedef Matrix<_Scalar,Dim::ret,1 > PolynomialType;
172172 typedef Matrix<_Scalar,_Deg,1 > EvalRootsType;
173+ typedef Matrix<RealScalar,_Deg,1 > RealRootsType;
173174
174175 cout << " Standard cases" << endl;
175176 PolynomialType pols = PolynomialType::Random (deg+1 );
@@ -182,15 +183,11 @@ void polynomialsolver(int deg)
182183 evalSolver<_Deg,PolynomialType>( pols );
183184
184185 cout << " Test sugar" << endl;
185- EvalRootsType realRoots = EvalRootsType ::Random (deg);
186+ RealRootsType realRoots = RealRootsType ::Random (deg);
186187 roots_to_monicPolynomial ( realRoots, pols );
187188 evalSolverSugarFunction<_Deg>(
188189 pols,
189- realRoots.template cast <
190- std::complex <
191- typename NumTraits<_Scalar>::Real
192- >
193- >(),
190+ realRoots.template cast <std::complex <RealScalar> >().eval (),
194191 realRoots );
195192}
196193
@@ -214,5 +211,6 @@ void test_polynomialsolver()
214211 internal::random<int >(9 ,13 )
215212 )) );
216213 CALL_SUBTEST_11 ((polynomialsolver<float ,Dynamic>(1 )) );
214+ CALL_SUBTEST_12 ((polynomialsolver<std::complex <double >,Dynamic>(internal::random<int >(2 ,13 ))) );
217215 }
218216}
0 commit comments