o
    پi                     @   s   d Z ddlmZ ddlZddlZddlZddlZddl	m
Z
mZmZ ddl	mZmZmZmZ ddl	mZ G dd	 d	eZdd
dZdddZedfddZdd Zee dS )ztDECORD Runtime NDArray API.

decord.ndarray provides a minimum runtime array structure to be
used with C++ library.
    )absolute_importN   )DECORDContext
DECORDTypeNDArrayBase)contextemptyfrom_dlpacknumpyasarray)_set_class_ndarrayc                   @   s   e Zd ZdZdd ZdS )NDArrayz/Lightweight NDArray class for DECORD framework.c                 C   s   t tj| jdS )Nr   )	functoolsreduceoperatormulshape)self r   B/home/ubuntu/.local/lib/python3.10/site-packages/decord/ndarray.py__len__   s   zNDArray.__len__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                 C   
   t d| S )zConstruct a CPU device

    Parameters
    ----------
    dev_id : int, optional
        The integer device id

    Returns
    -------
    ctx : DECORDContext
        The created context
    r   r   dev_idr   r   r   cpu      
r   c                 C   r   )zConstruct a GPU device

    Parameters
    ----------
    dev_id : int, optional
        The integer device id

    Returns
    -------
    ctx : DECORDContext
        The created context
       r   r   r   r   r   gpu&   r   r!   c                 C   s0   t | tjtfst| } t| j| j|| S )a  Create an array from source arr.

    Parameters
    ----------
    arr : numpy.ndarray
        The array to be copied from

    ctx : DECORDContext, optional
        The device context to create the array

    Returns
    -------
    ret : NDArray
        The created array
    )	
isinstance_npndarrayr   arrayr   r   dtypecopyfrom)arrctxr   r   r   r%   5   s   
r%   c                 C   s"   t | \}}t|}t|ddS )zCreate an array that shares the given numpy data.

    Parameters
    ----------
    np_data : numpy.ndarray
        The numpy data

    Returns
    -------
    NDArray
        The array
    T)is_view)r
   ctypespointerr   )np_datar(   _handler   r   r   zerocopy_from_numpyI   s   
r0   )r   )r   
__future__r   _absr+   r   r   numpyr#   _ffi.ndarrayr   r   r   r   r   r	   r
   r   r   r   r!   r%   r0   r   r   r   r   <module>   s    

