Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions paconvert/global_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class GlobalManager:
with open(json_file, "r") as file:
ALIAS_MAPPING = json.load(file)

json_file = os.path.dirname(__file__) + "/api_alias_mapping.json"
with open(json_file, "r") as file:
ALIAS_MAPPING = json.load(file)

# used to replace import (means replace api by all)
IMPORT_PACKAGE_MAPPING = {
"audiotools": "paddlespeech.audiotools",
Expand Down Expand Up @@ -78,6 +74,23 @@ class GlobalManager:

# 完全对齐的Pytorch API名单
NO_NEED_CONVERT_LIST = [
# Edit by AI Agent
"torch.fmax",
"torch.fmin",
"torch.bincount",
"torch.diag",
"torch.atan",
"torch.tan",
"torch.bitwise_and",
"torch.bitwise_not",
"torch.bitwise_xor",
"torch.nextafter",
"torch.angle",
"torch.heaviside",
"torch.asinh",
"torch.reciprocal",
"torch.square",

# Manfredss
"torch.asin",

Expand Down Expand Up @@ -978,7 +991,6 @@ class GlobalManager:
# algorithm1832
"torch.cosh",
"torch.frac",
"torch.diag",
"torch.Tensor.diag",

# lijialin
Expand Down
60 changes: 60 additions & 0 deletions tests/test_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,63 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_6():
"""2D复数张量"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[1+1j, 2+2j], [3+3j, 4+4j]])
result = torch.angle(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""3D复数张量"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[[1+1j, 2+2j], [3+3j, 4+4j]], [[5+5j, 6+6j], [7+7j, 8+8j]]])
result = torch.angle(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""实数输入"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([1.0, 2.0, 3.0])
result = torch.angle(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""零值复数"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([0+0j, 1+0j, 0+1j])
result = torch.angle(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""不同数据类型 - float64"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([1+1j, 2+2j, 3+3j], dtype=torch.complex128)
result = torch.angle(x)
"""
)
obj.run(pytorch_code, ["result"])
62 changes: 62 additions & 0 deletions tests/test_asinh.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,65 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["out", "result"])


def test_case_6():
"""2D张量"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[0.1606, -1.4267], [-1.0899, -1.0250]])
result = torch.asinh(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""3D张量"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[[0.1, -1.0], [-1.5, 2.0]], [[3.0, -4.0], [5.0, -6.0]]])
result = torch.asinh(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""边界值 - 零值和大值"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.0, 1.0, -1.0, 10.0, -10.0])
result = torch.asinh(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""不同数据类型 - float64"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.1606, -1.4267, -1.0899], dtype=torch.float64)
result = torch.asinh(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""梯度计算测试"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.5, 1.0, 2.0], requires_grad=True)
y = torch.asinh(a)
y.sum().backward()
a_grad = a.grad
"""
)
obj.run(pytorch_code, ["y", "a_grad"], check_stop_gradient=False)
62 changes: 62 additions & 0 deletions tests/test_atan.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,65 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["out", "result"])


def test_case_6():
"""2D张量"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[0.2341, 0.2539], [-0.6256, -0.6448]])
result = torch.atan(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""3D张量"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[[0.1, 0.2], [0.3, 0.4]], [[0.5, 0.6], [0.7, 0.8]]])
result = torch.atan(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""边界值 - 零值和无穷大"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.0, 1.0, -1.0, 100.0, -100.0])
result = torch.atan(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""不同数据类型 - float64"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.2341, 0.2539, -0.6256], dtype=torch.float64)
result = torch.atan(a)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""梯度计算测试"""
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([0.5, 1.0, 2.0], requires_grad=True)
y = torch.atan(a)
y.sum().backward()
a_grad = a.grad
"""
)
obj.run(pytorch_code, ["y", "a_grad"], check_stop_gradient=False)
49 changes: 49 additions & 0 deletions tests/test_bincount.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,52 @@ def test_case_7():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""边界值 - 空输入"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([], dtype=torch.int64)
result = torch.bincount(input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""边界值 - 所有索引相同"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([2, 2, 2, 2])
result = torch.bincount(input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""不同数据类型 - float64"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0, 1, 2, 1, 0])
weights = torch.tensor([1.5, 2.5, 3.5, 4.5, 5.5], dtype=torch.float64)
result = torch.bincount(input, weights=weights)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""不同数据类型 - int64输入"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0, 1, 2, 1, 0], dtype=torch.int64)
result = torch.bincount(input)
"""
)
obj.run(pytorch_code, ["result"])
Loading