Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / tests / nnapi / specs / V1_2 / reduce_sum.mod.py
1 #
2 # Copyright (C) 2018 The Android Open Source Project
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 def test(input0, output0, axes, keep_dims, input_data, output_data):
18   model = Model().Operation("REDUCE_SUM", input0, axes, keep_dims).To(output0)
19   Example({
20       input0: input_data,
21       output0: output_data,
22   }, model=model).AddVariations("relaxed", "float16")
23
24 test(
25     input0=Input("input0", "TENSOR_FLOAT32", "{3, 2}"),
26     input_data=[-1, -2,
27                 3, 4,
28                 5, -6],
29     axes=[-1],
30     keep_dims=False,
31     output0=Output("output0", "TENSOR_FLOAT32", "{3}"),
32     output_data=[-1 - 2, 3 + 4, 5 - 6],
33 )
34
35 # Tests below were adapted from tensorflow/lite/kernels/reduce_test.cc
36
37 test(
38     input0=Input("input0", "TENSOR_FLOAT32", "{1}"),
39     input_data=[9.527],
40     axes=[0],
41     keep_dims=True,
42     output0=Output("output0", "TENSOR_FLOAT32", "{1}"),
43     output_data=[9.527],
44 )
45
46 test(
47     input0=Input("input0", "TENSOR_FLOAT32", "{4, 3, 2}"),
48     input_data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
49                 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6,
50                 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4],
51     axes=[1, 0, -3, -3],
52     keep_dims=False,
53     output0=Output("output0", "TENSOR_FLOAT32", "{2}"),
54     output_data=[14.4, 15.6],
55 )
56
57 test(
58     input0=Input("input0", "TENSOR_FLOAT32", "{4, 3, 2}"),
59     input_data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
60                 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6,
61                 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4],
62     axes=[0, 2],
63     keep_dims=True,
64     output0=Output("output0", "TENSOR_FLOAT32", "{1, 3, 1}"),
65     output_data=[8.4, 10.0, 11.6],
66 )