mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Fix TensorReduction warnings and error bound for sum accuracy test.
The sum accuracy test currently uses the default test precision for the given scalar type. However, scalars are generated via a normal distribution, and given a large enough count and strong enough random generator, the expected sum is zero. This causes the test to periodically fail. Here we estimate an upper-bound for the error as `sqrt(N) * prec` for summing N values, with each having an approximate epsilon of `prec`. Also fixed a few warnings generated by MSVC when compiling the reduction test.
This commit is contained in:
committed by
Antonio Sanchez
parent
b3bea43a2d
commit
f6c8cc0e99
@@ -504,7 +504,11 @@ void test_sum_accuracy() {
|
||||
for (int i = 0; i < num_elements; ++i) {
|
||||
expected_sum += static_cast<double>(tensor(i));
|
||||
}
|
||||
VERIFY_IS_APPROX(sum(), static_cast<ScalarType>(expected_sum));
|
||||
// Scale tolerance to account for # elements. Otherwise, we periodically fail, since
|
||||
// E[sum] == prescribed_mean == 0 for the first iteration.
|
||||
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);
|
||||
VERIFY(err < tol);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user