gives RuntimeError with empty tensor Variable

The function is giving ‘RuntimeError: out of range’ when concatenating an empty variable and a non-empty variable. Please see the example below:

import torch
x = Variable(torch.randn(1, 5).cuda())
y = Variable(torch.randn(4, 5).cuda())
z =[x,y], 0) #works fine

The below code gives runtime error:

import torch
x = Variable(torch.randn(0, 5).cuda())
y = Variable(torch.randn(4, 5).cuda())
z =[x,y], 0) #'RuntimeError: out of range'

I checked the same scenario with tensors. It works fine.

import torch
x = torch.randn(0, 5).cuda()
y = torch.randn(4, 5).cuda()
z =[x,y], 0)
1 Like

Based on the discussion on the issue below, I am tempted think that empty tensors are not expected to function and only do so by accident, but you might check with someone who has first-hand knowledge.

Best regards


Thanks for your input!

Maybe, my understanding was the other way around that the empty tensors should work.
Anyway, there is a bit of inconsistency. If we can make it consistent, it will be great.

I am using torch version ‘0.1.12+036c3f9’. I am not sure where to find the file to modify the function.