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

Method checkResult

test/grad/BinaryGradTest.cpp:26–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 virtual ~BinaryGradTest() = default;
25
26 bool checkResult(VARP output, std::vector<float> outputDiff, std::vector<float> expectedOutputA, std::vector<float> expectedOutputB, const char* subname) {
27 const int len = outputDiff.size();
28 auto opExpr = output->expr().first;
29 auto grad = OpGrad::get(opExpr->get()->type());
30 if (grad == nullptr) {
31 MNN_ERROR("no grad defined for: %s %s\n", name, subname);
32 }
33 auto inputGrad = grad->onGrad(opExpr, {_Const(outputDiff.data(), {len})});
34 auto gotOutputA = inputGrad[0]->readMap<float>();
35 auto gotOutputB = inputGrad[1]->readMap<float>();
36
37 const float threshold = 1e-4;
38
39 bool res = true;
40 for (int i = 0; i < len; ++i) {
41 auto diff = ::fabsf(gotOutputA[i] - expectedOutputA[i]);
42 if (diff > threshold) {
43 MNN_ERROR("%s %s %d grad test failed for input A, expected: %f, but got: %f!\n", name, subname, i, expectedOutputA[i], gotOutputA[i]);
44 res = false;
45 }
46 diff = ::fabsf(gotOutputB[i] - expectedOutputB[i]);
47 if (diff > threshold) {
48 MNN_ERROR("%s %s %d grad test failed for input B, expected: %f, but got: %f!\n", name, subname, i, expectedOutputB[i], gotOutputB[i]);
49 res = false;
50 }
51 }
52 return res;
53 }
54
55 virtual bool run(int precision) {
56 const int len = 5;

Callers

nothing calls this directly

Calls 7

_ConstFunction · 0.85
getFunction · 0.50
sizeMethod · 0.45
typeMethod · 0.45
getMethod · 0.45
onGradMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected