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 17def test(input0, output0, axes, keep_dims, input_data, output_data): 18 model = Model().Operation("REDUCE_MIN", input0, axes, keep_dims).To(output0) 19 quant8 = DataTypeConverter().Identify({ 20 input0: ["TENSOR_QUANT8_ASYMM", 0.5, 127], 21 output0: ["TENSOR_QUANT8_ASYMM", 0.5, 127], 22 }) 23 Example({ 24 input0: input_data, 25 output0: output_data, 26 }, model=model).AddVariations("relaxed", "float16", quant8) 27 28test( 29 input0=Input("input0", "TENSOR_FLOAT32", "{3, 2}"), 30 input_data=[-1, -2, 31 3, 4, 32 5, -6], 33 axes=[-1], 34 keep_dims=False, 35 output0=Output("output0", "TENSOR_FLOAT32", "{3}"), 36 output_data=[-2, 3, -6], 37) 38 39# Tests below were adapted from tensorflow/lite/kernels/reduce_test.cc 40 41test( 42 input0=Input("input0", "TENSOR_FLOAT32", "{1}"), 43 input_data=[9.527], 44 axes=[0], 45 keep_dims=True, 46 output0=Output("output0", "TENSOR_FLOAT32", "{1}"), 47 output_data=[9.527], 48) 49 50test( 51 input0=Input("input0", "TENSOR_FLOAT32", "{4, 3, 2}"), 52 input_data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 53 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 54 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4], 55 axes=[1, 0, -3, -3], 56 keep_dims=False, 57 output0=Output("output0", "TENSOR_FLOAT32", "{2}"), 58 output_data=[0.1, 0.2], 59) 60 61test( 62 input0=Input("input0", "TENSOR_FLOAT32", "{4, 3, 2}"), 63 input_data=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 64 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 65 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4], 66 axes=[0, 2], 67 keep_dims=True, 68 output0=Output("output0", "TENSOR_FLOAT32", "{1, 3, 1}"), 69 output_data=[0.1, 0.3, 0.5], 70) 71