Concatenate Variables

I have an empty tensor wrapped in Variable

result = Variable(torch.Tensor().cuda())

and another non-empty cuda tensor wrapped in Variable which is output of a network

temp = self.forward(model, input)
temp = temp.view(-1)

How can I concatenate result and temp Variables?

result = torch.cat([result,temp]) throws the below error.

RuntimeError: dimension specified as 0 but tensor has no dimensions

This is with reference to this part of code, that I’m trying to port to pytorch. Thank you.

EDIT: some like below tensorflow code

result = []
input_downsampled = input
for i in range(3):
       result.append(self.forward(model, input_downsampled))
       if i != (2):
            input_downsampled = self.downsample(input_downsampled)
return result

It makes no sense to concatenate nothing with something.
At a guess you want something like this…

if result is None:
    result = temp
else:
    result = torch.cat([result, temp])

Something like below tensorflow code:

result = []
input_downsampled = input
for i in range(3):
       result.append(self.forward(model, input_downsampled))
       if i != (2):
            input_downsampled = self.downsample(input_downsampled)
return result

What about this…

result = None
input_downsampled = input
for i in range(3):
       if result is None:
            result = self.forward(model, input_downsampled)
       else:
            result = torch.cat([model, self.forward(model, input_downsampled)])
       if i != (2):
            input_downsampled = self.downsample(input_downsampled)
return result

The tensorflow code you posted returns a list. How is this list used? If it is used as a list of tensors and not as a tensor itself, then the code you posted should do the job just fine.