ddg.nonexact module
Module for global tolerance defaults and nonexact calculations.
Contains ways to set, get and reset the global tolerances and functions that use the global values as defaults.
- ddg.nonexact.get_tol_defaults()[source]
Get current global tolerance defaults.
- Returns:
- dict {‘atol’: float, ‘rtol’: float}
- ddg.nonexact.set_tol_defaults(atol=None, rtol=None)[source]
Set one or both global tolerance defaults.
- Parameters:
- atol, rtolfloat (default=None)
When None is given, the default will not be changed.
- ddg.nonexact.reset_tol_defaults()[source]
Reset global tolerance defaults to their original values.
- class ddg.nonexact.TolDefaults(atol=None, rtol=None)[source]
Bases:
objectContext manager to temporarily set global tolerances.
All alterations made to the tolerance defaults inside the context will be reset upon exiting it.
- Parameters:
- atol, rtolfloat (default=None)
Examples
>>> from ddg.nonexact import TolDefaults, get_tol_defaults >>> get_tol_defaults()["atol"] 1e-07 >>> with TolDefaults(atol=1e-5) as global_tols: ... get_tol_defaults()["atol"] == global_tols["atol"] == 1e-5 ... True >>> get_tol_defaults()["atol"] # Context has been exited 1e-07
global_tolsis the same asget_tol_defaultscalled right after entering the context.
- ddg.nonexact.isclose(a, b, rtol=None, atol=None, equal_nan=False)[source]
Wrapper for numpy.isclose that uses global tolerance defaults.
- ddg.nonexact.allclose(a, b, rtol=None, atol=None, equal_nan=False)[source]
Wrapper for numpy.allclose that uses global tolerance defaults.