1 //
2 //  SoftplusTest.cpp
3 //  MNNTests
4 //
5 //  Created by MNN on 2019/12/26.
6 //  Copyright © 2018, Alibaba Group Holding Limited
7 //
8 
9 #include <MNN/expr/Expr.hpp>
10 #include <MNN/expr/ExprCreator.hpp>
11 #include "MNNTestSuite.h"
12 #include "TestUtils.h"
13 
14 using namespace MNN::Express;
15 class SoftplusTest : public MNNTestCase {
16 public:
17     virtual ~SoftplusTest() = default;
run(int precision)18     virtual bool run(int precision) {
19         auto input = _Input(
20             {
21                 4,
22             },
23             NCHW);
24         input->setName("input_tensor");
25         // set input data
26         const float inpudata[] = {-1.0, -2.0, 3.0, 4.0};
27         auto inputPtr          = input->writeMap<float>();
28         memcpy(inputPtr, inpudata, 4 * sizeof(float));
29         input->unMap();
30         auto output                             = _Softplus(input);
31         const std::vector<float> expectedOutput = {0.31326166, 0.12692805, 3.0485873, 4.01815};
32         auto gotOutput                          = output->readMap<float>();
33         if (!checkVector<float>(gotOutput, expectedOutput.data(), 4, 0.0001)) {
34             MNN_ERROR("SoftplusTest test failed!\n");
35             return false;
36         }
37         return true;
38     }
39 };
40 MNNTestSuiteRegister(SoftplusTest, "op/softplus");
41