From 3f4dc9bf575427a0d7ea6c150ac026d8221e409b Mon Sep 17 00:00:00 2001 From: co63oc Date: Fri, 18 Aug 2023 15:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E8=A7=84=E5=88=99=20No.=2030?= =?UTF-8?q?9=20(#224)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add test --- paconvert/api_mapping.json | 13 +++++++ tests/test_trapezoid.py | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/test_trapezoid.py diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index b1adeff2d..1bb60a8cb 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -10389,6 +10389,19 @@ "dim1" ] }, + "torch.trapezoid": { + "Matcher": "GenericMatcher", + "paddle_api": "paddle.trapezoid", + "args_list": [ + "y", + "x", + "dx", + "dim" + ], + "kwargs_change": { + "dim": "axis" + } + }, "torch.triangular_solve": { "Matcher": "TriangularSolveMatcher", "paddle_api": "paddle.linalg.triangular_solve", diff --git a/tests/test_trapezoid.py b/tests/test_trapezoid.py new file mode 100644 index 000000000..dac12678a --- /dev/null +++ b/tests/test_trapezoid.py @@ -0,0 +1,78 @@ +# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import textwrap + +from apibase import APIBase + +obj = APIBase("torch.trapezoid") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + y = torch.tensor([1.0, 1, 1, 0, 1]) + result = torch.trapezoid(y) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + y = torch.tensor([1, 1, 1, 0, 1]).type(torch.float32) + x = torch.tensor([1, 2, 3, 0, 1]).type(torch.float32) + result = torch.trapezoid(y=y, x=x) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + y = torch.tensor([1, 1, 1, 0, 1]).type(torch.float32) + x = torch.tensor([1, 2, 3, 0, 1]).type(torch.float32) + result = torch.trapezoid(y=y, dim=-1, dx=2) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + y = torch.tensor([1, 1, 1, 0, 1]).type(torch.float32) + x = torch.tensor([1, 2, 3, 0, 1]).type(torch.float32) + result = torch.trapezoid(y, dx=2, dim=-1) + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + y = torch.tensor([1, 1, 1, 0, 1]).type(torch.float32) + x = torch.tensor([1, 2, 3, 0, 1]).type(torch.float32) + result = torch.trapezoid(y=y, x=x, dim=-1) + """ + ) + obj.run(pytorch_code, ["result"])