68adaad81d88b05d22b132614f177aba1ff193ab
[platform/core/ml/nnfw.git] / compiler / luci / partition / src / Nodes / CircleTransposeConv.test.cpp
1 /*
2  * Copyright (c) 2021 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 "luci/ConnectNode.h"
18
19 #include "ConnectNode.test.h"
20
21 #include <luci/Service/CircleNodeClone.h>
22
23 #include <gtest/gtest.h>
24
25 namespace
26 {
27
28 using namespace luci::test;
29
30 class NodeGraphlet : public NodeGraphletT<luci::CircleTransposeConv>
31 {
32 public:
33   NodeGraphlet() = default;
34
35 public:
36   void init(loco::Graph *g) override
37   {
38     NodeGraphletT<luci::CircleTransposeConv>::init(g);
39
40     _node->padding(luci::Padding::VALID);
41   }
42 };
43
44 class TestNodeGraph : public TestIsOGraph<4>, public NodeGraphlet
45 {
46 public:
47   TestNodeGraph() = default;
48
49 public:
50   void init(const ShapeU32 shape)
51   {
52     TestIsOGraph<4>::init({shape, shape, shape, shape}, shape);
53     NodeGraphlet::init(g());
54
55     node()->inputSizes(input(0));
56     node()->filter(input(1));
57     node()->outBackprop(input(2));
58     node()->bias(input(3));
59
60     output()->from(node());
61   }
62 };
63
64 } // namespace
65
66 TEST(ConnectNodeTest, connect_TransposeConv)
67 {
68   TestNodeGraph tng;
69   tng.init({2, 3});
70
71   ConnectionTestHelper cth;
72   cth.prepare_inputs(&tng);
73
74   auto *node = tng.node();
75   ASSERT_NO_THROW(loco::must_cast<luci::CircleTransposeConv *>(node));
76
77   auto *clone = luci::clone_node(node, cth.graph_clone());
78   ASSERT_NO_THROW(loco::must_cast<luci::CircleTransposeConv *>(clone));
79
80   cth.clone_connect(node, clone);
81
82   ASSERT_EQ(4, clone->arity());
83   ASSERT_EQ(cth.inputs(0), clone->arg(0));
84   ASSERT_EQ(cth.inputs(1), clone->arg(1));
85   ASSERT_EQ(cth.inputs(2), clone->arg(2));
86   ASSERT_EQ(cth.inputs(3), clone->arg(3));
87 }
88
89 TEST(ConnectNodeTest, connect_TransposeConv_NEG)
90 {
91   TestNodeGraph tng;
92   tng.init({2, 3});
93
94   ConnectionTestHelper cth;
95   cth.prepare_inputs_miss(&tng);
96
97   auto *node = tng.node();
98   ASSERT_NO_THROW(loco::must_cast<luci::CircleTransposeConv *>(node));
99
100   auto *clone = luci::clone_node(node, cth.graph_clone());
101   ASSERT_NO_THROW(loco::must_cast<luci::CircleTransposeConv *>(clone));
102
103   EXPECT_ANY_THROW(cth.clone_connect(node, clone));
104 }