MCPcopy Create free account
hub / github.com/alibaba/MNN / compareVar

Function compareVar

tools/cpp/testModelWithDescribe.cpp:112–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111template <typename T>
112bool compareVar(VARP var, std::string name) {
113 auto targetValue = createVar(name, var->getInfo()->dim, var->getInfo()->type);
114 auto absMax = _ReduceMax(_Abs(targetValue), {});
115 absMax = _Maximum(absMax, _Scalar<T>(0));
116 auto diff = _Abs(targetValue - var);
117 auto diffAbsMax = _ReduceMax(diff);
118 auto absMaxV = absMax->readMap<T>()[0];
119 auto diffAbsMaxV = diffAbsMax->readMap<T>()[0];
120 // The implemention of isnan in VS2017 isn't accept integer type, so cast all type to double
121#ifdef _MSC_VER
122#define ALI_ISNAN(x) std::isnan(static_cast<long double>(x))
123#else
124#define ALI_ISNAN(x) std::isnan(x)
125#endif
126 if (absMaxV * 0.01f < diffAbsMaxV || ALI_ISNAN(absMaxV)) {
127 std::cout << "TESTERROR " << name << " value error : absMaxV:" << absMaxV << " - DiffMax:" << diffAbsMaxV << std::endl;
128 return false;
129 }
130 return true;
131}
132
133void log_result(bool correct) {
134 if (correct) {

Callers

nothing calls this directly

Calls 5

createVarFunction · 0.85
_ReduceMaxFunction · 0.85
_AbsFunction · 0.85
_MaximumFunction · 0.85
getInfoMethod · 0.45

Tested by

no test coverage detected