15 #include <doctest/doctest.h> 24 template<
typename T,
bool isQuantized = true>
29 return (std::max(a, b) - std::min(a, b)) <= 1;
40 if (a == 0.0f || b == 0.0f)
45 if (std::isinf(a) && a == b)
50 if (std::isnan(a) && std::isnan(b))
69 return (((a == 0) && (b == 0)) || ((a != 0) && (b != 0)));
74 const std::vector<T>& expectedData,
77 bool compareBoolean =
false,
78 bool isDynamic =
false)
80 if (actualData.size() != expectedData.size())
83 res.
Message() <<
"Different data size [" 86 << expectedData.size()
94 res.
Message() <<
"Different number of dimensions [" 105 res.
Message() <<
"Different number of elements [" 118 for (
unsigned int i = 0; i < numberOfDimensions; ++i)
120 if (actualShape[i] != expectedShape[i])
123 res.
Message() <<
"Different shapes [" 134 std::vector<unsigned int> indices;
135 for (
unsigned int i = 0; i < numberOfDimensions; i++)
137 indices.emplace_back(0);
140 std::stringstream errorString;
141 int numFailedElements = 0;
142 constexpr
int maxReportedDifferences = 3;
143 unsigned int index = 0;
163 if (numFailedElements <= maxReportedDifferences)
165 if (numFailedElements >= 2)
170 for (
unsigned int i = 0; i < numberOfDimensions; ++i)
172 errorString << indices[i];
173 if (i != numberOfDimensions - 1)
180 errorString <<
" (" << +actualData[index] <<
" != " << +expectedData[index] <<
")";
184 ++indices[numberOfDimensions - 1];
185 for (
unsigned int i=numberOfDimensions-1; i>0; i--)
187 if (indices[i] == actualShape[i])
193 if (indices[0] == actualShape[0])
202 if (numFailedElements > 0)
205 comparisonResult.
Message() << numFailedElements <<
" different values at: ";
206 if (numFailedElements > maxReportedDifferences)
208 errorString <<
", ... (and " << (numFailedElements - maxReportedDifferences) <<
" other differences)";
210 comparisonResult.
Message() << errorString.str();
213 return comparisonResult;
216 template <
typename T>
222 std::mt19937 gen(seed);
223 std::uniform_real_distribution<float> dist(min, max);
226 for (
unsigned int i = 0; i < init.size(); i++)
234 return armnnUtils::QuantizedVector<T>(init, qScale, qOffset);
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified...
static bool Compare(T a, T b)
std::vector< T > MakeRandomTensor(const armnn::TensorInfo &tensorInfo, unsigned int seed, float min=-10.0f, float max=10.0f)
bool SelectiveCompareBoolean(T a, T b)
armnn::PredicateResult CompareTensors(const std::vector< T > &actualData, const std::vector< T > &expectedData, const armnn::TensorShape &actualShape, const armnn::TensorShape &expectedShape, bool compareBoolean=false, bool isDynamic=false)
std::stringstream & Message()
constexpr float g_FloatCloseToZeroTolerance
int32_t GetQuantizationOffset() const
float GetQuantizationScale() const
void SetResult(bool newResult)
bool SelectiveCompare(T a, T b)
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
bool within_percentage_tolerance(float a, float b, float tolerancePercent=1.0f)
Compare two floats and return true if their values are within a specified tolerance of each other...
static bool Compare(T a, T b)
unsigned int GetNumElements() const