|
| 1 | +# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License" |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from auto_scan_test import OPConvertAutoScanTest |
| 16 | +from hypothesis import reproduce_failure |
| 17 | +import hypothesis.strategies as st |
| 18 | +import numpy as np |
| 19 | +import unittest |
| 20 | +import random |
| 21 | + |
| 22 | + |
| 23 | +class TestReduceOpsConvert(OPConvertAutoScanTest): |
| 24 | + """ |
| 25 | + ONNX op: Reduce Ops |
| 26 | + OPset version: 7~15 |
| 27 | + """ |
| 28 | + |
| 29 | + def sample_convert_config(self, draw): |
| 30 | + input_shape = draw( |
| 31 | + st.lists( |
| 32 | + st.integers( |
| 33 | + min_value=20, max_value=30), min_size=3, max_size=5)) |
| 34 | + |
| 35 | + input_dtype = draw(st.sampled_from(["float32", "int32", "int64"])) |
| 36 | + |
| 37 | + axes = draw( |
| 38 | + st.lists( |
| 39 | + st.integers( |
| 40 | + min_value=-len(input_shape), max_value=len(input_shape) - |
| 41 | + 1), |
| 42 | + min_size=1, |
| 43 | + max_size=1)) |
| 44 | + |
| 45 | + keep_dim = draw(st.integers(min_value=0, max_value=1)) |
| 46 | + config = { |
| 47 | + "op_names": ["ReduceL1", "ReduceL2"], |
| 48 | + "test_data_shapes": [input_shape], |
| 49 | + "test_data_types": [input_dtype], |
| 50 | + "inputs_shape": [input_shape], |
| 51 | + "min_opset_version": 7, |
| 52 | + "max_opset_version": 15, |
| 53 | + "inputs_name": ["x"], |
| 54 | + "outputs_name": ["y"], |
| 55 | + "delta": 1e-4, |
| 56 | + "rtol": 1e-4, |
| 57 | + } |
| 58 | + |
| 59 | + attrs = { |
| 60 | + "axes": axes, |
| 61 | + "keepdims": keep_dim, |
| 62 | + } |
| 63 | + |
| 64 | + return (config, attrs) |
| 65 | + |
| 66 | + def test(self): |
| 67 | + self.run_and_statis(max_examples=50) |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == "__main__": |
| 71 | + unittest.main() |
0 commit comments