/* * 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 "math_unit_test.hpp" #include #include #include #include #include #include #include #include #include #include #include #ifdef BOOST_HAS_FLOAT128 #include using boost::multiprecision::float128; #endif using boost::math::constants::pi; using boost::math::constants::root_two; template void test_wavelet_dyadic_grid() { std::cout << "Testing wavelet dyadic grid on type " << boost::core::demangle(typeid(Real).name()) << "\n"; auto f = [&](auto i) { auto phijk = boost::math::dyadic_grid(0); auto phik = boost::math::detail::daubechies_scaling_integer_grid(); assert(phik.size() == phijk.size()); for (size_t k = 0; k < phik.size(); ++k) { CHECK_ULP_CLOSE(phik[k], phijk[k], 0); } for (int64_t j = 1; j < 10; ++j) { phijk = boost::math::dyadic_grid(j); phik = boost::math::detail::daubechies_scaling_integer_grid(); for (int64_t l = 0; l < static_cast(phik.size()); ++l) { CHECK_ULP_CLOSE(phik[l], phijk[l*(int64_t(1)<(0); for (int64_t l = 0; l < static_cast(phik.size()); ++l) { int64_t idx = l*(int64_t(1)<::epsilon()); } } }; boost::hana::for_each(std::make_index_sequence<18>(), f); } template void test_quadratures() { using boost::math::quadrature::trapezoidal; auto psi = boost::math::daubechies_wavelet(); Real tol = std::numeric_limits::epsilon(); Real error_estimate = std::numeric_limits::quiet_NaN(); Real L1 = std::numeric_limits::quiet_NaN(); auto [a, b] = psi.support(); CHECK_ULP_CLOSE(Real(-p+1), a, 0); CHECK_ULP_CLOSE(Real(p), b, 0); // A wavelet is a function of zero average; ensure the quadrature over its support is zero. /*Real Q = trapezoidal(psi, a, b, tol, 15, &error_estimate, &L1); if (!CHECK_MOLLIFIED_CLOSE(Real(0), Q, Real(0.0001))) { std::cerr << " Quadrature of " << p << " vanishing moment wavelet does not vanish.\n"; }*/ // psi is orthogonal to its integer translates: \int \psi(x-k) \psi(x) \, \mathrm{d}x = 0 // psi has L2 norm 1: // g_n = 1/sqrt(2) (Mallat, 7.55) } int main() { boost::hana::for_each(std::make_index_sequence<18>(), [&](auto i){ test_quadratures(); test_quadratures(); }); test_wavelet_dyadic_grid(); test_wavelet_dyadic_grid(); test_wavelet_dyadic_grid(); #ifdef BOOST_HAS_FLOAT128 test_wavelet_dyadic_grid(); #endif return boost::math::test::report_errors(); }