Move tensor to the same gpu of another tensor

Thanks @ptrblck. The problem I have with the “Tensor.new” function is that

  1. If “a” is on GPU and “b” on CPU, then “a.new(b)” does not work (error: …constructor received an invalid combination of arguments…). “a.new(b.numpy())” works though, but I am afraid that it is inefficient.

  2. If “a” and “b” are already on the same device, then “a.new(b)” will unnecessarily create a new copy of “b”

I am looking for a function like “b.type_as(a)”, but could automatically move the data to the same device as “a”.