mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Deprecate tensor.data<T>(), and codemod tensor.data<T>() to tensor.data_ptr<T>() (#24886)
Summary:
This PR adds deprecation message for `tensor.data<T>()` (91d94e7d41
), and changes all call sites of `tensor.data<T>()` to `tensor.data_ptr<T>()` in PyTorch core.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24886
Differential Revision: D16924576
Pulled By: yf225
fbshipit-source-id: 0943d6be73245c7c549c78597b74c3b07fa24440
This commit is contained in:
committed by
Facebook Github Bot
parent
aa66146974
commit
420b37f3c6
@ -119,27 +119,27 @@ TEST(TensorTest, ToDoesNotCopyWhenOptionsAreAllTheSame) {
|
||||
{
|
||||
auto tensor = at::empty({3, 4}, at::kFloat);
|
||||
auto hopefully_not_copy = tensor.to(at::kFloat);
|
||||
ASSERT_EQ(hopefully_not_copy.data<float>(), tensor.data<float>());
|
||||
ASSERT_EQ(hopefully_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
|
||||
}
|
||||
{
|
||||
auto tensor = at::empty({3, 4}, at::kFloat);
|
||||
auto hopefully_not_copy = tensor.to(tensor.options());
|
||||
ASSERT_EQ(hopefully_not_copy.data<float>(), tensor.data<float>());
|
||||
ASSERT_EQ(hopefully_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
|
||||
}
|
||||
{
|
||||
auto tensor = at::empty({3, 4}, at::kFloat);
|
||||
auto hopefully_not_copy = tensor.to(tensor.dtype());
|
||||
ASSERT_EQ(hopefully_not_copy.data<float>(), tensor.data<float>());
|
||||
ASSERT_EQ(hopefully_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
|
||||
}
|
||||
{
|
||||
auto tensor = at::empty({3, 4}, at::kFloat);
|
||||
auto hopefully_not_copy = tensor.to(tensor.device());
|
||||
ASSERT_EQ(hopefully_not_copy.data<float>(), tensor.data<float>());
|
||||
ASSERT_EQ(hopefully_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
|
||||
}
|
||||
{
|
||||
auto tensor = at::empty({3, 4}, at::kFloat);
|
||||
auto hopefully_not_copy = tensor.to(tensor);
|
||||
ASSERT_EQ(hopefully_not_copy.data<float>(), tensor.data<float>());
|
||||
ASSERT_EQ(hopefully_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user