From 99bada8ba0384540ec0d85430d29dd101a1bd8dc Mon Sep 17 00:00:00 2001 From: Xiang Gao Date: Mon, 5 Aug 2019 07:27:43 -0700 Subject: [PATCH] Zero sized tensor support for repeat_interleave (#23717) Summary: Fixes https://github.com/pytorch/pytorch/issues/22753 Pull Request resolved: https://github.com/pytorch/pytorch/pull/23717 Differential Revision: D16623598 Pulled By: mrshenli fbshipit-source-id: 297a3274fb5a5b2fcc0c3ad601337d7eb29fdca2 --- aten/src/ATen/native/Repeat.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aten/src/ATen/native/Repeat.h b/aten/src/ATen/native/Repeat.h index e44e32b6b..f57a5b7ff 100644 --- a/aten/src/ATen/native/Repeat.h +++ b/aten/src/ATen/native/Repeat.h @@ -9,6 +9,9 @@ static inline Tensor repeat_interleave_common(const Tensor &repeats) { TORCH_CHECK(repeats.dim() == 1, "repeat_interleave only accept 1D vector as repeat"); TORCH_CHECK(repeats.scalar_type() == at::kLong, "repeats has to be Long tensor"); TORCH_CHECK((repeats >= 0).all().item(), "repeats can not be negative"); + if (repeats.size(0) == 0) { + return at::empty_like(repeats); + } Tensor repeats_ = repeats.contiguous(); Tensor cumsum = repeats.cumsum(0); int64_t total = cumsum[-1].item();