Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.142.172.178
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_buffer.cpython-310.pyc
o

`b<��@sJddlZddlZddlmZddlmZddlmZmZddl	m
Z
mZmZddl
Z
ddlZddlZddlZddlZddlmZddlmZzddlTWneyWdZYnwzddlZWneyidZYnwzddlZWney{dZYnwz1e���#e_e
���dd	lmZWd�n1s�wYWd�n1s�wYWney�dZYnwzddl Z Wney�dZ Ynwd
Z!dddddddddddddddd�Z"er�e"d=e"d
=e�rze�#dd�de"d<de"d<Wnej$�yYnwddddddddddddddd>dd>fd�Z%dd�Z&e"e"e%e%e%e%d�Z'e�r>e'd D]Z(e&e(�e'd e(<�q2e"�)�Z*e"�)�Z+e"D]Z,e,d!v�rRe+e,=�qHe"�)�Z-e"D]Z,e,d"v�rde-e,=�qZe*e'd#<e*e'd$<e+e'd%<e-e'd&<e-e'd'<dZ.dZ/gd�gd(�fd%gd)gfd)gd)gfd$d#gd)gfd'd&gd)gfd*�Z0d+d,�Z1d-d.�Z2d/d0�Z3d1d2�Z4d�d4d5�Z5d	d6d7�Z6d	d8d9�Z7d:d;�Z8d<d=�Z9d>d?�e'd D�Z:d@dA�Z;dBdC�Z<dDdE�Z=dFdG�Z>dHdI�Z?dJdK�Z@dLdM�ZAdNdO�ZBdPdQ�ZCdRdS�ZDdTdU�ZEdVdW�ZFdXdY�ZGdZd[�ZHd\d]�ZId^d_�ZJd`da�ZKdbdc�ZLddde�ZMdfdg�ZNdhdi�ZOdjdk�ZPd�dodp�ZQdqdr�ZRdsdt�ZSd�dudv�ZTdwdx�ZUd�dydz�ZVd{d|�ZWd�d}d~�ZXdd��ZYd�d��ZZd�d��Z[d�d�d��Z\d�d�d��Z]d�d�d��Z^d�d�d��Z_d�d��Z`d�ZadlZbd�Zce!�r�d�Zad�Zbd�Zce]ZZe^Z[e_Ze�ded��e�ded��Gd�d��d�eje���Zfegd�k�r�e�h�dSdS)��N)�support)�	os_helper)�permutations�product)�	randrange�sample�choice)�Decimal)�Fraction)�*)�ndarrayT)�?�c�b�B�h�H�i�I�l�L�n�N�f�d�Prr�Q������q�r��r�)i�����)i�����)ri)���)rl�l������r���)r
rrrrrrrrrrrrrc	Cs�|dkrd}|S|dkrd}|S|dkrd}|S|dkr'dd	>dd	>f}|Sd
D]}z
t�|d|>d�WqCtjyBYq)w|d@rPd|>d|>fndd|>f}|S)zReturn range of a native type.rr!r
rrr'rr+r,)
r#��@�?� �����r)�struct�pack�error)�fmt�lh�exp�r<�9/usr/local/python-3.10/lib/python3.10/test/test_buffer.py�native_type_range_s*�
��	��&r>)��@�<�>�=�!r@Z
bBhHiIlLfdZBbc�m�@m�ar�@b)r?�1�2�3r?)r�array�numpy�
memoryview�bytefmtcCsvtt||�}|dkrt|g�}|dkr|dkrd}|dkr#t|�}|dks+|dkr9t�||�}t�||�d}|S)	zWReturn random item for a type specified by a mode and a single
       format character.rrM��r
rrr)r�fmtdict�bytes�boolr6r7�unpack)�mode�char�obj�xr<r<r=�
randrange_fmt�s
rZcCsJ|�d�\}}g}|D]}|�t|||��qt|�dkr!|dSt|�S)zReturn single random item.�#r+r)�split�appendrZ�len�tuple)r9rXrV�charsrYrr<r<r=�gen_item�s
racCs<|dkr	t||�Sdg|}t|�D]	}t||�||<q|S)z,Return a list of random items (or a scalar).r)ra�range)rr9rX�lstrr<r<r=�	gen_items�s

rdcCs�tt|t�}|d}|�d�}tdd�}t|�D]$}ttt|��}tt|t�}||t	|r3|nd�7}|||7}qt
|||�}	t||�}
||	|
fS)Nr[�ambr �
r+)r�cap�MODE�striprrbr_rR�MULT�intrdra)rrXrVZxfmtr9�nmemb�_rW�
multiplier�items�itemr<r<r=�struct_items�s



rqrcCs�|durtt|t�}|durttt|��}tt|t�}|d|t|r)|nd�}t|||�}t||�}|�	d�||}|||fS)z"Return random format, items, item.Nr[r+re)
rrgrhr_rRrjrkrdrari)rrXrVrWrnr9rorpr<r<r=�	randitems�s

rrccs6�t|tD]}t|D]
}t||||�Vq
qdS)z1Iterate through supported mode/char combinations.N)rgrhrRrr)rrXrVrWr<r<r=�	iter_mode�s���rsccs4�t||�D]}|Vq|dkrdSt||�VdS)zwYield (format, items, item) for all possible modes and format
       characters plus one random compound format string.rN)rsrq)�nitemsZtestobj�tr<r<r=�iter_format�s�rvcCsd|vpd|vpd|vS)Nrrrr<)r9r<r<r=�is_byte_format�srwcCs4t|�}|dks|dko|ddko||dtvS)zformat suitable for memoryviewr+r rr@)r^�
MEMORYVIEW)r9rYr<r<r=�is_memoryview_format�s�rycCsg|]}t|�s|�qSr<)rw��.0rr<r<r=�
<listcomp>��r|cCst|t�S)z9Tuple items (representing structs) are regarded as atoms.��
isinstance�list�rcr<r<r=�atomp��r�cCs
t|t�S�Nr~r�r<r<r=�listp��
r�cCs6t|�dkrdS|d}|dd�D]}||9}q|S)zProduct of list elements.rr+N)r^)rcrY�vr<r<r=�prod�s
r�cCs�|dkrdS|dkr.t|dd��|g}t|ddd�D]}||||d9<q|S|gt|dd��}td|�D]}||||d9<q>|S)zOCalculate strides of a contiguous array. Layout is 'C' or
       'F' (Fortran).rr<�Cr+Nr ���)r�rb)�ndim�shape�itemsizeZlayout�stridesrr<r<r=�strides_from_shapes�r�cCs�t|�r|St|�dkr|dSdg|d}|dr#t|�|dnd}t|d�D]}||}t||||�|dd��||<q+|S)zmConvert flat item list to the nested list representation of a
       multidimensional C array with shape 's'.rr+N)r�r^rb�_ca)ro�src�strider�startr<r<r=r�s$r�cCslt|�r|St|�dkr|dSdg|d}|d}t|d�D]}t||d|�|dd��||<q!|S)zsConvert flat item list to the nested list representation of a
       multidimensional Fortran array with shape 's'.rNr+)r�r^rb�_fa)ror�rcr�rr<r<r=r�%s"r�cC�2t|�rd|vrt|�t|�krtd��t||�S�Nrzprod(shape) != len(items))r�r�r^�
ValueErrorr��ror�r<r<r=�carray2� 
r�cCr�r�)r�r�r^r�r�r�r<r<r=�farray7r�r�cCsdd�|D�}t|�S)z(Generate all possible tuples of indices.cSsg|]}t|��qSr<�rb�r{r�r<r<r=r|>�zindices.<locals>.<listcomp>)r)r��	iterablesr<r<r=�indices<sr�cCs*d}t|�D]}|||||7}q|S)zAConvert multi-dimensional index to the position in the flat list.rr�)r��indr��retrr<r<r=�getindexAsr�c	Cs�|s|St|�}t||dd�}t||ddd�dd�}dgt|�}t|�D]}t|||�}t||ddd�|�}||||<q&|S)z�Transpose flat item list that is regarded as a multi-dimensional
       matrix defined by shape: dest...[k][j][i] = src[i][j][k]...  r+r�Nr�r)r^r�r�r�)	�srcr�r�ZsstridesZdstrides�destr��fr�tor<r<r=�	transposeHsr�cCs6|gkr|St|�r
|gSt|d�t|dd��S)zflatten listrr+N�r��_flattenr�r<r<r=r�Ws
r�cCst|�r|St|�S)zflatten list or return scalarr�r�r<r<r=�flatten_sr�cCs4t|�rgSt||d�gt|d|dd��S)zMGet the shape of lst after slicing: slices is a list of slice
       objects.rr+N)r�r^�slice_shape�rc�slicesr<r<r=r�es(r�cs&t|�r|S�fdd�|�dD�S)z=Multi-dimensional slicing: slices is a list of slice objects.csg|]}t|�dd���qS�r+N)�
multislice)r{Zsublst�r�r<r=r|pszmultislice.<locals>.<listcomp>r)r�r�r<r�r=r�lsr�csFt|�r|S��fdd�t|�d|�d�D�}||�d<|S)a�Multi-dimensional slice assignment: llst and rlst are the operands,
       lslices and rslices are lists of slice objects. llst and rlst must
       have the same structure.

       For a two-dimensional example, this is not implemented in Python:

         llst[0:3:2, 0:3:2] = rlst[1:3:1, 1:3:1]

       Instead we write:

         lslices = [slice(0,3,2), slice(0,3,2)]
         rslices = [slice(1,3,1), slice(1,3,1)]
         multislice_assign(llst, rlst, lslices, rslices)
    c	s.g|]\}}t||�dd��dd���qSr�)�m_assign)r{r�r��lslices�rslicesr<r=r|�s"�zm_assign.<locals>.<listcomp>r)r��zip��llst�rlstr�r�r<r�r=r�rs�r�cCsft||�}t||�}t|�t|�krdStt|��D]}||||kr'dS||dkr0dSqdS)z9Compare the structure of llst[lslices] and rlst[rslices].r�r)r�r^rb)r�r�r�r��lshape�rshaperr<r<r=�
cmp_structure�s

�r�cCs(t||||�dkr
td��t||||�S)z:Return llst after assigning: llst[lslices] = rlst[rslices]rz+lvalue and rvalue have different structures)r�r�r�r�r<r<r=�multislice_assign�sr�cs�|�rdS|dks|�|krdSt�fdd��D��rdS|dkr-|dko,�o,�Sd�vr3dSt��fdd�t|�D��}t��fdd�t|�D��}d||ko\||�|kS)z�Verify that the parameters represent a valid array within
       the bounds of the allocated memory:
           char *mem: start of the physical memory block
           memlen: length of the physical memory block
           offset: (char *)buf - mem
    Frc3s�|]}|�VqdSr�r<r��r�r<r=�	<genexpr>���z#verify_structure.<locals>.<genexpr>Tc3�0�|]}�|dkr�|�|dVqdS�rr+Nr<�r{�j�r�r�r<r=r����
�c3�0�|]}�|dkr�|�|dVqdSr�r<r�r�r<r=r��r�)�any�sumrb)�memlenr�r�r�r��offset�imin�imaxr<)r�r�r�r=�verify_structure�sr�cCs|D]}||}q|Sr�r<)rcr�rr<r<r=�get_item�s
r�c
Cs:|\}}}}}}|}t|�D]}	|||	||	7}q|S)z-Location of an item in the underlying memory.r�)
r�rur�r�r�r�r�r��prr<r<r=�memory_index�s
r�cCsR|\}}}}}}d|>}t|�D]}t||�}	d|	>}
||
@r"dS||
O}qdS)z�The structure 't' is overlapping if at least one memory location
       is visited twice while iterating through all possible tuples of
       indices.r+TF)r�r�)rur�r�r�r�r�r�Zvisitedr�r�bitr<r<r=�is_overlapping�s

r��r2r<csN�s]t|d�}|dkr2|r|||dddfStdd�}||}td�dkr(|n|}|||dd|fSd}	td�}
|
dkrA|rAd}	n|
dkrGd}	dg|�t|�D]}t|	|d��|<qPnt��}d	}td�}
|
dkrq|
d@rqd
nd}
dg|�|t||d��|d<|
s��|ddkr�|�|d<t|ddd�D]2}|�|dr��|dnd9}|
r�|t||d��|<q�d
td�|td|d��|<q�d}}d�vr�t��fdd�t|�D��}t��fdd�t|�D��}||}|�r
||}||d|}n|||}td�dk�r||n|}|||��|fS)z�Return random structure:
           (memlen, itemsize, ndim, shape, strides, offset)
       If 'valid' is true, the returned structure is valid, otherwise invalid.
       If 'shape' is given, use that instead of creating a random shape.
    r+rr<�r �d�_�Zr�TFr��r+r�c3r�r�r<r�r�r<r=r�r�z!rand_structure.<locals>.<genexpr>c3r�r�r<r�r�r<r=r�r�)rrbr^r�)r�Zvalid�maxdim�maxshaper�r�rtr�r��minshaperrZ	maxstrideZzero_strider�r�r<r�r=�rand_structure�s^

�
 
�
�
r�c
Csp||}t|d�}|r|||nd}td|d�}|||}t|||�}t||�\}}}}	|	|kr6t�|S)z=Create a random slice of len slicelen that fits into listlen.r+)r�slice�
slice_indices�RuntimeError)
�slicelenZlistlenZmaxstartr�Zmaxstep�step�stopr�rmZcontrolr<r<r=�randslice_from_slicelen'sr�cCspdg|}dg|}t|�D]!}||}|dkrtd|d�nd}t||�||<t||�||<qt|�t|�fS)zxCreate two sets of slices for an array x with shape 'shape'
       such that shapeof(x[lslices]) == shapeof(x[rslices]).rr+)rbrr�r_)r�r�r�r�rrr�r<r<r=�randslice_from_shape4s

r�cCs�td|d�}d}td�}|dkrd}n|dkrd}td�dkr"dnd	}dg|}dg|}dg|}dg|}	t|�D]�}t||d�}
t||d�}||
krU|
|}}
|r�t|
|
d�}t|
|
d�}
d
td�td|
d�}t||
|�}t||
�\}}}}n|
dkr�td|
d�nd}t||
�}t||�}td�dkr�||
||<||<|||	|<||<q<|
|||<||<|||	|<||<q<||t|�t|	�fS)z�Create (lshape, rshape, tuple(lslices), tuple(rslices)) such that
       shapeof(x[lslices]) == shapeof(y[rslices]), where x is an array
       with shape 'lshape' and y is an array with shape 'rshape'.r+r r�r�rr��PTFr�)rrbr�r�r�r_)r�r�r�r�rZ
all_randomr�r�r�r�Zsmall�bigr�r�r�Zs_smallrmr�Zs_bigr<r<r=�rand_aligned_slices@s<


r�cCs$|\}}}}}}t||d|d�S)zMReturn a list of random items for structure 't' with format
       'fmtchar'.r[rM)rd)r9rur�r�rmr<r<r=�randitems_from_structureksr�c
Cs(|\}}}}}}	t|||||	t|Bd�S)z:Return ndarray from the tuple returned by rand_structure()�r�r��formatr��flags)r�ND_WRITABLE)
ror9rur�r�r�r�r�r�r�r<r<r=�ndarray_from_structureqs
�r�cCsP|\}}}}}}t|�}	t|�D]\}
}t�||	|
||�qt|	||||d�S)z>Return numpy_array from the tuple returned by rand_structure())�bufferr�r��dtyper�)�	bytearray�	enumerater6�	pack_into�numpy_array)ror9rur�r�r�r�r�r��bufr�r�r<r<r=�numpy_array_from_structurews�r�cs�|j}|rt|��|krd|fSn$|gkr$|jdks�|kr#d|fSnt|��\}}|g}|dkr6d|fS|�����fdd�tdt����D�}g}|D]}	t�||	�d}
|
|
krbd|fS|�	|
�qN|gkrp||fS|d|fS)a�Interpret the raw memory of 'exporter' as a list of items with
       size 'itemsize'. If shape=None, the new structure is assumed to
       be 1-D with n * itemsize = bytelen. If shape is given, the usual
       constraint for contiguous arrays prod(shape) * itemsize = bytelen
       applies. On success, return (items, shape). If the constraints
       cannot be met, return (None, None). If a chunk of bytes is interpreted
       as NaN as a result of float conversion, return ('nan', None).Nrcsg|]
}�||���qSr<r<)r{r�r�Zmemr<r=r|��zcast_items.<locals>.<listcomp>�nan)
�nbytesr�r��divmod�tobytesrbr^r6rUr])Zexporterr9r�r�Zbytelenrr�Z	byteitemsror�rpr<r�r=�
cast_items�s,�� r�c#s��td�D]}|gVqtdd�}td�dkrdnd��fdd	�t|�D�Vtdd�}td�dkr4dnd��fd
d	�t|�D�VdS)z Generate shapes to test casting.r0��r�r�r+r c�g|]}t�d��qS�r��r�r{rm�r�r<r=r|��z!gencastshapes.<locals>.<listcomp>crrrrrr<r=r|�rN)rbr)rr�r<rr=�
gencastshapes�s�


rcCs0tt||d�t||d�t||d��S)z4Generate all possible slices for a single dimension.r+)rrb)rr<r<r=�	genslices�s0rcs�fdd�t|�D�}t|�S)z/Generate all possible slice tuples for 'shape'.csg|]}t�|��qSr<)r�r{r�r�r<r=r|�r}z"genslices_ndim.<locals>.<listcomp>)rbr)r�r�r�r<r
r=�genslices_ndim�srFcCs,|s|dkrdnd}t||d�}t||�S)z�Generate random slice for a single dimension of length n.
       If zero=True, the slices may be empty, otherwise they will
       be non-empty.rr+)rr�)r�allow_emptyZminlenr�r<r<r=�rslice�s
r
ccs �td�D]}t||�VqdS)z.Generate random slices for a single dimension.r�N)rbr
)rrrmr<r<r=r��s��r�c#sr�t|�D]}t�fdd�t|�D��Vqt|�D]}t�fdd�t|�D��Vqtdd�t|�D��VdS)z)Generate random slice tuples for 'shape'.c3s�|]	}t�|�VqdSr��r
r	r
r<r=r����zrslices_ndim.<locals>.<genexpr>c3s �|]}t�|dd�VqdS)T)rNrr	r
r<r=r��s�css�|]	}tddd�VqdSr�)r�rr<r<r=r��rN)rbr_)r�r�Z
iterationsrmr<r
r=�rslices_ndim�s�rccs2�t|�}|dur
t|�n|}tt||��VdSr�)r_r^r)�iterabler��poolr<r<r=�rpermutation�s�rc
Cs�z|��}Wnttfy|��}Ynwt|t�r"|j}|j}nd}d}td||j	|j
|j||j|j
|f�tj��dS)zPrint ndarray for debugging.�unknownz_ndarray(%s, shape=%s, strides=%s, suboffsets=%s, offset=%s, format='%s', itemsize=%s, flags=%s)N)�tolist�	TypeError�NotImplementedErrorr�rrr�r��printr�r��
suboffsetsr�r��sys�stdout�flush)�ndrYr�r�r<r<r=�
ndarray_print�s �

��rr�rf�r�z%struct module required for this test.z%ndarray object required for this testc@s�eZdZdd�Zddd�dd�Zd�dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dMdN�Z(dOdP�Z)e*j+Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4e5j6dcdd��Z7dedf�Z8dgdh�Z9didj�Z:dkdl�Z;dmdn�Z<dodp�Z=dqdr�Z>dsdt�Z?dudv�Z@dwdx�ZAdydz�ZBd{d|�ZCd}d~�ZDdd��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRe*jSd�d���ZTd�S)��TestBufferProtocolcCst�|_dSr�)Zget_sizeof_void_p�
sizeof_void_p��selfr<r<r=�setUpr�zTestBufferProtocol.setUpF)�sliced�castc
%
s,�	r	t�	���n	�st���n��d��jrg���d�d}td��D]}
�	|
dkr.qB�|
dkrA|�|
�	|
d7}q$|gdd�t�d�D���j}�ddkr\|}|gt�dd������j|���	�j
����	�j����	�j�����j
|���	�j����	�jt�	���
r��s���	�jt�����	�jt���t�t�s�t��rɈr����n���}��	|���s�dS|�s�t�}d}t�	�D]=}z&t�|�}t�|�}t|t�r�tj�g|�R�}nt��|�}|�|�Wnt�yd}Y�qw��	||�q�|�s���	���|�t��}d� dd	�|D��}��	|�!�|���r=�nd
}t"��}dD�]s}�}|dk�rit#�d
��r[t#�d��rht$|�	�}t|�	|t%d�}nt#�d
��rzt#�d��r�|dk�r�t|�	|d�}t&�t'|����	���|���(t)�|���dk�r��qEt|�}|�r�dnt*}t+�dt,����	t��|�����fdd�t|�D�}t|d�dk�r�dd�|D�}t|�	|�d�} ��	t| �t���t����}!��	|!��t��jdd�}!��	|!��t��jdd�}!��	|!��t+�dt,����	t��|�����fdd�t|�D�}t|d�dk�r=dd�|D�}t|�	|t%B�d�} ��	t| �t���t��jdd�}!��	|!��t+�d
t,����	t��|�����fdd�t|�D�}t|d�dk�r�dd�|D�}t#�d��r�t%nd}"t|�	|"|B�d�} ��	t| �t���t��jd
d�}!��	|!���qEt���rzt��}Wnt�y�YdSwt�t��rڈjn��|f���������	�
��fdd�	}#|#|�|�-��}$|#|$dd�Wd�n	1�s	wY|��dSdS)Nr<rr+cS�g|]}d�qS)r�r<r�r<r<r=r|�z-TestBufferProtocol.verify.<locals>.<listcomp>Tr?css�|]}d|VqdS)z%02xNr<rzr<r<r=r�Ur�z,TestBufferProtocol.verify.<locals>.<genexpr>r�r��F�Ar*r+r��r�r�r��r�r�c�g|]}t���|���qSr<�r6�unpack_fromr	��contigr9r�r<r=r|���cS�g|]}|d�qS�rr<r�r<r<r=r|�r��r�r�r���ordercr.r<r/r	r1r<r=r|�r3cSr4r5r<r�r<r<r=r|�r�cr.r<r/r	r1r<r=r|�r3cSr4r5r<r�r<r<r=r|�r�cs���|j����|j����|j����|j����|j|���|j����|jt	����	r7�s@��|j
t	�
����|jt	����dkrOdnt��}��t|�|��ra��
�n���}��|����|��dS)Nrr+)�assertIsrX�assertEqualr�r�r��readonlyr�r�r_r�rr^rr�)rE�expected_readonlyr�rep)�ex�expected_lenr9r�rcr��resultr#r�r%r�rr<r=�check_memoryview�sz3TestBufferProtocol.verify.<locals>.check_memoryview)r<).r�r^rZ
assertGreaterrbr!r�r9rXr:r�r�r�r;r�r�r_r�rrryrr�r�r��get_pointerr�r6r7�extend�BufferErrorrN�join�hexr��
is_contiguousr��
ND_FORTRAN�get_contiguous�
PyBUF_READ�
assertTrue�
cmp_contigr��py_buffer_to_contiguous�
PyBUF_FULL_RO�
toreadonly)%r#r@rXr�r9r;r�r�r�rcr%r&Z
suboffset0rZstride0r=rZbuf_errr�Zitem1Zitem2rYrErZffZ	flattenedr8�expectedZtransrl�roZinitlst�yZcontig_bytesrrAZmmr<)
r2r>r?r9r�rcr�r@r#r�r%r�rr=�verifys
�


�

�
����
����
�&
��zTestBufferProtocol.verifycCsddd�}|jr||t�s>||t�r|jr>||t�r|jr>||t�r$|jr>||t�s,|j	s>||t
�s4|jr>||t�sI||t�rI|j
tt||d�dSt|t�sSt|j�rX|��}n
t|td�}|��}||t�ridn|j}|j}	|j}
|j}||t�s�d}	|��}||t�s�d}||t�r�|jnd}||t
�r�|jnd}
t||d�}|j|||
|	||||
||d�
dS)	NcSs||@|kSr�r<)�req�flagr<r<r=�match�sz/TestBufferProtocol.verify_getbuf.<locals>.match��getbufFr?r+r<)	rXr�r9r;r�r�r�rcr%)r;�PyBUF_WRITABLE�PyBUF_C_CONTIGUOUS�c_contiguous�PyBUF_F_CONTIGUOUS�f_contiguous�PyBUF_ANY_CONTIGUOUS�
contiguous�PyBUF_INDIRECTr�
PyBUF_STRIDES�PyBUF_ND�PyBUF_FORMAT�assertRaisesrDrrryr�rrNr�r�r�r�r�rS)r#Zorig_exr>rTr%rVrcrrQr9r�r�r�r�r<r<r=�
verify_getbuf�sh����������	�	���




�z TestBufferProtocol.verify_getbufcs�tttttttttt	t
ttt
tf}dd�td�D�dfgd�dfgd�dfdd�td�D�d	ff}ggd
fgd�gd
fdggd
fdgdgd
fdgdgd
fdgdgd
fddggd
fddgddgd
fddgddgdfddgddgdff
}d
ttttBtttBf}d
ttttBf}|D]�\}}t�|��|D]�\}}	}
�fdd�|	D�}	|
�9}
|D]�}|	r�|t@r�q�|s�|t@r�q�|r�|n|d
}t|||||	|
d�}
|r�|
ddd�nd}t|
�}|r�t|�}|
jd
ks�|
jdkr�|r�|	r�|�||
�|�r|jdk�r|�r|	�r|�||�|D]4}|D].}|�|
|
||B�|�|
|||B�|�r:|j||||Bdd�|j||||Bdd��q
�q	q�q�q�gd�}t|dgtd�}|�tt|�tdgdg�}t|td�}|jtt|td�|jtt|td�|jtt|td�|jtt|td�|jtt|td�|jtt|td�t|td�}gd�gd�fD]@}d
tfD]8}t|||tBd�}|�t |d��|�t |d ��|D]}t||d�}|�t |d��|�t |d ���qȐq��q�dS)!NcSsg|]
}|dr
dnd�qS)r TFr<�r{rYr<r<r=r|r�z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>�r
�r+r rr�r�rr5r4�	rf�rgrrcSs$g|]}|drd|nd|�qS)r r&r%r<rfr<r<r=r|s$rr)r+rr+r�rjrr ���rr����r+r4csg|]}|��qSr<r<r�r�r<r=r|)r�)r�r�r�r�r�T)r%�r�r�rirW)r+rgr+)r5rr5r*r�)!r`rarb�PyBUF_SIMPLErZr\r^�
PyBUF_FULLrN�
PyBUF_RECORDS�PyBUF_RECORDS_RO�
PyBUF_STRIDED�PyBUF_STRIDED_RO�PyBUF_CONTIG�PyBUF_CONTIG_ROrbr�rH�ND_PILrYrcr6�calcsizerrNr�r:re�ND_GETBUF_FAILrdrDrKrG)r#�requestsZ	items_fmtZ	structureZndflagsZ
real_flagsror9r�r�r�r�Z_items�ex1�ex2�m1�m2rT�bitsr>�baserr8r<r�r=�test_ndarray_getbuf�s��

�
���
��������!���z&TestBufferProtocol.test_ndarray_getbufc
	Cs�tdgdg�}tdgdgtd�}t|j|jfD�]�}|�t|hd��|�t|gd��|�t|gd��|jt|gd�dhd	�|jt|gd�dgdhd
�|jt|gd�dggd�|jt|dgdgid�|jt|dgdgid
�|jt|dgdgid�|jt|dgdgdgtd�|jt|dggtd
�|jt|gdgd	�|jt|dgdgdd�|jtj	|dgdgdd�|jt|ddgdgdd�|jt|gd�dgdd�t
d}|jt|dg|dg|d	�|jt|dgdgd	�|jt|gd�dgd	�|jt|dgddgd	�|jt|gd�ddgdd�|jt|gd�dgdgd
�|jt|dgdgddgd
�|jt|ddgddgdgd
�|jt|gd�dgdgdd�|jt|gd�dgdd�|jt|gd�dgddd�|jt|gd�dgd d�|jtj	|dgdgd!d�gd"�}|jt||ddgd#d$gd%d&�|jt|t�d'd(�|jt|dgdgt
d�|�t|dg�q|jttd)td*�tdgdgtd�}|jt|jdgdgtd�td)�}|�t|jdgdg�|�t|j�tdgdg�}|�dgdg�t|�}|�t|jdgdg�|�t|j�|��|��|�t|j�~|�ttigd��|�ttd)i�tttd+��dgd+d	�}|�tt|d%g�tttd,��ddgd	�}|�tt|gd-��|�tt|ddg�|�tt|d#dg�|�tt|d.dg�tgd�dgdd�}t|td*�}|�t|j�tgd�dgdd�}t|�}	t|	�}|�t|j�td/gdgd0d�}|�t|j�t
}ttt|��dg|d	�}|�t|j�tdgdgd	�}|�ttddddd%�|�tt|d1d2�|�tt|d.d2�|�tt|td3�|�tt|td4�|�tt|td5�|�tt|d6d7�tdgdgd	�}|�ttddddd%�|�tti|�|�tt|i�tdgdgd	�}|�ttddddd%�|�ttid7�|�tt|d8�dS)9Nrir+�r�>r+r r)r+r rK)r+r �rr��r+r rrr
r��r�r�r-rm)r�rX�r�r�r�ZXXXri�r�r rr ZQLr�rKr#�r+r rr�r�rI�r+r rr��r�r�r�r�)r�r�r�r?z@#$)
r+r rr�r�rr5r4rirf���rkr�)r�r�r�r�r��123rWr�rg)r rr�r*)�r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+r+Z�LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL�xyzr��u �Z�r+��)r�ND_VAREXPORT�pushrdrrHrvr�r6r8ZND_MAX_NDIM�
OverflowErrorr�rorDrY�poprN�releaserBr�rbrnr�memoryview_from_bufferrIrJ�UnicodeEncodeErrorrLrG)
r#rZndmrrrorEr>rzr{r<r<r=�test_ndarray_exceptionsgs��������z*TestBufferProtocol.test_ndarray_exceptionscCs�ttd��D]F}dgd}tgd�dgtd�}t|�|d<tdd�D]}|jgd�dgd�t|�||<q"td�D]
}|||��q9|�t|j	�~qdS)Nr�rr�rrmr+r
)
rrbrr�rNr�r�rdrDr�)r#�permrErrr<r<r=�test_ndarray_linked_lists
�z+TestBufferProtocol.test_ndarray_linked_listcCsLtd�D]\}}}t�|�}t|d|d�}|j|d||dddd|d�	qdS)Nrr<r-T�rXr�r9r;r�r�r�rc)rvr6rwrrS)r#r9Zscalarrmr�rr<r<r=�test_ndarray_format_scalars
��z-TestBufferProtocol.test_ndarray_format_scalarc
Csltdd�}t|�D]*\}}}t�|�}dtfD]}t||g||d�}|j|d||dd|f|f|d�	qq	dS)Nr+rfrr,Tr�)rrvr6rwrvrrS)r#rtr9rormr�r�rr<r<r=�test_ndarray_format_shapes


���z,TestBufferProtocol.test_ndarray_format_shapecCs�tdd�}t|�D]V\}}}t�|�}tdd�D]F}|dkrqt|dd|��g}||g}|dkr8||dnd}	dtfD]}
t|||||	|
d�}|j|d||dd|||dd|�d�	q>qq	dS)	Nr+����r�rr�Tr�)	rrvr6rwrbr^rvrrS)r#rtr9rormr�r�r�r�r�r�rr<r<r=�test_ndarray_format_strides+s*


�����z.TestBufferProtocol.test_ndarray_format_stridescCs@gd�}t|ddd�}t|ttBd�}|�|��t|d��dS)Nrhr�)r+rr�rW)rr\rcr:rr�)r#ror>rr<r<r=�test_ndarray_fortran@sz'TestBufferProtocol.test_ndarray_fortrancCsXtd�D]�}dd�t|�D�}t|�}t|�D]�}t|�\}}}t�|�}dtfD]~}	|dkr4|	tkr4q)t||||	d�}
t|||d�}t	||�}|j
|
d||d||||d�	t|�r�t|||d	�}
t|
tt
Bd
�}
|�|
jdk�|
��}|j
|d||d||||d�	t||||	tBd�}
t|||d�}t||�}|j
|
d||d||||d�	q)qqdS)
Nr�cSsg|]}tdd��qS)r rfrrr<r<r=r|Hrz<TestBufferProtocol.test_ndarray_multidim.<locals>.<listcomp>rr,r�Tr�r-rWr<r*)rbr�rrrr6rwrvrr�r�rSryrurcrKr�r�rHr�)r#r��shape_trtr�r9rormr�r�rr�rcr>�mvr<r<r=�test_ndarray_multidimFsP

���
����z(TestBufferProtocol.test_ndarray_multidimcCs�tdgdgd�}|�t|jdd�t|�}|�||�|�t|jdd�tdgdgtd�}|�t|jd�t|�}|�||�|�t|jd�tdgdgtd�}|�t|j	d�|�t|jdd�t|�}|�||�|�t
|j	d�|�t
|jdd�gd�}t|t|�gdtd�}|�tj
|jd	d
�|�t|jdd�t|�}|�||�|�t|jd	d
�|�t|jdd�gd�}t|t|�gd
td�}|�t|jd	d
�|�tj
|jdd�dS)Nr+r
r4rmr*�r+r rr�r�rr5r4rr,r i,)r���)�r+r r�)r�rZLQ)s1r�)rrdr�__setitem__rNr:r��__delitem__r��__getitem__�
IndexErrorr^r6r8r�)r#rr�ror<r<r=�test_ndarray_index_invalidss:z-TestBufferProtocol.test_ndarray_index_invalidcCsJtddtd�}t|�}|�||�|d}|�|d�|d}|�|��|���|d}|�|d�|d}|�|��|���|�t|jd�|�t|jd�|�t|jdd�|�t|jdd�|�|��d�|�|��d�d|d<|�|��d�d|d<|�|��d�d|d<|�|��d�d|d<|�|��d�dS)	Nr+r<rm.rr4rir�)	rr�rNr:rrdrr�r�)r#rr�rYr<r<r=�test_ndarray_index_scalar�s"z,TestBufferProtocol.test_ndarray_index_scalarcCsRtttd��ddgtd�}t|td�}|�t|jd�|�t|jtddd��dS)	Nr4r r�rmrWr+rr�)	rr�rbr�rtrdrDr�r�)r#r>rr<r<r=�test_ndarray_index_null_strides�sz2TestBufferProtocol.test_ndarray_index_null_stridescCs�td�D]_\}}}t|dg|d�}tdd�D]}|�||||�q|�t|jd�|�t|jd�t|�rct|�}|�||�tdd�D]}|�||||�qF|�t|jd�|�t|jd�qtd�D]K\}}}t|dgt	|d�}t|t
tBd�}tdd�D]}|�||||�q�t|�r�|��}|�
|�|�t�tdd�D]}|�||||�q�qhgd�}t|dgd�}t|td�}tdd�D]}|�||||�q�gd�}t|dgd�}t|td�}tdd�D]}|�||||�q�dS)	Nr�r-r����r6rWr�r
)rvrrbr:rdr�r�ryrNr�rtrcr�r9�__eq__�NotImplementedrurn)r#r9rormrrr�r>r<r<r=�!test_ndarray_index_getitem_single�sH���z4TestBufferProtocol.test_ndarray_index_getitem_singlecCs�td�D]x\}}}t|dg|td�}td�D]
}|||<|||<q|�|��|�|�t|jd|�|�t|jd|�t	|�s@qt|dg|td�}t
|�}|�||�td�D]
}|||<|||<qW|�|��|�|�t|jd|�|�t|jd|�qtd�D]f\}}}t|dg|td�}tdd�D]}||d||<||d||<q�|�|��|�t	|�s�q�t|dg|td�}t
|�}|�||�tdd�D]}||d||<||d||<q�|�|��|�q�dS)Nr�r,r�r�r�r+)rvrr�rbr:rrdr�r�ryrN)r#r9roZsingle_itemrrr�r<r<r=�!test_ndarray_index_setitem_single�sF

�z4TestBufferProtocol.test_ndarray_index_setitem_singlec

Cs�d}t|�}t|�D]�}t|�\}}}dtfD]�}t||||d�}t||�}	t|d|d�D]J}
|�|	|
||
���t|d|d�D]1}|�|	|
|||
|���t|d|d�D]}|�|	|
||||
||�qdqHq0t||||t	Bd�}t
||�}	t|d|d�D]I}
|�|	|
||
���t|d|d�D]0}|�|	|
|||
|���t|d|d�D]}|�|	|
||||
||�q�q�q�qq
dS)N�r rr�rr,r+r )r�rrrrvrr�rbr:rrHr�)
r#r�rtr�r9rormr�rrcrr��kr<r<r=�#test_ndarray_index_getitem_multidims<
 &���
 &�����z6TestBufferProtocol.test_ndarray_index_getitem_multidimcCs�tddd�}|�ttdt��t|�}|�||�|�ttdt��td�D]E\}}}t|dg|d�}t|�D]\}}|�|||�|�	||v�q7t
|�rkt|�}t|�D]\}}|�|||�|�	||v�qWq&dS)Nr+r<r
z1 in ndz1 in mvr�r-)rrdr�eval�localsrNr:rvr�rKry)r#rr�r9rormrr�r<r<r=�test_ndarray_sequence:s"��z(TestBufferProtocol.test_ndarray_sequencec	Cs�gd�}t|dgtd�}t|�}|�t|jtddd�|�|�t|jtddd�|�t|dgtd�}t|dgtd�}t|td�}|�t|jtddd�|�t|dgdtd�}t|�}|�t	|j
tddd��|�t	|j
tddd��t|d	d
gdtd�}t|�}|�t	|j
tddd�tddd�f�|�t	|j
tddd�tddd�f�|�t|j
d�|�t|j
dtddd�f�|�t|j
tddd�if�|�t|j
tddd�tddd�f�|�t|j
d�t|dgdtd�}t|dgd
d�}t|�}t|�}|�t	|jtddd�|dd��|�|�
�|�|�t	|jtddd�|dd��|�|�
�|�t|dgdtd�}t|dgdd�}	t|�}t|�}|�t	|jtddd�|dd��|�|�
�|�|�t	|jtddd�|dd��|�|�
�|�t|d	d
gd
td�}t|dgd
d�}t|�}t|�}|�t	|jtddd�|dd��|�|�
�gd�gd�g�|�t|jtddd�|dd��t|dgd
td�}t|dgd
d�}t|�}t|�}|�t	|jtdd	d�|dd��|�|�
�|�|�t	|jtdd	d�|dd��|�|�
�|�|�tttddd	�i�|�ttdd�|�t	ttddd�d
�t|dgd
td�}
|�t|
j�t|dgdd�}t|td�}
|�t|
j�dS)Nr�r4rmrr+rWrr,r r�z@%$rrr-r5r�)r�rr5r4z###########)rr�rNrdrr�r�rbrDr�r�rr:rr�rv�add_suboffsetsrn)r#ro�xl�mlr>�xrrr��mr�yrrYr<r<r=�test_ndarray_slice_invalidMs�
�
�
�"""""
�""z-TestBufferProtocol.test_ndarray_slice_invalidcCsgd�}t|dgdtd�}t|dgdd�}|dd�|dd�<|�|��|�t|�}t|�}|�||�|�||�|dd�|dd�<|�|��|�t|ddgdtd�}t|ddgdd�}|d	d
�dd�f|d	d
�d
d
�f<|�|��t|ddg��dS)Nrhrgrr,r-rir�rr+r )rr�r:rrNr�)r#rorYrRr�r�r<r<r=�test_ndarray_slice_zero_shape�s$z0TestBufferProtocol.test_ndarray_slice_zero_shapec
Csd}t|�}t|�}t|�D]z}t|�\}}}t�|�}dtfD]g}	t||||	d�}
t||�}t	||�D]R}d}
zt
||�}WntyT}z	|j}
WYd}~nd}~wwd}z|
|}Wntyr}z	|j}WYd}~nd}~ww|sw|
r~|�
||
�q4|�|��|�q4q qdS�Nr�rr,)r^r�rrrr6rwrvrr�rr��	Exception�	__class__r9r:r)r#r�r�rtr�r9rormr�r�rrcr��listerrr%�e�nderr�ndslicedr<r<r=�test_ndarray_slice_multidim�s<

�������z.TestBufferProtocol.test_ndarray_slice_multidimcCs,d}t|�}t|�}t|�D]�}t|�\}}}t�|�}t|||d�}	|	��t|||d�}
|
��t|
�}t	||�}t
||�D]R}
d}zt||
�}Wnty`}z	|j
}WYd}~nd}~wwd}z|	|
}Wnty~}z	|j
}WYd}~nd}~ww|s�|r�|�||�q@|�|��|�q@qdS)N)r rr�r r-)r^r�rrrr6rwrr�rNr�rr�r�r�r9r:r)r#r�r�rtr�r9rormr�rr>r�rcr�r�r%r�r�r�r<r<r=�'test_ndarray_slice_redundant_suboffsets�s@

������z:TestBufferProtocol.test_ndarray_slice_redundant_suboffsetscCstd�D]�\}}}td�D]�}td�D]�}dtfD]�}|tB}t|dg||d�}t|dg||d�}	t|	�}
d}d}|dd�}
z|
|}|
|}|
||
|<t|�t|�k}Wntyl}z	|j}WYd}~nd}~wwd}z||||<Wnty�}z	|j}WYd}~nd}~ww|r�|�	|t
�n|�|��|
�|�	||�t
|�s�qd}z|
||
|<Wnty�}z	|j}WYd}~nd}~ww|r�|�	|t
�q|�|
��|
�|�|
|�|�	||�|j|
|	|j|d|j|j|j|��d�	qqq
qdS)Nr�rr,Fr�)rvrrvr�rrNr^r�r�r9r�r:rryrSr�r�r�r�)r#r9rorm�lslicer
r�rrr>r�ZlsterrZdiff_structurercZlvalZrvalr�r�Zmverrr<r<r=� test_ndarray_slice_assign_single�sl�����������z3TestBufferProtocol.test_ndarray_slice_assign_singlec
Cs$d}t|�}t|�}t|�D]�}t|�\}}}dtfD]s}tt�D]l}t||�\}	}
t||||t	Bd�}t
||�}d}
z	t|||	|
�}WntyY}z	|j
}
WYd}~nd}~wwd}z||
||	<Wntyy}z	|j
}WYd}~nd}~ww|s~|
r�|�||
�q!|�|��|�q!qqdSr�)r^r�rrrrvrb�
ITERATIONSr�rr�r�r�r�r�r9r:r)r#r�r�rtr�r9rormr�r�r�rrcr�r@r�r�r<r<r=�"test_ndarray_slice_assign_multidim3s@�
�������z5TestBufferProtocol.test_ndarray_slice_assign_multidimc
Cs4tt�D]�}tdD]�}t�|�}t|dttd�}|�t	|��t
||�}t|||�}|��}t
|�}t|�rA|��}	|�|	|�|ddkrqt|||td�}
|
��}|�||�t
|
�}t|�rq|�||
�|��}	|�|	|�tr�|d}d|vr|q
t|||�}
|j|d|
j|d|
j|
j|
j|
��d	�	q
qdS)
Nr@T�r�r�r rr�rFr�)rbr�rRr6rwr��MAXDIM�MAXSHAPErKr�r�r�rrNryr:rvr�r�rSr�r�r�r�)r#rmr9r�rurorYZxlistr�ZmvlistrRZylistr��zr<r<r=�test_ndarray_randomTsH
�
����z&TestBufferProtocol.test_ndarray_randomcCs�tt�D]j}tdD]c}t�|�}t|dttd�}|�t	|��t
||�}d}zt|||�}WntyD}z	|j
}WYd}~nd}~ww|�|�trmd}	zt|||�}
Wntyk}z	|j
}	WYd}~nd}~ww	q
qdS)Nr@Fr�)rbr�rRr6rwr�r�r��assertFalser�r�r�r�r�rKr�r�)r#rmr9r�ruror�rYr�Z	numpy_errrRr<r<r=�test_ndarray_random_invalid}s8
�
��
�����z.TestBufferProtocol.test_ndarray_random_invalidc
Cs*tt�D�]
}tdD�]}t�|�}tttd�\}}}}t|d|d�}t|d|d�}	|�	t
|��|�	t
|	��t||�}
t||	�}t|
||�}t|||	�}
|
|||<|�
�}|
�
�}t|�}t|
�}|�|�
�|�|�|�
�|�|ddkr�|	ddkr�t|
||td�}t|||	td�}||||<|�
�}|�
�}|�||�|�||�t|�}t|�}|�|�
�|�|�|�
�|�t�rd|vs�d|vr�qt|
||�}t|||	�}||||<t|�s�t|	�s�|j|d|j|d|j|j|j|�
�d	�	|j|
d|j|d|j|j|j|�
�d	�	qqdS)
Nr@r�Tr
r rr�Fr�)rbr�rRr6rwr�r�r�r�rKr�r�r�rrNr:rvr�r�r�rSr�r�r�r�)r#rmr9r�r�r�r�r��tl�trZlitemsZritemsr�r�ZxllistZxrlistr�r�Zylr�ZyllistZyrlistZzlZzrr<r<r=� test_ndarray_random_slice_assign�sh


�


�
����z3TestBufferProtocol.test_ndarray_random_slice_assigncCsvgd�}t|ddgtd�}t|�}|�|jt@�|�|j|�|�|jd�|�|j	�|�|j
�|�|j�dS)Nrhrr�rm)rr�)rrvrKr�r9rXr:rr�r[r]r_)r#rorr>r<r<r=�test_ndarray_re_export�sz)TestBufferProtocol.test_ndarray_re_exportc	Cs�dtfD]n}tgd�dg|d�}t|�}|�||�|�|��g�|�|��g�tgd�gd�|d�}|�|��g�tgd�gd�|d�}|�|��gggg�tgd�gd�|d�}|�|��ggggggggggggg�qdS)Nrr�rm�rrr�rrr)rrr�rvrrNr:r�r#r�rr�r<r<r=�test_ndarray_zero_shape�s
��z*TestBufferProtocol.test_ndarray_zero_shapecCsddtfD]+}tdgdgdg|d�}t|�}|�||�|�|��gd��|�|��gd��qdS)Nrr+r�r�)r+r+r+r+r+r�r�r<r<r=�test_ndarray_zero_strides�s�z,TestBufferProtocol.test_ndarray_zero_stridescCs>tttd��dgdd�}|�|jd�|�|��gd��dS)N�rr5r�)r5r4ri)rr�rbr:r�r�r#rr<r<r=�test_ndarray_offsetsz&TestBufferProtocol.test_ndarray_offsetcCs>dtfD]}tttd��dg|d�}|��}|�||�qdS�Nrrrm)rvrr�rbr�r:)r#r�rrEr<r<r=�#test_ndarray_memoryview_from_buffers
�z6TestBufferProtocol.test_ndarray_memoryview_from_buffercCsPdtfD]!}tttd��dg|d�}td�D]}|�||t||g��qqdSr�)rvrr�rbr:rB)r#r�rrr<r<r=�test_ndarray_get_pointers��z+TestBufferProtocol.test_ndarray_get_pointercCs\tttd��gd�d�}t|ttBd�}|�|��|���t|�}|�|��|���dS)Nr�)r r r�r
rW)rr�rbrbrcr:rrN)r#r>rrEr<r<r=� test_ndarray_tolist_null_stridess
z3TestBufferProtocol.test_ndarray_tolist_null_stridescCs�|�tdd��tttd��ddgd�}tttd��ddgd�}|�t||��tdgdgdd	�}|�t|d
��|�td
|��dS)Nr�s456rgrr�r
r+rr-rQ)r�rLrr�rbrK)r#rYrRr<r<r=�test_ndarray_cmp_contigsz*TestBufferProtocol.test_ndarray_cmp_contigcCs�t�dgd��}t|�}|�tt|�tttd���}tttd��dgd�}|�t|�t|��tttd��ddgd�}|�t|�t|��tttd��gd�d�}|�t|�t|��tt	ttd��ddgd��}tttd��ddgt
d�}|�t|�t|��tt	ttd��gd	�d��}tttd��gd	�t
d�}|�t|�t|��tttd���}tttd��gd
�td�}|�t|�t|��tttd��gd
�dd�}|�t|�t|����dS)Nrr�rgr
rr�)rr r rm�r rr �r r rr-)
rLrrdr��hashrSr�rbr:r�rHrvr�)r#rGrrr<r<r=�test_ndarray_hash&s*z$TestBufferProtocol.test_ndarray_hashc
Cs8tttttttttt	t
tf}|�t
tidt�tdddtd�}dD]}|D]}t|||�}|�||���q%q!tdgdgdtd�}dD]}|D]}t|||�}|�|d	�qGqCtttd
��gd�dtd�}dD]}|D]}t|||�}|�|d	�qkqgdtfD]O}tdgdgd|tBd�}|��}dD]}|D]}t|||�}|�||�q�q�tgd
�dgd|tBd�}|��}dD]}|D]}t|||�}|�||�q�q�qtgd
�dgdgtd�}|��}dD]}ttfD]}t|||�}|�||�q�q�|ddd�}|��}dD]#}|D]}zt|||�}Wnt�yY�qw|�||��q�qttd��}dtfD�]U}t|ddg|tBd�}t�rVtt|�ddgd|dk�rRdndd�}	|tk�rntt|ddg�ddgtd�}
|
��}n|��}|D]B}zt|d|�}Wnt�y�Y�qtw|�||�tdd�|D�ddgtd�}|�t|�t|��t�r�|�||	jdd���qt|dk�r�tt|ddg�ddgtd�}
n	t|ddgtd�}
|
��}tttttfD]D}zt|d|�}Wnt�y�Y�q�w|�||�tdd�|D�ddgttBd�}|�t|�t|��t�r"|�||	jdd���q�|tk�r7t|ddgtd�}
|
��}n|��}tttttfD]D}zt|d|�}Wnt�yWY�qBw|�||�tdd�|D�ddg|tBd�}|�t|�t|��t�r�|�||	jdd���qB�q2tttd��ddgttBd�}t|dt�}|�||���tdd�|D�ddgtd�}|�t|�t|��t|dt�}tt|ddg�ddgtd�}
|�||
���td d�|D�ddgttBd�}|�t|�t|��t|dt�}|�||���td!d�|D�ddgtd�}|�t|�t|��dS)"Nr*rir<rr,r)r+r�r4�r rr5rr�rrr r�r�rgr�rmrr�)r�r�r�r8cS�g|]}|�qSr<r<r�r<r<r=r|�r(zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>r7cSr�r<r<r�r<r<r=r|	r(r+cSr�r<r<r�r<r<r=r|	r(cSr�r<r<r�r<r<r=r|+	r(cSr�r<r<r�r<r<r=r|2	r(cSr�r<r<r�r<r<r=r|8	r()r`rarbrnrorNrprqrrrsrtrurdrrMrr�r:r�r�rbrHrDr�r�r�rNZtostringrv)
r#ryrr8ZrequestrrZndbytesrcZnarYrPrRr<r<r=�test_py_buffer_to_contiguousKs������������G�
�
��
��� �

�� �� z/TestBufferProtocol.test_py_buffer_to_contiguouscCsvdgfgd�dgfttd��gd�fg}|D]�\}}t||d�}t|�}|�|j�|�|j�t|�}t||dd�}t	||�}|j
||dd	d
||||d�	t|�}	|j
|	|dd	d
||||d�	t|ttBd�}
|�
|
jd
�|
��}|j
|ddd	d
||||d�	t|td�}
|�
|
jd�|�
|
jd
�|�
|
jd
�|
��}|dkr�|gn|}|j
|ddd	d
d|jgd|d�	q|D]K\}}t||td�}t|�}|�|j�|�|j�t|�}t||dd�}t||�}|j
||dd	d
||||d�	t|�}	|j
|	|dd	d
||||d�	q�|dd�D];\}}t||td�}t|�}t|�}t	||�}|j
||dd	d
|||j|d�	t|�}	|j
|	|dd	d
|||j|d�	�q|�ttdd�|�tti�tgd�dgd�}t|td�}
|�tt|
�t|ttBd�}
|�tt|
�tdgddgddd�}
|�tt|
�|�t|
j�|�tt|
td�|�tt|
td�|�tt|
ddd�td�dS)Nrir�rr�r�r
r+r�rTr�rWr<r?r�r+rmr*�9rYr#rr-r�)r�rbrrNrKr[r_r^r�r�rSrurcr:r�r�rnr�r�r�rHr]r�rvrdrrDr�rIrJ)r#Zitems_shaperor�r>rEr�r�rcr}rr<r<r=�test_memoryview_construction;	s�(
���
�
��
�
� z/TestBufferProtocol.test_memoryview_constructioncCs�gd�}gd�gd�gd�fD]}t||d�}|�|j�t|�}|�t|jd�qtdd�D]\}}}td�}|�|�}|�|�	�d�|�|�
�g�q/dS)	Nr�r�r�r
rr+rNr�)rrKr[rNrdrr&rvr:r�r)r#ror�r>�msrcr9rmrEr<r<r=�test_memoryview_cast_zero_shape�	s
�z2TestBufferProtocol.test_memoryview_cast_zero_shapecCs�|j}tj}d}d}ttd��}|td�||d|��t|ddgdd	�}|t|�||d|��t|gd
�dd	�}|t|�||d|��dS)NzPnin 2P2n2i5P PZ3nr4r�r+r r�rr-)r r r r)�check_sizeofrZcalcvobjsizer�rbrNr)r#�checkZvsizeZbase_structZper_dimrorGr<r<r=�test_memoryview_sizeof�	sz)TestBufferProtocol.test_memoryview_sizeofcCs�Gdd�dt�}Gdd�dt�}dd�}|d�|d�dtd	�d
tdd�gd
�hd�ddidddddtddtd�td�dddd|dd�g}tdd�D]�\}}}t|dg|td�}t|dg|td�}	t|�}
t	�
||	d|�||
d<|�|
d|	d�t	�|�}d|vr�qI|D]W}d}
z
t	�
||	||�Wn
t	j
y�t	j
}
Ynwd}z||
d <Wnttfy�}z	|j}WYd}~nd}~ww|
s�|r�|�|
d�|�|d�q�|�|
d |	d �q�qIdS)!Nc@�eZdZdd�Zdd�ZdS)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.INTcS�
||_dSr���val�r#r�r<r<r=�__init__�	r�zFTestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__init__cS�|jSr�r�r"r<r<r=�__int__�	�zETestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__int__N)�__name__�
__module__�__qualname__r�rr<r<r<r=�INT�	�rc@r�)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.IDXcSr�r�r�r�r<r<r=r��	r�zFTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__init__cSr�r�r�r"r<r<r=�	__index__�	rzGTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__index__N)rrrr�rr<r<r<r=�IDX�	rrcSsdS)Nr5r<r<r<r<r=r�	�z;TestBufferProtocol.test_memoryview_struct_module.<locals>.friy������@@z-21.1gffffff(@r�r r�>r�r�rr5r4r<�riTF�asabcrG�abccSs|Sr�r<)rYr<r<r=�<lambda>�	r	zBTestBufferProtocol.test_memoryview_struct_module.<locals>.<lambda>rfrNr,rrr+)�objectr	r
�Ellipsisr�rvrr�rNr6r�r:rwr8rr�r�ZassertIsNot)r#rrr�valuesr9rorpr>rrEr�r�Z
struct_errZmv_errr�r<r<r=�test_memoryview_struct_module�	sR�

�����z0TestBufferProtocol.test_memoryview_struct_modulecCs>tgd�dgdgd�}|�|j�t|�}|�t|jd�dS)Nr�rrr�r)rr�r[rNrdrr&)r#r>r�r<r<r=�!test_memoryview_cast_zero_strides	
sz4TestBufferProtocol.test_memoryview_cast_zero_stridesc	Cs2tD]C}td�rd|n|}t�|�}tD]/}td�rd|n|}t�|�}tttd��d|g|d�}t|�}|�t	|j
|d|g�qqtd�D]@\}}	}
t|	dg|d�}t|�}td�D]*\}}
}
t|�su|�t
|j
|d|g�q_t|�s�t|�s�|�t	|j
|d|g�q_qJt�d�}t�d�}tttd|��dd|gdd�}t|�}|jt	|j
dd|gdd�tttd	��gd
�d�}t|�}
|�t	|
j
�|�t	|
j
ddd�|�t	|
j
i�|�t
|
j
d
�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�tddgdgdd�}t|�}
|�t|
jd�|�t|
jdd�|�t|
j�tttd	��gd
�d�}t|�}
|jt	|
j
did�tttd	��d	gd�}t|�}
|jt|
j
ddgd�|jt
|
j
ddgd�|jt
|
j
dgd�d�|jt
|
j
dgd�d�|jt	|
j
dgd �d�ttd!d"�td#�D��gd$�d�}t|�}
|jt	|
j
d%gd&�d�tttd'��d'gd%d�}t|�}
|�t
|
j
d%dgd'�ttd(d"�td#�D��d#gd�}t|�}
|jt	|
j
d%gd&�d�ttd)d"�td#�D��d#gd�}t|�}
|jt	|
j
dgd&�d�tttd'��d'gd%d�}t|�}tttd'��d'gdd�}t|�}tjd*k�rv|�t	|j
dgd+��|�t
|j
dgd,��|�t
|j
d%gd-��dS|�t	|j
ddd.g�|�t
|j
dgd/��|�t
|j
d%gd0��dS)1Nr r@r0r-r+rrr��xr�r
r�Xz@Xz@XYz=Bz!Lz<Pz>lZBIZxBIr�r�ZIIrr4rr*r�)r rr�r�rr5r�)r rr�r�rr5r)r rr�r�rr5rYcSr'r
r<rr<r<r=r|^
r(zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>i�)rr�r5rjr)r rr�r�r#cSr'r
r<rr<r<r=r|h
r(cSr'r
r<rr<r<r=r|m
r(l����)r5r5�Ir-iQiAji��	)�r�rr4)rrrrr ��)rrr0r0r )rrr0r4r )�NON_BYTE_FORMATrr6rwrr�rbrNrdrr&rvryr�rwrr�r�rr�r�maxsize)r#ZsfmtZsformatZssizeZdfmtZdformatZdsizer>r�ZsitemsrmZsize_hZsize_drErr|r}r<r<r=�test_memoryview_cast_invalid
s�

�����


 "  ������z/TestBufferProtocol.test_memoryview_cast_invalidcsjddd�fddd�fddd�ff���fdd	�}t�d
�}tdgd
d�}t|dd
�\}}t|�}|�d�}�j||d
ddd
|d|dd�
t�d
�}tdg||gdd�}t|d
|gd�\}}t|�}|jd
gd�}�j|||d
dddd|dd�
tdd�D]\}	}
}t�|	|
�}t|�}||||
|	�q}tdd�D]\}	}
}t|
dg|	t	d�}t|�}||||
|	�q�dS)NrcSst|���Sr��r�r��r>r<r<r=r
�
sz9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>rcS�dd�t|���D�S)NcSs g|]}|dkr|dn|�qS)r-r"r<rfr<r<r=r|�
s �MTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>rrr<r<r=r
�
rrcSr)NcSsg|]	}tt|�d��qS)zlatin-1)rS�chrrfr<r<r=r|�
srrrr<r<r=r
�
rc

s�t�|�}�D]?\}}|�|�}||�}�j||d|ddd|gd|dd�
|�|�}	��|	|�|��}�j|	|||dddg|f|dd�
qdS)Nr+Fr1r�T�	rXr�r9r;r�r�r�rcr&)r6rwr&rSr:r)
r>rEror9�srcsizerOZto_bytelistr}rc�m3�Zbytespecr#r<r=�iter_roundtrip�
s$

�

��z?TestBufferProtocol.test_memoryview_cast.<locals>.iter_roundtriprrir-r+Tr�r!r
rr<r1rLrNr,)
r6rwrr�rNr&rSrvrLr�)r#r%r"r>Z	destitemsZ	destshaperEr}Zdestsizer9rormr<r$r=�test_memoryview_cast�
sD


�

�
��z'TestBufferProtocol.test_memoryview_castcCs�t�D]�}tdD]�}|dkrq	dtd�|}t�|�}t|�|}t|�r)dnd}t||�D]�\}}}	t�|�}
|dkrA|gng}||
g}t|||d�}
t	|
�}t
|
|||d	�\}}|durk|�t|j
||�q0|d
krpq0t|||d�}|j
||d	�}t|�}|j}|��}|j||
||d||||dd�
|�
|�}|j
||d	�}t|�}|
j}|
��}|j||
|
|d||||dd�
|j||
|
|d||||dd�
q0q	qt�r`Gd
d�dtj�}|dd�}t	|�}|�
d�}|�|j|�|�|jd�|�|jd�|�|jd�|�|j|jf�|�|jd�|�|jd�t�d�}t	|�}|�
d�}|�|j|�|�|jd�|�|jd�|�|jd�|�|j|jf�|�|jd�|�|jd�dSdS)Nr@r
)r?r@r rNrOrr-r
r�Tr!c@s eZdZdejfdejfgZdS)z>TestBufferProtocol.test_memoryview_cast_1D_ND.<locals>.BEPointrYrRN)rrr�ctypes�c_long�c_double�_fields_r<r<r<r=�BEPoint�
�r+r�g33333i@rr+Fr�r<�333333�?r)rrRrr6rwr�rwrvrrNr�rdrr&r^r�rrSr'�BigEndianStructurer:rXr�r9r;r�r�r�rr))r#Z_tshaperWZtfmtZtsizerrXr9rorm�sizer�Ztshaper>rEZtitemsrr}r�r�rcr#Zm4r+�pointr|rYr<r<r=�test_memoryview_cast_1D_ND�
s�



�
����6



�z-TestBufferProtocol.test_memoryview_cast_1D_NDcCs2t�dttdd���}t|�}|�||�|�|��|���|ddd�}|ddd�}|�||�|�|��|���tttd��gd�dd	�}t|�}|�|��|���td
dgdgdd	�}t|�}|�t|j�td
gdgdd	�}t|�}|�t|j�tgd�ddgdd	�}t|�}|�t|j�dS)Nrr�rr ri	)rjr r5rr�rr-)r r�)r5rjr:�12345r+r�)r�b�c�d�e�f)	rLr�rbrNr:rrrdr)r#rGrEr>r<r<r=�test_memoryview_tolists(z)TestBufferProtocol.test_memoryview_tolistcCsHttd��}|��}|�|�d��|��|��}|�|�d��dS)Nriz<memoryz	<released)rNr��__repr__rK�
startswithr�)r#rEr�r<r<r=�test_memoryview_repr3sz'TestBufferProtocol.test_memoryview_reprcCs|dD]%}td�}t�|d|dg�}t|�}|�d|�|�d|�|�d|�qtdgdd�}t|�}|�ttdt��dS)	N)rrg���?g@g"@rr�z9.0 in m)	�floatrLrNZassertInrrdrr�r�)r#r9�infr>rEr<r<r=�test_memoryview_sequence<sz+TestBufferProtocol.test_memoryview_sequenceccsN�|�t��}dVWd�n1swY|�t|j�d|f�dS)Nz#index out of bounds on dimension %d)rdr�r:�str�	exception)r#�dim�cmr<r<r=�assert_out_of_bounds_errorJs���z-TestBufferProtocol.assert_out_of_bounds_errorc	CsFtdgdd�}t|�}|�|dd�|�|d|�|�|d|�|�t|jd�tdgdd�}t|�}|�t|jd�tttd	��d	gt	d
�}t|�}|�t
|jd�|�t|jd�|�t|jd
�|�t
|jd�|�t
|jd�tttd��ddgt	d
�}t|�}|�|dd�|�|dd�|�|dd�|�|dd�|�|dd�dD]}|jdd��||dfWd�n1s�wYq�dD]}|jdd��|d|fWd�n1s�wYq�|�t
|jd�|�t
|jd�|�t|jd �|�t|jd!�|�t|jd�|�t|jd�dS)"N�)@rr-r<.rr�Ziiir5rmr*�@����r4rgrr��rr)r rr�rj�r�r�)r�rl�rrlr+�rB�r�r�r �r*rr)�rrr�rGrG)rrNr:rdrr�rr�rbr�r�rD)r#r>rE�indexr<r<r=�test_memoryview_indexQsN����z(TestBufferProtocol.test_memoryview_indexc	Cs�tdgdtd�}t|�}d|d<|�|dd�d|d<|�|dd�|�t|jdd	�tttd
��d
gd�}t|�}|�t|jdd
�tttd
��d
gtd�}t|�}|�t	|jdd�|�t|jdd
�|�t|jdd�|�t	|jdd�|�t	|jdd�t
dD]5}|dks�|dkr�q�tgd�dg|td�}t|�}tdd�}d||<|�||d�|�||||�q�tgd�dgdtd�}t|�}d|d<|�|dd�tgd �dgdtd�}t|�}d!|d"<|�|d"d!�td#gd"gdtd�}t|�}|�t|jdd$�tttd%��gd&�td�}t|�}t
d�
�D]R\}}|dk�r+�q |dk�r2�q |�|�}|\}	}
|d'k�sE|dk�rOdd(dd(}	}
|d)k�rh|�t|jd|	d"�|�t|jdd*�|�t|jd|
��q |�d�}|�t|jdd+�tttd"��d"gd,td�}t|�}|�t|jdd"�td-gd"gd.td�}t|�}|�t|jdd"�tttd/��dd0gtd�}t|�}d1|d2<|�|dd"d1�d3|d4<|�|ddd3�d5D] }|jd"d6��d||df<Wd�n	1�s�wY�q�d7D] }|jdd6��d|d|f<Wd�n	1�swY�q|�t	|jd8d�|�t	|jd9d�|�t|jd:d�|�t|jd;d�|�t|jdddg�dS)<NrErr,g�6@r<g�7@.rg33333�8@r5r
r rfrmr*rirFrGrjrHr�r4�r@rr
r�rr�)�1�2�3r�)TFTTr+�xr�rr�rrrr�s��ZxLr2r�rgr��*)rr+�+rJrKrLrMrNr)rOrP)rr�rNr:rdrr�r�rbr�rRrr9ror&r�rrD)r#r>rEr9rrr|Z_ranger}�lo�hirQr<r<r=�test_memoryview_assign�s�
��




����z)TestBufferProtocol.test_memoryview_assignc	Cs�tttd��dgtd�}t|�}|�t|jtddd��|�t|j	tddd�t
ddg��|�t|jd�tttd��dgtd�}t|�}|�t|jtddd�tddd�f�|�t|j	tddd�tddd�ft
ddg��|�t|jtddd�if�|�t|j	tddd�ift
ddg��|�t|j	tddd�dg�dt
fD]�}tttd��dgdgdt|Bd	�}tttd
��dgdg|d�}t|�}t|�}|dd�|dd�<|dd�|dd�<|�||�|�||�|dd�ddd�|dd
�ddd�<|dd�ddd�|dd
�ddd�<|�||�|�||�|ddd�ddd�|ddd�ddd�<|ddd�ddd�|ddd�ddd�<|�||�|�||�q�dS)Nrgrmrr r+r<r�rj)r�r�r�r��r�r�rr�rk)rr�rbr�rNrdr�r�r�r�r�rrrvr:)r#r>rEr�rzr{r|r}r<r<r=�test_memoryview_slice�sP
�
�
 �
��((,,�z(TestBufferProtocol.test_memoryview_slicecCs�dd�}tdd�D]�}t|d�D]�\}}}t|�D]�}t|�D]�}t�||�}t�||�}	t|	�}
|�|
|�|�|
��|���|�|
��|���|�t|
�t|��||||	|
|�d}d}z||}
||}||||<t|
�t|�k}Wnt	y�}z	|j
}WYd}~nd}~wwd}z|
||
|<Wnt	y�}z	|j
}WYd}~nd}~ww|r�|�|t�q|s�|r�|�||�q|�|
|�|�|
��|���|�|
��|���||||	|
|�qqqq	dS)Nc	Ss�t|�D]K\}}||}||}|�||�|||<||kr+|�||�|�||�n|�||�|�||�|||<|�||�|�||�|||<|||<qdSr�)r�r:�assertNotEqual)	ZtestcaserGrrE�
singleitemrrmZai�mir<r<r=�cmptest-s 
�z9TestBufferProtocol.test_memoryview_array.<locals>.cmptestr+r�rL)
rbrvrrLrNr:rr�r^r�r�r9r�)r#rbrr9ror`r�r
rGrrEZ	array_errZhave_resizeZal�arr�Zm_errr<r<r=�test_memoryview_array+sV��������z(TestBufferProtocol.test_memoryview_arrayc	Cs�t�dgd��}t�dgd��}t|�}t|�}dD]}|�t||�|�t�|�t||�|�t�qt|�}|��|�||�|�||�|�||�t|�}t|�}|��|�||�|�||�t|�}|�|gd��tdgdgdt	d�}d	t
d
�f|d<|�t|�|�t�dd
�}t|�}|�||�|�||�tr�Gdd�dtj�}|dd�}t|�}t|�}|�||�|�||�|�||�|�
t|j�dSdS)Nrr�)r+r r5)�__lt__�__le__�__gt__�__ge__rIr+zl x d xr,r�r�r�ur�c@� eZdZdejfdejfgZdS)zITestBufferProtocol.test_memoryview_compare_special_cases.<locals>.BEPointrYrRN�rrrr'r(r*r<r<r<r=r+�r,r+r�r�)rLrNr9�getattrr�r�r:r_rr�r=r'r.rdrr)	r#rGrr��w�attrrr+r0r<r<r=�%test_memoryview_compare_special_casesisH
�z8TestBufferProtocol.test_memoryview_compare_special_casescCsntdgdd�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�|�|�|��|�|�|��d|d<|�||�|�||�|�||�|�||�|�||�|�||�|�|�|��|�|�|��ttt	d��dgtt
Bd	�}ttt	d��dgtt
Bd	�}t|�}|�||�d
|d<|�||�tdgd
d�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�tdgd
d�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�|�||�|�||�dS)N��@Lr-rr,i�r<rgrmr�ri)rpr-r2ZLf5sZhf5s)i?���r-r2)rr�rNr:r��__ne__r_r�r�rbrv)r#�nd1�nd2r�rmrr>rEr<r<r=�!test_memoryview_compare_ndim_zero�sj��z4TestBufferProtocol.test_memoryview_compare_ndim_zerocCsXtgd�dgdd�}tgd�dgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tgd�dgdd�}tgd�dgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tgd�d	gdd�}tgd�dgdd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gd
d�}tgd�dgdd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gdd�}tgd�dgdtd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gdd�}tgd�dgdtd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��dS)N�����@�����'���r��@hr-)rwrxryrzi�z<iz>h)rwryr{rr r�rkz!hz<lr,zh  0cz>  h)rrNr:r_rv�r#rsrtr�rmr<r<r=� test_memoryview_compare_ndim_one�sl  � �$z3TestBufferProtocol.test_memoryview_compare_ndim_onecCs�tddgdgdd�}tddgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tddgdgdd�}tddgdgd	d�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)
N�r�rr|r-i|���i?���z= h0cz@   i�rrNr:r}r<r<r=�"test_memoryview_compare_zero_shape%
s$z5TestBufferProtocol.test_memoryview_compare_zero_shapecCs�tgd�dgdd�}tdgdgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�td	gddgd
d�}td	gdgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)N)rrrrr�rqr-rrrr�)rrz@ Liz!L  hr�r}r<r<r=�$test_memoryview_compare_zero_strides?
s$z7TestBufferProtocol.test_memoryview_compare_zero_stridesc
Cs�d}tdD]7}t|dd|�\}}}dtfD]&}t||g||d�}t|�}|�||�|ddd�}t|�}|�||�qqd}td�D]4}	t|�\}}}dtfD]&}t||g||d�}t|�}|�||�|ddd�}t|�}|�||�qQqDdS)	NrfrFrNr@rr,r�r�)rRrrrvrrNr:rb)
r#rrWr9ror`r�rrErmr<r<r=�&test_memoryview_compare_random_formatsY
s.�
��z9TestBufferProtocol.test_memoryview_compare_random_formatscCs�tttdd��gd�dd�}tttdd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�d	d�}td
gdgd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�d
d�}tttd��gd�d
d�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgdd�}tdgdddgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�d
d�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)N��r3�rr r�r|r-rr��rr+r z=f q xxL)g333333�r+r z< f 2Qr�r�rr5z! b B xLz
= Qx l xxLr�rr�rbrNr:r_r}r<r<r=�"test_memoryview_compare_multidim_cu
sZz5TestBufferProtocol.test_memoryview_compare_multidim_ccCs�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgd	d
dgdtd�}td
gd	d
dgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}tttd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nr�r3)r�r rr|r,rr��rr�rr r�=Qq)r�rz=qQr�rr�Z0llrH)rr�rbrHrNr:r_r}r<r<r=�(test_memoryview_compare_multidim_fortran�
s�����������z;TestBufferProtocol.test_memoryview_compare_multidim_fortranc	CsPttdd��}t|gd��}t|gd�dd�}t|gd�dtd�}t|�}t|�}|�||�|�||�|�||�dgd	}d
|d<t|gd��}t|gd�dd�}t|gd�d
td�}t|�}t|�}|�||�|�||�|�||�tttd��ddgdd�}|ddd�ddd�f}tttd��ddgdd�}|ddd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgdd�}|ddd�ddd�f}tdgdddgdd�}|ddd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd	��gd�dd�}|dd�ddd�f}tttd	��gd�dd�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd	��gd�dd�}|dd�ddd�f}tttd	��gd�dd�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgd	gd �d!d�}|dd�ddd�f}tdgd	gd �d"d�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)#Nr�r3r��@lr-rr,)gffffff
����rWr�)g�������r�rWr�zd b czd h c�(r4�@Irr+r�rkr)rr%�rjr z=iiz>iir�rr)r r��r�rr Zb3sZi3s)r�rbr�rrHrNr:r_)	r#�lst1�lst2rsrtr�rmrzr{r<r<r=�&test_memoryview_compare_multidim_mixed�
s�
z9TestBufferProtocol.test_memoryview_compare_multidim_mixedcCstttd��gd�dd�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dd�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nr�)rrr rr-)r�rr z@ir�r}r<r<r=�+test_memoryview_compare_multidim_zero_shape\s$z>TestBufferProtocol.test_memoryview_compare_multidim_zero_shapecCstdgdgd�dd�}tdggd�gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�|��|���td	gd
ddgd
d�}td	gddgddgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nrr�)r�r�r�rqr-rOrr�r�rfr r�z=lQrz<lQ)rrNr:rr}r<r<r=�-test_memoryview_compare_multidim_zero_stridesvs&z@TestBufferProtocol.test_memoryview_compare_multidim_zero_stridesc	Cs^tttd��ddgdd�}|ddd�ddd	�f}tttd��ddgd
td�}|ddd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgd
td�}d|dd<|ddd�ddd	�f}tdgdddgdttBd�}d|dd<|ddd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}|dd�ddd	�f}tttd��gd�dd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�dttBd�}|dd�ddd	�f}tdgdgd�dd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}|dd�ddd	�f}tttd��gd�dtd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�dttBd�}d|ddd<|dd�ddd	�f}tdgdgd�dttBd�}d|ddd<|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�ttdd ��}t|gd��}t|gd�d!td�}t|gd�d"t	tBd�}t|�}t|�}|�||�|�||�|�||�d#gd}d$|d%<t|gd��}t|gd�d&td�}t|gd�d't	tBd�}t|�}t|�}|�||�|�||�|�||�dS)(Nr�r�r4r�r-rr+r�rkrr,r�r�)r+rkr r5z>Qqr�r�rr�)r�r�ZBbr�r)shellor�r+�)rrrZ5s0sP)ssushir�r+r�r3r�r)ssashimisslicedg�����4@)sramensspicygfffff�"@rjz
< 10p 9p dz
> 10p 9p d)
rr�rbrvrNr:r_r�r�rH)	r#rzrsr{rtr�rmr�r�r<r<r=�+test_memoryview_compare_multidim_suboffsets�s�������
�z>TestBufferProtocol.test_memoryview_compare_multidim_suboffsetscCsRdD]�}tdgdgd�|dd�}tdgdgd�|dttBd�}d|d	d
ddd<t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�|dd�}tdgdgd�|dttBd�}d
|d	d
ddd<t|�}t|�}|�||�|�||�|�||�|�||�|�||�qdS)N)rCrArBrDr(r)rr�r r r rr-r,r+r r)r(r&r$ZQLH)r+r+r+)rr�rHrNr:r_)r#�	byteorderrYrRrGrr<r<r=�!test_memoryview_compare_not_equals8����z4TestBufferProtocol.test_memoryview_compare_not_equalcCst�dgd��}t|�}|��|�tt|�|�t|jd�|�tt|�|�t|j�|�t|j�|�tt	dt
��|�t|jd�|�t|jdd�dD]
}|�t|j
|�qPt�dgd��}t|�}t|�}|�||�|��|�||�|�||�|�||�dS)Nr)g�������?g������@gffffff
@rz1.0 in mrr+)rXr�r;r�r�r�r�r�rr[r]r_)rLrNr�rdr�r&rrr�r�r�r�r��__getattribute__r:r_)r#rGrErnrr|r}r<r<r=�test_memoryview_check_released/s*z1TestBufferProtocol.test_memoryview_check_releasedcsRd�t�dgdd�}t|�}|�||�|�|��|���t�gdgdd�}t|�}|�||�|�|��|���t�fdd�td	�D�gd
�dd�}t|�}|�||�|�|��|���t�fdd�td
�D�gd�dd�}t|�}|�||�|�|��|���tr�Gdd�dtj�}|dd�}t|�}|�|��t|��dSdS)Nrvr�r|r-r+z>hQiLlc�g|]}��qSr<r<r�rur<r=r|fr(z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>rgr�z=hQiLlcr�r<r<rr�r<r=r|kr(r)r�r r rr z<hQiLlc@rj)z;TestBufferProtocol.test_memoryview_tobytes.<locals>.BEPointrYrRNrkr<r<r<r=r+tr,r+r�r�)rrNr:r�rbr'r.rS)r#rrEr+r0rGr<r�r=�test_memoryview_tobytesWs2$�
�z*TestBufferProtocol.test_memoryview_tobytescCs�|�ttitd�|�ttdtd�tgd�dgdgd�}|�tt|td�tdd	d
d�}dD]}t|t|�}|�||�|�|d	d�q/tdd	d
td
�}dD]}t|t|�}|�||�|�|d	d�qPdD].}d|d	<t|t|�}|�||�|�|d	d�d|d	<|�|d	d�|�|d	d�qitdgdgd
td
�}dD]}t|t|�}|�t	|j
d�|�||�|�|��g�q�ttt
d��gd�d
td
�}dD]}t|t|�}|�t|���ggg�q�tdgdgdtd
�}dD]}t|t|�}|�||�|�|��|���q�tgd�dgdtd
�}dD]}t|t|�}|�||�|�|��|����qtgd�dgdgtd�}dD]2}t|t|�}|�||�|�|��|���|�t|jdd�|�|dd�|�|dd��qB|ddd�}dD]2}t|t|�}|�||�|�|��|���|�t|jdd�|�|dd�|�|dd��q~ttt
d��ddgtd�}dD]}t|t|�}|�t|���|����q�|�tt|td�t|t|�}|�t|���|���ttt
d��ddgttBd�}dD]}t|t|�}|�t|���|����q|�tt|td�t|t|�}|�t|���|���ttt
d��ddgttBd�}dD]}|�tt|t|�t|t|�}|�t|���|����qDtgd�dgdgd�}t|td�}|�|j�dS)Nr*rWr�r�r r�r+rir<rr-r)r,rfr+rr4r�rrrr�r�r�rgr�rm)r�r+)r*r+r�)rdrrIrJrDZPyBUF_WRITErr:r�r�r�rr�rbr�rHrvrKr[)r#rr8rEr<r<r=�test_memoryview_get_contiguouszs����z1TestBufferProtocol.test_memoryview_get_contiguouscCs�t�d�}t�dgd��}t|�}t�|�}td|�}|�|�|�|�	�|�t�d�}t
ttd��gd�dd�}t|�}t�|�}td|�}|�|�|�|�	�|�dS)Nrr�r�rrgr�r-)
r6rwrLrN�io�BytesIOr��readintor:r�rr�rb)r#r/rGrEr�rrr<r<r=�test_memoryview_serializing�s





z.TestBufferProtocol.test_memoryview_serializingc	Cs�tttd���}t|�}|�t|�t|��|jdddgd�}|�t|�t|��|ddd�}tttd��ddd��}|�t|�t|��tttd��gd�td	�}t|�}|�t|�t|��tttd��gd�d�}|ddd
�dd�ddd�f}t|�}|�t|�t|��tttd��gd�t	d	�}|ddd
�dd�ddd�f}t|�}|�t|�t|��tttd��dgd
d�}t|�}tttd��dgdd�}t|�}|�||�|�t|�t|��tttd��gd�dd�}t|�}|�
t|j�tttdd��gd�dd�}t|�}|�
t|j�tttd��gd�dd�}t|�}|�
t|j�tttdd��gd�dd�}t|�}|�
t|j�dS)Nrgrrr�r
rkr�r�rmr r�)r r�rrr-rr�rr�rrz= Lz< h)
rSr�rbrNr:r�r&rrHrvrdr��__hash__)	r#rrEZmcZmxrrYrGrRr<r<r=�test_memoryview_hash
sJz'TestBufferProtocol.test_memoryview_hashcCs�tgd��}t|�}t|�}|�t|j�~|��tgd��}t|�}t|ttd�}t|ttd�}|�|j	|�|�t|j�~~|��tgd��}t|�}t|�}t|�}|��|�t|j�~|��tgd��}t|�}t|�}t|ttd�}t|ttd�}|�|j	|�|��|�t|j�~~|��tgd�dgt
d�}t|�}|jgd�dgd�t|�}t|�}|�|�
�|�
��t|�}	|�|	�
�|�
��|�|	�
�|�
��|��|	��|��|�|�
�|�
��~|��|��dd	�}
td
�}t|��}|
|�|�|dtd��Wd�n	1�s#wYtttd
��gd�dd�}t|ttd�}	t|	ttd�}|�|j	|�t|��}|
|�|�|dd��
�gd�gd�gg�Wd�n	1�sqwYdtfD�]}td
�}t|��p}~t|t|d�}	t|	��R}~	t|t|d�}t|��4}
~|
|
�|
|�|
|�|�|dtd��|�|dtd��|�|
dtd��~
Wd�n	1�s�wY~Wd�n	1�s�wY~Wd�n	1�s�wYtd
�}t|��p}~t|t|d�}	t|	��S}~	t|t|d�}t|��6}
~|
|�|
|�|
|
�|�|dtd��|�|dtd��|�|
dtd��~~~
Wd�n	1�sZwYWd�n	1�sjwYWd�n	1�szwY�qztd
�}|�t��2t|��}t|�}|dtd�kWd�n1�s�wYWd�dSWd�dS1�s�wYdS)Nr��rXr�rrm)r�r�rr5r4r�r
cSs.t|��	}Wd�dS1swYdSr�)rN)rr}r<r<r=�catch22�s
"�z;TestBufferProtocol.test_memoryview_release.<locals>.catch22r�rrTrgr�rr-r+r�)rr�r�rUr rV)r�rNrrdrDr�rN�ND_REDIRECTr9rXr�r�r:rr��ordr�rb)r#rGrErrsrtr|r}rYrRr�r�r�r#r>r<r<r=�test_memoryview_releaseIs�
�
(�


�	�
�


������
 ��$�z*TestBufferProtocol.test_memoryview_releasecCs0tdd�td�D�dgdd�}t�ddd�td�D��}||fD]u}t|ttd�}t|ttd�}t|�}|�|j|�|�|j|�|�|j|�|�||�|�||�|�||�|�|dd	�|dd	��|�|dd	�|dd	��|�|dd	�|dd	��~~|�|dd	�|dd	��q dS)
NcS�g|]}d|�qS�r<r<rfr<r<r=r|�r�z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>rgrr-cSr�r�r<rfr<r<r=r|�r�r�r+r)	rrbrLrNr�rNr9rXr:)r#rrGrYrRr�rEr<r<r=�test_memoryview_redirect�s$�z+TestBufferProtocol.test_memoryview_redirectcCs�d}gd�}|�ttddd�t�}t|�}|j||d|dddgdg|d�	td�D]
}|�|||�q*~~t�}t|�}~~t�}t|td	�}t|td	�}t|�}|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~t�}t|ttd
�}t|ttd
�}t|�}|�	|j
|�|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~tdd�}t|�}|j|dd|dddgdg|d�	td�D]
}|�|||�q�~~tdd�}t|�}~~tdd�}t|td	�}t|td	�}t|�}|�	|j
d�|�	|j
|�|j||d|dddgdg|d�	~~~~tdd�}t|ttd
�}t|ttd
�}t|�}|�	|j
d�|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~dS)Nr)rr+r rr�r�rr5r4rirfrjr+r rTrgr�rWr�)Zlegacy_mode)rdrZstaticarrayrNrSrbr:rrNr9rXr�)r#r9rcrYrRrr�rEr<r<r=�$test_memoryview_from_static_exporter�s�
�
�
�

�


�

�z7TestBufferProtocol.test_memoryview_from_static_exportercCs*tgd�dgttBd�}|�tt|�dS)Nr�rr�)rrxZND_GETBUF_UNDEFINEDrdrDrNr�r<r<r=�#test_memoryview_getbuffer_undefined?sz6TestBufferProtocol.test_memoryview_getbuffer_undefinedcCs&tgd�dgtd�}|�tt|�dS)Nr�rrm)rrxrdrDrN)r#rYr<r<r=�test_issue_7385Esz"TestBufferProtocol.test_issue_7385cCs&dD]}|�t�|�t�|��qdS)N)r?�iiZ3s)r:�	_testcapiZPyBuffer_SizeFromFormatr6rw)r#r�r<r<r=�test_pybuffer_size_from_formatIs
��z1TestBufferProtocol.test_pybuffer_size_from_formatN�F)Urrrr$rSrer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rrrr&r1r8r;r?�
contextlib�contextmanagerrDrRr\r^rdrorur~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zcpython_onlyr�r<r<r<r=r �s��
K0i
-'	0.Y #6!)>
		%qu
8	s<T	
5m8>5?H>Ha(#u<^r �__main__)rNN)r�r2r<)r�r2r5r�r�r)ir�Zunittest�testrZtest.supportr�	itertoolsrr�randomrrr�warningsrrLr��os�decimalr	Z	fractionsr
Z_testbuffer�ImportErrorrr6r'ZEnvironmentVarGuard�environ�catch_warningsrMr�r�Z
SHORT_TESTZNATIVEr7r8ZSTANDARDr>rRr9�copyrxZARRAYr�ZBYTEFMTrhrjrgrZrardrqrrrsrvrwryrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
r�rrrr�r�r�Z
skipUnlessZTestCaser r�mainr<r<r<r=�<module>s� ���������	���
�	
�
�

�	



	


?
+

!






o�
© 2025 GrazzMean