code: def ndarray_from_dlpack(array_cls):
      """Returns a function that returns specified array_cls from dlpack.
  
      Returns
      -------
      fn : dlpack -> array_cls
      """
  
      def from_dlpack(dlpack):
          tp = type(dlpack)
          if tp.__module__ == "builtins" and tp.__name__ == "PyCapsule":
              dlpack = ctypes.py_object(dlpack)
          elif hasattr(dlpack, "__dlpack__"):
              device, device_id = dlpack.__dlpack_device__()
              if device != DLDeviceType.DLGPU:
                  dlpack = ctypes.py_object(dlpack.__dlpack__())
              else:
                  s = mx_int()
                  check_call(
                      _LIB.MXGetCurrentStream(
                          ctypes.c_int(device_id), ctypes.byref(s)
                      )
                  )
                  dlpack = ctypes.py_object(
                      dlpack.__dlpack__(stream=s.value)
                  )
          else:
              raise AttributeError(
                  "Required PyCapsule or object with __dlpack__"
              )
          handle = NDArrayHandle()
          assert ctypes.pythonapi.PyCapsule_IsValid(
              dlpack, _c_str_dltensor
          ), ValueError(
              "Invalid DLPack Tensor. DLTensor capsules can be consumed only once."
          )
          dlpack_handle = ctypes.c_void_p(
              ctypes.pythonapi.PyCapsule_GetPointer(
                  dlpack, _c_str_dltensor
              )
          )
          check_call(
              _LIB.MXNDArrayFromDLPack(
                  dlpack_handle, False, ctypes.byref(handle)
              )
          )
          # Rename PyCapsule (DLPack)
          ctypes.pythonapi.PyCapsule_SetName(
              dlpack, _c_str_used_dltensor
          )
          # delete the deleter of the old dlpack
          ctypes.pythonapi.PyCapsule_SetDestructor(dlpack, None)
          return array_cls(handle=handle)
  
      return from_dlpack
  
file_path: mxnet/python/mxnet/dlpack.py
imports: import ctypes
  import enum
  from mxnet.device import current_device
  from .base import _LIB, c_str, check_call, NDArrayHandle, mx_int
label_desc: Use image node_id 3 for calling a global function with example usage: ndarray_from_dlpack(array_cls) and returns: from_dlpack, array_cls