code: def _einsum(
      xp, dtype, in_subscripts, out_subscript, *inputs, **kwargs
  ):
      (check_undefined_ellipsis_sum,) = argument.parse_kwargs(
          kwargs, ("check_undefined_ellipsis_sum", False)
      )
      sum_ellipsis = "@" in in_subscripts and "@" not in out_subscript
      if sum_ellipsis:
          # einsum does not usually allow summing over '...'
          subscripts = "{}->...{}".format(
              in_subscripts.replace("@", "..."), out_subscript
          )
      else:
          subscripts = "{}->{}".format(
              in_subscripts, out_subscript
          ).replace("@", "...")
  
      # Use optimize option whenever it is critical in speed.
      # Otherwise avoid bugs in numpy>=1.12,<1.15.
      einsum_kwargs = {}
      if len(inputs) >= 3:
          einsum_kwargs["optimize"] = True
      try:
          y = xp.einsum(subscripts, *inputs, **einsum_kwargs)
      except TypeError:
          warnings.warn(
              "{xp}.einsum does not support optimize option. "
              "Use newer version of {xp} to speed up.".format(
                  xp=xp.__name__
              ),
              chainer.warnings.PerformanceWarning,
          )
          y = xp.einsum(subscripts, *inputs)
  
      if sum_ellipsis:
          sum_ndim = y.ndim - len(out_subscript)
          if check_undefined_ellipsis_sum and sum_ndim > 0:
              raise ValueError(
                  "einsum should not support summing over Ellipsis, "
                  "while NumPy 1.14 sometimes accidentally supports it. "
                  "This feature is no longer supported by Chainer. "
                  "See also NumPy issues #10926, #9984.",
              )
          y = xp.sum(y, axis=tuple(range(sum_ndim)))
  
      return utils.force_array(y, dtype)
  
imports: import warnings
  import chainer
  from chainer import backend
  from chainer.backends import cuda
  from chainer import function_node
  from chainer import utils
  from chainer.utils import argument
  from chainer.utils import type_check
label_desc: Use image node_id 2 for calling a global function with example usage: _einsum(xp, dtype, in_subscripts, out_subscript) and returns: utils