While running the following code
A = Variable(torch.zeros(10))
B = Variable(torch.randn(10,10))
for i in range(0,10):
A[i] = B[i,i]
I get the following error:
RuntimeError: in-place operations can be only used on variables that don't share storage with any other variables, but detected that there are 2 objects sharing it
I can work around the error by using A[6:] = 0. However, I am wondering the reason for prohibiting the use of in-place operations. Moreover, isn’t the operation A[6:] = 0 inplace as well?