Dear all,
I’m looking for a way of reinterpreting a PyTorch tensor as a different dtype of matched size. This kind of operation is provided by NumPy, but as far as I can tell PyTorch only provides casts. (naturally, reinterpreting types is an operation that would only make sense for tensors without gradients).
Here is an example of what I mean, using NumPy:
>>> a = np.linspace(0, 1, 5, dtype=np.float32)
>>> a
array([ 0.  ,  0.25,  0.5 ,  0.75,  1.  ], dtype=float32)

>>> a.view(np.int32)
array([         0, 1048576000, 1056964608, 1061158912, 1065353216], dtype=int32)

My current workaround involves a PyTorch -> NumPy -> PyTorch roundtrip, which is not very nice/efficient.

>>> a = torch.linspace(0, 1, 5)
>>> torch.Tensor(a.numpy().view(dtype=np.int32))
tensor([         0., 1048576000., 1056964608., 1061158912., 1065353216.])

I’d be very grateful for any suggestions on how PyTorch could be convinced to change the dtype for an already-created memory region.
Thanks,
Wenzel