// let us run this cell only if CUDA is available
if torch.cuda.is_available():
x = x.cuda()
y = y.cuda()
x + y
After Change
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construct a matrix filled zeros and of dtype long:
x = torch.zeros(5, 3, dtype=torch.long)
print(x)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construct a tensor directly from data:
x = torch.tensor([5.5, 3])
print(x)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// or create a tensor basing on existing tensor. These methods
// will reuse properties of the input tensor, e.g. dtype, unless
// new values are provided by user
x = x.new_ones(5, 3, dtype=torch.double) // new_* methods take in sizes
print(x)
x = torch.randn_like(x, dtype=torch.float) // override dtype!