code: def _topk_py_impl(op, x, k, axis, idx_dtype):
      ndim = x.ndim
      assert -ndim <= axis < ndim
      axis %= ndim
      if k == 0:
          raise ValueError("topk: kth cannot be zero")
      elif k > x.shape[axis]:
          raise ValueError(
              "topk: kth cannot be larger than the size of specified axis %d"
              % axis
          )
      if abs(k) == 1:
          # negative k means min instead of max
          fn_max = [None, np.max, np.min][k]
          fn_argmax = [None, np.argmax, np.argmin][k]
          if not op.return_indices:
              return np.expand_dims(fn_max(x, axis=axis), axis)
          elif op.return_values:
              zi = np.expand_dims(fn_argmax(x, axis=axis), axis)
              idx2 = tuple(
                  np.arange(s).reshape((s,) + (1,) * (ndim - i - 1))
                  if i != axis
                  else zi
                  for i, s in enumerate(x.shape)
              )
              zv = x[idx2]
              return zv, zi.astype(idx_dtype)
          else:
              zi = np.expand_dims(fn_argmax(x, axis=axis), axis)
              return zi.astype(idx_dtype)
  
      if x.shape[axis] == abs(k):
          if not op.return_indices:
              return x.copy()
          else:
              l = axis
              r = ndim - l
              reps = list(x.shape)
              reps[axis] = 1
              zi = np.arange(abs(k), dtype=idx_dtype)
              zi = zi.reshape((1,) * l + (k,) + (1,) * (r - 1))
              zi = np.tile(zi, reps)
              if op.return_values:
                  return x.copy(), zi
              else:
                  return zi
  
      idx = [slice(None)] * ndim
      idx[axis] = slice(-k, None) if k > 0 else slice(-k)
  
      if not op.return_indices:
          zv = np.partition(x, -k, axis=axis)[idx]
          return zv
      elif op.return_values:
          zi = np.argpartition(x, -k, axis=axis)[idx]
          idx2 = tuple(
              np.arange(s).reshape((s,) + (1,) * (ndim - i - 1))
              if i != axis
              else zi
              for i, s in enumerate(x.shape)
          )
          zv = x[idx2]
          return zv, zi.astype(idx_dtype)
      else:
          zi = np.argpartition(x, -k, axis=axis)[idx]
          return zi.astype(idx_dtype)
  
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import theano
  from theano.tensor.basic import mul, arange
  from theano.gradient import grad_undefined
  from theano.tensor.subtensor import set_subtensor
label_desc: Use image node_id 5 for calling a global function with example usage: _topk_py_impl(op, x, k, axis, idx_dtype) and returns: zv, np, x, zv,  zi, zi, zv,  zi, zi, x,  zi, zi