mirror of https://github.com/alibaba/MNN.git
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
//
|
|
// SeLUTest.cpp
|
|
// MNNTests
|
|
//
|
|
// Created by MNN on 2019/01/15.
|
|
// Copyright © 2018, Alibaba Group Holding Limited
|
|
//
|
|
|
|
#include <MNN/expr/Expr.hpp>
|
|
#include <MNN/expr/ExprCreator.hpp>
|
|
#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<float>();
|
|
memcpy(inputPtr, inpudata, 4 * sizeof(float));
|
|
input->unMap();
|
|
auto output = _Selu(input, 2.0, 0.5);
|
|
const std::vector<float> expectedOutput = {-0.63, -0.86, 6.0, 8.0};
|
|
auto gotOutput = output->readMap<float>();
|
|
if (!checkVector<float>(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");
|