Skip to content

Commit

Permalink
Check support_as_strided before using empty_strided.
Browse files Browse the repository at this point in the history
ghstack-source-id: 5fbdb907428e852ddec8fda8ef16dc643479d7cf
Pull Request resolved: #46746
  • Loading branch information
Ailing Zhang committed Oct 22, 2020
1 parent ce5bca5 commit bab2f4e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion aten/src/ATen/native/TensorFactories.cpp
Expand Up @@ -348,7 +348,7 @@ Tensor empty_like(
if (memory_format == MemoryFormat::Preserve) {
if (self.is_non_overlapping_and_dense()) {
result = at::empty_strided(self.sizes(), self.strides(), options.memory_format(c10::nullopt));
} else if (self.layout() == kStrided) {
} else if (self.unsafeGetTensorImpl()->support_as_strided() && self.layout() == kStrided) {
// If input tensor is not dense and non-overlapping but strided, we will infer an output strides
// which keeps the layout permutation of the input tensor.
std::vector<int64_t> strides = infer_dense_strides(self.sizes(), self.strides());
Expand Down

0 comments on commit bab2f4e

Please sign in to comment.