C++ API parity: at::Tensor::data

Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26008

Test Plan: Imported from OSS

Differential Revision: D17343488

Pulled By: pbelevich

fbshipit-source-id: b9ba5e26cad621a428a14292446d7fb5a6e5535d
This commit is contained in:
Pavel Belevich
2019-09-12 23:31:47 -07:00
committed by Facebook Github Bot
parent 5e2d25af34
commit 33221b19ac
10 changed files with 34 additions and 5 deletions

View File

@ -311,3 +311,11 @@ TEST(TensorTest, DataPtr) {
ASSERT_EQ(tensor_not_copy.data_ptr<float>(), tensor.data_ptr<float>());
ASSERT_EQ(tensor_not_copy.data_ptr(), tensor.data_ptr());
}
TEST(TensorTest, Data) {
const auto tensor = torch::empty({3, 3});
ASSERT_TRUE(torch::equal(tensor, tensor.data()));
const auto tensor2 = at::empty({3, 3});
ASSERT_THROW(tensor2.data(), c10::Error);
}