
    PiV                     (   d dl Z d dlmZ d dlZd dlZd dlZd dlmZ ej	        j
        Z ej        d          Zd Zd Zd Zeej	                            d ej                    d	f ej                    d
f ej                    df ej                    df ej                    df ej                    df ej                    df ej                    df ej                    df ej                    df ej                    dfg          d                         Zeej	                            dej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        g          d                         Zd Zd Z dS )    Nwraps)Versionnumpyc                 n    t           j                            t          j        |           |          dk    S )N   )ctypes	pythonapiPyCapsule_IsValid	py_object)capsulenames     m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pyarrow/tests/test_dlpack.pyr   r       s,    --f.>w.G.GNNRSSS    c                    |                                  }t          |d          du sJ t                              |           }t          j                            ||d           |                                 dk    sJ d S )Ns   dltensorT)strict)r   r   )
__dlpack__r   npfrom_dlpacktestingassert_array_equal__dlpack_device__)arrexpected_arrDLTensorresults       r   check_dlpack_exportr   $   s}    ~~HX{33t;;;;^^C  FJ!!&,t!DDD  ""f,,,,,,r   c                 <     t                      fd            }|S )Nc                      t          j                     t          j                    }	  | i |t          j                    |k    sJ S # t          j                    |k    sJ w xY w)N)gccollectpatotal_allocated_bytes)argskwargsallocated_bytesfs      r   wrapperz&check_bytes_allocated.<locals>.wrapper/   sw    

244	A1d%f%%+--@@@@@2+--@@@@@@@@s   A
 
A%r   )r'   r(   s   ` r   check_bytes_allocatedr)   .   s8    
1XXA A A A XA Nr   )
value_typenp_type_struint8uint16uint32uint64int8int16int32int64float16float32float64c                    t          t          j                  t          d          k     rt          j        d           t                              g dt                              |                    }t          j        ||           }t          ||           t          j	        
                    |          }t          ||           |                    dd          }t                              dgt                              |                    }t          ||           |                    dd          }t                              dgt                              |                    }t          ||           |                    d          }t                              dd	gt                              |                    }t          ||           t          j        g |           }t                              g t                              |                    }t          ||           t          j	        
                    |          }t          ||           d S )
N1.24.0yNo dlpack support in numpy versions older than 1.22.0, strict keyword in assert_array_equal added in numpy version 1.24.0r         dtypetyper   r;   r   r<   )r   r   __version__pytestskiparrayr>   r"   r   Tensor
from_numpyslice)r*   r+   expectedr   t
arr_slicedarr_zeros          r   test_dlpackrL   :   s   $ r~!2!222  	 	 	 xx			+)>)>x??H
(8*
-
-
-CX&&&
	X&&A8$$$1aJxx288K#8#8x99H
H---1aJxx288K#8#8x99H
H---1JxxAbhh{&;&;x<<H
H---x,,,Hxx"((;"7"7x88H(+++
	X&&A8$$$$$r   np_typec                 :   t          t          j                  t          d          k     rt          j        d           t                              g d          }t                              ||                               dd          }t          j        	                    |          }t          ||           t                              ||                               dd          }t          j        	                    |          }t          ||           d S )	Nr8   r9   )r   r;   r<            r   r   r=   )r;   r;   r;   C)orderF)r   r   rA   rB   rC   rD   reshaper"   rE   rF   r   )rM   r   rH   rI   s       r   test_tensor_dlpackrV   l   s     r~!2!222  	 	 	 ((+++
,
,Cxx7x++33IS3IIH
	X&&A8$$$xx7x++33IS3IIH
	X&&A8$$$$$r   c                     t          t          j                  t          d          k     rt          j        d           t          j        g d          } t          j        t          d          5  t          	                    |            d d d            n# 1 swxY w Y   t          j        ddgdd	ggt          j
        t          j                              
          } t          j        t          d          5  t          	                    |            d d d            n# 1 swxY w Y   t          j        g           } t          j        t          d          5  t          	                    |            d d d            n# 1 swxY w Y   t          j        g d          } t          j        t          d          5  t          	                    |            d d d            d S # 1 swxY w Y   d S )Nz1.22.0z6No dlpack support in numpy versions older than 1.22.0.)r   Nr<   z,Can only use DLPack on arrays with no nulls.matchr   r   r<   rO   r?   z+DataType is not compatible with DLPack spec)TFTz5Bit-packed boolean data type not supported by DLPack.)r   r   rA   rB   rC   r"   rD   raises	TypeErrorr   list_r2   )r   s    r   test_dlpack_not_supportedr]      s   r~!2!222LMMM
(<<<
 
 C	y )2 
3 
3 
3  
s               (
Q!QXbhjj!!  C 
y(U	V	V	V  
s               (2,,C	y(U	V	V	V  
s               (&&&
'
'C	y )2 
3 
3 
3  
s                 sH   0BBB<D##D'*D'FFF G((G,/G,c                     t          j        d          } t          j        t          j        dt          j                              g          }t          j        g dt          j                              }t          j        |g|          }|                     || 	                    d                    }| 
                    ||j                  }|d         }t          j        t          d          5  t                              |           d d d            n# 1 swxY w Y   t          j        t          d          5  |                                 d d d            d S # 1 swxY w Y   d S )	Nzpyarrow.cudaf0r:   r?   )schemar   z=DLPack support is implemented only for buffers on CPU device.rX   )rB   importorskipr"   r`   fieldr1   rD   record_batchserialize_record_batchContextread_record_batchrZ   NotImplementedErrorr   r   r   )cudar`   a0batchcbufcbatchcarrs          r   test_dlpack_cuda_not_supportedrn      s   ~..DYrxzz22344F	)))"(**	-	-	-BORD000E&&udll1oo>>D##D%,77F$<D 
* 39 
: 
: 
:  
t               
* 39 
: 
: 
: ! !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s$   5DD #D E$$E(+E()!r	   	functoolsr   r    rB   pyarrowr"   pyarrow.vendored.versionr   markr   
pytestmarkra   r   r   r   r)   parametrizer,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   rL   rV   r]   rn    r   r   <module>rv      s1  $        				      , , , , , , [
V!!T T T- - -	 	 	 !	W	h	h	h	F	W	W	W	y!	y!	y!  % %!  "%B (BIry")'28RXrx*bj"*?@ @% %	@ @ 
%   6! ! ! ! !r   