
    /_iV                        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                  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j0                         df ej2                         df ej4                         df ej6                         df ej8                         dfg      d               Zeej                  j#                  dej$                  ej&                  ej(                  ej*                  ej,                  ej.                  ej0                  ej2                  ej4                  ej6                  ej8                  g      d               Zd Zd Z y)    Nwraps)Versionnumpyc                 n    t         j                  j                  t        j                  |       |      dk(  S )N   )ctypes	pythonapiPyCapsule_IsValid	py_object)capsulenames     X/var/www/html/land_sniper/venv/lib/python3.12/site-packages/pyarrow/tests/test_dlpack.pyr   r       s,    --f.>.>w.GNRSSS    c                     | j                         }t        |d      du sJ t        j                  |       }t        j                  j                  ||d       | j                         dk(  sJ y )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   $   sa    ~~HX{3t;;;^^C FJJ!!&,t!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/   s\    


224	Ad%f%++-@@@2++-@@@s   A A'r   )r'   r(   s   ` r   check_bytes_allocatedr)   .   s"    
1XA 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        ||       t        j                  j                  |      }t        ||       |j                  dd      }t        j                  dgt        j                  |            }t        ||       |j                  dd      }t        j                  dgt        j                  |            }t        ||       |j                  d      }t        j                  dd	gt        j                  |            }t        ||       t        j
                  g |       }t        j                  g t        j                  |            }t        ||       t        j                  j                  |      }t        ||       y )
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   :   su   $ r~~!22  	 xx	+)>x?H
((8*
-CX&
		X&A8$1aJxx288K#8x9H
H-1aJxx288K#8x9H
H-1JxxAbhh{&;x<H
H-xx,Hxx"((;"7x8H(+
		X&A8$r   np_typec                    t        t        j                        t        d      k  rt        j                  d       t        j                  g d      }t        j                  ||       j                  dd      }t        j                  j                  |      }t        ||       t        j                  ||       j                  dd      }t        j                  j                  |      }t        ||       y )	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  	 ((+
,Cxx7x+33IS3IH
		X&A8$xx7x+33IS3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        j                  |        d d d        t        j                  ddgdd	ggt        j                  t        j                               
      } t        j                  t        d      5  t        j                  |        d d d        t        j                  g       } t        j                  t        d      5  t        j                  |        d d d        t        j                  g d      } t        j                  t        d      5  t        j                  |        d d d        y # 1 sw Y   $xY w# 1 sw Y   xY w# 1 sw Y   sxY w# 1 sw Y   y xY w)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]      sT   r~~!22LM
((<
 C	y )2 
3 
s ((
Q!QXXbhhj!C 
y(U	V 
s ((2,C	y(U	V 
s ((&
'C	y )2 
3 
s #   
 s0   -F%(F26F>G
%F/2F;>G
Gc                     t        j                  d      } t        j                  t        j                  dt        j
                               g      }t        j                  g dt        j
                               }t        j                  |g|      }| j                  || j                  d            }| j                  ||j                        }|d   }t        j                  t        d      5  t        j                  |       d d d        t        j                  t        d      5  |j                          d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)	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YYrxxz234F	)"((*	-BOORD0E&&udll1o>D##D%,,7F$<D 
* 39 
: 
t 
* 39 
: ! ! !	 ! !s   2E+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      s  $   	   , [[
V!T-	 !	W	h	h	h	F	W	W	W	y!	y!	y! %! "%B ((BIIryy"))''288RXXrxx**bjj"**?@%	@ 
% 6!r   