code: def _sum_axis(
      x_gpu,
      axis=None,
      out=None,
      calc_mean=False,
      ddof=0,
      keepdims=False,
  ):
      global _global_cublas_allocator
      assert isinstance(ddof, numbers.Integral)
  
      if axis is None or len(x_gpu.shape) <= 1:
          out_shape = (1,) * len(x_gpu.shape) if keepdims else ()
          if calc_mean == False:
              return gpuarray.sum(x_gpu).reshape(out_shape)
          else:
              return gpuarray.sum(x_gpu).reshape(out_shape) / (
                  x_gpu.dtype.type(x_gpu.size - ddof)
              )
  
      if axis < 0:
          axis += 2
      if axis > 1:
          raise ValueError("invalid axis")
  
      if x_gpu.flags.c_contiguous:
          n, m = x_gpu.shape[1], x_gpu.shape[0]
          lda = x_gpu.shape[1]
          trans = "n" if axis == 0 else "t"
          sum_axis, out_axis = (m, n) if axis == 0 else (n, m)
      else:
          n, m = x_gpu.shape[0], x_gpu.shape[1]
          lda = x_gpu.shape[0]
          trans = "t" if axis == 0 else "n"
          sum_axis, out_axis = (n, m) if axis == 0 else (m, n)
  
      if calc_mean:
          alpha = 1.0 / (sum_axis - ddof)
      else:
          alpha = 1.0
      if x_gpu.dtype == np.complex64:
          gemv = cublas.cublasCgemv
      elif x_gpu.dtype == np.float32:
          gemv = cublas.cublasSgemv
      elif x_gpu.dtype == np.complex128:
          gemv = cublas.cublasZgemv
      elif x_gpu.dtype == np.float64:
          gemv = cublas.cublasDgemv
      else:
          raise ValueError("unsupported dtype")
  
      alloc = _global_cublas_allocator
      ons = ones((sum_axis,), x_gpu.dtype, allocator=alloc)
  
      if keepdims:
          out_shape = (1, out_axis) if axis == 0 else (out_axis, 1)
      else:
          out_shape = (out_axis,)
  
      if out is None:
          out = gpuarray.empty(out_shape, x_gpu.dtype, alloc)
      else:
          assert out.dtype == x_gpu.dtype
          assert out.size >= out_axis
  
      gemv(
          _global_cublas_handle,
          trans,
          n,
          m,
          alpha,
          x_gpu.gpudata,
          lda,
          ons.gpudata,
          1,
          0.0,
          out.gpudata,
          1,
      )
      return out
  
imports: from __future__ import absolute_import, division
  import atexit
  import numbers
  from string import Template
  import pycuda.driver
  import pycuda.gpuarray
  import pycuda.elementwise
  import pycuda.reduction
  import pycuda.scan
  import pycuda.tools
  from pycuda.tools import context_dependent_memoize, dtype_to_ctype
  from pycuda.compiler import SourceModule
  from pytools import memoize
  import numpy
  from .None import cuda
  from .None import cublas
  import sys
  import operator
label_desc: Use image node_id 31 for calling a global function with example usage: _sum_axis(x_gpu, axis, out, calc_mean, ddof, keepdims) and returns: out, gpuarray, unknown