Template Function utils::integrandScale
Defined in File MiscUtils.hpp
Function Documentation
-
template<class F>
auto utils::integrandScale(const F &f, const std::vector<double> &points) -> double A characteristic scale for a vector-valued integrand, from a few sample evaluations.
Dividing an integrand by this scale makes it dimensionless and puts its smallest nonzero elements at order unity, so that SimControls::intAbsTol(), times the integral of the weighting function over the integration range, is a meaningful absolute tolerance for every element – see minNonZeroMagnitude()’s own comment. The floor at 1e-300 times the largest magnitude only matters if the elements span more than 300 orders of magnitude (e.g. a subnormal entry alongside an ordinary one): it keeps the largest scaled element at most 1e300, so it never overflows, while the smallest stays representable for any span up to about 1e600 – beyond that (a subnormal alongside a value near the largest double) the smallest may underflow to 0, a negligible contribution in any case.
- Template Parameters:
F – A callable taking a double and returning a std::vector<double>
- Parameters:
f – The integrand
points – The points to evaluate f at
- Returns:
The smallest nonzero magnitude among every element of f(x), over every x in points, but at least 1e-300 times the largest; or 1 if all are zero