b34b2e83fa30e992f7f08c50a2cdd0830dabd61d
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / LogSoftmax.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "GenModelTest.h"
18
19 TEST_F(GenModelTest, OneOp_LogSoftmax)
20 {
21   // NOTE For tf lite the params are fixed as:
22   // beta = 1.0, axis = -1
23
24   CircleGen cgen;
25   int in = cgen.addTensor({{1, 1, 1, 4, 2}, circle::TensorType::TensorType_FLOAT32});
26   int out = cgen.addTensor({{1, 1, 1, 4, 2}, circle::TensorType::TensorType_FLOAT32});
27   cgen.addOperatorLogSoftmax({{in}, {out}});
28   cgen.setInputsAndOutputs({in}, {out});
29
30   _context = std::make_unique<GenModelTestContext>(cgen.finish());
31   _context->setBackends({"cpu"});
32   _context->addTestCase(uniformTCD<float>(
33       {{0, -6, 2, 4, 3, -2, 10, 1}},
34       {{-.00247565, -6.00247, -2.12692, -.126928, -.00671534, -5.00671, -.000123374, -9.00012}}));
35
36   SUCCEED();
37 }
38
39 TEST_F(GenModelTest, neg_OneOp_LogSoftmax_InvalidModel)
40 {
41   CircleGen cgen;
42   int out = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_FLOAT32});
43   cgen.addOperatorLogSoftmax({{}, {out}}); // No input tensor
44   cgen.setInputsAndOutputs({}, {out});
45
46   _context = std::make_unique<GenModelTestContext>(cgen.finish());
47   _context->setBackends({"cpu"});
48   _context->expectFailModelLoad();
49
50   SUCCEED();
51 }