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

Method checkResult

test/grad/ReduceGradTest.cpp:23–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 virtual ~ReduceGradTest() = default;
22
23 bool checkResult(VARP output, VARP outputDiff, std::vector<float> expectedOutput, const char* subname) {
24 const int len = expectedOutput.size();
25 auto opExpr = output->expr().first;
26 auto grad = OpGrad::get(opExpr->get()->type());
27 if (grad == nullptr) {
28 MNN_ERROR("no grad defined for: %s %s\n", name, subname);
29 }
30 auto inputGrad = grad->onGrad(opExpr, {outputDiff});
31 auto gotOutput = inputGrad[0]->readMap<float>();
32
33 for (int i = 0; i < len; ++i) {
34 auto diff = ::fabsf(gotOutput[i] - expectedOutput[i]);
35 if (diff > 0.001) {
36 MNN_ERROR("%s %s grad test failed, expected: %f, but got: %f!\n", name, subname, expectedOutput[i], gotOutput[i]);
37 return false;
38 }
39 }
40 return true;
41 }
42
43 virtual bool run(int precision) {
44 const int len = 5;

Callers

nothing calls this directly

Calls 5

getFunction · 0.50
sizeMethod · 0.45
typeMethod · 0.45
getMethod · 0.45
onGradMethod · 0.45

Tested by

no test coverage detected