Chebyshev
Unit testing for scientific software
chebyshev::prec Namespace Reference

Precision testing module. More...

Namespaces

 distance
 Distance functions for use in prec::equals.
 
 estimator
 Precision estimators.
 
 fail
 Fail functions for use in prec::estimate.
 
 property
 Property testing of functions.
 

Classes

class  interval
 An interval on the real numbers. More...
 
class  estimate_result
 A structure holding the result of precision estimation. More...
 
class  estimate_options
 A structure holding the options for precision estimation. More...
 
class  equation_result
 A structure holding the result of an evaluation. More...
 
class  equation_options
 Structure holding options for equivalence evaluation. More...
 
class  prec_settings
 of the precision testing module. More...
 
class  prec_results
 of the precision testing module. More...
 

Typedefs

using FailFunction = std::function< bool(const estimate_result &)>
 A function which determines whether an estimation failed.
 
template<typename Type >
using DistanceFunction = std::function< long double(Type, Type)>
 Distance function between two elements.
 
template<typename R , typename ... Args>
using Estimator = typename estimate_options< R, Args... >::Estimator_t
 Generic precision estimator function signature.
 

Functions

void setup (std::string moduleName, int argc=0, const char **argv=nullptr)
 Setup the precision testing environment. More...
 
void terminate (bool exit=true)
 Terminate the precision testing environment, printing the results to standard output and output files. More...
 
template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void estimate (const std::string &name, Function1 funcApprox, Function2 funcExpected, estimate_options< R, Args... > opt)
 Estimate error integrals over a function with respect to an exact function, with the given options. More...
 
template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void estimate (const std::string &name, Function1 funcApprox, Function2 funcExpected, std::vector< interval > domain, long double tolerance, unsigned int iterations, FailFunction fail, Estimator< R, Args... > estimator, bool quiet=false)
 Estimate error integrals over a function with respect to an exact function. More...
 
void estimate (const std::string &name, EndoFunction< double > funcApprox, EndoFunction< double > funcExpected, interval domain, long double tolerance=settings.defaultTolerance, unsigned int iterations=settings.defaultIterations, FailFunction fail=fail::fail_on_max_err(), Estimator< double, double > estimator=estimator::quadrature1D< double >(), bool quiet=false)
 Estimate error integrals over a real function of real variable, with respect to an exact function. More...
 
template<typename T = double>
void equals (const std::string &name, const T &evaluated, const T &expected, equation_options< T > opt=equation_options< T >())
 Test an equivalence up to a tolerance, with the given options (e.g. More...
 
template<typename T = double>
void equals (const std::string &name, const T &evaluated, const T &expected, long double tolerance, DistanceFunction< T > distance, bool quiet=false)
 Test an equivalence up to a tolerance, with the given options (e.g. More...
 
void equals (const std::string &name, long double evaluated, long double expected, long double tolerance=settings.defaultTolerance, bool quiet=false)
 Test an equivalence up to a tolerance, with the given options (e.g. More...
 
template<typename T >
void equals (const std::string &name, std::vector< std::array< T, 2 >> values, long double tolerance=settings.defaultTolerance, bool quiet=false)
 Evaluate multiple pairs of values for equivalence up to the given tolerance (e.g. More...
 

Variables

struct chebyshev::prec::prec_settings settings
 
struct chebyshev::prec::prec_results results
 

Detailed Description

Precision testing module.

This module provides functions to estimate the precision and accuracy of mathematical approximations, over an entire domain using prec::estimate or at single points using prec:equals. For estimates over a domain, precision estimators are used.

Function Documentation

◆ equals() [1/4]

template<typename T = double>
void chebyshev::prec::equals ( const std::string &  name,
const T &  evaluated,
const T &  expected,
equation_options< T >  opt = equation_options<T>() 
)
inline

Test an equivalence up to a tolerance, with the given options (e.g.

for residual testing).

Parameters
nameThe name of the test case
evaluateThe evaluated value
expectedThe expected value
optThe options for the evaluation

◆ equals() [2/4]

template<typename T = double>
void chebyshev::prec::equals ( const std::string &  name,
const T &  evaluated,
const T &  expected,
long double  tolerance,
DistanceFunction< T >  distance,
bool  quiet = false 
)
inline

Test an equivalence up to a tolerance, with the given options (e.g.

for residual testing).

Parameters
nameThe name of the test case
evaluateThe evaluated value
expectedThe expected value
distanceThe distance function to use
toleranceThe tolerance for the evaluation
quietWhether to output the result

◆ equals() [3/4]

void chebyshev::prec::equals ( const std::string &  name,
long double  evaluated,
long double  expected,
long double  tolerance = settings.defaultTolerance,
bool  quiet = false 
)
inline

Test an equivalence up to a tolerance, with the given options (e.g.

for residual testing).

Parameters
nameThe name of the test case
evaluateThe evaluated value
expectedThe expected value
toleranceThe tolerance for the evaluation
quietWhether to output the result

◆ equals() [4/4]

template<typename T >
void chebyshev::prec::equals ( const std::string &  name,
std::vector< std::array< T, 2 >>  values,
long double  tolerance = settings.defaultTolerance,
bool  quiet = false 
)
inline

Evaluate multiple pairs of values for equivalence up to the given tolerance (e.g.

for residual testing).

Parameters
nameThe name of the function or test case
valuesA list of values to equate
toleranceThe tolerance for the evaluation
quietWhether to output the result

◆ estimate() [1/3]

void chebyshev::prec::estimate ( const std::string &  name,
EndoFunction< double >  funcApprox,
EndoFunction< double >  funcExpected,
interval  domain,
long double  tolerance = settings.defaultTolerance,
unsigned int  iterations = settings.defaultIterations,
FailFunction  fail = fail::fail_on_max_err(),
Estimator< double, double >  estimator = estimator::quadrature1D<double>(),
bool  quiet = false 
)
inline

Estimate error integrals over a real function of real variable, with respect to an exact function.

Parameters
nameThe name of the test case.
funcApproxThe approximation to test.
funcExpectedThe expected result.
intervalsThe (potentially multidimensional) domain of estimation.
iterationsThe number of function evaluations.
failThe fail function to determine whether the test failed (defaults to fail_on_max_err).
estimatorThe precision estimator to use (defaults to the trapezoid<double> estimator).
quietWhether to output the result.

◆ estimate() [2/3]

template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void chebyshev::prec::estimate ( const std::string &  name,
Function1  funcApprox,
Function2  funcExpected,
estimate_options< R, Args... >  opt 
)
inline

Estimate error integrals over a function with respect to an exact function, with the given options.

Parameters
nameThe name of the test case
funcApproxThe approximation to test
funcExpectedThe expected result
optThe options for the estimation

◆ estimate() [3/3]

template<typename R , typename ... Args, typename Function1 = std::function<R(Args...)>, typename Function2 = Function1>
void chebyshev::prec::estimate ( const std::string &  name,
Function1  funcApprox,
Function2  funcExpected,
std::vector< interval domain,
long double  tolerance,
unsigned int  iterations,
FailFunction  fail,
Estimator< R, Args... >  estimator,
bool  quiet = false 
)
inline

Estimate error integrals over a function with respect to an exact function.

Parameters
nameThe name of the test case.
funcApproxThe approximation to test.
funcExpectedThe expected result.
intervalsThe (potentially multidimensional) domain of estimation.
iterationsThe number of function evaluations.
failThe fail function to determine whether the test failed.
estimatorThe precision estimator to use.
quietWhether to output the result.

◆ setup()

void chebyshev::prec::setup ( std::string  moduleName,
int  argc = 0,
const char **  argv = nullptr 
)
inline

Setup the precision testing environment.

Parameters
moduleNameName of the module under test.
argcThe number of command line arguments
argvA list of C-style strings containing the command line arguments.

◆ terminate()

void chebyshev::prec::terminate ( bool  exit = true)
inline

Terminate the precision testing environment, printing the results to standard output and output files.

Parameters
exitWhether to exit after terminating the module.