Source code for mpt4py.tolerances
# Define various numerican tolerances for mpt4py
tolerances = {
'zero': 1e-8, # A value it considered zero if it is less than this value
'zero_normal': 1e-6, # A normal vector is considered zero if its norm is less than this value
'redundancy_elimination': 1e-6, # The support of a hyperplane is considered redundant if its offset is less than this value
'affine_hull': 1e-8, # Singular values less than this amount are considered zero when computing the affine hull
}
[docs]
def print_tolerances():
"""
Print all current tolerance values.
"""
print("Tolerances:")
print(f"{'Name':<25}{'Value':<15}")
print("-" * 38)
for name, value in tolerances.items():
print(f"{name:<25}{value:<15.6e}")
[docs]
def set_tolerance(name: str, value: float):
"""
Modify a tolerance at runtime.
"""
if name in tolerances:
tolerances[name] = value
else:
raise KeyError(f"Unknown tolerance: {name}.")
[docs]
def get_tolerance(name: str):
"""
Retrieve a tolerance value.
"""
if name in tolerances:
return tolerances.get(name)
else:
raise KeyError(f"Unknown tolerance: {name}.")