63#include <vigra/multi_array.hxx>
64#include <vigra/accumulator.hxx>
65#include <vigra/multi_math.hxx>
69template <
class dtype >
81 std::random_device rd ;
82 std::mt19937 gen ( rd() ) ;
83 std::uniform_real_distribution<> dis ( -1.0 , 1.0 ) ;
103template <
class dtype >
114 vigra::MultiArray < 1 , dtype > data ( vigra::Shape1 ( 400 ) ) ;
116 for (
int i = 0 ; i < 400 ; i++ )
118 dtype x = ( i - 200 ) ;
127 auto ev = vspline::make_evaluator < decltype(bspl), dtype > ( bspl ) ;
132 std::random_device rd ;
133 std::mt19937 gen ( rd() ) ;
134 std::uniform_real_distribution<long double> dis ( -2.0 , 2.0 ) ;
136 long double signal = 0 ;
137 long double spline = 0 ;
138 long double noise = 0 ;
140 long double max_error = 0 ;
145 for (
int i = 0 ; i < 10000 ; i++ )
147 long double x = dis ( gen ) ;
148 long double p = rp (
dtype ( x ) ) ;
150 long double s = ev (
dtype ( x + 200 ) ) ;
151 error = std::fabs ( p - s ) ;
152 if ( error > max_error )
154 signal += std::fabs ( p ) ;
155 spline += std::fabs ( s ) ;
161 if ( std::isnan ( noise ) || std::isnan ( noise ) )
163 std::cout << type_name <<
" aborted due to numeric overflow" << std::endl ;
167 long double mean_error = noise / 10000.0L ;
171 std::cout << type_name
174 <<
" Maximum error: "
177 << int ( 20 * std::log10 ( signal / noise ) )
182int main (
int argc ,
char * argv[] )
184 std::cout << std::fixed << std::showpos << std::showpoint
185 << std::setprecision(18) ;
187 for (
int degree = 1 ; degree < 15 ; degree++ )
189 std::cout <<
"testing spline against polynomial, degree " << degree << std::endl ;
190 polynominal_test < float > ( degree ,
"using float........" ) ;
191 polynominal_test < double > ( degree ,
"using double......." ) ;
192 polynominal_test < long double > ( degree ,
"using long double.." ) ;
std::vector< dtype > coefficient
random_polynomial(int _degree)
dtype operator()(dtype x)
class bspline now builds on class bspline_base, adding coefficient storage, while bspline_base provid...
void prefilter(vspline::xlf_type boost=vspline::xlf_type(1), int njobs=vspline::default_njobs)
prefilter converts the knot point data in the 'core' area into b-spline coefficients....
int main(int argc, char *argv[])
void polynominal_test(int degree, const char *type_name)
includes all headers from vspline (most of them indirectly)