Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero sized tensor support for repeat_interleave #23717

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions aten/src/ATen/native/Repeat.h
Expand Up @@ -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<uint8_t>(), "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<int64_t>();
Expand Down
9 changes: 9 additions & 0 deletions test/test_torch.py
Expand Up @@ -9121,6 +9121,15 @@ def test_repeat_interleave(self):
with self.assertRaises(RuntimeError):
torch.repeat_interleave(y, torch.arange(9).reshape(3, 3), dim=0)

# test zero sized dimension
x = torch.zeros((5, 0))
y = torch.repeat_interleave(x, repeats=3, dim=1)
self.assertEqual(y, x.new_zeros(5, 0))

x = torch.tensor([], dtype=torch.int64)
y = torch.repeat_interleave(x, x)
self.assertEqual(y, x)

@unittest.skipIf(not TEST_NUMPY, "Numpy not found")
def test_repeat_tile(self):

Expand Down