Skip to content
Snippets Groups Projects
Commit 13abde1e authored by Rahil Doshi's avatar Rahil Doshi
Browse files

Extend check_strictly_increasing with warning option instead of hard errors

parent 9d3da812
No related branches found
No related tags found
No related merge requests found
......@@ -276,18 +276,21 @@ def check_equidistant(temp: np.ndarray, rtol: float = 1e-5, atol: float = 1e-10)
return 0.0
def check_strictly_increasing(arr, name="Array", threshold=0.1):
def check_strictly_increasing(arr, name="Array", threshold=1e-10, raise_error=True):
"""
Check if array is strictly monotonically increasing and raise ValueError if not.
Check if array is strictly monotonically increasing.
Args:
arr: numpy array to check
name: name of array for reporting
threshold: minimum required difference between consecutive elements
raise_error: if True, raises ValueError; if False, returns False on failure
Returns:
bool: True if array is strictly increasing, False otherwise (if raise_error=False)
Raises:
ValueError: If array is not strictly increasing, with detailed information
about where the violation occurs
ValueError: If array is not strictly increasing and raise_error=True
"""
for i in range(1, len(arr)):
diff = arr[i] - arr[i-1]
......@@ -306,7 +309,13 @@ def check_strictly_increasing(arr, name="Array", threshold=0.1):
f"Difference: {diff:.10e}\n"
f"{context}"
)
raise ValueError(error_msg)
if raise_error:
raise ValueError(error_msg)
else:
print(f"Warning: {error_msg}")
return False
print(f"{name} is strictly monotonically increasing")
return True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment