Add comments for multidim tensor factory limitations, and rename ListInitTensor for better clarity (#26756)

Summary:
This PR includes the following improvements:
1. Add comments for limitations of the multidim tensor factory function `torch::tensor(...)`, noting the fact that `torch::tensor({})` and mixed data type such as `torch::tensor({{bool, 2.0}})` are not supported at the moment. (I will also update https://pytorch.org/cppdocs/notes/tensor_creation.html to include usage examples for the multidim tensor factory function `torch::tensor(...)`)
2. Rename `ListInitTensor` to `InitListTensor`, for better naming consistency.

This addresses reviews in https://github.com/pytorch/pytorch/pull/26210. I will work on a separate PR to move the factory function to `at::`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26756

Differential Revision: D17560136

Pulled By: yf225

fbshipit-source-id: eb8b45226e999784da48f75cc8953a998582df99
This commit is contained in:
Will Feng
2019-09-24 19:19:35 -07:00
committed by Facebook Github Bot
parent e54a9e1b5a
commit d4dc844ec3
2 changed files with 38 additions and 29 deletions
+5 -5
View File
@@ -248,25 +248,25 @@ TEST(TensorTest, MultidimTensorCtor_CUDA) {
}
}
TEST(TensorTest, PrettyPrintListInitTensor) {
TEST(TensorTest, PrettyPrintInitListTensor) {
{
ASSERT_EQ(
c10::str(torch::detail::ListInitTensor(1.1)),
c10::str(torch::detail::InitListTensor(1.1)),
"1.1");
}
{
ASSERT_EQ(
c10::str(torch::detail::ListInitTensor({1.1, 2.2})),
c10::str(torch::detail::InitListTensor({1.1, 2.2})),
"{1.1, 2.2}");
}
{
ASSERT_EQ(
c10::str(torch::detail::ListInitTensor({{1, 2}, {3, 4}})),
c10::str(torch::detail::InitListTensor({{1, 2}, {3, 4}})),
"{{1, 2}, {3, 4}}");
}
{
ASSERT_EQ(
c10::str(torch::detail::ListInitTensor({{{{{{{{1.1, 2.2, 3.3}}}}}, {{{{{4.4, 5.5, 6.6}}}}}, {{{{{7.7, 8.8, 9.9}}}}}}}})),
c10::str(torch::detail::InitListTensor({{{{{{{{1.1, 2.2, 3.3}}}}}, {{{{{4.4, 5.5, 6.6}}}}}, {{{{{7.7, 8.8, 9.9}}}}}}}})),
"{{{{{{{{1.1, 2.2, 3.3}}}}}, {{{{{4.4, 5.5, 6.6}}}}}, {{{{{7.7, 8.8, 9.9}}}}}}}}");
}
}