This might be a potential solution to your question,
def fnew(x):
  return (~(x==0.5))*torch.nan_to_num(torch.atanh(x)/(x-0.5)) + (x==0.5)*1

This would be a branchless example of your if-else statement above. If x != 0.5 (as defined by (~(x==0.5)) ) the left hand of the is multipled by 0 and it returns 1. If x == 0.5, the opposite behaviour happens and it returns atanh(x)/(x-0.5).
I’ve only placed a torch.nan_to_num in there so to convert any nans to 0. If your inputs are only within the range (-1 ,1) you can remove the torch.nan_to_num as it’ll serve no purpose.