49#include <vigra/multi_array.hxx>
50#include <vigra/accumulator.hxx>
51#include <vigra/multi_math.hxx>
64template <
typename T >
65double condense (
const T & t , std::true_type )
67 return std::abs ( t ) ;
70template <
typename T >
71double condense (
const T & t , std::false_type )
73 return sqrt ( sum ( t * t ) ) / t.size() ;
76template <
typename T >
77double condense (
const std::complex<T> & t , std::false_type )
79 return std::abs ( t ) ;
85 < std::is_fundamental < T > :: value ,
90template <
typename T >
96template <
int dim ,
typename T >
97double check_diff ( vigra::MultiArrayView < dim , T > & reference ,
98 vigra::MultiArrayView < dim , T > & candidate )
100 using namespace vigra::multi_math ;
101 using namespace vigra::acc;
103 assert ( reference.shape() == candidate.shape() ) ;
105 vigra::MultiArray < 1 , double >
106 error_array ( vigra::Shape1(reference.size() ) ) ;
108 for (
int i = 0 ; i < reference.size() ; i++ )
110 auto help = candidate[i] - reference[i] ;
113 error_array [ i ] =
condense ( help ) ;
116 AccumulatorChain < double , Select < Mean, Maximum > > ac ;
117 extractFeatures ( error_array.begin() , error_array.end() , ac ) ;
118 double mean = get<Mean>(ac) ;
119 double max = get<Maximum>(ac) ;
122 std::cout <<
"delta Mean: "
123 << mean << std::endl;
124 std::cout <<
"delta Maximum: "
141template <
int dim ,
typename T ,
typename math_ele_type >
void
146 typedef vigra::MultiArray < dim , T > array_type ;
149 vigra::TinyVector < vspline::bc_code , dim > bcv { bc } ;
155 std::random_device rd ;
156 std::mt19937 gen ( rd() ) ;
158 std::uniform_real_distribution<> dis ( -1.0 , 1.0 ) ;
159 for (
auto & e : bsp.
core )
162 array_type reference = bsp.
core ;
166 std::chrono::system_clock::time_point start
167 = std::chrono::system_clock::now() ;
169 for ( times = 0 ; times < 1000 ; )
172 vspline::restore < dim , T , math_ele_type > ( bsp ) ;
174 if ( times == 1 || times == 10 || times == 100 || times == 1000 )
176 std::cout <<
"after " << times
177 <<
" prefilter-restore cycles" << std::endl ;
178 double emax = check_diff < dim , T > ( reference , bsp.
core ) ;
183 <<
typeid(T()).name()
186 <<
" " << bsp.
core.shape()
188 <<
" DG " << spline_degree
191 << emax << std::endl ;
196 std::chrono::system_clock::time_point end
197 = std::chrono::system_clock::now() ;
199 std::cout <<
"average cycle duration: "
200 << std::chrono::duration_cast<std::chrono::milliseconds>
201 ( end - start ) . count() / float ( times )
202 <<
" ms" << std::endl ;
205 std::cout <<
"---------------------------------------------------" << std::endl ;
206 std::cout << std::endl ;
210int main (
int argc ,
char * argv[] )
214 std::cerr <<
"pass the spline degree as parameter" << std::endl ;
218 int degree = std::atoi ( argv[1] ) ;
220 std::cout <<
"performing arithmetics in single precision" << std::endl ;
221 grind_test < 2 , float , float > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
222 grind_test < 2 , double , float > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
223 grind_test < 2 , long double , float > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
224 std::cout <<
"performing arithmetics in double precision" << std::endl ;
225 grind_test < 2 , float , double > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
226 grind_test < 2 , double , double > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
227 grind_test < 2 , long double , double > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
228 std::cout <<
"performing arithmetics in long double precision" << std::endl ;
229 grind_test < 2 , float , long double > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
230 grind_test < 2 , double , long double > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
231 grind_test < 2 , long double , long double > ( { 1000 , 1000 } ,
vspline::PERIODIC , degree ) ;
vspline::bspline< pixel_type, 2 > spline_type
typename std::conditional< std::is_fundamental< T > ::value, std::true_type, std::false_type > ::type is_singular
int main(int argc, char *argv[])
void grind_test(vigra::TinyVector< int, dim > shape, vspline::bc_code bc, int spline_degree)
create an array of random data ditributed between -1 and 1. Then repeatedly prefilter and restore the...
double condense(const T &t, std::true_type)
double check_diff(vigra::MultiArrayView< dim, T > &reference, vigra::MultiArrayView< dim, T > &candidate)
const std::string bc_name[]
bc_name is for diagnostic output of bc codes
bc_code
This enumeration is used for codes connected to boundary conditions. There are two aspects to boundar...
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....
includes all headers from vspline (most of them indirectly)