Skip to content
Snippets Groups Projects
Commit 5fc900c6 authored by Cyril Moineau's avatar Cyril Moineau
Browse files

[approxEq] Check range for relative and absolute parameters.

parent 9cabcb41
No related branches found
No related tags found
No related merge requests found
...@@ -27,14 +27,17 @@ ...@@ -27,14 +27,17 @@
* @tparam T should correspond to the type of the tensor, define the type of the absolute and relative error * @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 t1 first :cpp:class:`Aidge::Tensor` to test
* @param t2 second :cpp:class:`Aidge::Tensor` to test * @param t2 second :cpp:class:`Aidge::Tensor` to test
* @param relative relative difference allowed * @param relative relative difference allowed (should be betwen 0 and 1)
* @param absolute absolute error allowed * @param absolute absolute error allowed (shoulmd be positive)
* @return true if both tensor are approximately equal and have the datatype, shape. Else return false * @return true if both tensor are approximately equal and have the datatype, shape. Else return false
*/ */
template <typename T> template <typename T>
bool approxEq(Aidge::Tensor t1, Aidge::Tensor t2, float relative, float absolute){ bool approxEq(Aidge::Tensor t1, Aidge::Tensor t2, float relative, float absolute){
assert(t1.dataType() == t2.dataType()); assert(t1.dataType() == t2.dataType());
assert(t1.dataType() == NativeType<T>::type); assert(t1.dataType() == NativeType<T>::type);
assert(relative >= 0);
assert(absolute >= 0 && absolute<=1);
if (t1.size() != t2.size()){ if (t1.size() != t2.size()){
return false; return false;
} }
......
...@@ -41,9 +41,9 @@ void addTensorUtilsFunction(py::module &m){ ...@@ -41,9 +41,9 @@ void addTensorUtilsFunction(py::module &m){
:type t1: :py:class:`aidge_core.Tensor` :type t1: :py:class:`aidge_core.Tensor`
:param t2: second tensor to test :param t2: second tensor to test
:type t2: :py:class:`aidge_core.Tensor` :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 :type relative: float
:param absolute: absolute error allowed :param absolute: absolute error allowed (shoulmd be positive)
:type absolute: float :type absolute: float
)mydelimiter"); )mydelimiter");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment