Chebyshev
Unit testing for scientific software
Loading...
Searching...
No Matches
prec_structures.h
Go to the documentation of this file.
1
5
6#ifndef CHEBYSHEV_PREC_STRUCTURES_H
7#define CHEBYSHEV_PREC_STRUCTURES_H
8
9#include <string>
10#include <vector>
11#include <functional>
12
13#include "../core/common.h"
14#include "./interval.h"
15#include "./distance.h"
16
17
18namespace chebyshev {
19
20 namespace prec {
21
22
26
28 std::string name = "unknown";
29
31 std::vector<interval> domain {};
32
34 long double tolerance = 0;
35
38
41
44
47
50
52 std::map<std::string, long double> additionalFields {};
53
55 bool failed = false;
56
58 bool quiet = false;
59
61 unsigned int iterations {0};
62 };
63
64
66 using FailFunction = std::function<bool(const estimate_result&)>;
67
68
70 template<typename Type>
71 using DistanceFunction = std::function<long double(Type, Type)>;
72
73
76 template<typename R, typename ...Args>
78
79 using Estimator_t = std::function<
81 std::function<R(Args...)>,
82 std::function<R(Args...)>,
84
86 std::vector<interval> domain {};
87
90 Estimator_t estimator = [](
91 std::function<R(Args...)> f1,
92 std::function<R(Args...)> f2,
94 return estimate_result();
95 };
96
99
102
106 return (r.maxErr > r.tolerance) || (r.maxErr != r.maxErr);
107 };
108
110 bool quiet = false;
111
112
117
118
124
125
131 Estimator_t estimator,
132 long double tolerance,
133 unsigned int iterations,
134 bool quiet = false)
137
138
142 estimate_options(std::vector<interval> omega, Estimator_t estimator)
144
149 std::vector<interval> omega,
150 Estimator_t estimator,
151 long double tolerance,
152 unsigned int iterations,
153 bool quiet = false)
156
157 };
158
159
161 template<typename R, typename ...Args>
162 using Estimator = typename estimate_options<R, Args...>::Estimator_t;
163
164
168
170 std::string name = "unknown";
171
174
177
180
183 std::map<std::string, long double> additionalFields {};
184
186 long double tolerance = 0;
187
189 bool failed = true;
190
192 bool quiet = false;
193 };
194
195
198 template<typename T>
200
203
207 const auto diff = x - y;
208 return (long double) (diff > 0 ? diff : -diff);
209 };
210
212 bool quiet = false;
213
214
217
218
222
223
228 };
229
230 }
231}
232
233#endif
#define CHEBYSHEV_PREC_ITER
Default number of function evaluations in precision testing.
Definition common.h:12
#define CHEBYSHEV_PREC_TOLERANCE
Default tolerance in precision testing.
Definition common.h:17
Distance functions.
Interval over the real numbers.
General namespace of the framework.
Definition benchmark.h:22
constexpr FloatType get_nan()
Get a quiet NaN of the specified floating point type.
Definition common.h:65
std::function< long double(Type, Type)> DistanceFunction
Distance function between two elements.
Definition prec_structures.h:71
std::function< bool(const estimate_result &)> FailFunction
A function which determines whether an estimation failed.
Definition prec_structures.h:66
typename estimate_options< R, Args... >::Estimator_t Estimator
Generic precision estimator function signature.
Definition prec_structures.h:162
Structure holding options for equivalence evaluation.
Definition prec_structures.h:199
bool quiet
Print to standard output or not.
Definition prec_structures.h:212
equation_options(long double tolerance, DistanceFunction< T > dist, bool quiet=false)
Construct equation options from the tolerance, the distance function and the quiet flag (defaults to ...
Definition prec_structures.h:226
long double tolerance
Tolerance on the absolute difference.
Definition prec_structures.h:202
equation_options()
Default constructor for equation options.
Definition prec_structures.h:216
DistanceFunction< T > distance
Distance function to measure the distance between the expected and evaluated value.
Definition prec_structures.h:206
equation_options(long double tolerance)
Construct equation options from the tolerance, setting the distance function to a simple Euclidean di...
Definition prec_structures.h:221
A structure holding the result of an evaluation.
Definition prec_structures.h:167
long double tolerance
Tolerance on the absolute difference.
Definition prec_structures.h:186
bool failed
Whether the test failed.
Definition prec_structures.h:189
bool quiet
Print to standard output or not.
Definition prec_structures.h:192
std::string name
Identifying name of the function or test case.
Definition prec_structures.h:170
long double difference
Evaluated difference between expected and evaluated values.
Definition prec_structures.h:179
std::map< std::string, long double > additionalFields
Additional fields by name, as a floating point value.
Definition prec_structures.h:183
long double evaluated
Evaluated value.
Definition prec_structures.h:173
long double expected
Expected value.
Definition prec_structures.h:176
A structure holding the options for precision estimation.
Definition prec_structures.h:77
FailFunction fail
The function to determine whether the test failed (defaults to fail::fail_on_max_err).
Definition prec_structures.h:105
estimate_options(interval omega, Estimator_t estimator, long double tolerance, unsigned int iterations, bool quiet=false)
Construct estimate options from a one-dimensional interval domain, an estimator, a tolerance and an o...
Definition prec_structures.h:129
unsigned int iterations
Number of function evaluations to use.
Definition prec_structures.h:101
estimate_options(interval omega, Estimator_t estimator)
Construct estimate options from a one-dimensional interval domain and an estimator,...
Definition prec_structures.h:122
estimate_options(std::vector< interval > omega, Estimator_t estimator)
Construct estimate options from a multidimensional interval domain and an estimator,...
Definition prec_structures.h:142
std::vector< interval > domain
The domain of estimation.
Definition prec_structures.h:86
Estimator_t estimator
The precision estimator to use (defaults to a dummy estimator)
Definition prec_structures.h:90
estimate_options(std::vector< interval > omega, Estimator_t estimator, long double tolerance, unsigned int iterations, bool quiet=false)
Construct estimate options from a multidimensional interval domain, an estimator, a tolerance and an ...
Definition prec_structures.h:148
long double tolerance
The tolerance to use to determine whether the test failed.
Definition prec_structures.h:98
bool quiet
Whether to show the test result or not.
Definition prec_structures.h:110
estimate_options()
Construct estimate options with all default values.
Definition prec_structures.h:116
A structure holding the result of precision estimation.
Definition prec_structures.h:25
std::string name
Identifying name of the function or test case.
Definition prec_structures.h:28
std::map< std::string, long double > additionalFields
Additional fields by name, as a floating point value.
Definition prec_structures.h:52
bool quiet
Print to standard output or not.
Definition prec_structures.h:58
long double meanErr
Estimated mean error on interval.
Definition prec_structures.h:40
long double relErr
Estimated relative error on interval.
Definition prec_structures.h:46
long double maxErr
Estimated maximum absolute error on interval.
Definition prec_structures.h:37
bool failed
Whether the test failed.
Definition prec_structures.h:55
std::vector< interval > domain
Interval of estimation.
Definition prec_structures.h:31
long double rmsErr
Estimated RMS error on interval.
Definition prec_structures.h:43
unsigned int iterations
Total number of iterations for integral quadrature.
Definition prec_structures.h:61
long double absErr
Estimated absolute error on interval.
Definition prec_structures.h:49
long double tolerance
Tolerance on the max absolute error.
Definition prec_structures.h:34
An interval on the real numbers.
Definition interval.h:16