mirror of
https://github.com/boostorg/math.git
synced 2025-05-11 21:33:52 +00:00
Add casting and tests
This commit is contained in:
parent
ebcc43091f
commit
d1bd7b6f80
@ -18,14 +18,18 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::bezier_polynomial;
|
||||
|
||||
template<typename Real>
|
||||
void test_linear()
|
||||
{
|
||||
std::vector<std::array<Real, 2>> control_points(2);
|
||||
control_points[0] = {0.0, 0.0};
|
||||
control_points[1] = {1.0, 1.0};
|
||||
control_points[0] = {Real(0), Real(0)};
|
||||
control_points[1] = {Real(1), Real(1)};
|
||||
auto control_points_copy = control_points;
|
||||
auto bp = bezier_polynomial(std::move(control_points_copy));
|
||||
|
||||
@ -54,9 +58,9 @@ template<typename Real>
|
||||
void test_quadratic()
|
||||
{
|
||||
std::vector<std::array<Real, 2>> control_points(3);
|
||||
control_points[0] = {0.0, 0.0};
|
||||
control_points[1] = {1.0, 1.0};
|
||||
control_points[2] = {2.0, 2.0};
|
||||
control_points[0] = {Real(0), Real(0)};
|
||||
control_points[1] = {Real(1), Real(1)};
|
||||
control_points[2] = {Real(2), Real(2)};
|
||||
auto control_points_copy = control_points;
|
||||
auto bp = bezier_polynomial(std::move(control_points_copy));
|
||||
|
||||
@ -79,10 +83,10 @@ template<typename Real>
|
||||
void test_convex_hull()
|
||||
{
|
||||
std::vector<std::array<Real, 2>> control_points(4);
|
||||
control_points[0] = {0.0, 0.0};
|
||||
control_points[1] = {0.0, 1.0};
|
||||
control_points[2] = {1.0, 1.0};
|
||||
control_points[3] = {1.0, 0.0};
|
||||
control_points[0] = {Real(0), Real(0)};
|
||||
control_points[1] = {Real(0), Real(1)};
|
||||
control_points[2] = {Real(1), Real(1)};
|
||||
control_points[3] = {Real(1), Real(0)};
|
||||
auto bp = bezier_polynomial(std::move(control_points));
|
||||
|
||||
for (Real t = 0; t <= 1; t += Real(1)/32) {
|
||||
@ -133,9 +137,9 @@ void test_reversal_symmetry()
|
||||
CHECK_ULP_CLOSE(control_points.back()[1], P1[1], 3);
|
||||
CHECK_ULP_CLOSE(control_points.back()[2], P1[2], 3);
|
||||
|
||||
for (Real t = 0; t <= 1; t += 1.0) {
|
||||
for (Real t = 0; t <= 1; t += Real(1.0)) {
|
||||
auto P0 = bp0(t);
|
||||
auto P1 = bp1(1.0-t);
|
||||
auto P1 = bp1(Real(1.0)-t);
|
||||
if (!CHECK_ULP_CLOSE(P0[0], P1[0], 3)) {
|
||||
std::cerr << " Error at t = " << t << "\n";
|
||||
}
|
||||
@ -184,21 +188,40 @@ void test_linear_precision()
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_linear<std::float32_t>();
|
||||
test_quadratic<std::float32_t>();
|
||||
test_convex_hull<std::float32_t>();
|
||||
test_linear_precision<std::float32_t>();
|
||||
test_reversal_symmetry<std::float32_t>();
|
||||
#else
|
||||
test_linear<float>();
|
||||
test_linear<double>();
|
||||
test_quadratic<float>();
|
||||
test_quadratic<double>();
|
||||
test_convex_hull<float>();
|
||||
test_convex_hull<double>();
|
||||
test_linear_precision<float>();
|
||||
test_linear_precision<double>();
|
||||
test_reversal_symmetry<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_linear<std::float64_t>();
|
||||
test_quadratic<std::float64_t>();
|
||||
test_convex_hull<std::float64_t>();
|
||||
test_linear_precision<std::float64_t>();
|
||||
test_reversal_symmetry<std::float64_t>();
|
||||
#else
|
||||
test_linear<double>();
|
||||
test_quadratic<double>();
|
||||
test_convex_hull<double>();
|
||||
test_linear_precision<double>();
|
||||
test_reversal_symmetry<double>();
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
test_linear<float128>();
|
||||
test_quadratic<float128>();
|
||||
test_convex_hull<float128>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,10 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::bilinear_uniform;
|
||||
|
||||
template<class Real>
|
||||
@ -25,7 +29,7 @@ void test_four_values()
|
||||
Real y0 = 0;
|
||||
Real dx = 1;
|
||||
Real dy = 1;
|
||||
Real value = 1.5;
|
||||
Real value = Real(1.5);
|
||||
std::vector<Real> v(2*2, value);
|
||||
auto v_copy = v;
|
||||
auto ub = bilinear_uniform<decltype(v)>(std::move(v_copy), 2, 2, dx, dy, x0, y0);
|
||||
@ -101,9 +105,21 @@ void test_linear()
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_four_values<std::float32_t>();
|
||||
#else
|
||||
test_four_values<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_four_values<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
#else
|
||||
test_four_values<double>();
|
||||
test_four_values<long double>();
|
||||
test_linear<double>();
|
||||
#endif
|
||||
|
||||
test_four_values<long double>();
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
@ -6,15 +6,22 @@
|
||||
*/
|
||||
|
||||
#include "math_unit_test.hpp"
|
||||
#include <cstdint>
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <boost/math/interpolators/cardinal_quadratic_b_spline.hpp>
|
||||
using boost::math::interpolators::cardinal_quadratic_b_spline;
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
template<class Real>
|
||||
void test_constant()
|
||||
{
|
||||
Real c = 7.2;
|
||||
Real c = Real(7.2);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 512;
|
||||
@ -44,8 +51,8 @@ void test_constant()
|
||||
template<class Real>
|
||||
void test_linear()
|
||||
{
|
||||
Real m = 8.3;
|
||||
Real b = 7.2;
|
||||
Real m = Real(8.3);
|
||||
Real b = Real(7.2);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 512;
|
||||
@ -79,9 +86,9 @@ void test_linear()
|
||||
template<class Real>
|
||||
void test_quadratic()
|
||||
{
|
||||
Real a = 8.2;
|
||||
Real b = 7.2;
|
||||
Real c = -9.2;
|
||||
Real a = Real(8.2);
|
||||
Real b = Real(7.2);
|
||||
Real c = Real(-9.2);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 513;
|
||||
@ -115,21 +122,29 @@ void test_quadratic()
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_constant<std::float32_t>();
|
||||
test_linear<std::float32_t>();
|
||||
#else
|
||||
test_constant<float>();
|
||||
test_linear<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_quadratic<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
test_quadratic<double>();
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_constant<long double>();
|
||||
#endif
|
||||
|
||||
test_linear<float>();
|
||||
test_linear<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_linear<long double>();
|
||||
#endif
|
||||
|
||||
test_quadratic<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_quadratic<long double>();
|
||||
#endif
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
@ -6,8 +6,11 @@
|
||||
*/
|
||||
|
||||
#include "math_unit_test.hpp"
|
||||
#include <cstdint>
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <boost/math/interpolators/cardinal_quintic_b_spline.hpp>
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
#include <boost/multiprecision/float128.hpp>
|
||||
@ -15,10 +18,14 @@ using boost::multiprecision::float128;
|
||||
#endif
|
||||
using boost::math::interpolators::cardinal_quintic_b_spline;
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
template<class Real>
|
||||
void test_constant()
|
||||
{
|
||||
Real c = 7.5;
|
||||
Real c = Real(7.5);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 513;
|
||||
@ -53,7 +60,7 @@ void test_constant()
|
||||
template<class Real>
|
||||
void test_constant_estimate_derivatives()
|
||||
{
|
||||
Real c = 7.5;
|
||||
Real c = Real(7.5);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 513;
|
||||
@ -88,8 +95,8 @@ template<class Real>
|
||||
void test_linear()
|
||||
{
|
||||
using std::abs;
|
||||
Real m = 8.3;
|
||||
Real b = 7.2;
|
||||
Real m = Real(8.3);
|
||||
Real b = Real(7.2);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 512;
|
||||
@ -137,8 +144,8 @@ template<class Real>
|
||||
void test_linear_estimate_derivatives()
|
||||
{
|
||||
using std::abs;
|
||||
Real m = 8.3;
|
||||
Real b = 7.2;
|
||||
Real m = Real(8.3);
|
||||
Real b = Real(7.2);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 512;
|
||||
@ -186,8 +193,8 @@ template<class Real>
|
||||
void test_quadratic()
|
||||
{
|
||||
Real a = Real(1)/Real(16);
|
||||
Real b = -3.5;
|
||||
Real c = -9;
|
||||
Real b = Real(-3.5);
|
||||
Real c = Real(-9);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 513;
|
||||
@ -229,8 +236,8 @@ template<class Real>
|
||||
void test_quadratic_estimate_derivatives()
|
||||
{
|
||||
Real a = Real(1)/Real(16);
|
||||
Real b = -3.5;
|
||||
Real c = -9;
|
||||
Real b = Real(-3.5);
|
||||
Real c = Real(-9);
|
||||
Real t0 = 0;
|
||||
Real h = Real(1)/Real(16);
|
||||
size_t n = 513;
|
||||
@ -266,41 +273,41 @@ void test_quadratic_estimate_derivatives()
|
||||
|
||||
int main()
|
||||
{
|
||||
test_constant<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_constant<long double>();
|
||||
#endif
|
||||
|
||||
test_constant_estimate_derivatives<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_constant_estimate_derivatives<long double>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_linear<std::float32_t>();
|
||||
#else
|
||||
test_linear<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_constant_estimate_derivatives<std::float64_t>();
|
||||
test_linear_estimate_derivatives<std::float64_t>();
|
||||
test_quadratic<std::float64_t>();
|
||||
test_quadratic_estimate_derivatives<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_linear<long double>();
|
||||
#endif
|
||||
|
||||
test_constant_estimate_derivatives<double>();
|
||||
test_linear_estimate_derivatives<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_linear_estimate_derivatives<long double>();
|
||||
#endif
|
||||
|
||||
test_quadratic<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_quadratic<long double>();
|
||||
#endif
|
||||
|
||||
test_quadratic_estimate_derivatives<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_constant<long double>();
|
||||
test_constant_estimate_derivatives<long double>();
|
||||
test_linear<long double>();
|
||||
test_linear_estimate_derivatives<long double>();
|
||||
test_quadratic<long double>();
|
||||
test_quadratic_estimate_derivatives<long double>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
test_constant<float128>();
|
||||
test_linear<float128>();
|
||||
test_linear_estimate_derivatives<float128>();
|
||||
test_constant<float128>();
|
||||
test_linear<float128>();
|
||||
test_linear_estimate_derivatives<float128>();
|
||||
#endif
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
|
@ -18,6 +18,10 @@
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
#include <boost/numeric/ublas/vector.hpp>
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using std::abs;
|
||||
using boost::multiprecision::cpp_bin_float_50;
|
||||
using boost::math::catmull_rom;
|
||||
@ -158,7 +162,7 @@ void test_circle()
|
||||
}
|
||||
|
||||
Real max_s = circle.max_parameter();
|
||||
for(Real s = 0; s < max_s; s += 0.01)
|
||||
for(Real s = 0; s < max_s; s += Real(0.01))
|
||||
{
|
||||
auto p = circle(s);
|
||||
Real x = p[0];
|
||||
@ -259,11 +263,11 @@ void test_helix()
|
||||
Real y = p[1];
|
||||
if (abs(x) < tol)
|
||||
{
|
||||
BOOST_CHECK_SMALL(cos(t), tol);
|
||||
BOOST_CHECK_SMALL(Real(cos(t)), tol);
|
||||
}
|
||||
if (abs(y) < tol)
|
||||
{
|
||||
BOOST_CHECK_SMALL(sin(t), tol);
|
||||
BOOST_CHECK_SMALL(Real(sin(t)), tol);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -282,16 +286,16 @@ void test_helix()
|
||||
BOOST_CHECK_CLOSE_FRACTION(x*x+y*y, (Real) 1, (Real) 0.01);
|
||||
if (abs(x) < 0.01)
|
||||
{
|
||||
BOOST_CHECK_SMALL(cos(t), (Real) 0.05);
|
||||
BOOST_CHECK_SMALL(Real(cos(t)), (Real) 0.05);
|
||||
}
|
||||
if (abs(y) < 0.01)
|
||||
{
|
||||
BOOST_CHECK_SMALL(sin(t), (Real) 0.05);
|
||||
BOOST_CHECK_SMALL(Real(sin(t)), (Real) 0.05);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_CLOSE_FRACTION(x, cos(t), (Real) 0.05);
|
||||
BOOST_CHECK_CLOSE_FRACTION(y, sin(t), (Real) 0.05);
|
||||
BOOST_CHECK_CLOSE_FRACTION(x, Real(cos(t)), (Real) 0.05);
|
||||
BOOST_CHECK_CLOSE_FRACTION(y, Real(sin(t)), (Real) 0.05);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -344,18 +348,18 @@ template<class Real>
|
||||
void test_data_representations()
|
||||
{
|
||||
std::cout << "Testing that the Catmull-Rom spline works with multiple data representations.\n";
|
||||
mypoint3d<Real> p0(0.1, 0.2, 0.3);
|
||||
mypoint3d<Real> p1(0.2, 0.3, 0.4);
|
||||
mypoint3d<Real> p2(0.3, 0.4, 0.5);
|
||||
mypoint3d<Real> p3(0.4, 0.5, 0.6);
|
||||
mypoint3d<Real> p4(0.5, 0.6, 0.7);
|
||||
mypoint3d<Real> p5(0.6, 0.7, 0.8);
|
||||
mypoint3d<Real> p0(Real(0.1), Real(0.2), Real(0.3));
|
||||
mypoint3d<Real> p1(Real(0.2), Real(0.3), Real(0.4));
|
||||
mypoint3d<Real> p2(Real(0.3), Real(0.4), Real(0.5));
|
||||
mypoint3d<Real> p3(Real(0.4), Real(0.5), Real(0.6));
|
||||
mypoint3d<Real> p4(Real(0.5), Real(0.6), Real(0.7));
|
||||
mypoint3d<Real> p5(Real(0.6), Real(0.7), Real(0.8));
|
||||
|
||||
|
||||
// Tests initializer_list:
|
||||
catmull_rom<mypoint3d<Real>> cat({p0, p1, p2, p3, p4, p5});
|
||||
|
||||
Real tol = 0.001;
|
||||
Real tol = Real(0.001);
|
||||
auto p = cat(cat.parameter_at_point(0));
|
||||
BOOST_CHECK_CLOSE_FRACTION(p[0], p0[0], tol);
|
||||
BOOST_CHECK_CLOSE_FRACTION(p[1], p0[1], tol);
|
||||
@ -388,7 +392,7 @@ void test_random_access_container()
|
||||
// Tests initializer_list:
|
||||
catmull_rom<mypoint3d<Real>, decltype(u)> cat(std::move(u));
|
||||
|
||||
Real tol = 0.001;
|
||||
Real tol = Real(0.001);
|
||||
auto p = cat(cat.parameter_at_point(0));
|
||||
BOOST_CHECK_CLOSE_FRACTION(p[0], p0[0], tol);
|
||||
BOOST_CHECK_CLOSE_FRACTION(p[1], p0[1], tol);
|
||||
@ -402,27 +406,51 @@ void test_random_access_container()
|
||||
BOOST_AUTO_TEST_CASE(catmull_rom_test)
|
||||
{
|
||||
#if !defined(TEST) || (TEST == 1)
|
||||
test_data_representations<float>();
|
||||
test_alpha_distance<double>();
|
||||
|
||||
test_linear<double>();
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_linear<long double>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_circle<std::float32_t>();
|
||||
test_data_representations<std::float32_t>();
|
||||
#else
|
||||
test_circle<float>();
|
||||
test_circle<double>();
|
||||
#endif
|
||||
#if !defined(TEST) || (TEST == 2)
|
||||
test_helix<double>();
|
||||
test_data_representations<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_alpha_distance<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_circle<std::float64_t>();
|
||||
#else
|
||||
test_alpha_distance<double>();
|
||||
test_linear<double>();
|
||||
test_circle<double>();
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
|
||||
test_linear<long double>();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(TEST) || (TEST == 2)
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_helix<std::float64_t>();
|
||||
test_affine_invariance<std::float64_t, 1>();
|
||||
test_affine_invariance<std::float64_t, 2>();
|
||||
test_affine_invariance<std::float64_t, 3>();
|
||||
test_affine_invariance<std::float64_t, 4>();
|
||||
test_random_access_container<std::float64_t>();
|
||||
#else
|
||||
test_helix<double>();
|
||||
test_affine_invariance<double, 1>();
|
||||
test_affine_invariance<double, 2>();
|
||||
test_affine_invariance<double, 3>();
|
||||
test_affine_invariance<double, 4>();
|
||||
|
||||
test_random_access_container<double>();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(TEST) || (TEST == 3)
|
||||
test_affine_invariance<cpp_bin_float_50, 4>();
|
||||
#endif
|
||||
|
@ -19,6 +19,9 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::cubic_hermite;
|
||||
using boost::math::interpolators::cardinal_cubic_hermite;
|
||||
@ -74,7 +77,7 @@ void test_constant()
|
||||
|
||||
auto circular_hermite_spline = cubic_hermite(std::move(x_buf), std::move(y_buf), std::move(dydx_buf));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(7), circular_hermite_spline(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), circular_hermite_spline.prime(t), 2);
|
||||
}
|
||||
@ -117,7 +120,7 @@ void test_linear()
|
||||
y_copy = y;
|
||||
dydx_copy = dydx;
|
||||
hermite_spline = cubic_hermite(std::move(x_copy), std::move(y_copy), std::move(dydx_copy));
|
||||
for (Real t = 0; t < x.back(); t += 0.5) {
|
||||
for (Real t = 0; t < x.back(); t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, hermite_spline(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), hermite_spline.prime(t), 0);
|
||||
}
|
||||
@ -139,7 +142,7 @@ void test_linear()
|
||||
|
||||
auto circular_hermite_spline = cubic_hermite(std::move(x_buf), std::move(y_buf), std::move(dydx_buf));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(t, circular_hermite_spline(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), circular_hermite_spline.prime(t), 2);
|
||||
}
|
||||
@ -156,7 +159,7 @@ void test_quadratic()
|
||||
{
|
||||
std::vector<Real> x(50);
|
||||
std::default_random_engine rd;
|
||||
std::uniform_real_distribution<Real> dis(0.1,1);
|
||||
std::uniform_real_distribution<Real> dis(Real(0.1), Real(1));
|
||||
Real x0 = dis(rd);
|
||||
x[0] = x0;
|
||||
for (size_t i = 1; i < x.size(); ++i) {
|
||||
@ -172,7 +175,7 @@ void test_quadratic()
|
||||
}
|
||||
|
||||
auto s = cubic_hermite(std::move(x), std::move(y), std::move(dydx));
|
||||
for (Real t = x0; t <= xmax; t+= 0.0125)
|
||||
for (Real t = x0; t <= xmax; t+= Real(0.0125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, s(t), 5);
|
||||
CHECK_ULP_CLOSE(t, s.prime(t), 138);
|
||||
@ -223,7 +226,7 @@ void test_cardinal_constant()
|
||||
|
||||
auto hermite_spline = cardinal_cubic_hermite(std::move(y), std::move(dydx), x0, dx);
|
||||
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += 0.25) {
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(7), hermite_spline(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), hermite_spline.prime(t), 2);
|
||||
}
|
||||
@ -237,7 +240,7 @@ void test_cardinal_constant()
|
||||
}
|
||||
auto hermite_spline_aos = cardinal_cubic_hermite_aos(std::move(data), x0, dx);
|
||||
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += 0.25) {
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += Real(0.25)) {
|
||||
if (!CHECK_ULP_CLOSE(Real(7), hermite_spline_aos(t), 2)) {
|
||||
std::cerr << " Wrong evaluation at t = " << t << "\n";
|
||||
}
|
||||
@ -297,7 +300,7 @@ void test_cardinal_linear()
|
||||
}
|
||||
|
||||
hermite_spline = cardinal_cubic_hermite(std::move(y), std::move(dydx), x0, dx);
|
||||
for (Real t = 0; t < 44; t += 0.5) {
|
||||
for (Real t = 0; t < 44; t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, hermite_spline(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), hermite_spline.prime(t), 0);
|
||||
}
|
||||
@ -309,7 +312,7 @@ void test_cardinal_linear()
|
||||
}
|
||||
|
||||
auto hermite_spline_aos = cardinal_cubic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = 0; t < 44; t += 0.5) {
|
||||
for (Real t = 0; t < 44; t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, hermite_spline_aos(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), hermite_spline_aos.prime(t), 0);
|
||||
}
|
||||
@ -352,7 +355,7 @@ void test_cardinal_quadratic()
|
||||
}
|
||||
|
||||
auto s = cardinal_cubic_hermite(std::move(y), std::move(dydx), x0, dx);
|
||||
for (Real t = x0; t <= x0 + 49*dx; t+= 0.0125)
|
||||
for (Real t = x0; t <= x0 + 49*dx; t+= Real(0.0125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, s(t), 12);
|
||||
CHECK_ULP_CLOSE(t, s.prime(t), 70);
|
||||
@ -367,7 +370,7 @@ void test_cardinal_quadratic()
|
||||
|
||||
|
||||
auto saos = cardinal_cubic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = x0; t <= x0 + 49*dx; t+= 0.0125)
|
||||
for (Real t = x0; t <= x0 + 49*dx; t+= Real(0.0125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, saos(t), 12);
|
||||
CHECK_ULP_CLOSE(t, saos.prime(t), 70);
|
||||
@ -400,7 +403,7 @@ void test_cardinal_interpolation_condition()
|
||||
std::vector<Real> y(n);
|
||||
std::vector<Real> dydx(n);
|
||||
std::default_random_engine rd;
|
||||
std::uniform_real_distribution<Real> dis(0.1,1);
|
||||
std::uniform_real_distribution<Real> dis(Real(0.1), Real(1));
|
||||
Real x0 = Real(2);
|
||||
Real dx = Real(1)/Real(128);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
@ -422,6 +425,16 @@ void test_cardinal_interpolation_condition()
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_constant<std::float32_t>();
|
||||
test_linear<std::float32_t>();
|
||||
test_quadratic<std::float32_t>();
|
||||
test_interpolation_condition<std::float32_t>();
|
||||
test_cardinal_constant<std::float32_t>();
|
||||
test_cardinal_linear<std::float32_t>();
|
||||
test_cardinal_quadratic<std::float32_t>();
|
||||
test_cardinal_interpolation_condition<std::float32_t>();
|
||||
#else
|
||||
test_constant<float>();
|
||||
test_linear<float>();
|
||||
test_quadratic<float>();
|
||||
@ -430,7 +443,18 @@ int main()
|
||||
test_cardinal_linear<float>();
|
||||
test_cardinal_quadratic<float>();
|
||||
test_cardinal_interpolation_condition<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_quadratic<std::float64_t>();
|
||||
test_interpolation_condition<std::float64_t>();
|
||||
test_cardinal_constant<std::float64_t>();
|
||||
test_cardinal_linear<std::float64_t>();
|
||||
test_cardinal_quadratic<std::float64_t>();
|
||||
test_cardinal_interpolation_condition<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
test_quadratic<double>();
|
||||
@ -439,6 +463,7 @@ int main()
|
||||
test_cardinal_linear<double>();
|
||||
test_cardinal_quadratic<double>();
|
||||
test_cardinal_interpolation_condition<double>();
|
||||
#endif
|
||||
|
||||
test_constant<long double>();
|
||||
test_linear<long double>();
|
||||
@ -450,12 +475,12 @@ int main()
|
||||
test_cardinal_interpolation_condition<long double>();
|
||||
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
test_constant<float128>();
|
||||
test_linear<float128>();
|
||||
test_cardinal_constant<float128>();
|
||||
test_cardinal_linear<float128>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
@ -16,6 +16,9 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::makima;
|
||||
|
||||
@ -33,7 +36,7 @@ void test_constant()
|
||||
auto y_copy = y;
|
||||
auto akima = makima(std::move(x_copy), std::move(y_copy));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(7), akima(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), akima.prime(t), 2);
|
||||
}
|
||||
@ -50,7 +53,7 @@ void test_constant()
|
||||
|
||||
auto circular_akima = makima(std::move(x_buf), std::move(y_buf));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(7), circular_akima(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), akima.prime(t), 2);
|
||||
}
|
||||
@ -88,7 +91,7 @@ void test_linear()
|
||||
x_copy = x;
|
||||
y_copy = y;
|
||||
akima = makima(std::move(x_copy), std::move(y_copy));
|
||||
for (Real t = 0; t < x.back(); t += 0.5) {
|
||||
for (Real t = 0; t < x.back(); t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, akima(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), akima.prime(t), 0);
|
||||
}
|
||||
@ -97,7 +100,7 @@ void test_linear()
|
||||
y_copy = y;
|
||||
// Test endpoint derivatives:
|
||||
akima = makima(std::move(x_copy), std::move(y_copy), Real(1), Real(1));
|
||||
for (Real t = 0; t < x.back(); t += 0.5) {
|
||||
for (Real t = 0; t < x.back(); t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, akima(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), akima.prime(t), 0);
|
||||
}
|
||||
@ -115,7 +118,7 @@ void test_linear()
|
||||
|
||||
auto circular_akima = makima(std::move(x_buf), std::move(y_buf));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(t, circular_akima(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), circular_akima.prime(t), 2);
|
||||
}
|
||||
@ -166,13 +169,26 @@ void test_interpolation_condition()
|
||||
int main()
|
||||
{
|
||||
#if (__GNUC__ > 7) || defined(_MSC_VER) || defined(__clang__)
|
||||
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_constant<std::float32_t>();
|
||||
test_linear<std::float32_t>();
|
||||
test_interpolation_condition<std::float32_t>();
|
||||
#else
|
||||
test_constant<float>();
|
||||
test_linear<float>();
|
||||
test_interpolation_condition<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_interpolation_condition<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
test_interpolation_condition<double>();
|
||||
#endif
|
||||
|
||||
test_constant<long double>();
|
||||
test_linear<long double>();
|
||||
|
@ -17,6 +17,9 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::pchip;
|
||||
|
||||
@ -35,7 +38,7 @@ void test_constant()
|
||||
auto pchip_spline = pchip(std::move(x_copy), std::move(y_copy));
|
||||
//std::cout << "Constant value pchip spline = " << pchip_spline << "\n";
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(7), pchip_spline(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), pchip_spline.prime(t), 2);
|
||||
}
|
||||
@ -52,7 +55,7 @@ void test_constant()
|
||||
|
||||
auto circular_pchip_spline = pchip(std::move(x_buf), std::move(y_buf));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(7), circular_pchip_spline(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), pchip_spline.prime(t), 2);
|
||||
}
|
||||
@ -90,7 +93,7 @@ void test_linear()
|
||||
x_copy = x;
|
||||
y_copy = y;
|
||||
pchip_spline = pchip(std::move(x_copy), std::move(y_copy));
|
||||
for (Real t = 0; t < x.back(); t += 0.5) {
|
||||
for (Real t = 0; t < x.back(); t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, pchip_spline(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), pchip_spline.prime(t), 0);
|
||||
}
|
||||
@ -99,7 +102,7 @@ void test_linear()
|
||||
y_copy = y;
|
||||
// Test endpoint derivatives:
|
||||
pchip_spline = pchip(std::move(x_copy), std::move(y_copy), Real(1), Real(1));
|
||||
for (Real t = 0; t < x.back(); t += 0.5) {
|
||||
for (Real t = 0; t < x.back(); t += Real(0.5)) {
|
||||
CHECK_ULP_CLOSE(t, pchip_spline(t), 0);
|
||||
CHECK_ULP_CLOSE(Real(1), pchip_spline.prime(t), 0);
|
||||
}
|
||||
@ -117,7 +120,7 @@ void test_linear()
|
||||
|
||||
auto circular_pchip_spline = pchip(std::move(x_buf), std::move(y_buf));
|
||||
|
||||
for (Real t = x[0]; t <= x.back(); t += 0.25) {
|
||||
for (Real t = x[0]; t <= x.back(); t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(t, circular_pchip_spline(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), circular_pchip_spline.prime(t), 2);
|
||||
}
|
||||
@ -230,25 +233,40 @@ void test_monotonicity()
|
||||
int main()
|
||||
{
|
||||
#if (__GNUC__ > 7) || defined(_MSC_VER) || defined(__clang__)
|
||||
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_constant<std::float32_t>();
|
||||
test_linear<std::float32_t>();
|
||||
test_interpolation_condition<std::float32_t>();
|
||||
test_monotonicity<std::float32_t>();
|
||||
#else
|
||||
test_constant<float>();
|
||||
test_linear<float>();
|
||||
test_interpolation_condition<float>();
|
||||
test_monotonicity<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_interpolation_condition<std::float64_t>();
|
||||
test_monotonicity<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
test_interpolation_condition<double>();
|
||||
test_monotonicity<double>();
|
||||
#endif
|
||||
|
||||
test_constant<long double>();
|
||||
test_linear<long double>();
|
||||
test_interpolation_condition<long double>();
|
||||
test_monotonicity<long double>();
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
test_constant<float128>();
|
||||
test_linear<float128>();
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
@ -20,6 +20,9 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::quintic_hermite;
|
||||
using boost::math::interpolators::cardinal_quintic_hermite;
|
||||
@ -38,7 +41,7 @@ void test_constant()
|
||||
}
|
||||
|
||||
auto qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
for (Real t = 0; t <= 81; t += 0.25)
|
||||
for (Real t = 0; t <= 81; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(7), qh(t), 24);
|
||||
CHECK_ULP_CLOSE(Real(0), qh.prime(t), 24);
|
||||
@ -57,7 +60,7 @@ void test_linear()
|
||||
|
||||
auto qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.25)
|
||||
for (Real t = 0; t <= 9; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(t), qh(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), qh.prime(t), 2);
|
||||
@ -65,7 +68,7 @@ void test_linear()
|
||||
}
|
||||
|
||||
boost::random::mt19937 rng;
|
||||
boost::random::uniform_real_distribution<Real> dis(0.5,1);
|
||||
boost::random::uniform_real_distribution<Real> dis(Real(0.5), Real(1));
|
||||
x.resize(512);
|
||||
x[0] = dis(rng);
|
||||
Real xmin = x[0];
|
||||
@ -81,7 +84,7 @@ void test_linear()
|
||||
|
||||
qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
|
||||
for (Real t = xmin; t <= xmax; t += 0.125)
|
||||
for (Real t = xmin; t <= xmax; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t, qh(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), qh.prime(t), 100);
|
||||
@ -109,7 +112,7 @@ void test_quadratic()
|
||||
|
||||
auto qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.0078125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(t*t)/2, qh(t), 2);
|
||||
CHECK_ULP_CLOSE(t, qh.prime(t), 12);
|
||||
@ -117,7 +120,7 @@ void test_quadratic()
|
||||
}
|
||||
|
||||
boost::random::mt19937 rng;
|
||||
boost::random::uniform_real_distribution<Real> dis(0.5,1);
|
||||
boost::random::uniform_real_distribution<Real> dis(Real(0.5), Real(1));
|
||||
x.resize(8);
|
||||
x[0] = dis(rng);
|
||||
Real xmin = x[0];
|
||||
@ -143,7 +146,7 @@ void test_quadratic()
|
||||
|
||||
qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
|
||||
for (Real t = xmin; t <= xmax; t += 0.125)
|
||||
for (Real t = xmin; t <= xmax; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(t*t)/2, qh(t), 4);
|
||||
CHECK_ULP_CLOSE(t, qh.prime(t), 53);
|
||||
@ -175,7 +178,7 @@ void test_cubic()
|
||||
|
||||
auto qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.0078125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t, qh(t), 10);
|
||||
CHECK_ULP_CLOSE(3*t*t, qh.prime(t), 15);
|
||||
@ -208,7 +211,7 @@ void test_quartic()
|
||||
|
||||
auto qh = quintic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2));
|
||||
|
||||
for (Real t = 1; t <= 11; t += 0.0078125)
|
||||
for (Real t = 1; t <= 11; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t*t, qh(t), 100);
|
||||
CHECK_ULP_CLOSE(4*t*t*t, qh.prime(t), 100);
|
||||
@ -266,7 +269,7 @@ void test_cardinal_constant()
|
||||
|
||||
auto qh = cardinal_quintic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx);
|
||||
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += 0.25)
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(7), qh(t), 24);
|
||||
CHECK_ULP_CLOSE(Real(0), qh.prime(t), 24);
|
||||
@ -282,7 +285,7 @@ void test_cardinal_constant()
|
||||
}
|
||||
|
||||
auto qh_aos = cardinal_quintic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += 0.25)
|
||||
for (Real t = x0; t <= x0 + 24*dx; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(7), qh_aos(t), 24);
|
||||
CHECK_ULP_CLOSE(Real(0), qh_aos.prime(t), 24);
|
||||
@ -321,7 +324,7 @@ void test_cardinal_linear()
|
||||
|
||||
auto qh = cardinal_quintic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.25) {
|
||||
for (Real t = 0; t <= 9; t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(t), qh(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), qh.prime(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), qh.double_prime(t), 2);
|
||||
@ -336,7 +339,7 @@ void test_cardinal_linear()
|
||||
|
||||
auto qh_aos = cardinal_quintic_hermite_aos(std::move(data), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.25) {
|
||||
for (Real t = 0; t <= 9; t += Real(0.25)) {
|
||||
CHECK_ULP_CLOSE(Real(t), qh_aos(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), qh_aos.prime(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(0), qh_aos.double_prime(t), 2);
|
||||
@ -382,7 +385,7 @@ void test_cardinal_quadratic()
|
||||
|
||||
auto qh = cardinal_quintic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.0078125) {
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125)) {
|
||||
Real computed = qh(t);
|
||||
CHECK_ULP_CLOSE(Real(t*t)/2, computed, 2);
|
||||
CHECK_ULP_CLOSE(t, qh.prime(t), 15);
|
||||
@ -397,7 +400,7 @@ void test_cardinal_quadratic()
|
||||
}
|
||||
auto qh_aos = cardinal_quintic_hermite_aos(std::move(data), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.0078125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125))
|
||||
{
|
||||
Real computed = qh_aos(t);
|
||||
CHECK_ULP_CLOSE(Real(t*t)/2, computed, 2);
|
||||
@ -448,7 +451,7 @@ void test_cardinal_cubic()
|
||||
|
||||
auto qh = cardinal_quintic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.0078125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125))
|
||||
{
|
||||
Real computed = qh(t);
|
||||
CHECK_ULP_CLOSE(t*t*t, computed, 10);
|
||||
@ -464,7 +467,7 @@ void test_cardinal_cubic()
|
||||
}
|
||||
|
||||
auto qh_aos = cardinal_quintic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = 0; t <= 9; t += 0.0078125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125))
|
||||
{
|
||||
Real computed = qh_aos(t);
|
||||
CHECK_ULP_CLOSE(t*t*t, computed, 10);
|
||||
@ -496,7 +499,7 @@ void test_cardinal_quartic()
|
||||
|
||||
auto qh = cardinal_quintic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= 6; t += 0.0078125)
|
||||
for (Real t = 0; t <= 6; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(t*t*t*t), qh(t), 250);
|
||||
CHECK_ULP_CLOSE(4*t*t*t, qh.prime(t), 250);
|
||||
@ -511,7 +514,7 @@ void test_cardinal_quartic()
|
||||
}
|
||||
|
||||
auto qh_aos = cardinal_quintic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = 0; t <= 6; t += 0.0078125)
|
||||
for (Real t = 0; t <= 6; t += Real(0.0078125))
|
||||
{
|
||||
Real computed = qh_aos(t);
|
||||
CHECK_ULP_CLOSE(t*t*t*t, computed, 10);
|
||||
@ -523,6 +526,20 @@ void test_cardinal_quartic()
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_constant<std::float32_t>();
|
||||
test_linear<std::float32_t>();
|
||||
test_quadratic<std::float32_t>();
|
||||
test_cubic<std::float32_t>();
|
||||
test_quartic<std::float32_t>();
|
||||
test_interpolation_condition<std::float32_t>();
|
||||
|
||||
test_cardinal_constant<std::float32_t>();
|
||||
test_cardinal_linear<std::float32_t>();
|
||||
test_cardinal_quadratic<std::float32_t>();
|
||||
test_cardinal_cubic<std::float32_t>();
|
||||
test_cardinal_quartic<std::float32_t>();
|
||||
#else
|
||||
test_constant<float>();
|
||||
test_linear<float>();
|
||||
test_quadratic<float>();
|
||||
@ -535,7 +552,22 @@ int main()
|
||||
test_cardinal_quadratic<float>();
|
||||
test_cardinal_cubic<float>();
|
||||
test_cardinal_quartic<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_quadratic<std::float64_t>();
|
||||
test_cubic<std::float64_t>();
|
||||
test_quartic<std::float64_t>();
|
||||
test_interpolation_condition<std::float64_t>();
|
||||
|
||||
test_cardinal_constant<std::float64_t>();
|
||||
test_cardinal_linear<std::float64_t>();
|
||||
test_cardinal_quadratic<std::float64_t>();
|
||||
test_cardinal_cubic<std::float64_t>();
|
||||
test_cardinal_quartic<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
test_quadratic<double>();
|
||||
@ -548,6 +580,7 @@ int main()
|
||||
test_cardinal_quadratic<double>();
|
||||
test_cardinal_cubic<double>();
|
||||
test_cardinal_quartic<double>();
|
||||
#endif
|
||||
|
||||
test_constant<long double>();
|
||||
test_linear<long double>();
|
||||
@ -562,7 +595,7 @@ int main()
|
||||
test_cardinal_cubic<long double>();
|
||||
test_cardinal_quartic<long double>();
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
test_constant<float128>();
|
||||
//test_linear<float128>();
|
||||
test_quadratic<float128>();
|
||||
@ -574,7 +607,7 @@ int main()
|
||||
test_cardinal_quadratic<float128>();
|
||||
test_cardinal_cubic<float128>();
|
||||
test_cardinal_quartic<float128>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
@ -18,6 +18,9 @@
|
||||
using boost::multiprecision::float128;
|
||||
#endif
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
# include <stdfloat>
|
||||
#endif
|
||||
|
||||
using boost::math::interpolators::septic_hermite;
|
||||
using boost::math::interpolators::cardinal_septic_hermite;
|
||||
@ -39,7 +42,7 @@ void test_constant()
|
||||
|
||||
auto sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = 0; t <= 81; t += 0.25)
|
||||
for (Real t = 0; t <= 81; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(7), sh(t), 24);
|
||||
CHECK_ULP_CLOSE(Real(0), sh.prime(t), 24);
|
||||
@ -52,7 +55,7 @@ void test_constant()
|
||||
d2ydx2.resize(128, 0);
|
||||
d3ydx3.resize(128, 0);
|
||||
auto csh = cardinal_septic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3), x0, dx);
|
||||
for (Real t = x0; t <= 127; t += 0.25)
|
||||
for (Real t = x0; t <= 127; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(7), csh(t), 24);
|
||||
CHECK_ULP_CLOSE(Real(0), csh.prime(t), 24);
|
||||
@ -68,7 +71,7 @@ void test_constant()
|
||||
data[i][3] = 0;
|
||||
}
|
||||
auto csh_aos = cardinal_septic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = x0; t <= 127; t += 0.25)
|
||||
for (Real t = x0; t <= 127; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(7), csh_aos(t), 24);
|
||||
CHECK_ULP_CLOSE(Real(0), csh_aos.prime(t), 24);
|
||||
@ -112,14 +115,14 @@ void test_linear()
|
||||
|
||||
auto sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.25)
|
||||
for (Real t = 0; t <= 9; t += Real(0.25))
|
||||
{
|
||||
CHECK_ULP_CLOSE(Real(t), sh(t), 2);
|
||||
CHECK_ULP_CLOSE(Real(1), sh.prime(t), 2);
|
||||
}
|
||||
|
||||
boost::random::mt19937 rng;
|
||||
boost::random::uniform_real_distribution<Real> dis(0.5,1);
|
||||
boost::random::uniform_real_distribution<Real> dis(Real(0.5), Real(1));
|
||||
x.resize(512);
|
||||
x[0] = dis(rng);
|
||||
Real xmin = x[0];
|
||||
@ -136,7 +139,7 @@ void test_linear()
|
||||
|
||||
sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = xmin; t <= xmax; t += 0.125)
|
||||
for (Real t = xmin; t <= xmax; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t, sh(t), 25);
|
||||
CHECK_ULP_CLOSE(Real(1), sh.prime(t), 850);
|
||||
@ -153,7 +156,7 @@ void test_linear()
|
||||
y[i] = i;
|
||||
}
|
||||
auto csh = cardinal_septic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3), x0, dx);
|
||||
for (Real t = 0; t <= 9; t += 0.125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t, csh(t), 15);
|
||||
CHECK_ULP_CLOSE(Real(1), csh.prime(t), 15);
|
||||
@ -169,7 +172,7 @@ void test_linear()
|
||||
data[i][3] = 0;
|
||||
}
|
||||
auto csh_aos = cardinal_septic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = 0; t <= 9; t += 0.125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t, csh_aos(t), 15);
|
||||
CHECK_ULP_CLOSE(Real(1), csh_aos.prime(t), 15);
|
||||
@ -222,14 +225,14 @@ void test_quadratic()
|
||||
|
||||
auto sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = 0; t <= 9; t += 0.0078125)
|
||||
for (Real t = 0; t <= 9; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, sh(t), 100);
|
||||
CHECK_ULP_CLOSE(t, sh.prime(t), 32);
|
||||
}
|
||||
|
||||
boost::random::mt19937 rng;
|
||||
boost::random::uniform_real_distribution<Real> dis(0.5,1);
|
||||
boost::random::uniform_real_distribution<Real> dis(Real(0.5), Real(1));
|
||||
x.resize(8);
|
||||
x[0] = dis(rng);
|
||||
Real xmin = x[0];
|
||||
@ -256,7 +259,7 @@ void test_quadratic()
|
||||
|
||||
sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = xmin; t <= xmax; t += 0.125)
|
||||
for (Real t = xmin; t <= xmax; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, sh(t), 50);
|
||||
CHECK_ULP_CLOSE(t, sh.prime(t), 300);
|
||||
@ -280,7 +283,7 @@ void test_quadratic()
|
||||
Real x0 = 0;
|
||||
Real dx = 1;
|
||||
auto csh = cardinal_septic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3), x0, dx);
|
||||
for (Real t = x0; t <= 9; t += 0.125)
|
||||
for (Real t = x0; t <= 9; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, csh(t), 24);
|
||||
CHECK_ULP_CLOSE(t, csh.prime(t), 24);
|
||||
@ -296,7 +299,7 @@ void test_quadratic()
|
||||
data[i][3] = 0;
|
||||
}
|
||||
auto csh_aos = cardinal_septic_hermite_aos(std::move(data), x0, dx);
|
||||
for (Real t = x0; t <= 9; t += 0.125)
|
||||
for (Real t = x0; t <= 9; t += Real(0.125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t/2, csh_aos(t), 24);
|
||||
CHECK_ULP_CLOSE(t, csh_aos.prime(t), 24);
|
||||
@ -333,7 +336,7 @@ void test_cubic()
|
||||
|
||||
auto sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = 0; t <= xmax; t += 0.0078125)
|
||||
for (Real t = 0; t <= xmax; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t, sh(t), 151);
|
||||
CHECK_ULP_CLOSE(3*t*t, sh.prime(t), 151);
|
||||
@ -354,7 +357,7 @@ void test_cubic()
|
||||
|
||||
auto csh = cardinal_septic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= xmax; t += 0.0078125)
|
||||
for (Real t = 0; t <= xmax; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t, csh(t), 151);
|
||||
CHECK_ULP_CLOSE(3*t*t, csh.prime(t), 151);
|
||||
@ -371,7 +374,7 @@ void test_cubic()
|
||||
|
||||
auto csh_aos = cardinal_septic_hermite_aos(std::move(data), x0, dx);
|
||||
|
||||
for (Real t = 0; t <= xmax; t += 0.0078125)
|
||||
for (Real t = 0; t <= xmax; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t, csh_aos(t), 151);
|
||||
CHECK_ULP_CLOSE(3*t*t, csh_aos.prime(t), 151);
|
||||
@ -411,7 +414,7 @@ void test_quartic()
|
||||
|
||||
auto sh = septic_hermite(std::move(x), std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3));
|
||||
|
||||
for (Real t = 1; t <= xmax; t += 0.0078125) {
|
||||
for (Real t = 1; t <= xmax; t += Real(0.0078125)) {
|
||||
CHECK_ULP_CLOSE(t*t*t*t, sh(t), 117);
|
||||
CHECK_ULP_CLOSE(4*t*t*t, sh.prime(t), 117);
|
||||
}
|
||||
@ -430,7 +433,7 @@ void test_quartic()
|
||||
|
||||
auto csh = cardinal_septic_hermite(std::move(y), std::move(dydx), std::move(d2ydx2), std::move(d3ydx3), Real(0), Real(1));
|
||||
|
||||
for (Real t = 1; t <= xmax; t += 0.0078125)
|
||||
for (Real t = 1; t <= xmax; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t*t, csh(t), 117);
|
||||
CHECK_ULP_CLOSE(4*t*t*t, csh.prime(t), 117);
|
||||
@ -447,7 +450,7 @@ void test_quartic()
|
||||
}
|
||||
|
||||
auto csh_aos = cardinal_septic_hermite_aos(std::move(data), Real(0), Real(1));
|
||||
for (Real t = 1; t <= xmax; t += 0.0078125)
|
||||
for (Real t = 1; t <= xmax; t += Real(0.0078125))
|
||||
{
|
||||
CHECK_ULP_CLOSE(t*t*t*t, csh_aos(t), 117);
|
||||
CHECK_ULP_CLOSE(4*t*t*t, csh_aos.prime(t), 117);
|
||||
@ -496,19 +499,37 @@ void test_interpolation_condition()
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef __STDCPP_FLOAT32_T__
|
||||
test_constant<std::float32_t>();
|
||||
test_linear<std::float32_t>();
|
||||
test_quadratic<std::float32_t>();
|
||||
test_cubic<std::float32_t>();
|
||||
test_quartic<std::float32_t>();
|
||||
test_interpolation_condition<std::float32_t>();
|
||||
#else
|
||||
test_constant<float>();
|
||||
test_linear<float>();
|
||||
test_quadratic<float>();
|
||||
test_cubic<float>();
|
||||
test_quartic<float>();
|
||||
test_interpolation_condition<float>();
|
||||
#endif
|
||||
|
||||
#ifdef __STDCPP_FLOAT64_T__
|
||||
test_constant<std::float64_t>();
|
||||
test_linear<std::float64_t>();
|
||||
test_quadratic<std::float64_t>();
|
||||
test_cubic<std::float64_t>();
|
||||
test_quartic<std::float64_t>();
|
||||
test_interpolation_condition<std::float64_t>();
|
||||
#else
|
||||
test_constant<double>();
|
||||
test_linear<double>();
|
||||
test_quadratic<double>();
|
||||
test_cubic<double>();
|
||||
test_quartic<double>();
|
||||
test_interpolation_condition<double>();
|
||||
#endif
|
||||
|
||||
test_constant<long double>();
|
||||
test_linear<long double>();
|
||||
@ -517,14 +538,14 @@ int main()
|
||||
test_quartic<long double>();
|
||||
test_interpolation_condition<long double>();
|
||||
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
#ifdef BOOST_HAS_FLOAT128
|
||||
test_constant<float128>();
|
||||
test_linear<float128>();
|
||||
test_quadratic<float128>();
|
||||
test_cubic<float128>();
|
||||
test_quartic<float128>();
|
||||
test_interpolation_condition<float128>();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return boost::math::test::report_errors();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user