-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support aten.atan2 converter (#2689)
- Loading branch information
Showing
3 changed files
with
334 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import torch | ||
import torch.nn as nn | ||
from parameterized import parameterized | ||
from torch.testing._internal.common_utils import run_tests | ||
|
||
from .harness import DispatchTestCase | ||
|
||
|
||
class TestAtan2Converter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
((10,), torch.float), | ||
((1, 20), torch.float), | ||
((2, 3, 4), torch.float), | ||
((2, 3, 4, 5), torch.float), | ||
] | ||
) | ||
def test_atan2_lhs_const(self, input_shape, dtype): | ||
class atan2(nn.Module): | ||
def forward(self, lhs_val, rhs_val): | ||
return torch.ops.aten.atan2.default(lhs_val, rhs_val) | ||
|
||
inputs = [ | ||
torch.randn(input_shape, dtype=dtype), | ||
torch.rand(1), | ||
] | ||
|
||
self.run_test( | ||
atan2(), | ||
inputs, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
((10,), torch.float), | ||
((1, 20), torch.float), | ||
((2, 3, 4), torch.float), | ||
((2, 3, 4, 5), torch.float), | ||
] | ||
) | ||
def test_atan2_rhs_const(self, input_shape, dtype): | ||
class atan2(nn.Module): | ||
def forward(self, lhs_val, rhs_val): | ||
return torch.ops.aten.atan2.default(lhs_val, rhs_val) | ||
|
||
inputs = [ | ||
torch.rand(1), | ||
torch.randn(input_shape, dtype=dtype), | ||
] | ||
|
||
self.run_test( | ||
atan2(), | ||
inputs, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
((10,), torch.float), | ||
((1, 20), torch.float), | ||
((2, 3, 4), torch.float), | ||
((2, 3, 4, 5), torch.float), | ||
] | ||
) | ||
def test_atan2_float(self, input_shape, dtype): | ||
class atan2(nn.Module): | ||
def forward(self, lhs_val, rhs_val): | ||
return torch.ops.aten.atan2.default(lhs_val, rhs_val) | ||
|
||
inputs = [ | ||
torch.randn(input_shape, dtype=dtype), | ||
torch.randn(input_shape, dtype=dtype), | ||
] | ||
|
||
self.run_test( | ||
atan2(), | ||
inputs, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
((50,), torch.int, -5, 5), | ||
((1, 20), torch.int32, -5, 5), | ||
((2, 3, 4), torch.int, -5, 5), | ||
] | ||
) | ||
def test_atan2_int(self, input_shape, dtype, low, high): | ||
class atan2(nn.Module): | ||
def forward(self, lhs_val, rhs_val): | ||
return torch.ops.aten.atan2.default(lhs_val, rhs_val) | ||
|
||
inputs = [ | ||
torch.randint(low, high, input_shape, dtype=dtype), | ||
torch.randint(low, high, input_shape, dtype=dtype), | ||
] | ||
self.run_test( | ||
atan2(), | ||
inputs, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
(torch.float, 0.0, 0.0), | ||
(torch.float, 0.0, torch.rand(1)), | ||
(torch.float, torch.rand(1), 0.0), | ||
(torch.int, 0, 0), | ||
(torch.int, 0, torch.randint(-5, 5, (1,))), | ||
(torch.int, torch.randint(1, 10, (1,)), 0), | ||
] | ||
) | ||
def test_atan2_zero(self, dtype, x_val, y_val): | ||
class Atan2(nn.Module): | ||
def forward(self, lhs_val, rhs_val): | ||
return torch.ops.aten.atan2.default(lhs_val, rhs_val) | ||
|
||
if isinstance(x_val, torch.Tensor): | ||
x_val = x_val.item() | ||
if isinstance(y_val, torch.Tensor): | ||
y_val = y_val.item() | ||
|
||
inputs = [ | ||
torch.tensor([x_val], dtype=dtype), | ||
torch.tensor([y_val], dtype=dtype), | ||
] | ||
|
||
self.run_test( | ||
Atan2(), | ||
inputs, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |