code: def logsumexp(x, keep_mask=None, add_one=True, dim=1):
      if keep_mask is not None:
          x = x.masked_fill(~keep_mask, c_f.neg_inf(x.dtype))
      if add_one:
          zeros = torch.zeros(
              x.size(dim - 1), dtype=x.dtype, device=x.device
          ).unsqueeze(dim)
          x = torch.cat([x, zeros], dim=dim)
  
      output = torch.logsumexp(x, dim=dim, keepdim=True)
      if keep_mask is not None:
          output = output.masked_fill(
              ~torch.any(keep_mask, dim=dim, keepdim=True), 0
          )
      return output
  
imports: import math
  import numpy
  import torch
  from .None import common_functions
label_desc: Use image node_id 1 for calling a global function with example usage: logsumexp(x, keep_mask, add_one, dim) and returns: output