mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[PyTorch] Add tests for empty tensors w/storage null data_ptr (#101426)
Further investigation seems to show that changing this behavior (making empty tensors sometimes have non-null data_ptr) was the real problem with #98090 . Adding tests to lock down this behavior so we don't change it by accident again. Differential Revision: [D45873002](https://our.internmc.facebook.com/intern/diff/D45873002/) Pull Request resolved: https://github.com/pytorch/pytorch/pull/101426 Approved by: https://github.com/zou3519
This commit is contained in:
parent
5d8596292b
commit
b435bff53a
|
|
@ -9108,6 +9108,18 @@ tensor([[[1.+1.j, 1.+1.j, 1.+1.j, ..., 1.+1.j, 1.+1.j, 1.+1.j],
|
|||
|
||||
self.assertEqual(b, c)
|
||||
|
||||
def test_data_ptr_of_empty_tensor_with_storage(self):
|
||||
t = torch.empty((2, 2))
|
||||
self.assertNotEqual(t.data_ptr(), 0)
|
||||
t.resize_((0, 2))
|
||||
self.assertEqual(t.data_ptr(), 0)
|
||||
|
||||
def test_data_ptr_of_empty_view_with_storage(self):
|
||||
t = torch.empty((2, 2))
|
||||
self.assertNotEqual(t.data_ptr(), 0)
|
||||
t2 = t[0:0].view(0, 1)
|
||||
self.assertEqual(t2.data_ptr(), 0)
|
||||
|
||||
# The following block extends TestTorch with negative dim wrapping tests
|
||||
# FIXME: replace these with OpInfo sample inputs or systemic OpInfo tests
|
||||
# Functions to test negative dimension wrapping
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user