Consider three tensors a = 5*torch.rand(5), b = torch.zeros(5,5) and c = torch.zeros(5). I just realized that b[a.long(),a.long()] = c disconnects a from the computation graph due to the casting operation (a.long()). In my case, a has history and a.requires_grad=True. How can I avoid it getting disconnected during this operation?