Skip to content

Commit c690172

Browse files
authored
Merge pull request #1 from boostorg/develop
Automatic merge of math/develop
2 parents 89ac04c + 8bb0d16 commit c690172

File tree

121 files changed

+4051
-1748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4051
-1748
lines changed

.drone.star

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ windowsglobalimage="cppalliance/dronevs2019"
1616
def main(ctx):
1717

1818
things_to_test = [ "special_fun", "distribution_tests", "mp", "misc", "interpolators", "quadrature", "autodiff", "long-running-tests", "float128_tests" ]
19+
gcc13_things_to_test = [ "special_fun", "distribution_tests", "mp", "misc", "interpolators", "quadrature", "autodiff", "long-running-tests", "float128_tests", "new_floats" ]
1920
sanitizer_test = [ "special_fun", "distribution_tests", "misc", "interpolators", "quadrature", "float128_tests" ]
2021
gnu_5_stds = [ "gnu++14", "c++14" ]
2122
gnu_6_stds = [ "gnu++14", "c++14", "gnu++17", "c++17" ]
2223
clang_6_stds = [ "c++14", "c++17" ]
2324
gnu_9_stds = [ "gnu++14", "c++14", "gnu++17", "c++17", "gnu++2a", "c++2a" ]
2425
clang_10_stds = [ "c++14", "c++17", "c++2a" ]
2526
gnu_non_native = [ "gnu++17" ]
27+
gcc13_stds = [ "c++23" ]
2628

2729
result = []
2830

@@ -59,6 +61,9 @@ def main(ctx):
5961
result.append(linux_cxx("Ubuntu g++ ARM64" + cxx + " " + suite, "g++", packages="g++", buildtype="boost", image="cppalliance/droneubuntu2204:multiarch", arch="arm64", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': cxx, 'TEST_SUITE': suite, }, globalenv=globalenv))
6062
for cxx in gnu_non_native:
6163
result.append(osx_cxx("M1 Clang " + cxx + " " + suite, "clang++", buildscript="drone", buildtype="boost", xcode_version="14.1", environment={'TOOLSET': 'clang', 'CXXSTD': cxx, 'TEST_SUITE': suite, 'DEFINE': 'BOOST_MATH_NO_REAL_CONCEPT_TESTS,BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS,BOOST_MATH_MULTI_ARCH_CI_RUN', }, globalenv=globalenv))
64+
for suite in gcc13_things_to_test:
65+
for cxx in gcc13_stds:
66+
result.append(linux_cxx("Ubuntu g++-13 " + cxx + " " + suite, "g++-13", packages="g++-13", buildtype="boost", image="cppalliance/droneubuntu2304:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-13', 'CXXSTD': cxx, 'TEST_SUITE': suite, }, globalenv=globalenv))
6267

6368
return result
6469

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
branches:
1010
- master
1111
- develop
12+
- feature/**
1213
pull_request:
1314
release:
1415
types: [published, created, edited]
@@ -47,7 +48,7 @@ jobs:
4748
if: steps.retry1.outcome=='failure'
4849
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
4950
- name: Install packages
50-
run: sudo apt install g++-12 clang-14 libgmp-dev libmpfr-dev libfftw3-dev
51+
run: sudo apt-get install -y g++-12 clang-14 libgmp-dev libmpfr-dev libfftw3-dev
5152
- name: Checkout main boost
5253
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
5354
- name: Update tools/boostdep
@@ -105,7 +106,7 @@ jobs:
105106
if: steps.retry1.outcome=='failure'
106107
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
107108
- name: Install packages
108-
run: sudo apt install g++-9 g++-11 clang-9 clang-10 libgmp-dev libmpfr-dev libfftw3-dev
109+
run: sudo apt-get install -y g++-9 g++-11 clang-9 clang-10 libgmp-dev libmpfr-dev libfftw3-dev
109110
- name: Checkout main boost
110111
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
111112
- name: Update tools/boostdep
@@ -364,7 +365,7 @@ jobs:
364365
if: steps.retry1.outcome=='failure'
365366
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
366367
- name: Install packages
367-
run: sudo apt install g++-10 libgmp-dev libmpfr-dev libfftw3-dev
368+
run: sudo apt-get install -y g++-10 libgmp-dev libmpfr-dev libfftw3-dev
368369
- name: Checkout main boost
369370
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
370371
- name: Update tools/boostdep
@@ -404,7 +405,7 @@ jobs:
404405
if: steps.retry1.outcome=='failure'
405406
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
406407
- name: Install packages
407-
run: sudo apt install clang-10 libgmp-dev libmpfr-dev libfftw3-dev
408+
run: sudo apt-get install -y clang-10 libgmp-dev libmpfr-dev libfftw3-dev libtbb-dev
408409
- name: Checkout main boost
409410
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
410411
- name: Update tools/boostdep
@@ -448,7 +449,7 @@ jobs:
448449
if: steps.retry1.outcome=='failure'
449450
run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
450451
- name: Install packages
451-
run: sudo apt install g++-10 libgmp-dev libmpfr-dev libfftw3-dev
452+
run: sudo apt-get install -y g++-10 libgmp-dev libmpfr-dev libfftw3-dev
452453
- name: Checkout main boost
453454
run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root
454455
- name: Update tools/boostdep
451 KB
Loading

doc/sf/daubechies.qbk

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,48 @@ The 2 vanishing moment scaling function.
127127
[$../graphs/daubechies_8_scaling.svg]
128128
The 8 vanishing moment scaling function.
129129

130+
Boost.Math also provides numerical evaluation of the Fourier transform of these functions.
131+
This is useful in sparse recovery problems where the measurements are taken in the Fourier basis.
132+
The usage is exhibited below:
133+
134+
#include <boost/math/special_functions/fourier_transform_daubechies_scaling.hpp>
135+
using boost::math::fourier_transform_daubechies_scaling;
136+
// Evaluate the Fourier transform of the 4-vanishing moment Daubechies scaling function at ω=1.8:
137+
std::complex<float> hat_phi = fourier_transform_daubechies_scaling<float, 4>(1.8f);
138+
139+
The Fourier transform convention is unitary with the sign of the imaginary unit being given in Daubechies Ten Lectures.
140+
In particular, this means that `fourier_transform_daubechies_scaling<float, p>(0.0)` returns 1/sqrt(2π).
141+
142+
The implementation computes an infinite product of trigonometric polynomials as can be found from recursive application of the identity 𝓕[φ](ω) = m(ω/2)𝓕[φ](ω/2).
143+
This is neither particularly fast nor accurate, but there appears to be no literature on this extremely useful topic, and hence the naive method must suffice.
144+
145+
[$../graphs/fourier_transform_daubechies.png]
146+
147+
A benchmark can be found in `reporting/performance/fourier_transform_daubechies_performance.cpp`; the results on a ~2021 M1 Macbook pro are presented below:
148+
149+
150+
Run on (10 X 24.1212 MHz CPU s)
151+
CPU Caches:
152+
L1 Data 64 KiB (x10)
153+
L1 Instruction 128 KiB (x10)
154+
L2 Unified 4096 KiB (x5)
155+
Load Average: 1.33, 1.52, 1.62
156+
-----------------------------------------------------------
157+
Benchmark Time
158+
-----------------------------------------------------------
159+
FourierTransformDaubechiesScaling<double, 1> 70.3 ns
160+
FourierTransformDaubechiesScaling<double, 2> 330 ns
161+
FourierTransformDaubechiesScaling<double, 3> 335 ns
162+
FourierTransformDaubechiesScaling<double, 4> 364 ns
163+
FourierTransformDaubechiesScaling<double, 5> 386 ns
164+
FourierTransformDaubechiesScaling<double, 6> 436 ns
165+
FourierTransformDaubechiesScaling<double, 7> 447 ns
166+
FourierTransformDaubechiesScaling<double, 8> 473 ns
167+
FourierTransformDaubechiesScaling<double, 9> 503 ns
168+
FourierTransformDaubechiesScaling<double, 10> 554 ns
169+
170+
Due to the low accuracy of this method, `float` precision is arg-promoted to `double`, and hence takes just as long as `double` precision to execute.
171+
130172
[heading References]
131173

132174
* Daubechies, Ingrid. ['Ten Lectures on Wavelets.] Vol. 61. Siam, 1992.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// (C) Copyright Nick Thompson 2023.
2+
// Use, modification and distribution are subject to the
3+
// Boost Software License, Version 1.0. (See accompanying file
4+
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
6+
#include <utility>
7+
#include <boost/math/filters/daubechies.hpp>
8+
#include <boost/math/tools/polynomial.hpp>
9+
#include <boost/multiprecision/cpp_bin_float.hpp>
10+
#include <boost/math/constants/constants.hpp>
11+
12+
using std::pow;
13+
using boost::multiprecision::cpp_bin_float_100;
14+
using boost::math::filters::daubechies_scaling_filter;
15+
using boost::math::tools::polynomial;
16+
using boost::math::constants::half;
17+
using boost::math::constants::root_two;
18+
19+
template<typename Real, size_t N>
20+
std::vector<Real> get_constants() {
21+
auto h = daubechies_scaling_filter<cpp_bin_float_100, N>();
22+
auto p = polynomial<cpp_bin_float_100>(h.begin(), h.end());
23+
24+
auto q = polynomial({half<cpp_bin_float_100>(), half<cpp_bin_float_100>()});
25+
q = pow(q, N);
26+
auto l = p/q;
27+
return l.data();
28+
}
29+
30+
template<typename Real>
31+
void print_constants(std::vector<Real> const & l) {
32+
std::cout << std::setprecision(std::numeric_limits<Real>::digits10 -10);
33+
std::cout << "return std::array<Real, " << l.size() << ">{";
34+
for (size_t i = 0; i < l.size() - 1; ++i) {
35+
std::cout << "BOOST_MATH_BIG_CONSTANT(Real, std::numeric_limits<Real>::digits, " << l[i]/root_two<Real>() << "), ";
36+
}
37+
std::cout << "BOOST_MATH_BIG_CONSTANT(Real, std::numeric_limits<Real>::digits, " << l.back()/root_two<Real>() << ")};\n";
38+
}
39+
40+
int main() {
41+
auto constants = get_constants<cpp_bin_float_100, 1>();
42+
print_constants(constants);
43+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// boost-no-inspect
2+
// (C) Copyright Nick Thompson 2023.
3+
// Use, modification and distribution are subject to the
4+
// Boost Software License, Version 1.0. (See accompanying file
5+
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <boost/math/special_functions/fourier_transform_daubechies.hpp>
8+
#include <boost/math/tools/ulps_plot.hpp>
9+
10+
using boost::math::fourier_transform_daubechies_scaling;
11+
using boost::math::tools::ulps_plot;
12+
13+
template<int p>
14+
void real_part() {
15+
auto phi_real_hi_acc = [](double omega) {
16+
auto z = fourier_transform_daubechies_scaling<double, p>(omega);
17+
return z.real();
18+
};
19+
20+
auto phi_real_lo_acc = [](float omega) {
21+
auto z = fourier_transform_daubechies_scaling<float, p>(omega);
22+
return z.real();
23+
};
24+
auto plot = ulps_plot<decltype(phi_real_hi_acc), double, float>(phi_real_hi_acc, float(0.0), float(100.0), 20000);
25+
plot.ulp_envelope(false);
26+
plot.add_fn(phi_real_lo_acc);
27+
plot.clip(100);
28+
plot.title("Accuracy of 𝔑(𝓕[𝜙](ω)) with " + std::to_string(p) + " vanishing moments.");
29+
plot.write("real_ft_daub_scaling_" + std::to_string(p) + ".svg");
30+
31+
}
32+
33+
template<int p>
34+
void imaginary_part() {
35+
auto phi_imag_hi_acc = [](double omega) {
36+
auto z = fourier_transform_daubechies_scaling<double, p>(omega);
37+
return z.imag();
38+
};
39+
40+
auto phi_imag_lo_acc = [](float omega) {
41+
auto z = fourier_transform_daubechies_scaling<float, p>(omega);
42+
return z.imag();
43+
};
44+
auto plot = ulps_plot<decltype(phi_imag_hi_acc), double, float>(phi_imag_hi_acc, float(0.0), float(100.0), 20000);
45+
plot.ulp_envelope(false);
46+
plot.add_fn(phi_imag_lo_acc);
47+
plot.clip(100);
48+
plot.title("Accuracy of 𝕴(𝓕[𝜙](ω)) with " + std::to_string(p) + " vanishing moments.");
49+
plot.write("imag_ft_daub_scaling_" + std::to_string(p) + ".svg");
50+
51+
}
52+
53+
54+
int main() {
55+
real_part<3>();
56+
imaginary_part<3>();
57+
real_part<6>();
58+
imaginary_part<6>();
59+
return 0;
60+
}

include/boost/math/concepts/real_concept.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
# include <cstdio>
4646
#endif
4747

48+
#if __has_include(<stdfloat>)
49+
# include <stdfloat>
50+
#endif
51+
4852
namespace boost{ namespace math{
4953

5054
namespace concepts
@@ -79,6 +83,12 @@ class real_concept
7983
#ifdef BOOST_MATH_USE_FLOAT128
8084
real_concept(BOOST_MATH_FLOAT128_TYPE c) : m_value(c){}
8185
#endif
86+
#ifdef __STDCPP_FLOAT32_T__
87+
real_concept(std::float32_t c) : m_value(static_cast<real_concept_base_type>(c)){}
88+
#endif
89+
#ifdef __STDCPP_FLOAT64_T__
90+
real_concept(std::float64_t c) : m_value(static_cast<real_concept_base_type>(c)){}
91+
#endif
8292

8393
// Assignment:
8494
real_concept& operator=(char c) { m_value = c; return *this; }
@@ -96,6 +106,12 @@ class real_concept
96106
real_concept& operator=(float c) { m_value = c; return *this; }
97107
real_concept& operator=(double c) { m_value = c; return *this; }
98108
real_concept& operator=(long double c) { m_value = c; return *this; }
109+
#ifdef __STDCPP_FLOAT32_T__
110+
real_concept& operator=(std::float32_t c) { m_value = c; return *this; }
111+
#endif
112+
#ifdef __STDCPP_FLOAT64_T__
113+
real_concept& operator=(std::float64_t c) { m_value = c; return *this; }
114+
#endif
99115

100116
// Access:
101117
real_concept_base_type value()const{ return m_value; }

include/boost/math/cstdfloat/cstdfloat_limits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#pragma GCC system_header
2525
#endif
2626

27-
#if defined(BOOST_CSTDFLOAT_HAS_INTERNAL_FLOAT128_T) && defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT)
27+
#if defined(BOOST_CSTDFLOAT_HAS_INTERNAL_FLOAT128_T) && defined(BOOST_MATH_USE_FLOAT128) && !defined(BOOST_CSTDFLOAT_NO_LIBQUADMATH_SUPPORT) && (!defined(__GNUC__) || (defined(__GNUC__) && __GNUC__ < 14))
2828

2929
#include <limits>
3030
#include <boost/math/tools/nothrow.hpp>

include/boost/math/differentiation/autodiff.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ fvar<RealType, Order> sqrt(fvar<RealType, Order> const& cr) {
14911491
BOOST_IF_CONSTEXPR (order == 0)
14921492
return fvar<RealType, Order>(*derivatives);
14931493
else {
1494-
root_type numerator = 0.5;
1494+
root_type numerator = root_type(0.5);
14951495
root_type powers = 1;
14961496
#ifndef BOOST_NO_CXX17_IF_CONSTEXPR
14971497
derivatives[1] = numerator / *derivatives;

include/boost/math/differentiation/finite_difference.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace detail {
153153

154154
const Real eps = (numeric_limits<Real>::epsilon)();
155155
// Error bound ~eps^4/5
156-
Real h = pow(11.25*eps, static_cast<Real>(1) / static_cast<Real>(5));
156+
Real h = pow(Real(11.25)*eps, static_cast<Real>(1) / static_cast<Real>(5));
157157
h = detail::make_xph_representable(x, h);
158158
Real ymth = f(x - 2 * h);
159159
Real yth = f(x + 2 * h);
@@ -222,7 +222,7 @@ namespace detail {
222222
// Mathematica code to get the error:
223223
// Series[(f[x+h]-f[x-h])*(4/5) + (1/5)*(f[x-2*h] - f[x+2*h]) + (4/105)*(f[x+3*h] - f[x-3*h]) + (1/280)*(f[x-4*h] - f[x+4*h]), {h, 0, 9}]
224224
// If we used Kahan summation, we could get the max error down to h^8|f^(9)(x)|/630 + |f(x)|eps/h.
225-
Real h = pow(551.25*eps, static_cast<Real>(1) / static_cast<Real>(9));
225+
Real h = pow(Real(551.25)*eps, static_cast<Real>(1) / static_cast<Real>(9));
226226
h = detail::make_xph_representable(x, h);
227227

228228
Real yh = f(x + h);

0 commit comments

Comments
 (0)