// // SeLUTest.cpp // MNNTests // // Created by MNN on 2019/01/15. // Copyright © 2018, Alibaba Group Holding Limited // #include #include #include "MNNTestSuite.h" #include "TestUtils.h" using namespace MNN::Express; class SeluTest : public MNNTestCase { public: virtual ~SeluTest() = default; bool _run(int precision, bool lazy) { auto input = _Input( { 4, }, NCHW); input->setName("input_tensor"); // set input data const float inpudata[] = {-1.0, -2.0, 3.0, 4.0}; auto inputPtr = input->writeMap(); memcpy(inputPtr, inpudata, 4 * sizeof(float)); input->unMap(); auto output = _Selu(input, 2.0, 0.5); const std::vector expectedOutput = {-0.63, -0.86, 6.0, 8.0}; auto gotOutput = output->readMap(); if (!checkVector(gotOutput, expectedOutput.data(), 4, 0.01)) { MNN_ERROR("SeluTest test failed!\n"); return false; } return true; } virtual bool run(int precision) { ExecutorScope::Current()->lazyEval = false; auto res = _run(precision, false); if (!res) { FUNC_PRINT(1); return false; } ExecutorScope::Current()->lazyEval = true; ExecutorScope::Current()->setLazyComputeMode(MNN::Express::Executor::LAZY_CONTENT); res = _run(precision, true); if (!res) { FUNC_PRINT(1); return false; } ExecutorScope::Current()->setLazyComputeMode(MNN::Express::Executor::LAZY_FULL); res = _run(precision, true); return res; } }; MNNTestSuiteRegister(SeluTest, "op/selu");