code: def log_substraction_exp(a, b):
      """return (a.exp() - b.exp()).log(): a numeracal safe implementation"""
      ans = torch.ones_like(a) * float("-inf")
  
      # avoid -inf in input
      mask1 = torch.logical_and(~torch.isinf(a), ~torch.isinf(b))
      a_ = torch.where(mask1, a, -1.0)  # avoid any operation on -inf
      b_ = torch.where(mask1, b, -2.0)
  
      # avoid -inf in output: need to be very small
      # as these values would be picked by mask1
      ans_tmp = b_ + ((a_ - b_).exp() - 1).log()
      a_ = torch.where(torch.isinf(ans_tmp), -2000.0, a_)
      b_ = torch.where(torch.isinf(ans_tmp), -2001.0, b_)
  
      ans1 = b_ + ((a_ - b_).exp() - 1).log()
      ans = torch.where(mask1, ans1, ans)
  
      mask2 = torch.logical_and(~torch.isinf(a), torch.isinf(b))
      ans = torch.where(mask2, a, ans)
  
      return ans
  
file_path: espnet/espnet2/asr/bayes_risk_ctc.py
imports: import logging
  import _k2
  import k2
  import torch
label_desc: Use image node_id 1 for calling a global function with example usage: log_substraction_exp(a, b) and returns: ans