Elegantly handling empty indices for Tensor indexing

Suppose I have a tensor T and x and y coordinate vectors. T[x, y] works fine but sometimes x and y are empty/Variable of dimension=0 e.g. when x is found by calling .nonzero() on another tensor. We could explicitly check x and y are non empty but this would require doing something like

if len(x.size())>0:
modify T
else:
leave T unchanged

but I believe this would slow down the code since the if-else statement causes a synchronize()? Is there a better way to do nothing when x and y are empty?