From 13abde1e0464704eff0226d831b543372e217170 Mon Sep 17 00:00:00 2001
From: Rahil Doshi <rahil.doshi@fau.de>
Date: Fri, 28 Feb 2025 17:49:02 +0100
Subject: [PATCH] Extend check_strictly_increasing with warning option instead
 of hard errors

---
 src/pymatlib/core/data_handler.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/pymatlib/core/data_handler.py b/src/pymatlib/core/data_handler.py
index 5cc1152..3cfa095 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
 
-- 
GitLab