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

Function compareOutput

tools/cpp/SequenceModuleTest.cpp:21–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19using namespace MNN;
20
21static bool compareOutput(VARP output, const std::string& directName, const std::string& name, Dimensionformat dataFormat, int order) {
22 auto info = output->getInfo();
23 auto ptr = output->readMap<float>();
24 if (nullptr == info || nullptr == ptr) {
25 MNN_ERROR("TESTERROR ptr / info nullptr\n");
26 return false;
27 }
28 std::string targetFileName;
29 std::ifstream outputOrigin;
30 // First find key
31 {
32 std::ostringstream outputFileOs;
33 outputFileOs << directName << "/" << name <<".txt";
34 targetFileName = outputFileOs.str();
35 outputOrigin.open(targetFileName.c_str());
36 }
37 // Second find order
38 if (outputOrigin.fail()) {
39 std::ostringstream outputFileOs;
40 outputFileOs << directName << "/" << order <<".txt";
41 targetFileName = outputFileOs.str();
42 outputOrigin.open(targetFileName.c_str());
43 }
44 if (info->order == NC4HW4 && info->dim.size() > 1) {
45 output = _Convert(output, dataFormat);
46 info = output->getInfo();
47 }
48 if (info->type.code != halide_type_float) {
49 output = _Cast<float>(output);
50 info = output->getInfo();
51 }
52 MNN_PRINT("%s: (", name.c_str());
53 for (int i=0; i<info->dim.size(); ++i) {
54 MNN_PRINT("%d, ", info->dim[i]);
55 }
56 MNN_PRINT(")\n");
57 auto targetValue = _Input({info->dim}, info->order, info->type);
58 auto targetPtr = targetValue->writeMap<float>();
59 for (int i=0; i<info->size; ++i) {
60 outputOrigin >> targetPtr[i];
61 }
62 auto absMax = _ReduceMax(_Abs(targetValue), {});
63 absMax = _Maximum(absMax, _Scalar<float>(0.0001f));
64 auto diff = _Abs(targetValue - output);
65 auto diffAbsMax = _ReduceMax(diff);
66 auto absMaxV = absMax->readMap<float>()[0];
67 auto diffAbsMaxV = diffAbsMax->readMap<float>()[0];
68 if (absMaxV * 0.01f < diffAbsMaxV || std::isnan(absMaxV)) {
69 MNN_ERROR("TESTERROR from %s value error : absMaxV:%f - DiffMax %f\n", targetFileName.c_str(), absMaxV, diffAbsMaxV);
70 return false;
71 }
72 return true;
73}
74
75#define LOAD_DATA(TYPE)\
76 if (inputInfo.find(inputName) != inputInfo.end()) {\

Callers 1

mainFunction · 0.70

Calls 11

_ConvertFunction · 0.85
_InputFunction · 0.85
_ReduceMaxFunction · 0.85
_AbsFunction · 0.85
_MaximumFunction · 0.85
isnanFunction · 0.85
getInfoMethod · 0.45
strMethod · 0.45
openMethod · 0.45
c_strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected