From 5fc900c628ac84b8d7e8353e93c972f393653808 Mon Sep 17 00:00:00 2001
From: cmoineau <cyril.moineau@cea.fr>
Date: Fri, 22 Sep 2023 15:36:58 +0000
Subject: [PATCH] [approxEq] Check range for relative and absolute parameters.

---
 include/aidge/utils/TensorUtils.hpp         | 7 +++++--
 python_binding/utils/pybind_TensorUtils.cpp | 4 ++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/aidge/utils/TensorUtils.hpp b/include/aidge/utils/TensorUtils.hpp
index ef8883fe4..638761954 100644
--- a/include/aidge/utils/TensorUtils.hpp
+++ b/include/aidge/utils/TensorUtils.hpp
@@ -27,14 +27,17 @@
  * @tparam T should correspond to the type of the tensor, define the type of the absolute and relative error
  * @param t1  first :cpp:class:`Aidge::Tensor` to test
  * @param t2  second :cpp:class:`Aidge::Tensor` to test
- * @param relative relative difference allowed
- * @param absolute absolute error allowed
+ * @param relative relative difference allowed (should be betwen 0 and 1)
+ * @param absolute absolute error allowed (shoulmd be positive)
  * @return true if both tensor are approximately equal and have the datatype, shape. Else return false
  */
 template <typename T>
 bool approxEq(Aidge::Tensor t1, Aidge::Tensor t2, float relative, float absolute){
     assert(t1.dataType() == t2.dataType());
     assert(t1.dataType() == NativeType<T>::type);
+    assert(relative >= 0);
+    assert(absolute >= 0 && absolute<=1);
+
     if (t1.size() != t2.size()){
         return false;
     }
diff --git a/python_binding/utils/pybind_TensorUtils.cpp b/python_binding/utils/pybind_TensorUtils.cpp
index 07dc7e932..78825a5f3 100644
--- a/python_binding/utils/pybind_TensorUtils.cpp
+++ b/python_binding/utils/pybind_TensorUtils.cpp
@@ -41,9 +41,9 @@ void addTensorUtilsFunction(py::module &m){
         :type t1: :py:class:`aidge_core.Tensor`
         :param t2: second tensor to test
         :type t2: :py:class:`aidge_core.Tensor`
-        :param relative: relative difference allowed
+        :param relative: relative difference allowed (should be betwen 0 and 1)
         :type relative: float
-        :param absolute: absolute error allowed
+        :param absolute: absolute error allowed (shoulmd be positive)
         :type absolute: float
         )mydelimiter");
 }
-- 
GitLab