Use default dtype for torch::tensor(floating_point_values) and torch::tensor(empty braced-init-list) when dtype is not specified (#29632)

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

This PR is BC-breaking in the following way:

Previously, C++ `torch::tensor` with a floating-point literal with no suffix (e.g. `torch::tensor(1.1)`) or a (nested) braced-init-list of
floating-point literals with no suffix (e.g. `torch::tensor({{1.1, 2.2}})` produces a tensor with dtype `at::kDouble`. After this PR, it produces a tensor with dtype `torch::get_default_dtype()`, matching Python `torch.tensor` behavior.

Test Plan: Imported from OSS

Differential Revision: D18465819

Pulled By: yf225

fbshipit-source-id: 6834fe50335c677bc3832f2a5e9cf8d1ede9f665
This commit is contained in:
Will Feng
2019-11-13 15:14:08 -08:00
committed by Facebook Github Bot
parent 3fb9bbc99b
commit 2bcac59a30
9 changed files with 174 additions and 72 deletions
+2 -2
View File
@@ -462,7 +462,7 @@ TEST_F(FunctionalTest, GridSample) {
TEST_F(FunctionalTest, AffineGrid) {
{
// 2D affine.
auto theta = torch::arange(1, 13, torch::kDouble)
auto theta = torch::arange(1., 13)
.view(std::vector<int64_t>({2, 2, 3}));
auto size = std::vector<int64_t>({2, 3, 2, 2});
auto align_corners = true;
@@ -480,7 +480,7 @@ TEST_F(FunctionalTest, AffineGrid) {
}
{
// 3D affine.
auto theta = torch::arange(1, 13, torch::kDouble)
auto theta = torch::arange(1., 13)
.view(std::vector<int64_t>({1, 3, 4}));
auto size = std::vector<int64_t>({1, 1, 3, 2, 2});
auto align_corners = true;