Hi,
I’ll try to address your questions in the following points.
- For training neural networks, using
float
is more than enough precision-wise, so no need fordouble
. - For keeping track of indices,
int32
might not be enough for large models, soint64
(long
) is preferred. That’s probably one of the reasons why we uselong
whenever we pass indices to functions (includingNLLLoss
) - Note that you can also convert a numpy array to a tensor using
torch.Tensor(numpy_array)
, and you can specify the type of the output tensor you want, in your casetorch.LongTensor(numpy_array)
. This constructor does not share memory with the numpy array, so it’s slower and less memory efficient than thefrom_numpy
equivalent. - You can get the type of the tensor by passing no arguments to the
type
function, sotensor.type()
returns the type of the tensor, and you can do things like
tensor = torch.rand(3).double()
new_tensor = torch.rand(5).type(tensor.type())