How to make Tensor pass by reference?

In-place function could achieve it, but many operators has no in-place method, such as followings. How should I do pass by reference for such cases?

def foo(a, b):
   a = torch.max(a, b)

def foo2(a, b, c):
   a = torch.where(c, a, b)

Hi,

All objects are passed by reference in python.
But doing a = does not try to change a inplace. It only give the name “a” to the object returned by the right hand side.
You can change a inplace by doing explicit inplace change: a.copy_(torch.max(a, b)) for example.

5 Likes