Cleanup types in resample

This commit is contained in:
Martin Hořeňovský 2024-01-14 20:59:05 +01:00
parent 863c662c0e
commit a0ef2115f8
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
1 changed files with 2 additions and 7 deletions

View File

@ -38,21 +38,16 @@ namespace Catch {
double const* last, double const* last,
Estimator& estimator ) { Estimator& estimator ) {
auto n = static_cast<size_t>( last - first ); auto n = static_cast<size_t>( last - first );
std::uniform_int_distribution<decltype( n )> dist( 0, std::uniform_int_distribution<size_t> dist( 0, n - 1 );
n - 1 );
sample out; sample out;
out.reserve( resamples ); out.reserve( resamples );
// We allocate the vector outside the loop to avoid realloc
// per resample
std::vector<double> resampled; std::vector<double> resampled;
resampled.reserve( n ); resampled.reserve( n );
for ( size_t i = 0; i < resamples; ++i ) { for ( size_t i = 0; i < resamples; ++i ) {
resampled.clear(); resampled.clear();
for ( size_t s = 0; s < n; ++s ) { for ( size_t s = 0; s < n; ++s ) {
resampled.push_back( resampled.push_back( first[dist( rng )] );
first[static_cast<std::ptrdiff_t>(
dist( rng ) )] );
} }
const auto estimate = const auto estimate =
estimator( resampled.data(), resampled.data() + resampled.size() ); estimator( resampled.data(), resampled.data() + resampled.size() );