Home | History | Annotate | Download | only in V1_2
      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_PROD", 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=[1.0,  2.0,  3.0,  4.0,  5.0,  6.0,  7.0,  8.0,
     49                 9.0,  1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 1.60,
     50                 1.70, 1.80, 1.90, 2.00, 2.10, 2.20, 2.30, 2.40],
     51     axes=[1, 0, -3, -3],
     52     keep_dims=False,
     53     output0=Output("output0", "TENSOR_FLOAT32", "{2}"),
     54     output_data=[3.16234143225e+4, 1.9619905536e+4],
     55 )
     56 
     57 test(
     58     input0=Input("input0", "TENSOR_FLOAT32", "{4, 3, 2}"),
     59     input_data=[1.0,  2.0,  3.0,  4.0,  5.0,  6.0,  7.0,  8.0,
     60                 9.0,  1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 1.60,
     61                 1.70, 1.80, 1.90, 2.00, 2.10, 2.20, 2.30, 2.40],
     62     axes=[0, 2],
     63     keep_dims=True,
     64     output0=Output("output0", "TENSOR_FLOAT32", "{1, 3, 1}"),
     65     output_data=[7.74592e+2, 1.197504e+3, 6.6889152e+2],
     66 )
     67