diff --git a/src/pymatlib/core/data_handler.py b/src/pymatlib/core/data_handler.py index 5cc11528e9fb1a63e5f398daf15a3effe7457128..3cfa095350dfcd312cfd31e2b8ce5d1b3d95f873 100644 --- a/src/pymatlib/core/data_handler.py +++ b/src/pymatlib/core/data_handler.py @@ -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