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

[approxEq] relactive and absolute T -> float.

parent f8a49175
No related branches found
No related tags found
1 merge request!9Fuse bn
Pipeline #31941 failed
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#ifndef AIDGE_CORE_UTILS_TENSOR_UTILS_H_ #ifndef AIDGE_CORE_UTILS_TENSOR_UTILS_H_
#define AIDGE_CORE_UTILS_TENSOR_UTILS_H_ #define AIDGE_CORE_UTILS_TENSOR_UTILS_H_
#include <cmath> // std::abs
#include "aidge/data/Tensor.hpp" #include "aidge/data/Tensor.hpp"
/** /**
...@@ -32,14 +32,14 @@ ...@@ -32,14 +32,14 @@
* @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, T relative, T 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);
if (t1.size() != t2.size()){ if (t1.size() != t2.size()){
return false; return false;
} }
for(size_t i; i < t1.size(); ++i){ for(size_t i; i < t1.size(); ++i){
if (abs(t1.get<T>(i) - t2.get<T>(i)) > (absolute + (relative * abs(t2.get<T>(i))))){ if (static_cast<float>(std::abs(t1.get<T>(i) - t2.get<T>(i))) > (absolute + (relative * static_cast<float>(std::abs(t2.get<T>(i)))))){
return false; return false;
} }
} }
......
...@@ -42,9 +42,9 @@ void addTensorUtilsFunction(py::module &m){ ...@@ -42,9 +42,9 @@ void addTensorUtilsFunction(py::module &m){
: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
:type relative: compatible datatype with compared :py:class:`aidge_core.Tensor` :type relative: float
:param absolute: absolute error allowed :param absolute: absolute error allowed
:type absolute: compatible datatype with compared :py:class:`aidge_core.Tensor` :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