Templatize Tensor.data_ptr() (#24847)

Summary:
This PR templatizes `Tensor.data_ptr()`, to prepare for the deprecation of `Tensor.data<T>()` and introduction of `Tensor.data()` that has the same semantics as `Variable.data()`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24847

Differential Revision: D16906061

Pulled By: yf225

fbshipit-source-id: 8f9db9fd105b146598a9d759aa4b4332011da8ea
This commit is contained in:
Will Feng
2019-08-19 17:00:18 -07:00
committed by Facebook Github Bot
parent bf978e7890
commit eb7b39e02f
5 changed files with 23 additions and 6 deletions

View File

@ -304,3 +304,10 @@ TEST(TensorTest, Item_CUDA) {
ASSERT_EQ(scalar.to<int>(), 123);
}
}
TEST(TensorTest, DataPtr) {
auto tensor = at::empty({3, 4}, at::kFloat);
auto tensor_not_copy = tensor.to(tensor.options());
ASSERT_EQ(tensor_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
ASSERT_EQ(tensor_not_copy.data_ptr(), tensor.data_ptr());
}