
    z-Phh                     R   d dl Z d dlmZ d dlZd dlZ	 d dlZn# e$ r dZY nw xY wd dlZ	d dl
mZ ej        j        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d Zd ZdS )    Nwraps)Versionc                 n    t           j                            t          j        |           |          dk    S )N   )ctypes	pythonapiPyCapsule_IsValid	py_object)capsulenames     Y/var/www/html/test/jupyter/venv/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          j        |           }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>.wrapper4   sw    

244	A1d%f%%+--@@@@@2+--@@@@@@@@s   A
 
A%r   )r&   r'   s   ` r   check_bytes_allocatedr(   3   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          j        g dt          j        |                    }t          j        ||           }t          ||           |	                    dd          }t          j        dgt          j        |                    }t          ||           |	                    dd          }t          j        dgt          j        |                    }t          ||           |	                    d          }t          j        dd	gt          j        |                    }t          ||           t          j        g |           }t          j        g t          j        |                    }t          ||           d S )
Nz1.24.0zyNo 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   r8   r   r9   )
r   r   __version__pytestskiparrayr:   r!   r   slice)r)   r*   expectedr   
arr_slicedarr_zeros         r   test_dlpackrE   ?   s   $ r~!2!222  	 	 	 x			+)>)>???H
(8*
-
-
-CX&&&1aJx28K#8#8999H
H---1aJx28K#8#8999H
H---1JxAbh{&;&;<<<H
H---x,,,Hx"(;"7"7888H(+++++r   c                     t          t          j                  t          d          k     rt          j        d           t          j        g d          } t          j        t          d          5  t          j	        |            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          j	        |            d d d            n# 1 swxY w Y   t          j        g           } t          j        t          d          5  t          j	        |            d d d            n# 1 swxY w Y   t          j        g d          } t          j        t          d          5  t          j	        |            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   Nr9   z,Can only use DLPack on arrays with no nulls.matchr   r   r9      r;   z+DataType is not compatible with DLPack spec)TFTz5Bit-packed boolean data type not supported by DLPack.)r   r   r=   r>   r?   r!   r@   raises	TypeErrorr   list_r1   )r   s    r   test_dlpack_not_supportedrM   k   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6DDDE22E69E6.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          j        |           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f0r7   r;   )schemar   z=DLPack support is implemented only for buffers on CPU device.rG   )r>   importorskipr!   rP   fieldr0   r@   record_batchserialize_record_batchContextread_record_batchrJ   NotImplementedErrorr   r   r   )cudarP   a0batchcbufcbatchcarrs          r   test_dlpack_cuda_not_supportedr^      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   r>   numpyr   ImportErrorpyarrowr!   pyarrow.vendored.versionr   mark
pytestmarkr
   r   r(   parametrizer+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   rE   rM   r^    r   r   <module>rh      s  $        				    	BBB     , , , , , ,
 [
T T T- - -	 	 	 !	W	h	h	h	F	W	W	W	y!	y!	y!  , ,!  ",6  6! ! ! ! !s    ##