CClassifierPytorch casts all arrays to float32
When transforming a CArray in PyTorch tensor, _from_tensor
sets the type of the tensor to torch.FloatTensor
, which corresponds to 32-bit float. However, the implicit data type for ndarray and CArray is float64. This casting should be removed (PyTorch accepts all numpy data types), or it can be changed to torch.DoubleTensor
to cast arrays to float64.
A small code example to show the effect of this issue:
from secml.array import CArray
import torch
x = CArray.rand(1, random_state=0)
print(x.item())
x = x.tondarray()
x = torch.from_numpy(x)
x = x.type(torch.FloatTensor) # comment or change with `torch.DoubleTensor` to fix the issue
print(x.item())