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

Method run

test/grad/SeluGradTest.cpp:23–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 virtual ~SeluGradTest() = default;
22
23 virtual bool run(int precision) {
24 const int len = 4;
25 auto input = _Input({len}, NCHW);
26 const float inpudata[] = {-1.0, -2.0, 0.0, 4.0};
27 auto inputPtr = input->writeMap<float>();
28 memcpy(inputPtr, inpudata, len * sizeof(float));
29
30 float scale = 1.0507009873554804934193349852946f;
31 float alpha = 1.6732632423543772848170429916717f;
32 auto output = _Selu(input, scale, alpha);
33 auto opExpr = output->expr().first;
34
35 auto grad = OpGrad::get(opExpr->get()->type());
36 float outputDiff[len] = {0.1, -0.2, -0.3, 0.4};
37 auto inputGrad = grad->onGrad(opExpr, {_Const(outputDiff, {len})});
38
39 const std::vector<float> expectedOutput = {0.0647, -0.0476, -0.5274, 0.4203};
40 auto gotOutput = inputGrad[0]->readMap<float>();
41
42 for (int i = 0; i < len; ++i) {
43 auto diff = ::fabsf(gotOutput[i] - expectedOutput[i]);
44 if (diff > 0.0001) {
45 MNN_ERROR("%s grad test failed, expected: %f, but got: %f!\n", name, expectedOutput[i], gotOutput[i]);
46 return false;
47 }
48 }
49
50 return true;
51 }
52};
53
54MNNTestSuiteRegister(SeluGradTest, "grad/selu");

Callers

nothing calls this directly

Calls 7

_InputFunction · 0.85
_SeluFunction · 0.85
_ConstFunction · 0.85
getFunction · 0.50
typeMethod · 0.45
getMethod · 0.45
onGradMethod · 0.45

Tested by

no test coverage detected