Set_index() for tensor.device()

I want to write a code to explicitly delegate index to all tensors and the result is that every tensor should have a default device().index() 0.

So I wrote the code as follows:

  if (! rawTensor.device().has_index()){
    rawTensor.device().set_index(0);
  }

However, this seems not work. Does this mean that I must explicitly call tensor.to( ‘cpu:0’) ? If so, what is the point of offering a set_index() function?

If so, what is the point of offering a set_index() function?

I am not a specialist of that part of the code but I would expect this function to simply update the device object that was returned (so that you can pass it to a further constructor or .to function). I don’t expect it to modify the Tensor itself.
Also note that all these functions that move Tensors across devices are applied out of place so you need to get the new object they return to get the new Tensor.