torch.pow does not work
I'm trying to create a custom loss function using PyTorch, and am running into a simple error. 

When I try to use torch.pow to take the exponent of a PyTorch Variable, I get the following error message:

AttributeError: 'torch.LongTensor' object has no attribute 'pow'

In the python terminal, I created a simple Variable, and attempted to do the same, and received the same error. Here's a snippet that should recreate the problem:

import torch
from torch.autograd import Variable
import numpy as np

v = Variable(torch.from_numpy(np.array([1, 2, 3, 4])))
torch.pow(v, 2)


I can't find any information on this issue, and nothing is showing up in search results. Help?

EDIT: this problem also occurs when I try to use torch.sqrt()
EDIT: same problem also happens if I try to do 

v.pow(2)


pow is definitely a method of v, and the docs clearly state that pow is a method that exists and takes a tensor as it's argument. I really don't see how this is happening, and it seems to me that the docs are just flat out wrong and these methods don't actually work. 

You need to initialize the tensor as floats, because pow always returns a Float.

import torch
from torch.autograd import Variable
import numpy as np

v = Variable(torch.from_numpy(np.array([1, 2, 3, 4], dtype="float32")))
torch.pow(v, 2)


You can cast it back to integers afterwards 

torch.pow(v, 2).type(torch.LongTensor)


yields 

Variable containing:
  1
  4
  9
 16
[torch.LongTensor of size 4]

