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.
18 from unittest.mock import patch
20 from mo.front.caffe.extractors.eltwise import eltwise_ext
21 from mo.utils.unittest.extractors import FakeMultiParam
25 def __init__(self, operation, coeff=[1]):
26 self.eltwise_param = FakeMultiParam({'operation': operation,
30 class TestEltwise(unittest.TestCase):
31 @patch('mo.front.caffe.extractors.eltwise.eltwise_infer')
32 def test_eltwise_op_mul(self, eltwise_infer_mock):
33 eltwise_infer_mock.return_value = {}
34 res = eltwise_ext(FakeProtoLayer(0), None)
41 for i in exp_res.keys():
44 args = eltwise_infer_mock.call_args
45 actual_lambda = args[0][1]
46 self.assertTrue(eltwise_infer_mock.called)
47 self.assertEqual(actual_lambda(3, 5), 3 * 5)
49 self.assertEqual(res[i], exp_res[i])
51 @patch('mo.front.caffe.extractors.eltwise.eltwise_infer')
52 def test_eltwise_op_add(self, eltwise_infer_mock):
53 eltwise_infer_mock.return_value = {}
54 res = eltwise_ext(FakeProtoLayer(1, coeff=[0.39]), None)
62 for i in exp_res.keys():
65 args = eltwise_infer_mock.call_args
66 actual_lambda = args[0][1]
67 self.assertTrue(eltwise_infer_mock.called)
68 self.assertEqual(actual_lambda(3, 5), 3 + 5)
70 self.assertEqual(res[i], exp_res[i])
72 @patch('mo.front.caffe.extractors.eltwise.eltwise_infer')
73 def test_eltwise_op_max(self, eltwise_infer_mock):
74 eltwise_infer_mock.return_value = {}
75 res = eltwise_ext(FakeProtoLayer(2), None)
82 for i in exp_res.keys():
85 args = eltwise_infer_mock.call_args
86 actual_lambda = args[0][1]
87 self.assertTrue(eltwise_infer_mock.called)
88 self.assertEqual(actual_lambda(3, 5), 5)
90 self.assertEqual(res[i], exp_res[i])
92 def test_eltwise_op_exeption(self):
93 self.assertRaises(Exception, eltwise_ext, FakeProtoLayer(4), None)