class_docstr: Cached operator handle.
docstr: ctypes implementation of imperative invoke wrapper
docstr_tok: ["ctypes","implementation","of","imperative","invoke","wrapper"]
code: def __call__(self, *args, **kwargs):
      """ctypes implementation of imperative invoke wrapper"""
      # New FFI only supports numpy ndarray
      default_device = kwargs.pop("default_device", None)
      if not default_device:
          default_device = kwargs.pop("default_ctx", None)
      out = kwargs.pop("out", None)
      if kwargs:
          raise TypeError(
              "CachedOp.__call__ got unexpected keyword argument(s): "
              + ", ".join(kwargs.keys())
          )
      if self.is_np_sym:
          if len(args) == 1 and args[0] is None:
              args = []
          type_id = (
              default_device.device_typeid if default_device else None
          )
          device_id = (
              default_device.device_id if default_device else None
          )
          out_arg = (
              out
              if out is not None and not isinstance(out, NDArrayBase)
              else (out,)
          )
          output_vars = _api_internal.invoke(
              self.handle,
              len(args),
              *args,
              type_id,
              device_id,
              *out_arg,
          )
          if out is not None:
              return out
          if isinstance(output_vars, NDArrayBase):
              return output_vars
          else:
              return list(output_vars)
      else:
          if out is not None:
              original_output = out
              if isinstance(out, NDArrayBase):
                  out = (out,)
              num_output = ctypes.c_int(len(out))
              output_vars = c_handle_array(out)
              output_vars = ctypes.cast(
                  output_vars, ctypes.POINTER(NDArrayHandle)
              )
          else:
              original_output = None
              output_vars = ctypes.POINTER(NDArrayHandle)()
              num_output = ctypes.c_int(0)
  
          # return output stypes to avoid the c_api call for checking
          # a handle's stype in _ndarray_cls
          out_stypes = ctypes.POINTER(ctypes.c_int)()
  
          # (None, ) -> []
          if len(args) == 1 and args[0] is None:
              args = []
              assert (
                  default_device is not None
              ), "default_device is required if no input is provided"
          else:
              default_device = (
                  args[0].device
                  if default_device is None
                  else default_device
              )
  
          check_call(
              _LIB.MXInvokeCachedOp(
                  self.handle,
                  ctypes.c_int(len(args)),
                  c_handle_array(args),
                  ctypes.c_int(default_device.device_typeid),
                  ctypes.c_int(default_device.device_id),
                  ctypes.byref(num_output),
                  ctypes.byref(output_vars),
                  ctypes.byref(out_stypes),
              )
          )
  
          if original_output is not None:
              return original_output
          create_ndarray_fn = _global_var._ndarray_cls
          if num_output.value == 1:
              return create_ndarray_fn(
                  ctypes.cast(output_vars[0], NDArrayHandle),
                  stype=out_stypes[0],
              )
          else:
              return [
                  create_ndarray_fn(
                      ctypes.cast(output_vars[i], NDArrayHandle),
                      stype=out_stypes[i],
                  )
                  for i in range(num_output.value)
              ]
  
file_path: mxnet/python/mxnet/_ctypes/cached_op.py
imports: import ctypes
  from ..base import _LIB
  from ..base import c_handle_array
  from ..base import NDArrayHandle, CachedOpHandle, SymbolHandle
  from ..base import check_call
  from ..None import _global_var
  from ..ndarray._internal import NDArrayBase
  from .None import _api_internal
label_desc: Use image node_id 4 for calling the CachedOp obj's underlying member method code with example usage: obj.__call__() and returns: out, output_vars, list, original_output, create_ndarray_fn, unknown