Skip to content

Commit c93ce82

Browse files
authored
[API Compatibility] enhance torch.aminmax tests -part (#859)
enhance torch.aminmax tests
1 parent 8b6529b commit c93ce82

2 files changed

Lines changed: 110 additions & 9 deletions

File tree

paconvert/api_mapping.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,15 +3132,7 @@
31323132
"Matcher": "ChangePrefixMatcher"
31333133
},
31343134
"torch.aminmax": {
3135-
"Matcher": "AMinMaxMatcher",
3136-
"min_input_args": 1,
3137-
"args_list": [
3138-
"input",
3139-
"*",
3140-
"dim",
3141-
"keepdim",
3142-
"out"
3143-
]
3135+
"Matcher": "ChangePrefixMatcher"
31443136
},
31453137
"torch.amp.autocast": {
31463138
"Matcher": "ChangePrefixMatcher"

tests/test_aminmax.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,112 @@ def test_case_6():
8787
"""
8888
)
8989
obj.run(pytorch_code, ["out"])
90+
91+
92+
def test_case_7():
93+
"""1D tensor input"""
94+
pytorch_code = textwrap.dedent(
95+
"""
96+
import torch
97+
t = torch.tensor([5.0, 1.0, 3.0, 9.0, 2.0])
98+
result = torch.aminmax(t)
99+
"""
100+
)
101+
obj.run(pytorch_code, ["result"])
102+
103+
104+
def test_case_8():
105+
"""3D tensor with dim=0"""
106+
pytorch_code = textwrap.dedent(
107+
"""
108+
import torch
109+
t = torch.tensor([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]])
110+
result = torch.aminmax(t, dim=0)
111+
"""
112+
)
113+
obj.run(pytorch_code, ["result"])
114+
115+
116+
def test_case_9():
117+
"""3D tensor with dim=1 and keepdim=True"""
118+
pytorch_code = textwrap.dedent(
119+
"""
120+
import torch
121+
t = torch.tensor([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]])
122+
result = torch.aminmax(t, dim=1, keepdim=True)
123+
"""
124+
)
125+
obj.run(pytorch_code, ["result"])
126+
127+
128+
def test_case_10():
129+
"""float64 dtype"""
130+
pytorch_code = textwrap.dedent(
131+
"""
132+
import torch
133+
t = torch.tensor([[1.5, 2.3, 3.7], [4.1, 5.9, 6.2]], dtype=torch.float64)
134+
result = torch.aminmax(t, dim=1)
135+
"""
136+
)
137+
obj.run(pytorch_code, ["result"])
138+
139+
140+
def test_case_11():
141+
"""explicit keepdim=False"""
142+
pytorch_code = textwrap.dedent(
143+
"""
144+
import torch
145+
t = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.float)
146+
result = torch.aminmax(t, dim=0, keepdim=False)
147+
"""
148+
)
149+
obj.run(pytorch_code, ["result"])
150+
151+
152+
def test_case_12():
153+
"""input as keyword argument only"""
154+
pytorch_code = textwrap.dedent(
155+
"""
156+
import torch
157+
result = torch.aminmax(input=torch.tensor([3.0, 1.0, 4.0, 1.0, 5.0]))
158+
"""
159+
)
160+
obj.run(pytorch_code, ["result"])
161+
162+
163+
def test_case_13():
164+
"""kwargs unpacking"""
165+
pytorch_code = textwrap.dedent(
166+
"""
167+
import torch
168+
t = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
169+
kwargs = {"dim": 0, "keepdim": True}
170+
result = torch.aminmax(t, **kwargs)
171+
"""
172+
)
173+
obj.run(pytorch_code, ["result"])
174+
175+
176+
def test_case_14():
177+
"""expression as dim argument"""
178+
pytorch_code = textwrap.dedent(
179+
"""
180+
import torch
181+
t = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
182+
result = torch.aminmax(t, dim=2 - 1)
183+
"""
184+
)
185+
obj.run(pytorch_code, ["result"])
186+
187+
188+
def test_case_15():
189+
"""dim with out parameter and keepdim"""
190+
pytorch_code = textwrap.dedent(
191+
"""
192+
import torch
193+
t = torch.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
194+
out = tuple([torch.tensor([0.0, 0.0]), torch.tensor([0.0, 0.0])])
195+
result = torch.aminmax(t, dim=1, keepdim=False, out=out)
196+
"""
197+
)
198+
obj.run(pytorch_code, ["out", "result"])

0 commit comments

Comments
 (0)