I seems to run into this error very now and then, most times unexpectedly. I tried to explain or find explanation it using tensor storage models but still do not have a reasonable explantion.
RuntimeError: unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.
For simplicity, I use these two similar statements in python (C++ has same result). One is successful, one has the
a=torch.ones(3,3) (a.mean(1, True) + a).expand_as(a).mul_(a)
a=torch.ones(3,3) (a.mean(1, True)).expand_as(a).mul_(a) RuntimeError: unsupported operation: ... ...