vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
Classes | Typedefs | Functions | Variables
restore_test.cc File Reference
#include <vigra/multi_array.hxx>
#include <vigra/accumulator.hxx>
#include <vigra/multi_math.hxx>
#include <iostream>
#include <typeinfo>
#include <random>
#include <vspline/vspline.h>

Go to the source code of this file.

Classes

struct  test< dim, T >
 
struct  test< 0, T >
 
struct  multitest< dim, tuple_type, ntypes >
 
struct  multitest< dim, tuple_type, 0 >
 

Typedefs

template<class T >
using is_singular = typename std::conditional< std::is_fundamental< T > ::value, std::true_type, std::false_type > ::type
 

Functions

template<typename T >
double condense (const T &t, std::true_type)
 
template<typename T >
double condense (const T &t, std::false_type)
 
template<typename T >
double condense (const std::complex< T > &t, std::false_type)
 
template<typename T >
double condense (const T &t)
 
template<int dim, typename T >
double check_diff (vigra::MultiArrayView< dim, T > &reference, vigra::MultiArrayView< dim, T > &candidate)
 
template<int dim, typename T >
double restore_test (vigra::MultiArrayView< dim, T > &arr, vspline::bc_code bc, int spline_degree)
 do a restore test. This test fills the array that's passed in with small random data, constructs a b-spline with the requested parameters over the data, then calls vspline::restore(), which evaluates the spline at discrete locations. While this test fails to address several aspects (derivatives, behaviour at locations which aren't discrete), it does make sure that prefiltering has produced a correct result and reconstruction succeeds: If the spline coefficients were wrong, reconstruction would fail just as it would if the coefficients were right and the evaluation code was wrong. That both should be wrong and accidentally produce a correct result is highly unlikely. More...
 
template<class arr_t >
double view_test (arr_t &arr)
 
int main (int argc, char *argv[])
 

Variables

bool verbose = true
 restore_test - create b-splines from random data and restore the original data from the spline. This has grown to function as a unit test instantiating all sorts of splines and evaluators and using the evaluators with the functions in transform.h. More...
 
int d0 []
 
int d1 []
 
int d2 [] { 2 , 3 , 5 , 8 , 13 , 21 }
 
int d3 [] { 2 , 3 , 5 , 8 , 13 }
 
int * dext [] { d0 , d1 , d2 , d3 }
 
int dsz []
 

Typedef Documentation

◆ is_singular

template<class T >
using is_singular = typename std::conditional < std::is_fundamental < T > :: value , std::true_type , std::false_type > :: type

Definition at line 120 of file restore_test.cc.

Function Documentation

◆ check_diff()

template<int dim, typename T >
double check_diff ( vigra::MultiArrayView< dim, T > &  reference,
vigra::MultiArrayView< dim, T > &  candidate 
)

Definition at line 136 of file restore_test.cc.

◆ condense() [1/4]

template<typename T >
double condense ( const std::complex< T > &  t,
std::false_type   
)

Definition at line 114 of file restore_test.cc.

◆ condense() [2/4]

template<typename T >
double condense ( const T &  t)

Definition at line 128 of file restore_test.cc.

◆ condense() [3/4]

template<typename T >
double condense ( const T &  t,
std::false_type   
)

Definition at line 108 of file restore_test.cc.

◆ condense() [4/4]

template<typename T >
double condense ( const T &  t,
std::true_type   
)

Definition at line 102 of file restore_test.cc.

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 565 of file restore_test.cc.

◆ restore_test()

template<int dim, typename T >
double restore_test ( vigra::MultiArrayView< dim, T > &  arr,
vspline::bc_code  bc,
int  spline_degree 
)

do a restore test. This test fills the array that's passed in with small random data, constructs a b-spline with the requested parameters over the data, then calls vspline::restore(), which evaluates the spline at discrete locations. While this test fails to address several aspects (derivatives, behaviour at locations which aren't discrete), it does make sure that prefiltering has produced a correct result and reconstruction succeeds: If the spline coefficients were wrong, reconstruction would fail just as it would if the coefficients were right and the evaluation code was wrong. That both should be wrong and accidentally produce a correct result is highly unlikely.

This routine has grown to be more of a unit test for all of vspline, additional vspline functions are executed and the results are inspected. This way we can assure that the transform-type routines are usable with all supported data types and vectorized and unvectorized results are consistent.

Definition at line 187 of file restore_test.cc.

◆ view_test()

template<class arr_t >
double view_test ( arr_t &  arr)

Definition at line 453 of file restore_test.cc.

Variable Documentation

◆ d0

int d0[]
Initial value:
{ 1 , 2 , 3 , 5 , 8 , 13 , 16 , 21 ,
34 , 55 , 123 , 128 , 289 , 500 , 1031 ,
2001 , 4999 }

Definition at line 477 of file restore_test.cc.

◆ d1

int d1[]
Initial value:
{ 1 , 2 , 3 , 5 , 8 , 13 , 16 , 21 ,
34 , 89 , 160 , 713 }

Definition at line 480 of file restore_test.cc.

◆ d2

int d2[] { 2 , 3 , 5 , 8 , 13 , 21 }

Definition at line 482 of file restore_test.cc.

◆ d3

int d3[] { 2 , 3 , 5 , 8 , 13 }

Definition at line 483 of file restore_test.cc.

◆ dext

int* dext[] { d0 , d1 , d2 , d3 }

Definition at line 485 of file restore_test.cc.

◆ dsz

int dsz[]
Initial value:
{ sizeof(d0) / sizeof(int) ,
sizeof(d1) / sizeof(int) ,
sizeof(d2) / sizeof(int) ,
sizeof(d3) / sizeof(int) }
int d3[]
int d2[]
int d1[]
int d0[]

Definition at line 486 of file restore_test.cc.

◆ verbose

bool verbose = true

restore_test - create b-splines from random data and restore the original data from the spline. This has grown to function as a unit test instantiating all sorts of splines and evaluators and using the evaluators with the functions in transform.h.

Ideally, this test should result in restored data which are identical to the initial random data, but several factors come into play:

the precision of the coefficient calculation is parametrizable in vspline, via the 'tolerance' parameter, or, in some places, the 'horizon' parameter.

the data type of the spline is important - single precision data are unfit to produce coefficients capable of reproducing the data very precisely

the spline degree is important. High degrees need wide horizons, but wide horizons also need many calculation steps, which may introduce errors.

The dimension of the spline is also important. Since higher-dimension splines need more calculations for prefiltering and evaluation, results are less precise. This test program can test up to 4D.

Please note that, since this program uses a good many different data types and tries to test as much of vspline's code as possible, compile times may be very long, especially if the higher-D tests are not commented out.

With dimensions > 2 running this program in full takes a long time, since it tries to be comprehensive to catch any corner cases which might have escaped scrutiny. Run time of this program is not a very good indicator of vspline's speed, since many operations (like statistics, array copy operations) are neither multithreaded nor vectorized. For speed tests, 'roundtrip' or 'grind' are better.

A quick way to test is to run only the 1D tests and only look at the maximum error for each data type, like:

./hwy_restore_test_clang++ 1 | grep 'max err'

This should create output like:

test for type FfvE: max error = +0.000001370906829834 test for type FdvE: max error = +0.000000000000002887 test for type FevE: max error = +0.000000000000000001 test for type FSt7complexIfEvE: max error = +0.000001788139343262 test for type FSt7complexIdEvE: max error = +0.000000000000003442 test for type FSt7complexIeEvE: max error = +0.000000000000000002 test for type FN5vigra8RGBValueIfLj0ELj1ELj2EEEvE: max error = +0.000000963557215769 test for type FN5vigra8RGBValueIdLj0ELj1ELj2EEEvE: max error = +0.000000000000001859 test for type FN5vigra8RGBValueIeLj0ELj1ELj2EEEvE: max error = +0.000000000000000001 test for type FN5vigra10TinyVectorIfLi3EEEvE: max error = +0.000001170033762005 test for type FN5vigra10TinyVectorIdLi3EEEvE: max error = +0.000000000000001602 test for type FN5vigra10TinyVectorIeLi3EEEvE: max error = +0.000000000000000001 test for type FN5vigra10TinyVectorIfLi2EEEvE: max error = +0.000000927230667240 test for type FN5vigra10TinyVectorIdLi2EEEvE: max error = +0.000000000000002355 test for type FN5vigra10TinyVectorIfLi1EEEvE: max error = +0.000001609325408936 test for type FN5vigra10TinyVectorIdLi1EEEvE: max error = +0.000000000000002776

Definition at line 97 of file restore_test.cc.