
    "hh                        d dl 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 ej                  j
                  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d Zd Zy# e$ r dZY 'w xY w)    Nwraps)Versionc                 n    t         j                  j                  t        j                  |       |      dk(  S )N   )ctypes	pythonapiPyCapsule_IsValid	py_object)capsulenames     V/var/www/html/sandstorm/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>.wrapper4   s\    


224	Ad%f%++-@@@2++-@@@s   A A'r   )r&   r'   s   ` r   check_bytes_allocatedr(   3   s"    
1XA A Nr   )
value_typenp_type_struint8uint16uint32uint64int8int16int32int64float16float32float64c                 f   t        t        j                        t        d      k  rt        j                  d       t        j
                  g dt        j                  |            }t        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        ||       y )
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  	 xx	+)>?H
((8*
-CX&1aJxx288K#89H
H-1aJxx288K#89H
H-1JxxAbhh{&;<H
H-xx,Hxx"((;"7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        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   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   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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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   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      sH  $   	   ,
 [[
T-	 !	W	h	h	h	F	W	W	W	y!	y!	y! ,! ",66![  	Bs   D5 5E ?E 