a
    yn„f  ã                   @  s~   d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZ dZeƒ d	d
d	ddddœdd„ƒZdS )é    )Úannotations)ÚDLPackDevice)Úhigh_level_function)Úfrom_arraylibÚwrap_layout)ÚCupy)ÚNumpy)Ú	NumpyLike)Úfrom_dlpackTFNÚerror)Ú
prefer_cpuÚregulararrayÚ	highlevelÚbehaviorÚprimitive_policyÚattrsc             
   C  sþ   z
| j }W n8 tyB } z tdt| ƒ› �ƒ|‚W Y d}~n
d}~0 0 |ƒ \}	}
|	tjkrbt ¡ }nx|	tjkrvt	 ¡ }nd|	tj
krŠt ¡ }nP|	tjkržt	 ¡ }n<|	tjkrº|r°tnt	 ¡ }n |	tjkrÖ|rÌtnt	 ¡ }nt‚| | ¡} tt| |d|d�||d�S )a¯  
    Args:
        array (cp.ndarray): The DLPack-supporting array to convert into an
            Awkward Array.
        prefer_cpu (bool): If True, and the array device supports both CPU and
            GPU backends, prefer the CPU; otherwise, prefer the GPU.
        regulararray (bool): If True and the array is multidimensional,
            the dimensions are represented by nested #ak.contents.RegularArray
            nodes; if False and the array is multidimensional, the dimensions
            are represented by a multivalued #ak.contents.NumpyArray.shape.
            If the array is one-dimensional, this has no effect.
        highlevel (bool): If True, return an #ak.Array; otherwise, return
            a low-level #ak.contents.Content subclass.
        behavior (None or dict): Custom #ak.behavior for the output array, if
            high-level.
        attrs (None or dict): Custom attributes for the output array, if
            high-level.

    Converts a DLPack-aware array into an Awkward Array.

    The resulting layout may involve the following #ak.contents.Content types
    (only):

    * #ak.contents.NumpyArray
    * #ak.contents.RegularArray if `regulararray=True`.
    zAExpected an object that implements the DLPack protocol, received NF)r   )r   r   )Z__dlpack_device__ÚAttributeErrorÚ	TypeErrorÚtyper   ZCPUr   ÚinstanceÚCUDAr   ZCUDA_PINNEDZROCMZROCM_PINNEDZCUDA_MANAGEDÚAssertionErrorr
   r   r   )Úarrayr   r   r   r   r   r   Zdlpack_info_funcÚerrZdevice_typeZ	device_idZnplike© r   úd/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/awkward/operations/ak_from_dlpack.pyr
      s8    %
ÿþ











ýr
   )Ú
__future__r   Zawkward._connect.dlpackr   Zawkward._dispatchr   Zawkward._layoutr   r   Zawkward._nplikes.cupyr   Zawkward._nplikes.numpyr   Zawkward._nplikes.numpy_liker	   Ú__all__r
   r   r   r   r   Ú<module>   s   ø