2 Copyright (c) 2018-2019 Intel Corporation
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
21 from mo.graph.graph import Node
22 from mo.ops.power import Power
23 from mo.utils.unittest.graph import build_graph
26 class TestPowerOp(unittest.TestCase):
28 def create_graph(single_input=True):
32 'shape': np.array([1, 3, 224, 224]),
37 'shape': np.array([]),
38 'value': np.array(1.0),
42 'shape': np.array([1, 3, 224, 224]),
50 return build_graph(nodes_attributes,
53 ('power', 'power_data')
56 return build_graph(nodes_attributes,
60 ('power', 'power_data')
63 def test_power_single_input_infer1(self):
64 graph = self.create_graph(single_input=True)
65 graph.graph['layout'] = 'NCHW'
66 power_node = Node(graph, 'power')
67 power_node['power'] = 1.0
69 Power.infer(power_node)
71 self.assertTrue(np.array_equal(power_node.out_node().shape, power_node.in_node(0).shape))
73 def test_power_two_input_infer1(self):
74 graph = self.create_graph(single_input=False)
75 graph.graph['layout'] = 'NCHW'
76 power_node = Node(graph, 'power')
78 Power.infer(power_node)
80 self.assertTrue(np.array_equal(power_node.out_node().shape, power_node.in_node(0).shape))
82 def test_power_two_input_infer2(self):
83 graph = self.create_graph(single_input=False)
84 power_node = Node(graph, 'power')
85 input2 = Node(graph, 'input2')
86 input2.value = np.ones((1, 2, 3))
88 Power.infer(power_node)
90 self.assertIsNone(power_node.out_node().shape)
92 def test_power_two_input_infer3(self):
93 graph = self.create_graph(single_input=False)
94 power_node = Node(graph, 'power')
95 input2 = Node(graph, 'input2')
98 Power.infer(power_node)
100 self.assertIsNone(power_node.out_node().shape)