mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Test Plan: revert-hammer Differential Revision: D34856571 (3ded7b1da3) Original commit changeset: 0dca038bcad5 Original Phabricator Diff: D34856571 (3ded7b1da3) fbshipit-source-id: 594553fa0b710d78beba59d5d2b646f1f1270386 (cherry picked from commit 8090eb9b12dcf452a9e7dc01792a66fb91b563b6)
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
# Owner(s): ["module: complex"]
|
|
|
|
import torch
|
|
from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes
|
|
from torch.testing._internal.common_utils import TestCase, run_tests
|
|
from torch.testing._internal.common_dtype import get_all_complex_dtypes
|
|
|
|
devices = (torch.device('cpu'), torch.device('cuda:0'))
|
|
|
|
class TestComplexTensor(TestCase):
|
|
@dtypes(*get_all_complex_dtypes())
|
|
def test_to_list(self, device, dtype):
|
|
# test that the complex float tensor has expected values and
|
|
# there's no garbage value in the resultant list
|
|
self.assertEqual(torch.zeros((2, 2), device=device, dtype=dtype).tolist(), [[0j, 0j], [0j, 0j]])
|
|
|
|
@dtypes(torch.float32, torch.float64)
|
|
def test_dtype_inference(self, device, dtype):
|
|
# issue: https://github.com/pytorch/pytorch/issues/36834
|
|
default_dtype = torch.get_default_dtype()
|
|
torch.set_default_dtype(dtype)
|
|
x = torch.tensor([3., 3. + 5.j], device=device)
|
|
torch.set_default_dtype(default_dtype)
|
|
self.assertEqual(x.dtype, torch.cdouble if dtype == torch.float64 else torch.cfloat)
|
|
|
|
instantiate_device_type_tests(TestComplexTensor, globals())
|
|
|
|
if __name__ == '__main__':
|
|
run_tests()
|