pytorchdivision

tensor division in pytorch. Assertion error


This is kind of a pytorch beginner question. In pytorch I'm trying to do element wise division with two tensors of size [5,5,3]. In numpy it works fine using np.divide(), but somehow I get an error here. I'm using PyTorch version 0.1.12 for Python 3.5.

c = [torch.DoubleTensor of size 5x5x3]

input_patch = [torch.FloatTensor of size 5x5x3]

input_patch is a slice of a torch.autograd Variable, and c is made by doing c = torch.from_numpy(self.patch_filt[:, :, :, 0]).float()

When doing:

torch.div(input_patch, c)

I get this error that I don't understand.

line 317, in div
assert not torch.is_tensor(other)
AssertionError

Does it mean that variable c should not be a torch_tensor? After casting c to also be a FloatTensor gives the same error still.

Thank you!


Solution

  • Input_patch is a slice of a torch.autograd Variable, and c is made by doing

    c = torch.from_numpy(self.patch_filt[:, :, :, 0]).float() 
    

    Anyway, mexmex, thanks to your comment I've solved it by defining c as

    Variable(torch.from_numpy(self.patch_filt[:, :, :, 0])).float()