mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix three flaky tests: packetmath, array_cwise, polynomialsolver
libeigen/eigen!2267 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
@@ -115,7 +115,7 @@ void evalSolverSugarFunction(const POLYNOMIAL& pols, const ROOTS& roots, const R
|
||||
|
||||
for (size_t i = 0; i < calc_realRoots.size(); ++i) {
|
||||
bool found = false;
|
||||
for (size_t j = 0; j < calc_realRoots.size() && !found; ++j) {
|
||||
for (size_t j = 0; j < real_roots.size() && !found; ++j) {
|
||||
if (internal::isApprox(calc_realRoots[i], real_roots[j], psPrec)) {
|
||||
found = true;
|
||||
}
|
||||
@@ -178,13 +178,19 @@ void polynomialsolver(int deg) {
|
||||
roots_to_monicPolynomial(allRoots, pols);
|
||||
evalSolver<Deg_, PolynomialType>(pols);
|
||||
|
||||
cout << "Test sugar" << endl;
|
||||
RealRootsType realRoots = RealRootsType::Random(deg);
|
||||
// sort by ascending absolute value to mitigate precision lost during polynomial expansion
|
||||
std::sort(realRoots.begin(), realRoots.end(),
|
||||
[](RealScalar a, RealScalar b) { return numext::abs(a) < numext::abs(b); });
|
||||
roots_to_monicPolynomial(realRoots, pols);
|
||||
evalSolverSugarFunction<Deg_>(pols, realRoots.template cast<std::complex<RealScalar> >().eval(), realRoots);
|
||||
// The companion matrix eigenvalue approach has limited accuracy for float at
|
||||
// high degrees. The PolynomialSolver documentation itself warns: "With 32bit
|
||||
// (float) floating types this problem shows up frequently." Skip the sugar
|
||||
// function test (which requires exact root matching) for float beyond degree 8.
|
||||
if (deg <= 8 || sizeof(RealScalar) > sizeof(float)) {
|
||||
cout << "Test sugar" << endl;
|
||||
RealRootsType realRoots = RealRootsType::Random(deg);
|
||||
// sort by ascending absolute value to mitigate precision lost during polynomial expansion
|
||||
std::sort(realRoots.begin(), realRoots.end(),
|
||||
[](RealScalar a, RealScalar b) { return numext::abs(a) < numext::abs(b); });
|
||||
roots_to_monicPolynomial(realRoots, pols);
|
||||
evalSolverSugarFunction<Deg_>(pols, realRoots.template cast<std::complex<RealScalar> >().eval(), realRoots);
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(polynomialsolver) {
|
||||
|
||||
Reference in New Issue
Block a user