numerics
Contains the tolerance checks that are required within numerics calculations with the
FLOAT_TOLERANCE
attribute alongside the ability to set your own global tolerance.
Tolerance Control
FLOAT_TOLERANCE
Global attribute of tolerance for toolbox
equal_within_tolerance
Function to check equality of two real numbers up to a tolerance
set_tolerance
Function used to set global tolerance
FLOAT_TOLERANCE = 1e-09
module-attribute
The default tolerance to use when testing for equality of real numbers.
equal_within_tolerance(x, y, rel_tol=None, abs_tol=None)
Test equality of two real numbers or sequences of real numbers up to a tolerance.
This function compares either two real numbers or two sequences of real numbers element-wise, determining if they are close within specified tolerances.
Parameters:
-
x
(Union[Real, Sequence[Real]]
) –Real numbers or sequences of real numbers to test equality of.
-
y
(Union[Real, Sequence[Real]]
) –Real numbers or sequences of real numbers to test equality of.
-
rel_tol
(Real
, default:None
) –The maximum allowed relative difference. Dynamically passed at runtime to allow for updating of FLOAT_TOLERANCE. Defaults to FLOAT_TOLERANCE (1e-9) if no change.
-
abs_tol
(Real
, default:None
) –The minimum permitted absolute difference. Dynamically passed at runtime to allow for updating of FLOAT_TOLERANCE. Defaults to FLOAT_TOLERANCE (1e-9) if no change.
Returns:
-
bool
–Whether the two numbers or sequences of numbers are equal up to the relative and absolute tolerances.
Source code in exauq/core/numerics.py
set_tolerance(tol)
Allows the updating of the global FLOAT_TOLERANCE from default (1e-9) to the tol value passed.
Parameters:
-
tol
(float
) –The new tolerance you wish to set the global FLOAT_TOLERANCE to.