Compare commits

...

6 Commits

Author SHA1 Message Date
7cedac341d Merge branch 'master' into issue#58739 2021-06-17 15:55:42 +02:00
7781b9f16f add blank lines for readability 2021-06-17 15:55:35 +02:00
2119e032fb revert submodule update 2021-06-17 15:54:36 +02:00
8a2bcf9ebf revert submodule update 2021-06-17 16:40:38 +05:30
1ee019fa52 reverted changes 2021-06-17 16:13:25 +05:30
0864aaaeb7 add support for constant 2021-06-17 14:00:51 +05:30
2 changed files with 24 additions and 0 deletions

View File

@ -2975,6 +2975,22 @@ class TestTorchDeviceType(TestCase):
with self.assertWarnsOnceRegex(UserWarning, "torch.is_deterministic is deprecated"):
torch.is_deterministic()
# Validates that mathematical constants are defined properly, as required by
# the Python Array API (https://data-apis.org/array-api/latest/API_specification/constants.html)
@onlyCPU
def test_constants(self, device):
self.assertIsInstance(torch.e, float)
self.assertEqual(torch.e, math.e, atol=0, rtol=0)
self.assertIsInstance(torch.pi, float)
self.assertEqual(torch.pi, math.pi, atol=0, rtol=0)
self.assertIsInstance(torch.nan, float)
self.assertEqual(torch.nan, math.nan, equal_nan=True)
self.assertIsInstance(torch.inf, float)
self.assertEqual(torch.inf, math.inf)
@dtypes(torch.float32, torch.complex64)
def test_storage(self, device, dtype):
v = torch.randn(3, 5, dtype=dtype, device=device)

View File

@ -511,6 +511,14 @@ def is_warn_always_enabled():
"""
return _C._get_warnAlways()
################################################################################
# Define numeric constants
################################################################################
# for Python Array API consistency (https://data-apis.org/array-api/latest/API_specification/constants.html) and NumPy consistency (https://numpy.org/devdocs/reference/constants.html)
from math import e , nan , inf , pi
__all__.extend(['e', 'pi', 'nan', 'inf'])
################################################################################
# Define Storage and Tensor classes
################################################################################