Skip to content

Commit

Permalink
转换规则 No. 309 (#224)
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
co63oc authored Aug 18, 2023
1 parent 24825f9 commit 3f4dc9b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
13 changes: 13 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
78 changes: 78 additions & 0 deletions tests/test_trapezoid.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 3f4dc9b

Please sign in to comment.