From 1d7afe18f7707fa0a4a7c7b8bf7dab4cd748a488 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Thu, 23 Oct 2025 13:21:55 +0200 Subject: [PATCH 1/2] Fix undefined types with new GCC --- .../math/interpolators/cubic_hermite.hpp | 7 ++++--- .../detail/barycentric_rational_detail.hpp | 15 ++++++------- .../cardinal_quintic_b_spline_detail.hpp | 21 ++++++++++--------- .../detail/cubic_hermite_detail.hpp | 7 ++++--- .../detail/quintic_hermite_detail.hpp | 7 ++++--- .../detail/septic_hermite_detail.hpp | 7 ++++--- .../vector_barycentric_rational_detail.hpp | 15 ++++++------- .../math/interpolators/quintic_hermite.hpp | 7 ++++--- .../math/interpolators/septic_hermite.hpp | 7 ++++--- 9 files changed, 51 insertions(+), 42 deletions(-) diff --git a/include/boost/math/interpolators/cubic_hermite.hpp b/include/boost/math/interpolators/cubic_hermite.hpp index 48346ab1ec..04d1fa787f 100644 --- a/include/boost/math/interpolators/cubic_hermite.hpp +++ b/include/boost/math/interpolators/cubic_hermite.hpp @@ -8,6 +8,7 @@ #define BOOST_MATH_INTERPOLATORS_CUBIC_HERMITE_HPP #include #include +#include namespace boost { namespace math { @@ -41,7 +42,7 @@ class cubic_hermite { impl_->push_back(x, y, dydx); } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } @@ -80,7 +81,7 @@ class cardinal_cubic_hermite { return os; } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } @@ -121,7 +122,7 @@ class cardinal_cubic_hermite_aos { return os; } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } diff --git a/include/boost/math/interpolators/detail/barycentric_rational_detail.hpp b/include/boost/math/interpolators/detail/barycentric_rational_detail.hpp index a363e1861b..004bf3f9b5 100644 --- a/include/boost/math/interpolators/detail/barycentric_rational_detail.hpp +++ b/include/boost/math/interpolators/detail/barycentric_rational_detail.hpp @@ -12,6 +12,7 @@ #include // for std::move #include // for std::is_sorted #include +#include #include #include @@ -100,22 +101,22 @@ template void barycentric_rational_imp::calculate_weights(size_t approximation_order) { using std::abs; - int64_t n = m_x.size(); + std::int64_t n = m_x.size(); m_w.resize(n, 0); - for(int64_t k = 0; k < n; ++k) + for(std::int64_t k = 0; k < n; ++k) { - int64_t i_min = (std::max)(k - static_cast(approximation_order), static_cast(0)); - int64_t i_max = k; + std::int64_t i_min = (std::max)(k - static_cast(approximation_order), static_cast(0)); + std::int64_t i_max = k; if (k >= n - (std::ptrdiff_t)approximation_order) { i_max = n - approximation_order - 1; } - for(int64_t i = i_min; i <= i_max; ++i) + for(std::int64_t i = i_min; i <= i_max; ++i) { Real inv_product = 1; - int64_t j_max = (std::min)(static_cast(i + approximation_order), static_cast(n - 1)); - for(int64_t j = i; j <= j_max; ++j) + std::int64_t j_max = (std::min)(static_cast(i + approximation_order), static_cast(n - 1)); + for(std::int64_t j = i; j <= j_max; ++j) { if (j == k) { diff --git a/include/boost/math/interpolators/detail/cardinal_quintic_b_spline_detail.hpp b/include/boost/math/interpolators/detail/cardinal_quintic_b_spline_detail.hpp index f189e79dd8..fcaa33661e 100644 --- a/include/boost/math/interpolators/detail/cardinal_quintic_b_spline_detail.hpp +++ b/include/boost/math/interpolators/detail/cardinal_quintic_b_spline_detail.hpp @@ -7,6 +7,7 @@ #ifndef BOOST_MATH_INTERPOLATORS_CARDINAL_QUINTIC_B_SPLINE_DETAIL_HPP #define BOOST_MATH_INTERPOLATORS_CARDINAL_QUINTIC_B_SPLINE_DETAIL_HPP #include +#include #include #include #include @@ -157,7 +158,7 @@ class cardinal_quintic_b_spline_detail m_alpha[n+3] = rhs[n+3]/diagonal[n+3]; m_alpha[n+2] = rhs[n+2] - first_superdiagonal[n+2]*m_alpha[n+3]; - for (int64_t i = int64_t(n+1); i >= 0; --i) { + for (std::int64_t i = std::int64_t(n+1); i >= 0; --i) { m_alpha[i] = rhs[i] - first_superdiagonal[i]*m_alpha[i+1] - second_superdiagonal[i]*m_alpha[i+2]; } @@ -176,10 +177,10 @@ class cardinal_quintic_b_spline_detail Real x = (t-m_t0)*m_inv_h; // Support of B_5 is [-3, 3]. So -3 < x - j + 2 < 3, so x-1 < j < x+5. // TODO: Zero pad m_alpha so that only the domain check is necessary. - int64_t j_min = (std::max)(int64_t(0), int64_t(ceil(x-1))); - int64_t j_max = (std::min)(int64_t(m_alpha.size() - 1), int64_t(floor(x+5)) ); + std::int64_t j_min = (std::max)(std::int64_t(0), std::int64_t(ceil(x-1))); + std::int64_t j_max = (std::min)(std::int64_t(m_alpha.size() - 1), std::int64_t(floor(x+5)) ); Real s = 0; - for (int64_t j = j_min; j <= j_max; ++j) { + for (std::int64_t j = j_min; j <= j_max; ++j) { // TODO: Use Cox 1972 to generate all integer translates of B5 simultaneously. s += m_alpha[j]*cardinal_b_spline<5, Real>(x - j + 2); } @@ -196,10 +197,10 @@ class cardinal_quintic_b_spline_detail } Real x = (t-m_t0)*m_inv_h; // Support of B_5 is [-3, 3]. So -3 < x - j + 2 < 3, so x-1 < j < x+5 - int64_t j_min = (std::max)(int64_t(0), int64_t(ceil(x-1))); - int64_t j_max = (std::min)(int64_t(m_alpha.size() - 1), int64_t(floor(x+5)) ); + std::int64_t j_min = (std::max)(std::int64_t(0), std::int64_t(ceil(x-1))); + std::int64_t j_max = (std::min)(std::int64_t(m_alpha.size() - 1), std::int64_t(floor(x+5)) ); Real s = 0; - for (int64_t j = j_min; j <= j_max; ++j) { + for (std::int64_t j = j_min; j <= j_max; ++j) { s += m_alpha[j]*cardinal_b_spline_prime<5, Real>(x - j + 2); } return s*m_inv_h; @@ -216,10 +217,10 @@ class cardinal_quintic_b_spline_detail } Real x = (t-m_t0)*m_inv_h; // Support of B_5 is [-3, 3]. So -3 < x - j + 2 < 3, so x-1 < j < x+5 - int64_t j_min = (std::max)(int64_t(0), int64_t(ceil(x-1))); - int64_t j_max = (std::min)(int64_t(m_alpha.size() - 1), int64_t(floor(x+5)) ); + std::int64_t j_min = (std::max)(std::int64_t(0), std::int64_t(ceil(x-1))); + std::int64_t j_max = (std::min)(std::int64_t(m_alpha.size() - 1), std::int64_t(floor(x+5)) ); Real s = 0; - for (int64_t j = j_min; j <= j_max; ++j) { + for (std::int64_t j = j_min; j <= j_max; ++j) { s += m_alpha[j]*cardinal_b_spline_double_prime<5, Real>(x - j + 2); } return s*m_inv_h*m_inv_h; diff --git a/include/boost/math/interpolators/detail/cubic_hermite_detail.hpp b/include/boost/math/interpolators/detail/cubic_hermite_detail.hpp index 921902e1f2..0e04d37390 100644 --- a/include/boost/math/interpolators/detail/cubic_hermite_detail.hpp +++ b/include/boost/math/interpolators/detail/cubic_hermite_detail.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace boost { namespace math { @@ -154,7 +155,7 @@ class cubic_hermite_detail { return x_.size(); } - int64_t bytes() const + std::int64_t bytes() const { return 3*x_.size()*sizeof(Real) + 3*sizeof(x_); } @@ -278,7 +279,7 @@ class cardinal_cubic_hermite_detail { return y_.size(); } - int64_t bytes() const + std::int64_t bytes() const { return 2*y_.size()*sizeof(Real) + 2*sizeof(y_) + 2*sizeof(Real); } @@ -413,7 +414,7 @@ class cardinal_cubic_hermite_detail_aos { return dat_.size(); } - int64_t bytes() const + std::int64_t bytes() const { return dat_.size()*dat_[0].size()*sizeof(Real) + sizeof(dat_) + 2*sizeof(Real); } diff --git a/include/boost/math/interpolators/detail/quintic_hermite_detail.hpp b/include/boost/math/interpolators/detail/quintic_hermite_detail.hpp index 50c1b85ea7..ad7eee13a1 100644 --- a/include/boost/math/interpolators/detail/quintic_hermite_detail.hpp +++ b/include/boost/math/interpolators/detail/quintic_hermite_detail.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace boost { namespace math { @@ -193,7 +194,7 @@ class quintic_hermite_detail { return os; } - int64_t bytes() const + std::int64_t bytes() const { return 4*x_.size()*sizeof(x_); } @@ -380,7 +381,7 @@ class cardinal_quintic_hermite_detail { return d2ydx2; } - int64_t bytes() const + std::int64_t bytes() const { return 3*y_.size()*sizeof(Real) + 2*sizeof(Real); } @@ -561,7 +562,7 @@ class cardinal_quintic_hermite_detail_aos { return d2ydx2; } - int64_t bytes() const + std::int64_t bytes() const { return data_.size()*data_[0].size()*sizeof(Real) + 2*sizeof(Real); } diff --git a/include/boost/math/interpolators/detail/septic_hermite_detail.hpp b/include/boost/math/interpolators/detail/septic_hermite_detail.hpp index 47d155561b..f4677ce0b6 100644 --- a/include/boost/math/interpolators/detail/septic_hermite_detail.hpp +++ b/include/boost/math/interpolators/detail/septic_hermite_detail.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace boost { namespace math { @@ -189,7 +190,7 @@ class septic_hermite_detail { return os; } - int64_t bytes() + std::int64_t bytes() { return 5*x_.size()*sizeof(Real) + 5*sizeof(x_); } @@ -419,7 +420,7 @@ class cardinal_septic_hermite_detail { return d2ydx2; } - int64_t bytes() const + std::int64_t bytes() const { return 4*y_.size()*sizeof(Real) + 2*sizeof(Real) + 4*sizeof(y_); } @@ -629,7 +630,7 @@ class cardinal_septic_hermite_detail_aos { return d2ydx2; } - int64_t bytes() const + std::int64_t bytes() const { return data_.size()*data_[0].size()*sizeof(Real) + 2*sizeof(Real) + sizeof(data_); } diff --git a/include/boost/math/interpolators/detail/vector_barycentric_rational_detail.hpp b/include/boost/math/interpolators/detail/vector_barycentric_rational_detail.hpp index f4650784bf..fdece724c1 100644 --- a/include/boost/math/interpolators/detail/vector_barycentric_rational_detail.hpp +++ b/include/boost/math/interpolators/detail/vector_barycentric_rational_detail.hpp @@ -8,6 +8,7 @@ #ifndef BOOST_MATH_INTERPOLATORS_VECTOR_BARYCENTRIC_RATIONAL_DETAIL_HPP #define BOOST_MATH_INTERPOLATORS_VECTOR_BARYCENTRIC_RATIONAL_DETAIL_HPP +#include #include #include #include // for std::move @@ -64,22 +65,22 @@ void vector_barycentric_rational_imp::calculate_w { using Real = typename TimeContainer::value_type; using std::abs; - int64_t n = t_.size(); + std::int64_t n = t_.size(); w_.resize(n, Real(0)); - for(int64_t k = 0; k < n; ++k) + for(std::int64_t k = 0; k < n; ++k) { - int64_t i_min = (std::max)(k - static_cast(approximation_order), static_cast(0)); - int64_t i_max = k; + std::int64_t i_min = (std::max)(k - static_cast(approximation_order), static_cast(0)); + std::int64_t i_max = k; if (k >= n - (std::ptrdiff_t)approximation_order) { i_max = n - approximation_order - 1; } - for(int64_t i = i_min; i <= i_max; ++i) + for(std::int64_t i = i_min; i <= i_max; ++i) { Real inv_product = 1; - int64_t j_max = (std::min)(static_cast(i + approximation_order), static_cast(n - 1)); - for(int64_t j = i; j <= j_max; ++j) + std::int64_t j_max = (std::min)(static_cast(i + approximation_order), static_cast(n - 1)); + for(std::int64_t j = i; j <= j_max; ++j) { if (j == k) { diff --git a/include/boost/math/interpolators/quintic_hermite.hpp b/include/boost/math/interpolators/quintic_hermite.hpp index c0ba067de2..1c00b15469 100644 --- a/include/boost/math/interpolators/quintic_hermite.hpp +++ b/include/boost/math/interpolators/quintic_hermite.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace boost { @@ -50,7 +51,7 @@ class quintic_hermite { impl_->push_back(x, y, dydx, d2ydx2); } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } @@ -85,7 +86,7 @@ class cardinal_quintic_hermite { return impl_->double_prime(x); } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } @@ -123,7 +124,7 @@ class cardinal_quintic_hermite_aos { return impl_->double_prime(x); } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } diff --git a/include/boost/math/interpolators/septic_hermite.hpp b/include/boost/math/interpolators/septic_hermite.hpp index f428a7651a..e8cb8e5493 100644 --- a/include/boost/math/interpolators/septic_hermite.hpp +++ b/include/boost/math/interpolators/septic_hermite.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace boost { @@ -47,7 +48,7 @@ class septic_hermite return os; } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } @@ -87,7 +88,7 @@ class cardinal_septic_hermite return impl_->double_prime(x); } - int64_t bytes() const + std::int64_t bytes() const { return impl_->bytes() + sizeof(impl_); } @@ -126,7 +127,7 @@ class cardinal_septic_hermite_aos { return impl_->double_prime(x); } - int64_t bytes() const + std::int64_t bytes() const { return impl_.size() + sizeof(impl_); } From 863c7ebc4e78936b7a740897cb8cdf64c06ed556 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Thu, 23 Oct 2025 13:24:54 +0200 Subject: [PATCH 2/2] Add std namespace and header for cstdint types --- .../math/quadrature/naive_monte_carlo.hpp | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/include/boost/math/quadrature/naive_monte_carlo.hpp b/include/boost/math/quadrature/naive_monte_carlo.hpp index 4ad95ad832..954612c268 100644 --- a/include/boost/math/quadrature/naive_monte_carlo.hpp +++ b/include/boost/math/quadrature/naive_monte_carlo.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -45,20 +46,20 @@ class naive_monte_carlo std::vector> const & bounds, Real error_goal, bool singular = true, - uint64_t threads = std::thread::hardware_concurrency(), - uint64_t seed = 0) noexcept : m_num_threads{threads}, m_seed{seed}, m_volume(1) + std::uint64_t threads = std::thread::hardware_concurrency(), + std::uint64_t seed = 0) noexcept : m_num_threads{threads}, m_seed{seed}, m_volume(1) { using std::numeric_limits; using std::sqrt; using boost::math::isinf; - uint64_t n = bounds.size(); + std::uint64_t n = bounds.size(); m_lbs.resize(n); m_dxs.resize(n); m_limit_types.resize(n); static const char* function = "boost::math::quadrature::naive_monte_carlo<%1%>"; - for (uint64_t i = 0; i < n; ++i) + for (std::uint64_t i = 0; i < n; ++i) { if (bounds[i].second <= bounds[i].first) { @@ -122,7 +123,7 @@ class naive_monte_carlo m_integrand = [this, &integrand](std::vector & x)->Real { Real coeff = m_volume; - for (uint64_t i = 0; i < x.size(); ++i) + for (std::uint64_t i = 0; i < x.size(); ++i) { // Variable transformation are listed at: // https://en.wikipedia.org/wiki/Numerical_integration @@ -170,15 +171,15 @@ class naive_monte_carlo RandomNumberGenerator gen(seed); Real inv_denom = 1/static_cast(((gen.max)()-(gen.min)())); - m_num_threads = (std::max)(m_num_threads, static_cast(1)); - m_thread_calls.reset(new std::atomic[threads]); + m_num_threads = (std::max)(m_num_threads, static_cast(1)); + m_thread_calls.reset(new std::atomic[threads]); m_thread_Ss.reset(new std::atomic[threads]); m_thread_averages.reset(new std::atomic[threads]); Real avg = 0; - for (uint64_t i = 0; i < m_num_threads; ++i) + for (std::uint64_t i = 0; i < m_num_threads; ++i) { - for (uint64_t j = 0; j < m_lbs.size(); ++j) + for (std::uint64_t j = 0; j < m_lbs.size(); ++j) { x[j] = (gen()-(gen.min)())*inv_denom; } @@ -263,7 +264,7 @@ class naive_monte_carlo return m_avg.load(); } - uint64_t calls() const + std::uint64_t calls() const { return m_total_calls.load(); // relaxed load } @@ -272,7 +273,7 @@ class naive_monte_carlo Real m_integrate() { - uint64_t seed; + std::uint64_t seed; // If the user tells us to pick a seed, pick a seed: if (m_seed == 0) { @@ -307,23 +308,23 @@ class naive_monte_carlo } std::vector threads(m_num_threads); - for (uint64_t i = 0; i < threads.size(); ++i) + for (std::uint64_t i = 0; i < threads.size(); ++i) { threads[i] = std::thread(&naive_monte_carlo::m_thread_monte, this, i, gen()); } do { std::this_thread::sleep_for(std::chrono::milliseconds(100)); - uint64_t total_calls = 0; - for (uint64_t i = 0; i < m_num_threads; ++i) + std::uint64_t total_calls = 0; + for (std::uint64_t i = 0; i < m_num_threads; ++i) { - uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); + std::uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); total_calls += t_calls; } Real variance = 0; Real avg = 0; - for (uint64_t i = 0; i < m_num_threads; ++i) + for (std::uint64_t i = 0; i < m_num_threads; ++i) { - uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); + std::uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); // Will this overflow? Not hard to remove . . . avg += m_thread_averages[i].load(std::memory_order_relaxed)*(static_cast(t_calls) / static_cast(total_calls)); variance += m_thread_Ss[i].load(std::memory_order_relaxed); @@ -346,18 +347,18 @@ class naive_monte_carlo std::rethrow_exception(m_exception); } // Incorporate their work into the final estimate: - uint64_t total_calls = 0; - for (uint64_t i = 0; i < m_num_threads; ++i) + std::uint64_t total_calls = 0; + for (std::uint64_t i = 0; i < m_num_threads; ++i) { - uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); + std::uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); total_calls += t_calls; } Real variance = 0; Real avg = 0; - for (uint64_t i = 0; i < m_num_threads; ++i) + for (std::uint64_t i = 0; i < m_num_threads; ++i) { - uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); + std::uint64_t t_calls = m_thread_calls[i].load(std::memory_order_consume); // Averages weighted by the number of calls the thread made: avg += m_thread_averages[i].load(std::memory_order_relaxed)*(static_cast(t_calls) / static_cast(total_calls)); variance += m_thread_Ss[i].load(std::memory_order_relaxed); @@ -375,7 +376,7 @@ class naive_monte_carlo return m_avg.load(std::memory_order_consume); } - void m_thread_monte(uint64_t thread_index, uint64_t seed) + void m_thread_monte(std::uint64_t thread_index, std::uint64_t seed) { using std::numeric_limits; try @@ -390,7 +391,7 @@ class naive_monte_carlo // The idea is that the unstabilized additions have error sigma(f)/sqrt(N) + epsilon*N, which diverges faster than it converges! // Kahan summation turns this to sigma(f)/sqrt(N) + epsilon^2*N, and the random walk occurs on a timescale of 10^14 years (on current hardware) Real compensator = 0; - uint64_t k = m_thread_calls[thread_index].load(std::memory_order_consume); + std::uint64_t k = m_thread_calls[thread_index].load(std::memory_order_consume); while (!m_done) // relaxed load { int j = 0; @@ -401,7 +402,7 @@ class naive_monte_carlo int magic_calls_before_update = 2048; while (j++ < magic_calls_before_update) { - for (uint64_t i = 0; i < m_lbs.size(); ++i) + for (std::uint64_t i = 0; i < m_lbs.size(); ++i) { x[i] = (gen() - (gen.min)())*inv_denom; } @@ -412,7 +413,7 @@ class naive_monte_carlo // The call to m_integrand transform x, so this error message states the correct node. std::stringstream os; os << "Your integrand was evaluated at {"; - for (uint64_t i = 0; i < x.size() -1; ++i) + for (std::uint64_t i = 0; i < x.size() -1; ++i) { os << x[i] << ", "; } @@ -443,18 +444,18 @@ class naive_monte_carlo } std::function &)> m_integrand; - uint64_t m_num_threads; - std::atomic m_seed; + std::uint64_t m_num_threads; + std::atomic m_seed; std::atomic m_error_goal; std::atomic m_done{}; std::vector m_lbs; std::vector m_dxs; std::vector m_limit_types; Real m_volume; - std::atomic m_total_calls{}; + std::atomic m_total_calls{}; // I wanted these to be vectors rather than maps, // but you can't resize a vector of atomics. - std::unique_ptr[]> m_thread_calls; + std::unique_ptr[]> m_thread_calls; std::atomic m_variance; std::unique_ptr[]> m_thread_Ss; std::atomic m_avg;