code: def _logsumexp(a, xp, axis=None):
      vmax = xp.amax(a, axis=axis, keepdims=True)
      if xp is numpy:
          vmax += xp.log(
              xp.sum(
                  xp.exp(a - vmax),
                  axis=axis,
                  keepdims=True,
                  dtype=a.dtype,
              )
          )
      else:
          _logsumexp_impl = cuda.reduce(
              "T x, T vmax",
              "T y",
              "exp(x - vmax)",
              "a + b",
              "y += log(a)",
              "0",
              "logsumexp_impl",
          )
          _logsumexp_impl(a, vmax, vmax, axis=axis, keepdims=True)
      return xp.squeeze(vmax, axis=axis)
  
imports: import numpy
  import six
  import chainer
  from chainer import backend
  from chainer.backends import cuda
  from chainer import function
  from chainer import utils
  from chainer.utils import collections_abc
  from chainer.utils import type_check
label_desc: Use image node_id 1 for calling a global function with example usage: _logsumexp(a, xp, axis) and returns: xp