This is required for PyTorch which runs into an issue with narrowing types. Requires an explicit cast.