| 94 | |
| 95 | template< int Deg, typename POLYNOMIAL, typename ROOTS, typename REAL_ROOTS > |
| 96 | void evalSolverSugarFunction( const POLYNOMIAL& pols, const ROOTS& roots, const REAL_ROOTS& real_roots ) |
| 97 | { |
| 98 | using std::sqrt; |
| 99 | typedef typename POLYNOMIAL::Scalar Scalar; |
| 100 | |
| 101 | typedef PolynomialSolver<Scalar, Deg > PolynomialSolverType; |
| 102 | |
| 103 | PolynomialSolverType psolve; |
| 104 | if( aux_evalSolver<Deg, POLYNOMIAL, PolynomialSolverType>( pols, psolve ) ) |
| 105 | { |
| 106 | //It is supposed that |
| 107 | // 1) the roots found are correct |
| 108 | // 2) the roots have distinct moduli |
| 109 | |
| 110 | typedef typename POLYNOMIAL::Scalar Scalar; |
| 111 | typedef typename REAL_ROOTS::Scalar Real; |
| 112 | |
| 113 | //Test realRoots |
| 114 | std::vector< Real > calc_realRoots; |
| 115 | psolve.realRoots( calc_realRoots ); |
| 116 | VERIFY( calc_realRoots.size() == (size_t)real_roots.size() ); |
| 117 | |
| 118 | const Scalar psPrec = sqrt( test_precision<Scalar>() ); |
| 119 | |
| 120 | for( size_t i=0; i<calc_realRoots.size(); ++i ) |
| 121 | { |
| 122 | bool found = false; |
| 123 | for( size_t j=0; j<calc_realRoots.size()&& !found; ++j ) |
| 124 | { |
| 125 | if( internal::isApprox( calc_realRoots[i], real_roots[j], psPrec ) ){ |
| 126 | found = true; } |
| 127 | } |
| 128 | VERIFY( found ); |
| 129 | } |
| 130 | |
| 131 | //Test greatestRoot |
| 132 | VERIFY( internal::isApprox( roots.array().abs().maxCoeff(), |
| 133 | abs( psolve.greatestRoot() ), psPrec ) ); |
| 134 | |
| 135 | //Test smallestRoot |
| 136 | VERIFY( internal::isApprox( roots.array().abs().minCoeff(), |
| 137 | abs( psolve.smallestRoot() ), psPrec ) ); |
| 138 | |
| 139 | bool hasRealRoot; |
| 140 | //Test absGreatestRealRoot |
| 141 | Real r = psolve.absGreatestRealRoot( hasRealRoot ); |
| 142 | VERIFY( hasRealRoot == (real_roots.size() > 0 ) ); |
| 143 | if( hasRealRoot ){ |
| 144 | VERIFY( internal::isApprox( real_roots.array().abs().maxCoeff(), abs(r), psPrec ) ); } |
| 145 | |
| 146 | //Test absSmallestRealRoot |
| 147 | r = psolve.absSmallestRealRoot( hasRealRoot ); |
| 148 | VERIFY( hasRealRoot == (real_roots.size() > 0 ) ); |
| 149 | if( hasRealRoot ){ |
| 150 | VERIFY( internal::isApprox( real_roots.array().abs().minCoeff(), abs( r ), psPrec ) ); } |
| 151 | |
| 152 | //Test greatestRealRoot |
| 153 | r = psolve.greatestRealRoot( hasRealRoot ); |