mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Cleanup benchmark headers a tiny bit
This commit is contained in:
parent
bad8b7c866
commit
0c6fda6e7d
@ -21,6 +21,27 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using Catch::Benchmark::Detail::sample;
|
||||||
|
|
||||||
|
template <typename URng, typename Estimator>
|
||||||
|
sample resample(URng& rng, int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) {
|
||||||
|
auto n = last - first;
|
||||||
|
std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
|
||||||
|
|
||||||
|
sample out;
|
||||||
|
out.reserve(resamples);
|
||||||
|
std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
|
||||||
|
std::vector<double> resampled;
|
||||||
|
resampled.reserve(n);
|
||||||
|
std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; });
|
||||||
|
return estimator(resampled.begin(), resampled.end());
|
||||||
|
});
|
||||||
|
std::sort(out.begin(), out.end());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
double erf_inv(double x) {
|
double erf_inv(double x) {
|
||||||
// Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2
|
// Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2
|
||||||
double w, p;
|
double w, p;
|
||||||
|
@ -18,12 +18,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iterator>
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <random>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@ -63,23 +61,6 @@ namespace Catch {
|
|||||||
return sum / count;
|
return sum / count;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename URng, typename Iterator, typename Estimator>
|
|
||||||
sample resample(URng& rng, int resamples, Iterator first, Iterator last, Estimator& estimator) {
|
|
||||||
auto n = last - first;
|
|
||||||
std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
|
|
||||||
|
|
||||||
sample out;
|
|
||||||
out.reserve(resamples);
|
|
||||||
std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
|
|
||||||
std::vector<double> resampled;
|
|
||||||
resampled.reserve(n);
|
|
||||||
std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; });
|
|
||||||
return estimator(resampled.begin(), resampled.end());
|
|
||||||
});
|
|
||||||
std::sort(out.begin(), out.end());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Estimator, typename Iterator>
|
template <typename Estimator, typename Iterator>
|
||||||
sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
|
sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
|
||||||
auto n = last - first;
|
auto n = last - first;
|
||||||
|
Loading…
Reference in New Issue
Block a user