2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00
Files
math/reporting/performance/bilinear_interpolation_performance.cpp
Nick 769f4f690d Interpolate a uniform grid with a bilinear function. (#643)
* Interpolate a uniform grid with a bilinear function.

* Typo removal.

* Invalid syntax in Jamfile.

* Do domain verification before computation.

* Fix OOB access on print.

* pimpl the class so it can be shared between threads.

* Add google/benchmark file to measure the performance of the bilinear interpolation.

* Fix up docs.

* Remove non-ASCII characters from print statements. Add a float128 test.

* Improve the documentation of the bilinear uniform class.

* Remove float128 as it doesn't support to_string.

* Don't use decltype(fieldData.size()) as the indexer; that makes MSVC 14.2 choke. Use RandomAccessContainer::size_type.

* Use ADL for to_string for compatibility with multiprecision.

* Improve error message which rows*cols != fieldData.size().
2021-06-22 10:38:00 -04:00

41 lines
1.3 KiB
C++

// (C) Copyright Nick Thompson 2020.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <random>
#include <benchmark/benchmark.h>
#include <boost/math/interpolators/bilinear_uniform.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
using boost::math::interpolators::bilinear_uniform;
template<class Real>
void Bilinear(benchmark::State& state)
{
std::random_device rd;
std::mt19937_64 mt(rd());
std::uniform_real_distribution<Real> unif(0, 10);
std::vector<double> v(state.range(0)*state.range(0), std::numeric_limits<Real>::quiet_NaN());
for (auto& x : v) {
x = unif(mt);
}
auto ub = bilinear_uniform<decltype(v)>(std::move(v), state.range(0), state.range(0));
Real x = static_cast<Real>(unif(mt));
Real y = static_cast<Real>(unif(mt));
for (auto _ : state)
{
benchmark::DoNotOptimize(ub(x, y));
x += std::numeric_limits<Real>::epsilon();
y += std::numeric_limits<Real>::epsilon();
}
state.SetComplexityN(state.range(0));
}
BENCHMARK_TEMPLATE(Bilinear, double)->RangeMultiplier(2)->Range(1 << 6, 1 << 20)->Complexity();
BENCHMARK_MAIN();