I want to compare two tensors by identity / by reference. Normally, comparing two objects in python by identity works with ‘is’ or by comparing id() values. However, this does not seem to work:
a = torch.tensor([1,2,3])
b = a.detach()
print(a.data is b.data) # False
print(id(a.data) == id(b.data)) # True
Shouldn’t both of these statements be True?
It looks like I can make a reference comparison with id()==id(), but I am reluctant to trust that this will always work because to my knowledge using ‘is’ should be the way to do it, and that isn’t working.
Can anyone clarify if that is a bug or a feature? How are you supposed to compare two tensors by reference?