ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::misc::fp32 Namespace Reference

Functions

float relative_diff (float lhs, float rhs)
 Get the difference between two float values as a relative value.
 
bool epsilon_equal (float expected, float obtained, uint32_t tolerance=1)
 Verify that an obtained float value is equal to the expected float value by using FLT_EPSILON.
 
bool absolute_epsilon_equal (float expected, float obtained, float tolerance=0.001)
 Verify that an obtained float value is equal to the expected float value by comparing absolute tolerance value.
 

Function Documentation

◆ absolute_epsilon_equal()

bool nnfw::misc::fp32::absolute_epsilon_equal ( float  expected,
float  obtained,
float  tolerance = 0.001 
)
inline

Verify that an obtained float value is equal to the expected float value by comparing absolute tolerance value.

Parameters
[in]expectedAn expected float value to be compared
[in]obtainedAn obtained float value to be compared
[in]toleranceA tolerance value
Returns
true if both values are equal, otherwise false

Definition at line 82 of file fp32.h.

83{
84 if (std::isnan(expected) && std::isnan(obtained))
85 {
86 return true;
87 }
88
89 // Let's use absolute epsilon comparision
90 const auto diff = std::fabs(expected - obtained);
91
92 return diff <= tolerance;
93}

◆ epsilon_equal()

bool nnfw::misc::fp32::epsilon_equal ( float  expected,
float  obtained,
uint32_t  tolerance = 1 
)
inline

Verify that an obtained float value is equal to the expected float value by using FLT_EPSILON.

Parameters
[in]expectedAn expected float value to be compared
[in]obtainedAn obtained float value to be compared
[in]toleranceA tolerance value
Returns
true if both values are equal, otherwise false

Definition at line 60 of file fp32.h.

61{
62 if (std::isnan(expected) && std::isnan(obtained))
63 {
64 return true;
65 }
66
67 // Let's use relative epsilon comparision
68 const auto diff = std::fabs(expected - obtained);
69 const auto max = std::max(std::fabs(expected), std::fabs(obtained));
70
71 return diff <= (max * FLT_EPSILON * tolerance);
72}

◆ relative_diff()

float nnfw::misc::fp32::relative_diff ( float  lhs,
float  rhs 
)
inline

Get the difference between two float values as a relative value.

Parameters
[in]lhsA float value to be compared
[in]rhsA float value to be compared
Returns
A relative value of difference between two float values.

Definition at line 44 of file fp32.h.

45{
46 const auto diff = std::fabs(lhs - rhs);
47 const auto base = std::max(std::fabs(lhs), std::fabs(rhs));
48
49 return diff / base;
50}