o
    پi                     @   s8   d Z ddlmZ ddlmZ dd Zdd Zd	d
 ZdS )zDECORD Pytorch bridge    )absolute_import   )_from_dlpackc               
   C   s>   d} zt ddgdW S  ty } z| s|t| d}~ww )zqTry import torch at runtime.

    Returns
    -------
    torch module if found. Raise ImportError otherwise
    z>torch is required, you can install by pip: `pip install torch`ztorch.utils.dlpackobject)fromlistN)
__import__ImportError)messagee r   I/home/ubuntu/.local/lib/python3.10/site-packages/decord/bridge/torchdl.pytry_import_torch   s   r   c                 C   s   t  }||  S )zFrom decord to torch.
    The tensor will share the memory with the object represented in the dlpack.
    Note that each dlpack can only be consumed once.)r   from_dlpack	to_dlpack)
decord_arrdlpackr   r   r   to_torch      r   c                 C   s   t  }t|| S )ztFrom torch to decord.
    The dlpack shares the tensors memory.
    Note that each dlpack can only be consumed once.)r   r   r   )tensorr   r   r   r   
from_torch   r   r   N)__doc__
__future__r   _ffi._ctypes.ndarrayr   r   r   r   r   r   r   r   <module>   s    