Remove legacy constructor calls from pytorch codebase. (#54142)

Summary:
Follow up from https://github.com/pytorch/pytorch/issues/53889
Related to https://github.com/pytorch/pytorch/issues/47112

Removing every occurrence of the legacy constructor call present in PyTorch at:
- _docs_
- _benchmarks_
- _test_
- _caffe2_
- _CONTRIBUTING.md_

Pull Request resolved: https://github.com/pytorch/pytorch/pull/54142

Reviewed By: ngimel

Differential Revision: D27699450

Pulled By: mruberry

fbshipit-source-id: 530aa3f5746cc8bc1407d5d51b2bbd8075e30546
This commit is contained in:
Yukio Siraichi
2021-04-11 15:43:54 -07:00
committed by Facebook GitHub Bot
parent fa29a647db
commit 93bf0ae6fc
40 changed files with 350 additions and 351 deletions

View File

@ -85,7 +85,7 @@ class TestNumPyInterop(TestCase):
self.assertEqual(x[i][j], y[i][j])
# empty
x = torch.Tensor().to(dtp)
x = torch.tensor([]).to(dtp)
y = x.numpy()
self.assertEqual(y.size, 0)
@ -273,10 +273,10 @@ class TestNumPyInterop(TestCase):
if np.dtype(dtype).kind == 'u': # type: ignore[misc]
# .type expects a XxxTensor, which have no type hints on
# purpose, so ignore during mypy type checking
x = torch.Tensor([1, 2, 3, 4]).type(tp) # type: ignore
x = torch.tensor([1, 2, 3, 4]).type(tp) # type: ignore
array = np.array([1, 2, 3, 4], dtype=dtype)
else:
x = torch.Tensor([1, -2, 3, -4]).type(tp) # type: ignore
x = torch.tensor([1, -2, 3, -4]).type(tp) # type: ignore
array = np.array([1, -2, 3, -4], dtype=dtype)
# Test __array__ w/o dtype argument
@ -311,7 +311,7 @@ class TestNumPyInterop(TestCase):
float_types = [torch.DoubleTensor, torch.FloatTensor]
float_dtypes = [np.float64, np.float32]
for tp, dtype in zip(float_types, float_dtypes):
x = torch.Tensor([1, 2, 3, 4]).type(tp) # type: ignore
x = torch.tensor([1, 2, 3, 4]).type(tp) # type: ignore
array = np.array([1, 2, 3, 4], dtype=dtype)
for func in ['sin', 'sqrt', 'ceil']:
ufunc = getattr(np, func)
@ -323,7 +323,7 @@ class TestNumPyInterop(TestCase):
# Test functions with boolean return value
for tp, dtype in zip(types, dtypes):
x = torch.Tensor([1, 2, 3, 4]).type(tp) # type: ignore
x = torch.tensor([1, 2, 3, 4]).type(tp) # type: ignore
array = np.array([1, 2, 3, 4], dtype=dtype)
geq2_x = np.greater_equal(x, 2)
geq2_array = np.greater_equal(array, 2).astype('uint8')