mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-08 17:59:00 +08:00
Compare summation results against forward error bound.
This commit is contained in:
parent
5c642950a5
commit
55e3ae02ac
@ -501,14 +501,16 @@ void test_sum_accuracy() {
|
|||||||
|
|
||||||
// Compute the reference value in double precsion.
|
// Compute the reference value in double precsion.
|
||||||
double expected_sum = 0.0;
|
double expected_sum = 0.0;
|
||||||
|
double abs_sum = 0.0;
|
||||||
for (int i = 0; i < num_elements; ++i) {
|
for (int i = 0; i < num_elements; ++i) {
|
||||||
expected_sum += static_cast<double>(tensor(i));
|
expected_sum += static_cast<double>(tensor(i));
|
||||||
|
abs_sum += static_cast<double>(numext::abs(tensor(i)));
|
||||||
}
|
}
|
||||||
// Scale tolerance to account for # elements. Otherwise, we periodically fail, since
|
// Test against probabilistic forward error bound. In reality, the error is much smaller
|
||||||
// E[sum] == prescribed_mean == 0 for the first iteration.
|
// when we use tree summation.
|
||||||
double err = Eigen::numext::abs(static_cast<double>(sum()) - expected_sum);
|
double err = Eigen::numext::abs(static_cast<double>(sum()) - expected_sum);
|
||||||
double tol = Eigen::numext::sqrt(num_elements) * static_cast<double>(test_precision<ScalarType>()) * numext::maxi(1.0, prescribed_mean);
|
double tol = numext::sqrt(num_elements) * NumTraits<ScalarType>::epsilon() * static_cast<ScalarType>(abs_sum);
|
||||||
VERIFY(err < tol);
|
VERIFY_LE(err, tol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user