Pointer type behavior in pytorch
Is there pointer type assignment in pytorch? What I would like to do is have the following (pseudo-code):
b=8
a-&gt;b
print(a) --&gt; 8
b=10
print(a) --&gt; 10


It depends on how you modify b :
# Assign a new object to b : b*2
&gt;&gt;&gt; b = torch.tensor([8]); a=b; print(a); b=b*2; print(a)
tensor([8])
tensor([8])

# Assign a new object to b : tensor([10])
&gt;&gt;&gt; b = torch.tensor([8]); a=b; print(a); b=torch.tensor([10]); print(a)
tensor([8])
tensor([8])

# In-place operation which doesn't assign a new object
&gt;&gt;&gt; b = torch.tensor([8]); a=b; print(a); b*=2; print(a)
tensor([8])
tensor([16])

# In-place operation because it acts directly on the underlying data
&gt;&gt;&gt; b = torch.tensor([8]); a=b; print(a); b.data*=2; print(a)
tensor([8])
tensor([16])


So you can't really do pointer assignment in Pytorch...
But you can get the desired result using in-place operations or directly acting on the underlying data of the tensor.
