From 5e977201006de429436c10a5c48155840025888f Mon Sep 17 00:00:00 2001 From: Ruiyang Liu Date: Tue, 18 Dec 2018 16:28:14 -0800 Subject: [PATCH] Replace resize_dim() with set_sizes_and_strides() in (#15348) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15348 We have a function resize_dim() on TensorImpl in c10/core/TensorImpl.h which lets you change the dimensionality of a tensor, resizing both sizes and strides. Unfortunately, this API is fairly easy to misuse, because it fills in the new entries with garbage when you size it larger. We want to refactor the call sites to use set_sizes_and_strides() instead, so that there is never an intermediate tensor state where the sizes/strides don't make sense. In this diff, resize_dim() is replaced with set_sizes_and_strides() in aten/src/TH/THTensor.hpp. Reviewed By: ezyang Differential Revision: D13505512 fbshipit-source-id: 193bab89f0018c13ca07488be336d8e967746b76 --- aten/src/TH/THTensor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aten/src/TH/THTensor.hpp b/aten/src/TH/THTensor.hpp index 1a868cd..4001bc4 100644 --- a/aten/src/TH/THTensor.hpp +++ b/aten/src/TH/THTensor.hpp @@ -43,7 +43,7 @@ inline THStorage* THTensor_getStoragePtr(const THTensor* tensor) { inline void THTensor_maybe_zero_dim(THTensor *tensor, bool condition_when_zero_dim) { bool set_zero_dim = condition_when_zero_dim && tensor->sizes().size() == 1 && tensor->size(0) == 1; if (set_zero_dim) { - tensor->resize_dim(0); + tensor->set_sizes_and_strides({}, {}); } } -- 2.7.4