Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_buffer.cpython-311.pyc
�

�Ke<���l�ddlZddlZddlmZddlmZddlmZmZddl	m
Z
mZmZddl
Z
ddlZddlZddlZddlZddlmZddlmZ	ddlTn
#e$rdZYnwxYw	ddlZn
#e$rdZYnwxYw	ddlZn
#e$rdZYnwxYw	ej��5e_e
j��5dd	lmZddd��n#1swxYwYddd��n#1swxYwYn
#e$rdZYnwxYw	ddl Z n
#e$rdZ YnwxYwd
Z!dddddddddddddddd�Z"ere"d=e"d
=er-	ej#dd��de"d<de"d<n#ej$$rYnwxYwdddddddddddddddzddzfd�Z%d�Z&e"e"e%e%e%e%d�Z'ere'dD]Z(e&e(��e'de(<�e"�)��Z*e"�)��Z+e"D]	Z,e,d vre+e,=�
e"�)��Z-e"D]	Z,e,d!vre-e,=�
e*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*�Z1d+�Z2d,�Z3d-�Z4dhd/�Z5d	d0�Z6d	d1�Z7d2�Z8d3�Z9d4�e'dD��Z:d5�Z;d6�Z<d7�Z=d8�Z>d9�Z?d:�Z@d;�ZAd<�ZBd=�ZCd>�ZDd?�ZEd@�ZFdA�ZGdB�ZHdC�ZIdD�ZJdE�ZKdF�ZLdG�ZMdH�ZNdI�ZOdJ�ZPdidN�ZQdO�ZRdP�ZSdjdQ�ZTdR�ZUdkdS�ZVdT�ZWdldU�ZXdV�ZYdW�ZZdX�Z[dmdZ�Z\dmd[�Z]dnd\�Z^dld]�Z_d^�Z`d_ZadKZbd`Zce!rd`ZadaZbdbZce]ZZe^Z[e_Zejdedc��ejdedd��Gde�dfeje������Zfegdgkrejh��dSdS)o�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���)rrrrrrrrrrrrrrc��|dkrd}nr|dkrd}ni|dkrd}n`|dkrdd	zdd	zf}nNd
D]4}	tj|d|zdz
��n#tj$rY�1wxYw|dzrd|zd|zfndd|zf}|S)zReturn range of a native type.rr"rr rr(rr,r-)
r$��@�?� �����r)�struct�pack�error)�fmt�lh�exps   �:/usr/local/apps/python3/lib/python3.11/test/test_buffer.py�native_type_ranger?_s���
�c�z�z�
���	����
���	����
���	�����4��j�!�T�'�
"���;�	�	�C�
���C�!�S�&�!��,�,�,�����<�
�
�
���
����$'�!�G�
<��3��i��C��
 �
 �!�Q��V���
�Is�A�A"�!A")��@�<�>�=�!rA�
bBhHiIlLfd�Bbc�m�@m�ar�@b)r@�1�2�3r@)r
�array�numpy�
memoryview�bytefmtc�$�tt||�}|dkrt|g��}|dkr|dkrd}|dkrt|��}|dks|dkr0t	j||��}t	j||��d}|S)	zWReturn random item for a type specified by a mode and a single
       format character.rrP��rrrr)r�fmtdict�bytes�boolr8r9�unpack)�mode�char�obj�xs    r>�
randrange_fmtr^�s���	�7�4�=��&�'�A��s�{�{��1�#�J�J���'�>�>�a�7�l�l��A��s�{�{���G�G���s�{�{�d�c�k�k��K��a� � ���M�$��"�"�1�%���H�c���|�d��\}}g}|D]&}|�t|||�����'t|��dkr|dnt	|��S)zReturn single random item.�#r,r)�split�appendr^�len�tuple)r;r\rZ�charsr]rs      r>�gen_itemrg�sl���)�)�C�.�.�K�D�%�
�A�
�.�.��	����t�Q��,�,�-�-�-�-��q�6�6�Q�;�;�1�Q�4�4�E�!�H�H�,r_c��|dkrt||��Sdg|z}t|��D]}t||��||<�|S)z,Return a list of random items (or a scalar).r)rg�range)rr;r\�lstrs     r>�	gen_itemsrk�sU���A�v�v���S�!�!�!��#��'�C�
�1�X�X�$�$���#�s�#�#��A����Jr_c���tt|t��}|dz}|�d��}t	dd��}t|��D]o}tt
t|����}tt|t��}||t|r|nd��zz
}|||zz
}�pt|||��}	t||��}
||	|
fS)Nra�ambr!�
r,)r	�cap�MODE�striprrirerV�MULT�intrkrg)rr\rZ�xfmtr;�nmemb�_r[�
multiplier�items�items           r>�struct_itemsrz�s����#�c�(�4�.�!�!�D��#�:�D�
�*�*�U�
�
�C��a����E�
�5�\�\�#�#���e�G�D�M�*�*�+�+���C��H�T�N�+�+�
����*�;�J�J�!�<�<�<�=���
�T�!�"����a��s�#�#�E��D�#���D���t��r_r
c��|�%tt|t��}|�'ttt|����}tt|t
��}|dz|t
|r|nd��zz}t|||��}t||��}|�	d��|z|z}|||fS)z"Return random format, items, item.Nrar,rm)
r	rorprerVrrrsrkrgrq)rr\rZr[rwr;rxrys        r>�	randitemsr|�s����|��c�#�h�t�n�%�%���|��e�G�D�M�*�*�+�+����C����'�'�J�
��*�t�c�
�"A�*�*��B�B�B�
B�C��a��c�"�"�E��C����D�
�*�*�U�
�
�j�
(�4�
/�C���t��r_c#�K�t|tD]&}t|D]}t||||��V���'dS)z1Iterate through supported mode/char combinations.N)rorprVr|)rr\rZr[s    r>�	iter_moder~�s\�����C����0�0���D�M�	0�	0�D��A�s�D�$�/�/�/�/�/�/�	0�0�0r_c#�lK�t||��D]}|V��|dkrdSt||��V�dS)zwYield (format, items, item) for all possible modes and format
       characters plus one random compound format string.r
N)r~rz)�nitems�testobj�ts   r>�iter_formatr��sX�����v�w�
'�
'����������)�����
�v�w�
'�
'�'�'�'�'�'r_c��d|vpd|vpd|vS)Nrrr�)r;s r>�is_byte_formatr��s���#�:�1����1�s�c�z�1r_c�t�t|��}|dks|dko|ddko||dz
tvS)zformat suitable for memoryviewr,r!rrA)rd�
MEMORYVIEW)r;r]s  r>�is_memoryview_formatr��sD���C���A�
�!�V�
1��Q��0�3�q�6�S�=�
#���!��H�
�"�$r_c�0�g|]}t|���|��Sr�)r���.0rs  r>�
<listcomp>r��s%��D�D�D��.��2C�2C�D�1�D�D�Dr_c�.�t|t��S)z9Tuple items (representing structs) are regarded as atoms.��
isinstance�list�rjs r>�atompr��s���#�t�$�$�$�$r_c�,�t|t��S�Nr�r�s r>�listpr��s���c�4� � � r_c�d�t|��dkrdS|d}|dd�D]}||z}�|S)zProduct of list elements.rr,N)rd)rjr]�vs   r>�prodr��sF��
�3�x�x�1�}�}��q��A��A�
����W����	�Q�����Hr_c�H�|dkrdS|dkrLt|dd���|gz}t|dz
dd��D]}||xx||dzzcc<�nG|gt|dd���z}td|��D]}||xx||dz
zcc<�|S)zOCalculate strides of a contiguous array. Layout is 'C' or
       'F' (Fortran).rr��Cr,Nr!���)r�ri)�ndim�shape�itemsize�layout�stridesrs      r>�strides_from_shaper�s����q�y�y��r�
��}�}��u�Q�R�R�y�/�/�X�J�.���t�A�v�r�2�&�&�	'�	'�A��A�J�J�J�'�!�A�#�,�&�J�J�J�J�	'��*�t�E�#�2�#�J�/�/�/���q�$���	'�	'�A��A�J�J�J�'�!�A�#�,�&�J�J�J�J��Nr_c�@�t|��r|St|��dkr|dSdg|dz}|drt|��|dznd}t|d��D]-}||z}t||||z�|dd���||<�.|S)zmConvert flat item list to the nested list representation of a
       multidimensional C array with shape 's'.rr,N)r�rdri�_ca)rx�srj�strider�starts      r>r�r�s���
�U�|�|����
�1�v�v��{�{��Q�x���#��!��*�C�#$�Q�4�
.�S��Z�Z�1�Q�4�
�
�Q�F�
�1�Q�4�[�[�7�7���&����U�5��v��-�.��!�"�"��6�6��A����Jr_c��t|��r|St|��dkr|dSdg|dz}|d}t|d��D]&}t||d|�|dd���||<�'|S)zsConvert flat item list to the nested list representation of a
       multidimensional Fortran array with shape 's'.rNr,)r�rdri�_fa)rxr�rjr�rs     r>r�r�%s���
�U�|�|����
�1�v�v��{�{��Q�x���#��!��*�C�
�q�T�F�
�1�Q�4�[�[�.�.���U�1�9�f�9�%�q����u�-�-��A����Jr_c��t|��r3d|vr/t|��t|��krtd���t	||��S�Nrzprod(shape) != len(items))r�r�rd�
ValueErrorr��rxr�s  r>�carrayr�2�M���U�|�|�6�A��J�J�4��;�;�#�e�*�*�+D�+D��4�5�5�5��u�e���r_c��t|��r3d|vr/t|��t|��krtd���t	||��Sr�)r�r�rdr�r�r�s  r>�farrayr�7r�r_c�,�d�|D��}t|�S)z(Generate all possible tuples of indices.c�,�g|]}t|����Sr��ri�r�r�s  r>r�zindices.<locals>.<listcomp>>s��)�)�)�a��q���)�)�)r_)r)r��	iterabless  r>�indicesr�<s ��)�)�5�)�)�)�I��I��r_c�V�d}t|��D]}|||||zz
}�|S)zAConvert multi-dimensional index to the position in the flat list.rr�)r��indr��retrs     r>�getindexr�As:��
�C�
�4�[�[�#�#���w�q�z�C��F�"�"����Jr_c�<�|s|St|��}t||dd��}t||ddd�dd��}dgt|��z}t|��D]8}t|||��}t||ddd�|��}||||<�9|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)rdr�r�r�)	�srcr�r��sstrides�dstrides�destr��fr�tos	         r>�	transposer�Hs������
��u�:�:�D�!�$��q�#�6�6�H�!�$��d�d��d��Q��<�<�H�
�3��S���>�D��u�~�~����
�d�C��
*�
*��
�d�C���"��I�x�
0�
0���r�7��R����Kr_c��|gkr|St|��r|gSt|d��t|dd���zS)zflatten listrr,N�r��_flattenr�s r>r�r�WsL��
�b�y�y��
��S�z�z���u���C��F���h�s�1�2�2�w�/�/�/�/r_c�B�t|��r|St|��S)zflatten list or return scalarr�r�s r>�flattenr�_s!���S�z�z���
��C�=�=�r_c��t|��rgSt||d��gt|d|dd���zS)zMGet the shape of lst after slicing: slices is a list of slice
       objects.rr,N)r�rd�slice_shape�rj�slicess  r>r�r�esK��
�S�z�z���	���F�1�I���� �;�s�1�v�v�a�b�b�z�#B�#B�B�Br_c�Z��t|��r|S�fd�|�dD��S)z=Multi-dimensional slicing: slices is a list of slice objects.c�@��g|]}t|�dd�����S�r,N)�
multislice)r��sublstr�s  �r>r�zmultislice.<locals>.<listcomp>ps+���H�H�H�v�J�v�v�a�b�b�z�*�*�H�H�Hr_r)r�r�s `r>r�r�ls8����S�z�z���
�H�H�H�H��V�A�Y��H�H�H�Hr_c����t|��r|S��fd�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
�Z��g|]'\}}t||�dd��dd�����(Sr�)�m_assign)r�r�r�lslices�rslicess   ��r>r�zm_assign.<locals>.<listcomp>�sQ���A�A�A���1�
�Q��7�1�2�2�;������4�4�A�A�Ar_r)r��zip��llst�rlstr�r�s  ``r>r�r�rs}����
�T�{�{����A�A�A�A�A��D����,�d�7�1�:�.>�?�?�A�A�A�D��D������Kr_c��t||��}t||��}t|��t|��krdStt|����D]&}||||krdS||dkrdS�'dS)z9Compare the structure of llst[lslices] and rlst[rslices].r�r)r�rdri)r�r�r�r��lshape�rshapers       r>�
cmp_structurer��s���
��w�
'�
'�F�
��w�
'�
'�F��F���s�6�{�{�"�"��r�
�3�v�;�;�
�
�����!�9��q�	�!�!��2�2��!�9��>�>��1�1���1r_c�p�t||||��dkrtd���t||||��S)z:Return llst after assigning: llst[lslices] = rlst[rslices]rz+lvalue and rvalue have different structures)r�r�r�r�s    r>�multislice_assignr��s>���T�4��'�2�2�Q�6�6��F�G�G�G��D�$���1�1�1r_c�p����|�zrdS|dks	|�z|krdSt�fd��D����rdS|dkr|dko�o�Sd�vrdSt��fd�t|��D����}t��fd�t|��D����}d||zko||z�z|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
    Frc3�"�K�|]	}|�zV��
dSr�r��r�r�r�s  �r>�	<genexpr>z#verify_structure.<locals>.<genexpr>�s'�����
)�
)�A�1�x�<�
)�
)�
)�
)�
)�
)r_Tc3�X�K�|]$}�|dk��|�|dz
zV��%dS�rr,Nr��r��jr�r�s  ��r>r�z#verify_structure.<locals>.<genexpr>�sI�����#�#�1��!�*��/�/��q�z�5��8�A�:�&�!�/�/�/�#�#r_c3�X�K�|]$}�|dk��|�|dz
zV��%dSr�r�r�s  ��r>r�z#verify_structure.<locals>.<genexpr>�sI�����"�"�1��!�*�q�.�.��q�z�5��8�A�:�&� �.�.�.�"�"r_)�any�sumri)�memlenr�r�r�r��offset�imin�imaxs ` ``   r>�verify_structurer��s0����������u�
��z�z�V�H�_�v�-�-��u�
�
)�
)�
)�
)��
)�
)�
)�)�)���u��q�y�y��q�y�6��Y�6�w�;�6��E�z�z��t��#�#�#�#�#��d���#�#�#�#�#�D��"�"�"�"�"��d���"�"�"�"�"�D�
��t���>��t��H� 4�� >�>r_c� �|D]
}||}�|Sr�r�)rjr�rs   r>�get_itemr��s!��
�����!�f����Jr_c�h�|\}}}}}}|}t|��D]}	|||	||	zz
}�|S)z-Location of an item in the underlying memory.r�)
r�r�r�r�r�r�r�r��prs
          r>�memory_indexr��sL��56�2�F�H�d�E�7�F��A�
�4�[�[�#�#��	�W�Q�Z���
�
"�"����Hr_c��|\}}}}}}d|z}t|��D]$}t||��}	d|	z}
||
zrdS||
z}�%dS)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�)r�r�r�r�r�r�r��visitedr�r�bits           r>�is_overlappingr��so��67�2�F�H�d�E�7�F���i�G��u�~�~������a� � ����d���S�=�	��4�4��3�����5r_�r4r�c�n����s�t|dz��}|dkr?|r|||dddfStdd��}||z}td��dkr|n|}|||dd|fSd}	td��}
|
dkr|rd}	n|
dkrd}	dg|z�t|��D]}t|	|dz���|<�nt���}d	}td��}
|
dkr|
dzrd
nd}
dg|z�|t||dz��z�|dz
<|
s�|dz
dkr|�|dz
<t|dz
dd��D]i}|�|dzr�|dzndz}|
r|t||dz��z�|<�:d
td��|ztd|dz��z�|<�jdx}}d�vrRt��fd�t|��D����}t��fd�t|��D����}||z
}|r||z}||dz|zz}n$||z|z}td��dkr||z
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�c3�X�K�|]$}�|dk��|�|dz
zV��%dSr�r�r�s  ��r>r�z!rand_structure.<locals>.<genexpr>sI�����'�'�q��a�j�A�o�o��1�:�u�Q�x��z�*�%�o�o�o�'�'r_c3�X�K�|]$}�|dk��|�|dz
zV��%dSr�r�r�s  ��r>r�z!rand_structure.<locals>.<genexpr>sI�����&�&�q��a�j�1�n�n��1�:�u�Q�x��z�*�$�n�n�n�&�&r_)rrirdr�)r��valid�maxdim�maxshaper�r�r�r�r��minshaperr�	maxstride�zero_strider�r�r�s    `           @r>�rand_structurer
�s.����������"�"���A�I�I��
>���4��R��:�:�"�1�d�+�+���(�*��&/��l�l�a�&7�&7�(���V���x��r�2�v�=�=����c�N�N����7�7�u�7��H�H�
�"�W�W��H���d�
���t���	7�	7�A� ��8�A�:�6�6�E�!�H�H�	7��5�z�z���I��#���A��r�'�'�a�!�e�'�$�$��K��c�D�j�G���I�:�y��{�!C�!C�C�G�D��F�O��#�7�4��6�?�a�/�/�"���Q���
�4��6�2�r�
"�
"�@�@���5��1��:�4�U�1�Q�3�Z�Z�1�4�	��	@�!�I�y�j�)�A�+�$F�$F�F�G�A�J�J� ��1���.�"�#�%.�q�)�A�+�%>�%>�?�G�A�J�J��O�D�4���:�:��'�'�'�'�'�E�$�K�K�'�'�'�'�'���&�&�&�&�&�E�$�K�K�&�&�&�&�&���D�[�F��A����!���4��6�X�-�-����%�$�,�(�*��#,�Q�<�<�1�#4�#4�$��x���&���8�T�5�'�6�9�9r_c���||z
}t|dz��}|r||z
|znd}td|dz��}|||zz}t|||��}t||��\}}}}	|	|krt�|S)z=Create a random slice of len slicelen that fits into listlen.r,)r�slice�
slice_indices�RuntimeError)
�slicelen�listlen�maxstartr��maxstep�step�stopr�rv�controls
          r>�randslice_from_slicelenr's�����!�H��h�q�j�!�!�E�/7�>�w���8�+�+�Q�G��Q���	�"�"�D��8�d�?�"�D�
�e�T�4� � �A�$�Q��0�0��A�q�!�W��(������Hr_c��dg|z}dg|z}t|��D]K}||}|dkrtd|dz��nd}t||��||<t||��||<�Lt|��t|��fS)zxCreate two sets of slices for an array x with shape 'shape'
       such that shapeof(x[lslices]) == shapeof(x[rslices]).rr,)rirrre)r�r�r�r�rrrs       r>�randslice_from_shaper4s����c�D�j�G��c�D�j�G�
�4�[�[�:�:���!�H��()�A���9�Q��!��$�$�$�1��,�X�q�9�9���
�,�X�q�9�9���
�
���>�>�5��>�>�)�)r_c�~�td|dz��}d}td��}|dkrd}n|dkrd}td��dkrdnd	}dg|z}dg|z}dg|z}dg|z}	t|��D�])}t||dz��}
t||dz��}||
kr|
|}
}|rxt|
|
dz��}t|
|
dz��}
d
td��td|
dz��z}t||
|��}t||
��\}}}}n+|
dkrtd|
dz��nd}t	||
��}t	||��}td��dkr||
c||<||<||c|	|<||<��|
|c||<||<||c|	|<||<��+||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)rrirr
rre)rrr�rr�
all_randomr�r�r�r��small�bigr�rr�s_smallrvr�s_bigs                   r>�rand_aligned_slicesr @s���Q��q��!�!�D��H��#���A��B�w�w����	
�b�����"�3���2�-�-���5�J��S��X�F���D��v��c�$�h�G�1�#�d�(��
�4�[�[�4�4���(�H�Q�J�/�/����(�1�*�-�-����;�;����C��	?��u�f�e�A�g�.�.�E��e�V�U�1�W�-�-�D��)�A�,�,�'�)�A�u�Q�w�*?�*?�?�D��E�4��.�.�G� -�g�u� =� =��A�q�!�X�X�05��	�	�y��E�!�G�,�,�,�q�H�-�h��>�>�G�(��#�6�6���Q�<�<�1���#&�� �F�1�I�v�a�y�%*�G�"�G�A�J���
�
�#(�#� �F�1�I�v�a�y�%,�e�"�G�A�J���
�
��6�5��>�>�5��>�>�9�9r_c�B�|\}}}}}}t||zd|zd��S)zMReturn a list of random items for structure 't' with format
       'fmtchar'.rarP)rk)r;r�r�r�rvs     r>�randitems_from_structurer"ks1��$%� �F�H�a��A�q��V�X�%�s�3�w��8�8�8r_c	�N�|\}}}}}}	t|||||	t|z���S)z:Return ndarray from the tuple returned by rand_structure()�r�r��formatr��flags)r
�ND_WRITABLE)
rxr;r�r&r�r�r�r�r�r�s
          r>�ndarray_from_structurer(qs=��56�2�F�H�d�E�7�F��5��w�s� ��E�(9�;�;�;�;r_c��|\}}}}}}t|��}	t|��D]\}
}tj||	|
|z|��� t	|	||||���S)z>Return numpy_array from the tuple returned by rand_structure())�bufferr�r��dtyper�)�	bytearray�	enumerater8�	pack_into�numpy_array)rxr;r�r�r�r�r�r�r��bufr�r�s            r>�numpy_array_from_structurer1ws|��56�2�F�H�d�E�7�F�
�F�
�
�C��%� � �2�2���1����c�1�X�:�q�1�1�1�1��c��� ��1�1�1�1r_c�����|j}|rt|���z|krd|fSn<|gkr|jdks�|krd|fSn t|���\}}|g}|dkrd|fS|������fd�tdt
������D��}g}|D]>}	tj||	��d}
|
|
krd|fcS|�	|
���?|gkr||fn	|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).Nrc�*��g|]}�||�z���Sr�r�)r�rr��mems  ��r>r�zcast_items.<locals>.<listcomp>�s&���I�I�I�q��Q�q��z�\�"�I�I�Ir_�nan)
�nbytesr�r��divmod�tobytesrirdr8rYrc)�exporterr;r�r��bytelenrr��	byteitemsrxr�ryr4s  `        @r>�
cast_itemsr<�sN�����o�G��
���;�;��!�W�,�,���;��-�	�"����=�A����W�!4�!4���;��"5��g�x�(�(���1������6�6���;��
�
�
�
�
�C�I�I�I�I�I�E�!�S��X�X�x�,H�,H�I�I�I�I��E�
�����}�S�!�$�$�Q�'���4�<�<��%�<����
���T�����"�b�[�[�E�5�>�>�u�Q�x��.?�?r_c#�J�K�td��D]}|gV��tdd��}td��dkrdnd��fd�t|��D��V�tdd��}td��dkrdnd��fd	�t|��D��V�d
S)z Generate shapes to test casting.r2��r�rr,r!c�0��g|]}t�d����S�r��r�r�rvrs  �r>r�z!gencastshapes.<locals>.<listcomp>��#���
7�
7�
7�a�9�X�q�!�!�
7�
7�
7r_c�0��g|]}t�d����SrArBrCs  �r>r�z!gencastshapes.<locals>.<listcomp>�rDr_N)rir)rr�rs  @r>�
gencastshapesrF�s������
�2�Y�Y�����c�	�	�	�	��Q��?�?�D��c�N�N�R�'�'�q�q�Q�H�
7�
7�
7�
7�5��;�;�
7�
7�
7�7�7�7��Q��?�?�D��c�N�N�R�'�'�q�q�Q�H�
7�
7�
7�
7�5��;�;�
7�
7�
7�7�7�7�7�7r_c	��tt||dz��t||dz��t||dz����S)z4Generate all possible slices for a single dimension.r,)rri)rs r>�	genslicesrH�s>���5�!��Q�q�S�>�>�5�!��Q�q�S�>�>�5�!��Q�q�S�>�>�B�B�Br_c�L���fd�t|��D��}t|�S)z/Generate all possible slice tuples for 'shape'.c�:��g|]}t�|����Sr�)rH�r�rr�s  �r>r�z"genslices_ndim.<locals>.<listcomp>�s%���:�:�:���5��8�$�$�:�:�:r_)rir)r�r�r�s ` r>�genslices_ndimrL�s-���:�:�:�:�e�D�k�k�:�:�:�I��I��r_Fc�`�|s|dkrdnd}t||dz��}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_empty�minlenrs    r>�rslicerP�s=���
.��a���Q�Q�Q�F����1��%�%�H�"�8�Q�/�/�/r_c#�RK�td��D]}t||��V��dS)z.Generate random slices for a single dimension.r�N)rirP)rrNrvs   r>r�r��s>����
�1�X�X�%�%���Q��$�$�$�$�$�$�%�%r_c#�L�K�t|��D],}t�fd�t|��D����V��-t|��D],}t�fd�t|��D����V��-td�t|��D����V�dS)z)Generate random slice tuples for 'shape'.c3�B�K�|]}t�|��V��dSr��rPrKs  �r>r�zrslices_ndim.<locals>.<genexpr>�s/�����:�:��F�5��8�$�$�:�:�:�:�:�:r_c3�F�K�|]}t�|d���V��dS)T)rNNrTrKs  �r>r�zrslices_ndim.<locals>.<genexpr>�s4�����L�L�1�F�5��8��6�6�6�L�L�L�L�L�Lr_c3�8K�|]}tddd��V��dSr�)r�r�rvs  r>r�zrslices_ndim.<locals>.<genexpr>�s,����2�2���a��!���2�2�2�2�2�2r_N)rire)r�r��
iterationsrvs `  r>�rslices_ndimrY�s�������:�
�
�;�;���:�:�:�:�e�D�k�k�:�:�:�:�:�:�:�:�:�
�:�
�
�M�M���L�L�L�L��d���L�L�L�L�L�L�L�L�L�
�2�2�e�D�k�k�2�2�2�
2�
2�2�2�2�2�2r_c#�K�t|��}|�t|��n|}tt||����V�dSr�)rerdr)�iterabler��pools   r>�rpermutationr]�sF������?�?�D��Y��D�	�	�	�A�A�
��t�Q���
 �
 � � � � � r_c��	|���}n+#ttf$r|���}YnwxYwt	|t
��r|j}|j}nd}d}td|�d|j	�d|j
�d|j�d|�d|j�d|j
�d	|�d
���tj���dS)zPrint ndarray for debugging.�unknownzndarray(z, shape=z
, strides=z
, suboffsets=z	, offset=z
, format='z', itemsize=z, flags=�)N)�tolist�	TypeError�NotImplementedErrorr8r�r
r�r&�printr�r��
suboffsetsr%r��sys�stdout�flush)�ndr]r�r&s    r>�
ndarray_printrj�s�����I�I�K�K�����*�+�����J�J�L�L���������"�g���������������	�E��1�1�b�h�h�h��
�
�
�B�M�M�M�6�6�6�
�9�9�9�b�k�k�k�5�5�5�*�+�+�+��J�������s��%?�?r�rn�r>z%struct module required for this test.z%ndarray object required for this testc�(�eZdZd�Zddd�d�ZdQd�Zd�Zd�Zd�Zd	�Z	d
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �Z d!�Z!d"�Z"d#�Z#d$�Z$d%�Z%d&�Z&d'�Z'd(�Z(d)�Z)e*j+Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4e5j6d3���Z7d4�Z8d5�Z9d6�Z:d7�Z;d8�Z<d9�Z=d:�Z>d;�Z?d<�Z@d=�ZAd>�ZBd?�ZCd@�ZDdA�ZEdB�ZFdC�ZGdD�ZHdE�ZIdF�ZJdG�ZKdH�ZLdI�ZMdJ�ZNdK�ZOdL�ZPdM�ZQdN�ZRe*jSdO���ZTdPS)R�TestBufferProtocolc�,�t��|_dSr�)�get_sizeof_void_p�
sizeof_void_p��selfs r>�setUpzTestBufferProtocol.setUps��.�0�0����r_F)�sliced�castc

�:��������	�
�%�&�'�(��rt����z�'n�st�	���'n��'d�(�jr����d��d}t	d���D]4}
�|
dkrn%�|
dkr|�|
�|
dz
zz
}�5|gd�t	�dz
��D��z�(�j}�ddkr|}|gt
�dd���z����j|����	�j
�'����	�j�����	�j������j
|����	�j�����	�jt!������
r�(s(��	�jt!�������	�jt!�(����t%�t&��st)���r@�r����n����}��	|�	���sdS|�s�t/��}d}t1���D]�}	t3�|��}t5�	|��}t%|t ��rt7j�g|�R�}nt7j�|��}|�|��n#t<$rd}YnwxYw��	||����|�s'��	����|��t?���}d� d�|D����}��	|�!��|���r�nd}tE�	��}d	D�]�}�}|d
krItG�d��rtG�d��r(tI|���}t'|�|tJ�
��}n8tG�d��rtG�d
��r|dkrt'|�|���}tM�tN|���%��	�%���|����(tS�%|�����dkr��t|��}|rdntT}tW�dtX���%��	t�%��|�z���%��fd�t	|��D��}t|d��dkrd�|D��}t'|�|����} ��	t?| ��t?�����t?������}!��	|!�%��t?����d���}!��	|!�%��t?����d���}!��	|!�%��tW�d
tX���%��	t�%��|�z���%��fd�t	|��D��}t|d��dkrd�|D��}t'|�|tJz����} ��	t?| ��t?�����t?����d
���}!��	|!�%��tW�dtX���%��	t�%��|�z���%��fd�t	|��D��}t|d��dkrd�|D��}tG�d
��rtJnd}"t'|�|"|z����} ��	t?| ��t?�����t?����d���}!��	|!�%�����t)���r�	t?���}n#t<$rYdSwxYwt%�t>��r�jn��&|f�&�'���	�����
��(fd�	}#|#|��|�-��5}$|#|$d���ddd��n#1swxYwY|���dSdS)Nr�rr,c��g|]}d��S)r�r�r�s  r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>s��(C�(C�(C���(C�(C�(Cr_Tr@c3� K�|]	}d|zV��
dS)z%02xNr�r�s  r>r�z,TestBufferProtocol.verify.<locals>.<genexpr>Us&����2�2�1�F�Q�J�2�2�2�2�2�2r_r�r��F�Arzr{r��r�r%r&�r�r%c�B��g|]}tj��|�z����Sr��r8�unpack_from�r�r�contigr;r�s  ���r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>��<���6�6�6�#$� &�1�#�v�q��z�J�J�6�6�6r_c��g|]
}|d��S�rr�r�s  r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>����"9�"9�"9�A�1�Q�4�"9�"9�"9r_�r�r&r%��orderc�B��g|]}tj��|�z����Sr�rr�s  ���r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>�r�r_c��g|]
}|d��Sr�r�r�s  r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>�r�r_c�B��g|]}tj��|�z����Sr�rr�s  ���r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>�r�r_c��g|]
}|d��Sr�r�r�s  r>r�z-TestBufferProtocol.verify.<locals>.<listcomp>�r�r_c�d����|j�����|j�����|j�����|j�����|j|����|j�	����|jt������
r�s(��|j
t�������|jt������	dkrdnt���}��t|��|���r�
�
��n�
���}��|�����|�
��dS)Nrr,)�assertIsr\�assertEqualr6r�r%�readonlyr�r�rer�rerdrar8)rH�expected_readonlyr�rep�ex�expected_lenr;r�rjr��resultrrr�rtr�res    ������������r>�check_memoryviewz3TestBufferProtocol.verify.<locals>.check_memoryview�s�����
�
�a�e�R�(�(�(�� � ���<�8�8�8�� � ���X�6�6�6�� � ���3�/�/�/�� � ���->�?�?�?�� � ����.�.�.�� � ���%��,�,�7�7�7��@�:�@��$�$�Q�Y��g���?�?�?�� � ���u�Z�/@�/@�A�A�A�����A�A��C����� � ��Q����+�+�+�),�B�f�m�m�o�o�o�&�.�.�2B�2B��� � ��c�*�*�*�� � ��F�+�+�+�+�+r_)r�).r�rdre�
assertGreaterrirpr�r�r\r�r6r�r%r�r�r�rer�r�r
r�rar8r,r��get_pointerr�r8r9�extend�BufferErrorrQ�join�hexr��
is_contiguousr��
ND_FORTRAN�get_contiguous�
PyBUF_READ�
assertTrue�
cmp_contigr'�py_buffer_to_contiguous�
PyBUF_FULL_RO�
toreadonly))rrr�r\r�r;r�r�r�r�rjrtru�
suboffset0r�stride0r�r�buf_errr��item1�item2r]rHr�ff�	flattenedr��expected�transru�ro�initlst�y�contig_bytesrr��mmr�r�r�res)`` `` `````                          @@@@r>�verifyzTestBufferProtocol.verifys
���������������
�	(���;�;�x�/�L�L��
(�"�3�x�x���'���
���	4����t�Q�'�'�'��J��1�d�^�^�
=�
=����8�q�=�=��E��1�:��?�?��7�1�:�+��q��!��"<�<�J��$��(C�(C�U�4��6�]�]�(C�(C�(C�C�J��(�G��q�z�A�~�~�"�(���i�$�w�q�r�r�{�"3�"3�3�G��
�
�f�j�#�&�&�&�������5�5�5������(�3�3�3�������,�,�,��
�
�f�o�x�0�0�0������d�+�+�+������u�U�|�|�4�4�4��	=�:�	=����V�^�U�7�^�^�<�<�<�����*�E�*�,=�,=�>�>�>��f�g�&�&�	'�*>�s�*C�*C�	'�%(�>�&�-�-�/�/�/�f�n�n�.>�.>�C����S�#�&�&�&��	��F��o	;����A��G��u�~�~�
/�
/��
�'���4�4�E�$�S�#�.�.�E�!�%��/�/�4�"�K��4�e�4�4�4���"�K��U�3�3���H�H�Q�K�K�K�K��"����"�G��E�E������ � ���.�.�.�.��^
;�� � ����!1�!1�1�5�5�5��v�&�&���G�G�2�2��2�2�2�2�2��� � ������!�,�,�,� �(�S�S�S��#�C�L�L�	�
-�M;�M;�E�%�H���|�|�,�V�S�9�9�A�(���5�5�A�%.�i��$?�$?�E�'.�u�E�"�5?�(A�(A�(A�H�� -�V�S�9�9�R�(���5�5�R�:?�3�,�,�'.�y��b�'Q�'Q�'Q�H�+�F�J��F�F�F��$�$�V�^�^�%5�%5�q�9�9�9��O�O�J�v�x�$@�$@�A�A�A��q�y�y� ��	�N�N�E�&�7���K�B�5�V�S�-�P�P�F��$�$�S��[�[�%�(�2B�C�C�C�6�6�6�6�6�6�(-�e���6�6�6�G��7�1�:���!�+�+�"9�"9��"9�"9�"9����u�B�s�K�K�K�A��$�$�Z��]�]�J�v�4F�4F�G�G�G�#-�f�#5�#5�#=�#=�#?�#?�L��$�$�\�6�:�:�:�#-�f�#5�#5�#=�#=�D�#=�#I�#I�L��$�$�\�6�:�:�:�#-�f�#5�#5�#=�#=�C�#=�#H�#H�L��$�$�\�6�:�:�:�5�V�S�-�P�P�F��$�$�S��[�[�%�(�2B�C�C�C�6�6�6�6�6�6�(-�e���6�6�6�G��7�1�:���!�+�+�"9�"9��"9�"9�"9����u�B�z�M�'*�,�,�,�A��$�$�Z��]�]�J�v�4F�4F�G�G�G�#-�f�#5�#5�#=�#=�C�#=�#H�#H�L��$�$�\�6�:�:�:�5�V�S�-�P�P�F��$�$�S��[�[�%�(�2B�C�C�C�6�6�6�6�6�6�(-�e���6�6�6�G��7�1�:���!�+�+�"9�"9��"9�"9�"9��&3�F�C�&@�&@�G�
�
�a�A���u�A�b�D��M�M�M�A��$�$�Z��]�]�J�v�4F�4F�G�G�G�#-�f�#5�#5�#=�#=�C�#=�#H�#H�L��$�$�\�6�:�:�:�:���$�$�	�
��v�&�&�����
�
�
����
����)�&�*�=�=�I����6�B�6>�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�&
��Q���������
=�2� � ��t�<�<�<�<�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=�
=����
=�
=�
=�
=�
�I�I�K�K�K�K�K�;	�	s7�A2L�L�L�0b�
b�
b� c:�:c>�c>c�$�d�}|jr||t��s�||t��r|jr�||t��r|jrj||t��r|jrR||t��s|j	s:||t��s|jr"||t��s6||t��r%|�
tt||���dSt!|t��st#|j��r|���}n*t|t(���}|���}||t��rdn|j}|j}	|j}
|j}||t��sd}	|���}||t��sd}||t��r|jnd}||t��r|jnd}
t||���}|�|||
|	||||
||��
�
dS)Nc��||z|kSr�r�)�req�flags  r>�matchz/TestBufferProtocol.verify_getbuf.<locals>.match�s����X�$�&�'r_��getbufFr@r,r�)	r\r�r;r�r�r�r�rjrt)r��PyBUF_WRITABLE�PyBUF_C_CONTIGUOUS�c_contiguous�PyBUF_F_CONTIGUOUS�f_contiguous�PyBUF_ANY_CONTIGUOUS�
contiguous�PyBUF_INDIRECTre�
PyBUF_STRIDES�PyBUF_ND�PyBUF_FORMAT�assertRaisesr�r
r�r�r%rar�r�r�r8r�r�r�)rr�orig_exr�r�rtr�rjrir�r;r�r�r�r�s              r>�
verify_getbufz TestBufferProtocol.verify_getbuf�s|��	(�	(�	(��[�	�"�U�3��7�7�	��U�3�*�
+�
+�	�57�O�	��U�3�*�
+�
+�		�57�O�		�
�U�3�,�
-�
-�	�
79�m�	���s�N�+�+�	�13�
�	���s�M�*�*�	�46�?�	���s�H�%�%�	�+0�%��\�*B�*B�	�
���k�7�B�s��C�C�C��F��b�'�"�"�	�&:�2�9�&E�&E�	��)�)�+�+�C�C���M�2�2�2�B��)�)�+�+�C��e�C��0�0�
A�U�U�b�k���i���;���w���u�S�,�'�'�	$��C��/�/�#�#�C��u�S�(�#�#�	��D�!&��s�H�!5�!5�=��
�
�2��%*�U�3�
�%>�%>�F�'�/�/�B��
�R��
$�
$�
$�����B�B�%�3���U�G��F�	�	,�	,�	,�	,�	,r_c��	��tttttt
tttttttttf}d�td��D��dfgd�dfgd�dfd�td��D��dff}ggd	fgd
�gd	fdggd	fdgdgdfd
gdgd	fd
gdgdfddggd	fddgddgdfddgddgdfddgddgdff
}d	t t"t"t zt$t$t zf}d	t&t(t&t(zf}|D�]x\}}t+j|���|D�]Z\}}	}
�fd�|	D��}	|
�z}
|D�]<}|	r|t"zr�|s|t$zr�|r|n|d	}t/|||||	|
���}
|r|
ddd�nd}t1|
��}|rt1|��}|
jd	ks|
jdkr|r|	r|�||
��|r%|jdkr|r|	r|�||��|D]u}|D]p}|�|
|
||z��|�|
|||z��|r8|�||||zd���|�||||zd����q�v��>��\��zgd�}t/|dgt8���}|�t<t.|��t/dgdg��}t/|t���}|�t<t.|t&���|�t<t.|t���|�t<t.|t���|�t<t.|t���|�t<t.|t
���|�t<t.|t���t/|t���}gd�gd�fD]�}d	t"fD]�}t/|||t z���}|�tA|d����|�tA|d����|D]Y}t/||���}|�tA|d����|�tA|d�����Z����dS) Nc� �g|]}|dzrdnd��S)r!TFr��r�r]s  r>r�z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>s%��
:�
:�
:�1�a�!�e�&�d�d��
:�
:�
:r_�r�r,r!rkr>r�r?r7r6�	rn�r�rrc�,�g|]}|dzrd|z
nd|z��S)r!r'r&r�r�s  r>r�z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>s-��
D�
D�
D�Q�1�q�5�0�u�Q�w�w�v�a�x�
D�
D�
Dr_rr)r,rkr,r�r�r?r!���rkr>���r,r6c���g|]}|�z��Sr�r�r�s  �r>r�z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>)s���9�9�9�A�1�x�<�9�9�9r_)r%r&r�r�r�T)rt�r�r&r�r�)r,r�r,)r7rr7rzr�)!r�r�r��PyBUF_SIMPLEr�r�r��
PyBUF_FULLr��
PyBUF_RECORDS�PyBUF_RECORDS_RO�
PyBUF_STRIDED�PyBUF_STRIDED_RO�PyBUF_CONTIG�PyBUF_CONTIG_ROrir'r��ND_PILr�r�r8�calcsizer
rQr�r�r��ND_GETBUF_FAILr�r�r�r�)rr�requests�	items_fmt�	structure�ndflags�
real_flagsrxr;r�r�r�r&�_items�ex1�ex2�m1�m2r��bitsr��baserir�r�s                       @r>�test_ndarray_getbufz&TestBufferProtocol.test_ndarray_getbuf�s����
�M�8�\�� 2�4H��
��+��+��/�	
��;�
:��b�	�	�
:�
:�
:�C�@�
)�
)�
)�3�/�
)�
)�
)�3�/�
D�
D�%��)�)�
D�
D�
D�c�J�	
�	���Q�K�
�W�W�b�!���T�2�q�M��T�B�4����S�1�#�q�M��S�2�$��O���V�R��O���V�b�"�X�r�"���V�a��V�Q����V�b�"�X�q�!�
�	�
�{�J�
�;�(>��F�;�&�
��
���$�\�1�3�
�$�!	@�!	@�J�E�3���s�+�+�H�*3�
@�
@�&��w��9�9�9�9��9�9�9���(�"��$�@�@�E��!�E�*�$4�!� � �!�e�F�l�!� �&+�9�U�U��q��F�!�&��E�(-�w�v�O�O�O�C�',�6�#�d�d��d�)�)�$�C�#�C���B��-�'��_�_���x�1�}�}���Q���5��W���(�(��S�1�1�1��2�s�x�1�}�}��}�7�}��(�(��S�1�1�1�'�@�@��$.�@�@�D� �.�.�s�C��T��B�B�B� �.�.�s�B��D��A�A�A�"�@� $� 2� 2�3��S��X�:>�!3�!@�!@�!@� $� 2� 2�3��C��H�:>�!3�!@�!@�!@��
@�@�)@�
@�B-�,�,���U�2�$�n�
=�
=�
=�����+�w��3�3�3���s�Q�C� � ��
�T�,�
/�
/�
/�����+�w��>��J�J�J����+�w��8��D�D�D����+�w��=��I�I�I����+�w��;M��N�N�N����+�w��;M��N�N�N����+�w��;O��P�P�P�
�R��
-�
-�
-���X�X�w�w�w�&�		<�		<�E��J��
<�
<���U�%�u�[�7H�I�I�I�����
�b�#� 6� 6�7�7�7����
�b�#� 6� 6�7�7�7�%�<�<�E� ��E�2�2�2�B��O�O�M�"�c�$:�$:�;�;�;��O�O�M�"�c�$:�$:�;�;�;�;�<�
<�		<�		<r_c	��tdgdg��}tdgdgt���}t|j|jfD�]�}|�t|hd���|�t|gd���|�t|gd���|�t|gd�dh�	��|�t|gd�dgdh�
��|�t|gd�dgg���|�t|dgdgi���|�t|dgdgi�
��|�t|dgdgi���|�t|dgdgdgt
���|�t|dggt�
��|�t|gdg�	��|�t|dgdgd���|�tj	|dgdgd���|�t|ddgdgd���|�t|gd�dgd���tdz}|�t|dg|zdg|z�	��|�t|dgdg�	��|�t|gd�dg�	��|�t|dgddzg�	��|�t|gd�ddgd���|�t|gd�dgdg�
��|�t|dgdgddzg�
��|�t|ddgddgdg�
��|�t|gd�dgdgd���|�t|gd�dgd���|�t|gd�dgdd���|�t|gd�dgd ���|�tj	|dgdgd!���gd"�}|�t||ddgd#d$gd%�&��|�t|t��d'�(��|�t|dgdgt���|�t|dg�����|�ttd)t�*��tdgdgt���}|�t|jdgdgt���td)��}|�t|jdgdg��|�t|j��tdgdg��}|�dgdg��t#|��}|�t|jdgdg��|�t|j��|���|���|�t|j��~|�tt&igd���|�tt&d)i��tt)t+d+����dgd+z�	��}|�tt&|d%g��tt)t+d,����ddg�	��}|�tt&|gd-���|�tt&|ddg��|�tt&|d#dg��|�tt&|d.dg��tgd�dgd���}t|t,�*��}|�t|j��tgd�dgd���}t|��}	t|	��}|�t|j��td/gdgd0���}|�t|j��t}tt)t+|����dg|z�	��}|�t|j��tdgdg�	��}|�tt2ddddd%��|�tt2|d1d2��|�tt2|d.d2��|�tt2|t4d3��|�t6t2|t4d4��|�tt2|t4d5��|�tt2|d6d7��tdgdg�	��}|�tt8ddddd%��|�tt8i|��|�tt8|i��tdgdg�	��}|�tt:ddddd%��|�tt:id7��|�tt:|d8��dS)9Nr�r,�r&>r,r!rk)r,r!rN)r,r!�rkr>�r,r!rkrk�r��r�r��r�r�r}r�)r�r��r�r�r&�XXXri�r�r!rkr!�QLr�rNr$�r,r!rkr>r�rL�r,r!rkr>�r�r�r%r>)r�r�r%r@z@#$)
r,r!rkr>r�r?r7r6r�rn���r�r�)r�r�r�r�r%�123r�r�r�)r!rkr>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,��LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL�xyzr��u �Z�r{��)r
�ND_VAREXPORT�pushr�rbr�r�r�r8r:�ND_MAX_NDIM�
OverflowErrorr,r�r�r��poprQ�releaser�r�rir�ra�memoryview_from_bufferr�r��UnicodeEncodeErrorr�r�)
rrri�ndmrrrxrHr�r�r�s
          r>�test_ndarray_exceptionsz*TestBufferProtocol.test_ndarray_exceptionsgsy
��
�a�S�1�#�
�
���q�c�A�3�l�3�3�3���2�7�C�H�-�G	1�G	1�A����i��G�G�G�4�4�4����i��I�I�I�6�6�6����i��K�K�K�8�8�8����i��G�G�G�A�3��?�?�?����i��G�G�G�A�3����L�L�L����i��G�G�G�A�3�r��J�J�J����i��Q�C��s�2��F�F�F����i��Q�C��s�"��E�E�E����i��Q�C��s�2��F�F�F�
���i��Q�C��s�Q�C�$.�
�
0�
0�
0�
���i��Q�C�r���H�H�H�
���j�!�R��s��;�;�;����j�!�e�W�Q�C���L�L�L����f�l�A��v�a�S���M�M�M����j�!�a��Y�q�c�#��N�N�N����j�!�W�W�W�Q�C���M�M�M��A�
�A����j�!�a�S��U�1�#�a�%��@�@�@�
���j�!�a�S����=�=�=����j�!�W�W�W�S�E��B�B�B����m�Q���A�s�F�8��D�D�D����j�!�[�[�[��1��a��P�P�P�
���j�!�W�W�W�Q�C�#���O�O�O����m�Q���A�3�'(�#�v�h�
�
0�
0�
0�
���j�!�a��U�1�Q�%�!���M�M�M����j�!�Y�Y�Y�q�c�A�3�%(�
�
*�
*�
*�
���j�!�W�W�W�Q�C���J�J�J����j�!�W�W�W�Q�C��%(�
�
*�
*�
*�
���j�!�W�W�W�Q�C���K�K�K����f�l�A��y���%*�
�
,�
,�
,�+�*�*�E����j�!�U�1�Q�%�')�2�h�q�
�
:�
:�
:�
���i��I�K�K���D�D�D�
���i��Q�C��s�:��N�N�N�
���i��Q�C�0�0�0�0�	
���+�w��~��N�N�N��a�S�1�#�\�
2�
2�
2�����*�b�g��s�Q�C�|��L�L�L��V�_�_�����+�r�w���a�S�9�9�9����+�r�v�.�.�.��a�S�1�#�
�
��
�����a�S�����r�N�N�����+�r�w���a�S�9�9�9����+�r�v�.�.�.�	�	�	����
������	
���+�r�v�.�.�.��	
���)�[�"�g�g�g�>�>�>����)�[�&�"�=�=�=�
�T�%��*�*�%�%�a�S��W�
5�
5�
5�����*�k�2��s�;�;�;�
�T�%��)�)�_�_�Q�q�E�
2�
2�
2�����*�k�2�w�w�w�?�?�?����*�k�2��!�u�=�=�=����*�k�2��1�v�>�>�>����-��b�5��)�D�D�D��W�W�W�Q�C��
4�
4�
4��
�R��
-�
-�
-�����*�b�i�0�0�0��g�g�g�a�S��5�5�5���c�l�l��
�S�\�\�����)�R�%>�?�?�?�
�h�Z��s�7�
;�
;�
;�����)�R�%>�?�?�?���
�T�%��(�(�^�^�A�3�q�5�
1�
1�
1�����*�b�&?�@�@�@��a�S���
$�
$�
$�����)�^�Q��1�a��C�C�C����)�^�R���D�D�D����-���U�C�H�H�H����)�^�R��S�I�I�I����,�n�b�*�"�	$�	$�	$����*�n�b�*�c�J�J�J����*�n�b�#�s�C�C�C��a�S���
$�
$�
$�����)�Z��A�q�!�Q�?�?�?����)�Z��R�8�8�8����)�Z��R�8�8�8��a�S���
$�
$�
$�����)�]�A�q�!�Q��B�B�B����)�]�B��<�<�<����)�]�B��<�<�<�<�<r_c���ttd����D]�}dgdz}tgd�dgt���}t	|��|d<tdd��D].}|�gd�dg���t	|��||<�/td��D]"}|||����#|�t|j	��~��dS)Nr�rr�rkr�r,r�)
rrir
rrQrrr�r�r
)rr�permrHrirs     r>�test_ndarray_linked_listz+TestBufferProtocol.test_ndarray_linked_lists��� ��q���*�*�
	�
	�D���A��A�������<�@�@�@�B��b�>�>�A�a�D��1�a�[�[�
&�
&���������s��+�+�+�!�"�~�~��!����1�X�X�
%�
%���$�q�'�
�"�"�$�$�$�$����k�2�6�2�2�2���
	�
	r_c��td��D]J\}}}tj|��}t|d|���}|�|d||dddd|��	�	�KdS)Nrr�r}T�r\r�r;r�r�r�r�rj)r�r8r�r
r�)rrr;�scalarrvr�ris      r>�test_ndarray_format_scalarz-TestBufferProtocol.test_ndarray_format_scalars��)�!�n�n�	$�	$�N�C�����s�+�+�H���r�#�6�6�6�B��K�K���!)�s�T��b�"�"�
�
$�
$�
$�
$�	$�	$r_c
��tdd��}t|��D]Z\}}}tj|��}dtfD]6}t||g||���}|�|d||dd|f|f|��	�	�7�[dS)Nr,rnrr|Tr)rr�r8r�r�r
r�)rrr�r;rxrvr�r&ris        r>�test_ndarray_format_shapez,TestBufferProtocol.test_ndarray_format_shapes����A�r�"�"��(��0�0�	'�	'�M�C�����s�+�+�H��V��
'�
'���U�6�(�3�e�L�L�L�����B�D�%-�3��!"�6�)�h�[� %��'�'�'�'�
'�	'�	'r_c��tdd��}t|��D]�\}}}tj|��}t	dd��D]�}|dkr�	t|dd|���g}||zg}|dkr||dz
znd}	dtfD]>}
t|||||	|
���}|�|d||dd|||dd|���	�	�?����dS)	Nr,����r�rr$Tr)	rr�r8r�rirdr�r
r�)rrr�r;rxrvr�rr�r�r�r&ris            r>�test_ndarray_format_stridesz.TestBufferProtocol.test_ndarray_format_strides+s*���1�b�!�!��(��0�0�	3�	3�M�C�����s�+�+�H��b�!���
3�
3���1�9�9���U�6�6�T�6�]�+�+�,����=�/��04�q����6�!�8�,�,�a����[�3�3�E� ��e�W�(+�F�%�I�I�I�B��K�K���)1�s�T�%&�e�W�$)�&�&�D�&�M� �3�3�3�3�3�
3�	3�	3r_c���gd�}t|dd���}t|ttz���}|�|���t|d����dS)Nr�r�)r,rkr�r�)r
r�r�r�rar�)rrrxr�ris    r>�test_ndarray_fortranz'TestBufferProtocol.test_ndarray_fortran@sg��,�,�,��
�U�&�&�
9�
9�
9��
�R� 2�<� ?�
@�
@�
@����������f�U�F�&;�&;�<�<�<�<�<r_c��td��D�]�}d�t|��D��}t|��}t|��D�]�}t|��\}}}t	j|��}dtfD�]R}	|dkr|	tkr�t||||	���}
t|||d��}t||��}|�
|
d||d||||��	�	t|��r�t|||���}
t|
ttz�	��}
|�|
jd
k��|
���}|�
|d||d||||��	�	t||||	t"z���}
t|||d��}t%||��}|�
|
d||d||||��	�	��T������dS)Nr�c�.�g|]}tdd����S)r!rnrBrWs  r>r�z<TestBufferProtocol.test_ndarray_multidim.<locals>.<listcomp>Hs"��=�=�=�A�y��B�'�'�=�=�=r_rr|r�Trr}r�r�rz)rir�rr|r8r�r�r
r�r�r�r�r�r�r�r�rr�r�)rrr��shape_tr�r�r;rxrvr�r&rir�rjr��mvs               r>�test_ndarray_multidimz(TestBufferProtocol.test_ndarray_multidimFs-���!�H�H�*	)�*	)�D�=�=��t���=�=�=�G��'�]�]�F�%�g�.�.�'
)�'
)�� )�&� 1� 1�
��U�A�!�?�3�/�/����[�")�")�E��q�y�y�U�f�_�_� �!��e�C�u�M�M�M�B�0��u�h��L�L�G� ���.�.�C��K�K���)1�s�T�%)���$'� �)�)�)�
,�C�0�0�	-�$�U�%��D�D�D��$�R���0L�M�M�M������
�b�(8�9�9�9��6�6�8�8�����B�D�-5�3��)-�U�G�(+�$�-�-�-�!��e�C�',�Z�'7�9�9�9�B�1��u�h��L�L�G� ���.�.�C��K�K���)1�s�T�%)���$'� �)�)�)�)�?")�'
)�*	)�*	)r_c�$�tdgdg���}|�t|jdd��t	|��}|�||��|�t|jdd��tdgdgt���}|�t|jd��t	|��}|�||��|�t|jd��tdgdgt���}|�t|j	d��|�t|jdd��t	|��}|�||��|�t|j	d��|�t|jdd��gd�}t|t|��gdt���}|�tj
|jd	d
��|�t|jdd��t	|��}|�||��|�t|jd	d
��|�t|jdd��gd�}t|t|��gd
t���}|�t|jd	d
��|�tj
|jdd��dS)Nr,r�r6r�r+�r,r!rkr>r�r?r7r6rr|r!i,)r���)�r,r!r�)r�r?�LQ)s1r&)r
r�rb�__setitem__rQr�r'�__delitem__r	�__getitem__�
IndexErrorrdr8r:r�)rrrir"rxs    r>�test_ndarray_index_invalidz-TestBufferProtocol.test_ndarray_index_invalidss���
�a�S���
$�
$�
$�����)�R�^�Q��:�:�:�
��^�^������R� � � ����)�R�^�Q��:�:�:��a�S���;�
7�
7�
7�����)�R�^�Q�7�7�7�
��^�^������R� � � ����)�R�^�Q�7�7�7��a�S���;�
7�
7�
7�����-����?�?�?����-�����B�B�B�
��^�^������R� � � ����*�b�n�e�<�<�<����*�b�n�e�Q�?�?�?�"�!�!��
�U�3�u�:�:�,�s�+�
N�
N�
N�����&�,����3�?�?�?����*�b�n�a��D�D�D�
��^�^������R� � � ����*�b�n�a��=�=�=����)�R�^�Q�
�C�C�C�%�%�%��
�U�3�u�:�:�,�t�;�
O�
O�
O�����*�b�n�a��=�=�=����&�,����?�K�K�K�K�Kr_c��tddt���}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�r�.rr6r�r�)	r
r'rQr�rar�rbr+r))rrrir"r]s    r>�test_ndarray_index_scalarz,TestBufferProtocol.test_ndarray_index_scalar�s��
�Q�b��
4�
4�
4��
��^�^������R� � � ��r�F��T�%�%�a��+�+�+��s�G��T�%�%�a�h�h�j�j�"�)�)�+�+�>�>�>��r�F��T�%�%�a��+�+�+��s�G��T�%�%�a�h�h�j�j�"�)�)�+�+�>�>�>����)�R�^�Q�7�7�7����)�R�^�Q�7�7�7����)�R�^�Q��:�:�:����)�R�^�Q��:�:�:���������a�(�(�(���������a�(�(�(���2��D�$�$�R�Y�Y�[�[�!�4�4�4���2��D�$�$�R�Y�Y�[�[�!�4�4�4���3��T�%�%�b�i�i�k�k�1�5�5�5���3��T�%�%�b�i�i�k�k�1�5�5�5�5�5r_c	�:�tttd����ddgt���}t|t���}|�t|jd��|�t|jtddd����dS)	Nr6r!r>r�r�r,rkr�)	r
r�rir'r�r�r�r+r)rrr�ris   r>�test_ndarray_index_null_stridesz2TestBufferProtocol.test_ndarray_index_null_strides�s���
�T�%��*�*�%�%�a��V�;�
G�
G�
G��
�R��
-�
-�
-��	
���+�r�~�q�9�9�9����+�r�~�u�Q�q��|�|�D�D�D�D�Dr_c�4�td��D�]<\}}}t|dg|���}tdd��D]$}|�||||���%|�t
|jd��|�t
|jd��t|��r�t|��}|�||��tdd��D]$}|�||||���%|�t
|jd��|�t
|jd����>td��D]�\}}}t|dgt|���}t|ttz���}tdd��D]$}|�||||���%t|��rw|���}|�
|�|��t��tdd��D]$}|�||||���%��gd�}t|dg���}t|t ���}tdd��D]$}|�||||���%gd�}t|dg���}t|t"���}tdd��D]$}|�||||���%dS)	Nr�r}r���r�r�r�r�)r�r
rir�r�r,r+r�rQr'r�r�rr��__eq__�NotImplementedr�r�)rrr;rxrvrirr"r�s        r>�!test_ndarray_index_getitem_singlez4TestBufferProtocol.test_ndarray_index_getitem_single�s��(��^�^�	A�	A�M�C�����q�c�#�6�6�6�B��2�q�\�\�
2�
2��� � ��A���a��1�1�1�1����j�"�.�"�=�=�=����j�"�.�!�<�<�<�#�C�(�(�
A���^�^��� � ��R�(�(�(��r�1���6�6�A��$�$�R��U�E�!�H�5�5�5�5��!�!�*�b�n�b�A�A�A��!�!�*�b�n�a�@�@�@��)��^�^�	6�	6�M�C�����q�c��S�I�I�I�B���L��$=�>�>�>�B��2�q�\�\�
2�
2��� � ��A���a��1�1�1�1�#�C�(�(�
6��.�.�0�0���
�
�b�i�i��m�m�^�<�<�<��r�1���6�6�A��$�$�R��U�E�!�H�5�5�5�5������
�U�1�#�
&�
&�
&��
�R��
0�
0�
0���r�1���	.�	.�A����R��U�E�!�H�-�-�-�-�����
�U�1�#�
&�
&�
&��
�R��
-�
-�
-���r�1���	.�	.�A����R��U�E�!�H�-�-�-�-�	.�	.r_c�~�td��D�]~\}}}t|dg|t���}td��D]}|||<|||<�
|�|���|��|�t|jd|��|�t|jd|��t|��s��t|dg|t���}t|��}|�||��td��D]}|||<|||<�
|�|���|��|�t|jd|��|�t|jd|�����td��D�]\}}}t|dg|t���}tdd��D]}||dz||<||dz||<�|�|���|��t|��s��t|dg|t���}t|��}|�||��tdd��D]}||dz||<||dz||<�|�|���|����dS)Nr�r|r3rr>r,)r�r
r'rir�rar�r,r)r�rQ)rrr;rx�single_itemrirr"s       r>�!test_ndarray_index_setitem_singlez4TestBufferProtocol.test_ndarray_index_setitem_single�s���'2�1�~�~�	J�	J�#�C�����q�c�#�[�I�I�I�B��1�X�X�
$�
$��&��a��#��1������R�Y�Y�[�[�%�0�0�0����j�"�.�"�k�J�J�J����j�"�.�!�[�I�I�I�'��,�,�
����q�c�#�[�I�I�I�B��B���B����R��$�$�$��1�X�X�
$�
$��&��a��#��1������R�Y�Y�[�[�%�0�0�0����j�"�.�"�k�J�J�J����j�"�.�!�[�I�I�I�I�(3�1�~�~�	1�	1�#�C�����q�c�#�[�I�I�I�B��2�q�\�\�
 �
 �� ��1��:��a���1�Q�3���1������R�Y�Y�[�[�%�0�0�0�'��,�,�
����q�c�#�[�I�I�I�B��B���B����R��$�$�$��2�q�\�\�
 �
 �� ��1��:��a���1�Q�3���1������R�Y�Y�[�[�%�0�0�0�0�!	1�	1r_c
�d�d}t|��}t|��D�]�}t|��\}}}dtfD�]l}t	||||���}t||��}	t
|d|d��D]�}
|�|	|
||
�����t
|d|d��D]�}|�|	|
|||
|�����t
|d|d��D]<}|�|	|
||||
||���=����t	||||tz���}t||��}	t
|d|d��D]�}
|�|	|
||
�����t
|d|d��D]�}|�|	|
|||
|�����t
|d|d��D]<}|�|	|
||||
||���=�����n���dS)N�r!rkr�rr|r,r!)r�rr|r�r
r�rir�rar�r�)
rrr!r�r�r;rxrvr&rirjrr��ks
             r>�#test_ndarray_index_getitem_multidimz6TestBufferProtocol.test_ndarray_index_getitem_multidims������g����!�'�*�*�	H�	H�E�%�f�-�-�M�C����V��
H�
H���U�%��5�I�I�I���U�E�*�*����a��y�%��(�3�3�H�H�A��$�$�S��V�R��U�\�\�^�^�<�<�<�"�E�!�H�9�e�A�h�7�7�H�H���(�(��Q����B�q�E�!�H�O�O�4E�4E�F�F�F�!&��a��y�%��(�!;�!;�H�H�A� �,�,�S��V�A�Y�q�\�2�a�5��8�A�;�G�G�G�G�H�H��U�%��#(��#3�5�5�5���U�E�*�*����a��y�%��(�3�3�H�H�A��$�$�S��V�R��U�\�\�^�^�<�<�<�"�E�!�H�9�e�A�h�7�7�H�H���(�(��Q����B�q�E�!�H�O�O�4E�4E�F�F�F�!&�u�Q�x��q��!:�!:�H�H�A� �,�,�S��V�A�Y�q�\�2�a�5��8�A�;�G�G�G�G�H�H�H�#
H�		H�	Hr_c���tdd���}|�ttdt	����t|��}|�||��|�ttdt	����td��D]�\}}}t|dg|���}t|��D]8\}}|�|||��|�	||v���9t|��rWt|��}t|��D]8\}}|�|||��|�	||v���9��dS)Nr,r�r�z1 in ndz1 in mvr�r})r
r�rb�eval�localsrQr�r�r-r�r�)rrrir"r;rxrvrr�s        r>�test_ndarray_sequencez(TestBufferProtocol.test_ndarray_sequence:s`��
�Q�b�
!�
!�
!�����)�T�9�f�h�h�?�?�?�
��^�^������R� � � ����)�T�9�f�h�h�?�?�?�(��^�^�
	-�
	-�M�C�����q�c�#�6�6�6�B�!�"�
�
�
)�
)���1�� � ��E�!�H�-�-�-�����R��(�(�(�(�#�C�(�(�
-���^�^��%�b�M�M�-�-�D�A�q��$�$�Q��a��1�1�1��O�O�A��G�,�,�,�,��
	-�
	-r_c
�l�gd�}t|dgt���}t|��}|�t|jt
ddd��|��|�t|jt
ddd��|��t|dgt���}t|dgt���}t|t���}|�t|jt
ddd��|��t|dgdt���}t|��}|�t|j
t
ddd����|�t|j
t
ddd����t|d	d
gdt���}t|��}|�t|j
t
ddd��t
ddd��f��|�t|j
t
ddd��t
ddd��f��|�t|j
d��|�t|j
dt
ddd��f��|�t|j
t
ddd��if��|�t|j
t
ddd��t
ddd��f��|�t|j
d��t|dgdt���}t|dgd
���}t|��}t|��}|�t|jt
ddd��|dd���|�|�
��|��|�t|jt
ddd��|dd���|�|�
��|��t|dgdt���}t|dgd���}	t|��}t|��}|�t|jt
ddd��|dd���|�|�
��|��|�t|jt
ddd��|dd���|�|�
��|��t|d	d
gd
t���}t|dgd
���}t|��}t|��}|�t|jt
ddd��|dd���|�|�
��gd�gd�g��|�t|jt
ddd��|dd���t|dgd
t���}t|dgd
���}t|��}t|��}|�t|jt
dd	d��|dd���|�|�
��|��|�t|jt
dd	d��|dd���|�|�
��|��|�ttt
ddd	��i��|�ttdd��|�ttt
ddd��d
��t|dgd
t���}
|�t|
j��t|dgd���}t|t"���}
|�t|
j��dS)Nr%r6r�rr,r�rr|r!r>z@%$rrr}r7r�)r�r?r7r6z###########)r
r'rQr�rbr)rr�r�r�r+rcr�rar
r��add_suboffsetsr�)rrrx�xl�mlr��xrrir"�mr�yrr]s           r>�test_ndarray_slice_invalidz-TestBufferProtocol.test_ndarray_slice_invalidMs���!�!�!���U�1�#�[�
9�
9�
9��
��^�^�����)�R�^�U�1�Q�q�\�\�5�I�I�I����)�R�^�U�1�Q�q�\�\�5�I�I�I��U�1�#�[�
9�
9�
9��
�U�1�#�[�
9�
9�
9��
�R��
)�
)�
)�����+�r�~�u�Q�q��|�|�R�H�H�H��U�1�#�c��
E�
E�
E��
��^�^�����*�b�n�e�A�a��l�l�C�C�C����*�b�n�e�A�a��l�l�C�C�C�
�U�1�Q�%��;�
G�
G�
G��
��^�^�����*�b�n� ��1�Q�<�<��q��1���6�	8�	8�	8����*�b�n� ��1�Q�<�<��q��1���6�	8�	8�	8����)�R�^�U�;�;�;����)�R�^�e�U�1�Q�q�\�\�5J�K�K�K����)�R�^�e�A�a��l�l�B�5G�H�H�H�	
���-�r�~� ��1�Q�<�<��q��1���6�	8�	8�	8����)�R�^�U�;�;�;��U�1�#�c��
E�
E�
E��
�U�1�#�c�
2�
2�
2��
��^�^��
��^�^�����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������e�,�,�,����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������e�,�,�,��U�1�#�c��
E�
E�
E��
�U�1�#�c�
2�
2�
2��
��^�^��
��^�^�����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������e�,�,�,����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������e�,�,�,��U�1�a�&��K�
H�
H�
H��
�U�1�#�c�
2�
2�
2��
��^�^��
��^�^�����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������y�y�y�)�)�)�&<�=�=�=����-�r�~�u�Q�q��|�|��Q�q�S�'�	#�	#�	#��U�1�#�c��
E�
E�
E��
�U�1�#�c�
2�
2�
2��
��^�^��
��^�^�����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������e�,�,�,����*�b�n�e�A�a��l�l�B�q��s�G�L�L�L���������e�,�,�,�	
���)�]�E�!�A�a�L�L�"�E�E�E����)�]�M�1�E�E�E����*�m�U�1�Q�q�\�\�1�E�E�E��E�!��S��?�?�?�����)�Q�%5�6�6�6�
�U�1�#�c�
2�
2�
2���B�|�,�,�,�����)�Q�%5�6�6�6�6�6r_c���gd�}t|dgdt���}t|dgd���}|dd�|dd�<|�|���|��t	|��}t	|��}|�||��|�||��|dd�|dd�<|�|���|��t|ddgdt���}t|ddgd���}|d	d
�dd�f|d	d
�d
d
�f<|�|���t|ddg����dS)Nr�r�rr|r}r�r>rkr,r!)r
r'r�rarQr�)rrrxr]r�rErGs      r>�test_ndarray_slice_zero_shapez0TestBufferProtocol.test_ndarray_slice_zero_shape�sl��,�,�,���E�"��c��E�E�E���E�"��c�2�2�2���1�Q�3���!�A�#����������U�+�+�+�
��]�]��
��]�]������Q��������Q�����Q�q�S�'��1�Q�3����������e�,�,�,��E�!�Q���;�G�G�G���E�!�Q���4�4�4����!��Q�q�S��k��!�A�#�q��s�(����������V�E�A�q�6�%:�%:�;�;�;�;�;r_c�~�d}t|��}t|��}t|��D�]}t|��\}}}t	j|��}dtfD]�}	t||||	���}
t||��}t||��D]�}d}
	t||��}n#t$r}|j}
Yd}~nd}~wwxYwd}	|
|}n#t$r}|j}Yd}~nd}~wwxYw|s|
r|�
||
���y|�|���|�����ؐ�
dS�Nr;rr|)rdr�rr|r8r�r�r
r�rYr��	Exception�	__class__r�r�ra)rrr!r�r�r�r;rxrvr�r&rirjr��listerrrt�e�nderr�ndsliceds                  r>�test_ndarray_slice_multidimz.TestBufferProtocol.test_ndarray_slice_multidim�s������7�|�|���g����!�'�*�*�	D�	D�E�%�f�-�-�M�C�����s�+�+�H��V��
D�
D���U�%��5�I�I�I���U�E�*�*��*�4��7�7�D�D�F�"�G�.�!+�C��!8�!8����$�.�.�.�"#�+�����������.����!�E�,�#%�f�:����$�,�,�,� !������������,�����D��D��
�
�e�W�5�5�5�5��(�(����):�):�F�C�C�C�C�#D�	
D�	D�	Ds0�B.�.
C		�8C	�C		�C�
C3	�"C.	�.C3	c��d}t|��}t|��}t|��D�]G}t|��\}}}t	j|��}t
|||���}	|	���t
|||���}
|
���t|
��}t||��}t||��D]�}
d}	t||
��}n#t$r}|j
}Yd}~nd}~wwxYwd}	|	|
}n#t$r}|j
}Yd}~nd}~wwxYw|s|r|�||���y|�|���|������IdS)N)r!rkr�r!r})rdr�rr|r8r�r
rCrQr�rYr�rNrOr�r�ra)rrr!r�r�r�r;rxrvr�rir�r"rjr�rPrtrQrRrSs                   r>�'test_ndarray_slice_redundant_suboffsetsz:TestBufferProtocol.test_ndarray_slice_redundant_suboffsets�s������7�|�|���g����!�'�*�*�	@�	@�E�%�f�-�-�M�C�����s�+�+�H���e�C�8�8�8�B���������e�C�8�8�8�B��������B���B����&�&�C�&�t�U�3�3�
@�
@����*�'��V�4�4�F�F�� �*�*�*��k�G�G�G�G�G�G�����*������(�!�&�z�H�H�� �(�(�(��K�E�E�E�E�E�E�����(�����@�G�@��M�M�%��1�1�1�1��$�$�X�_�_�%6�%6��?�?�?�?�#
@�	@�	@s0�C+�+
D�5D�D�D�
D0�D+�+D0c���td��D�]e\}}}td��D�]M}td��D�]9}dtfD�]+}|tz}t	|dg||���}t	|dg||���}	t|	��}
d}d}|dd�}
	|
|}|
|}|
||
|<t
|��t
|��k}n#t$r}|j}Yd}~nd}~wwxYwd}	||||<n#t$r}|j}Yd}~nd}~wwxYw|r|�	|t��n>|�|���|
��|�	||��t|��s��Gd}	|
||
|<n#t$r}|j}Yd}~nd}~wwxYw|r|�	|t�����|�|
���|
��|�|
|��|�	||��|�|
|	|j|d|j|j|j|�����	�	��-��;��O��gdS)Nr�rr|Fr)r�rHr�r'r
rQrdrNrOr�r�r�rar�r�r�r�r�r�)rrr;rxrv�lslicerPr&rrir�r"�lsterr�diff_structurerj�lval�rvalrQrR�mverrs                   r>� test_ndarray_slice_assign_singlez3TestBufferProtocol.test_ndarray_slice_assign_single�s���(��^�^�3	/�3	/�M�C���#�A�,�,�2
/�2
/��'��l�l�1/�1/�F�"#�V��0/�0/��!�+�-��$�U�1�#�c��K�K�K��$�U�1�#�c��K�K�K��'��^�^��!%��)-��#�A�A�A�h��1�#&�v�;�D�#&�v�;�D�*-�f�+�C��K�-0��Y�Y�#�d�)�)�-C�N�N��(�1�1�1�%&�[�F�F�F�F�F�F�����1����!%��0�)+�F��B�v�J�J��(�0�0�0�$%�K�E�E�E�E�E�E�����0����*�9� �M�M�%��<�<�<�<� �,�,�R�Y�Y�[�[�#�>�>�>� �M�M�%��8�8�8�3�C�8�8�%�$� $��0�)+�F��B�v�J�J��(�0�0�0�$%�K�E�E�E�E�E�E�����0����*�	/� �M�M�%��<�<�<�<� �,�,�R�Y�Y�[�[�#�>�>�>� �,�,�R��4�4�4� �M�M�%��8�8�8� �K�K���')�{��e�#%�7�"�(�B�J�"$�)�)�+�+�(�/�/�/�/�[0/�1/�2
/�3	/�3	/sH�;C�
C.�C)�)C.�4D�
D�
D�D�F�
F5�$F0�0F5c
��d}t|��}t|��}t|��D�]}t|��\}}}dtfD]�}tt��D]�}t||��\}	}
t||||tz���}t||��}d}
	t|||	|
��}n#t$r}|j
}
Yd}~nd}~wwxYwd}	||
||	<n#t$r}|j
}Yd}~nd}~wwxYw|s|
r|�||
����|�|���|������dSrM)rdr�rr|r�ri�
ITERATIONSrr
r'r�r�rNrOr�r�ra)rrr!r�r�r�r;rxrvr&r�r�rirjrPr�rQrRs                 r>�"test_ndarray_slice_assign_multidimz5TestBufferProtocol.test_ndarray_slice_assign_multidim3s������7�|�|���g����!�'�*�*�	>�	>�E�%�f�-�-�M�C����V��
>�
>���z�*�*�>�>�A�';�D�%�'H�'H�$�G�W� ��e�C�',�[�'8�:�:�:�B� ���.�.�C�"�G�.�!2�3��W�g�!N�!N����$�.�.�.�"#�+�����������.����!�E�,�&(��k��7����$�,�,�,� !������������,�����>��>��
�
�e�W�5�5�5�5��(�(������f�=�=�=�=�->�
>�		>�	>s0�(B;�;
C	�C	�C	�C(�(
D	�2C>	�>D	c��tt��D�]�}tdD�]�}tj|��}t|dtt���}|�t|���t||��}t|||��}|���}t|��}t|��r*|���}	|�|	|��|ddkr�t|||t ���}
|
���}|�||��t|
��}t|��r@|�||
��|���}	|�|	|��t"rc|d}d|vr���t%|||��}
|�|d|
j|d|
j|
j|
j|
����	�	�	�����dS)
NrAT�rrr!rr�rkFr)rir`rVr8r�r
�MAXDIM�MAXSHAPEr�r�r"r(rarQr�r�r�r/r1r�r�r�r�r�)rrrvr;r�r�rxr]�xlistr"�mvlistr��ylistr��zs              r>�test_ndarray_randomz&TestBufferProtocol.test_ndarray_randomTs����z�"�"�%	0�%	0�A��s�|�$
0�$
0��!�?�3�/�/��"�8�T�&�,4�6�6�6����� 0�!� 4�5�5�5�0��a�8�8��*�5�#�q�9�9�����
�
����]�]��'��,�,�4��Y�Y�[�[�F��$�$�V�U�3�3�3��Q�4�!�8�8�.�u�c�1�F�K�K�K�A��H�H�J�J�E��$�$�U�E�2�2�2�#�A���B�+�C�0�0�8��(�(��Q�/�/�/�!#�������(�(���7�7�7��0��a�D�E��E�z�z� �2�5�#�q�A�A�A��K�K��t�)*���u�%&�V�1�7�A�I�$%�H�H�J�J� �0�0�0��C$
0�%	0�%	0r_c��tt��D]�}tdD]�}tj|��}t|dtt���}|�t|���t||��}d}	t|||��}n#t$r}|j
}Yd}~nd}~wwxYw|�|��tr4d}		t!|||��}
n#t$r}|j
}	Yd}~nd}~wwxYw	���dS)NrAFrc)rir`rVr8r�r
rdre�assertFalser�r"r(rNrOr�r/r1)rrrvr;r�r�rxrRr]rQ�	numpy_errr�s           r>�test_ndarray_random_invalidz.TestBufferProtocol.test_ndarray_random_invalid}sJ���z�"�"�	3�	3�A��s�|�
3�
3��!�?�3�/�/��"�8�U�6�,4�6�6�6��� � �!1�1�!5�6�6�6�0��a�8�8����(�.�u�c�1�=�=�A�A�� �(�(�(��K�E�E�E�E�E�E�����(��������&�&�&��3� %�I�0�6�u�c�1�E�E����$�0�0�0�$%�K�	�	�	�	�	�	�����0����3��-
3�	3�	3s0�B�
B3�"B.�.B3�C'�'
D�1C=�=Dc�6�tt��D�]�}tdD�]p}tj|��}ttt���\}}}}t|d|���}t|d|���}	|�	t|���|�	t|	���t||��}
t||	��}t|
||��}t|||	��}
|
|||<|�
��}|
�
��}t|��}t|
��}|�|�
��|��|�|�
��|��|ddk�r	|	ddkr�t|
||t ���}t|||	t ���}||||<|�
��}|�
��}|�||��|�||��t|��}t|��}|�|�
��|��|�|�
��|��t"r�d|vsd|vr���t%|
||��}t%|||	��}||||<t'|��sSt'|	��sD|�|d|j|d|j|j|j|�
���	�	�	|�|
d|j|d|j|j|j|�
���	�	�	��r���dS)
NrArcTr�r!rr�Fr)rir`rVr8r�r rdrer
r�r�r"r(rarQr�r�r/r1r�r�r�r�r�r�)rrrvr;r�r�r�r�r��tl�tr�litems�ritemsrDrF�xllist�xrlistrErG�ylrH�yllist�yrlist�zl�zrs                        r>� test_ndarray_random_slice_assignz3TestBufferProtocol.test_ndarray_random_slice_assign�sd���z�"�"�:	E�:	E�A��s�|�9
E�9
E��!�?�3�/�/��(�v��I�I�I�1�����#�H�d�&�A�A�A��#�H�d�&�A�A�A����� 0�"� 5�6�6�6���� 0�"� 5�6�6�6�1�#�r�:�:��1�#�r�:�:��+�F�C��<�<��+�F�C��<�<�� ��k��7����������������^�^����^�^��� � ������f�5�5�5�� � ������f�5�5�5��a�5�1�9�9��A�����/���R�v�N�N�N�B�/���R�v�N�N�N�B�"$�W�+�B�w�K��Y�Y�[�[�F��Y�Y�[�[�F��$�$�V�V�4�4�4��$�$�V�V�4�4�4�#�B���B�#�B���B��$�$�R�Y�Y�[�[�&�9�9�9��$�$�R�Y�Y�[�[�&�9�9�9��E��F�{�{�a�6�k�k� �3�F�C��D�D�B�3�F�C��D�D�B�"$�W�+�B�w�K�)�"�-�-�I�n�R�6H�6H�I����B�D�-/�[�c�E�)+����,.�J�B�I�I�K�K�$�I�I�I�
�K�K���)+��#��%'�W�B�H�(*�
��	�	��� �E�E�E��m9
E�:	E�:	Er_c��gd�}t|ddgt���}t|��}|�|jtz��|�|j|��|�|jd��|�|j	��|�|j
��|�|j��dS)Nr�rkr>r�)rr�)r
r�r�r&r�r\r�rerlr�r�r�)rrrxrir�s    r>�test_ndarray_re_exportz)TestBufferProtocol.test_ndarray_re_export�s���,�,�,��
�U�1�Q�%�v�
6�
6�
6��
�R�[�[�������6�)�*�*�*��
�
�b�f�b�!�!�!�������0�0�0������)�)�)������)�)�)������'�'�'�'�'r_c	���dtfD�]V}tgd�dg|���}t|��}|�||��|�|���g��|�|���g��tgd�gd�|���}|�|���g��tgd�gd�|���}|�|���gggg��tgd�gd�|���}|�|���ggggggggggggg����XdS)Nrr�r��rrkrk�rkrrk)rkrkr�r�r
rQr�ra�rrr&rir"s    r>�test_ndarray_zero_shapez*TestBufferProtocol.test_ndarray_zero_shape�sw����[�	I�	I�E�������5�9�9�9�B��B���B����R��$�$�$����R�Y�Y�[�[�"�-�-�-����R�Y�Y�[�[�"�-�-�-��������u�=�=�=�B����R�Y�Y�[�[�"�-�-�-��������u�=�=�=�B����R�Y�Y�[�[�2�r�2�,�7�7�7��������u�=�=�=�B����R�Y�Y�[�[�!�2�r�l�R��R�L�2�r�2�,�G�
I�
I�
I�
I�	I�	Ir_c�<�dtfD]�}tdgdgdg|���}t|��}|�||��|�|���gd���|�|���gd�����dS)Nrr,r�r�)r,r,r,r,r,r�r�s    r>�test_ndarray_zero_stridesz,TestBufferProtocol.test_ndarray_zero_strides�s�����[�	;�	;�E��!��Q�C�!��E�B�B�B�B��B���B����R��$�$�$����R�Y�Y�[�[�/�/�/�:�:�:����R�Y�Y�[�[�/�/�/�:�:�:�:�	;�	;r_c���tttd����dgd���}|�|jd��|�|���gd���dS)N�rkr7r�)r7r6r�)r
r�rir�r�ra�rrris  r>�test_ndarray_offsetz&TestBufferProtocol.test_ndarray_offsetsd��
�T�%��)�)�_�_�Q�C��
:�
:�
:�������A�&�&�&���������g�g�g�.�.�.�.�.r_c���dtfD]Y}tttd����dg|���}|���}|�||���ZdS�Nrrkr�)r�r
r�rirr�)rrr&rirHs    r>�#test_ndarray_memoryview_from_bufferz6TestBufferProtocol.test_ndarray_memoryview_from_buffersk����[�	$�	$�E���e�A�h�h����s�%�@�@�@�B��)�)�+�+�A����Q��#�#�#�#�	$�	$r_c	���dtfD]l}tttd����dg|���}td��D]-}|�||t||g�����.�mdSr�)r�r
r�rir�r�)rrr&rirs    r>�test_ndarray_get_pointerz+TestBufferProtocol.test_ndarray_get_pointers�����[�	>�	>�E���e�A�h�h����s�%�@�@�@�B��1�X�X�
>�
>��� � ��A���B���(<�(<�=�=�=�=�
>�	>�	>r_c��tttd����gd����}t|ttz���}|�|���|�����t|��}|�|���|�����dS)Nr�)r!r!r�r�r�)r
r�rir�r�r�rarQ)rrr�rirHs    r>� test_ndarray_tolist_null_stridesz3TestBufferProtocol.test_ndarray_tolist_null_stridess���
�T�%��)�)�_�_�G�G�G�
4�
4�
4��
�R��� 5�
6�
6�
6����������b�i�i�k�k�2�2�2��r�N�N����������R�Y�Y�[�[�1�1�1�1�1r_c��|�tdd����ttt	d����ddg���}ttt	d����ddg���}|�t||����tdgdgd�	��}|�t|d
����|�td
|����dS)Nr�s456r�rkr>r�r,rr}rU)rlr�r
r�rir�)rrr]r�s   r>�test_ndarray_cmp_contigz*TestBufferProtocol.test_ndarray_cmp_contigs�������F�F�3�3�4�4�4��D��r���O�O�A�a�5�1�1�1���D��r���O�O�A�a�5�1�1�1������A�q�)�)�*�*�*��Q�C��s�3�/�/�/�����
�1�g�.�.�/�/�/����
�7�A�.�.�/�/�/�/�/r_c	�~�tjdgd���}t|��}|�tt|��tt
td������}tt
td����dg���}|�t	|��t	|����tt
td����ddg���}|�t	|��t	|����tt
td����gd����}|�t	|��t	|����ttt
td����ddg�����}tt
td����ddgt���}|�t	|��t	|����ttt
td����gd	������}tt
td����gd	�t���}|�t	|��t	|����tt
td������}tt
td����gd
�t���}|�t	|��t	|����tt
td����gd
�d���}|�t	|��t	|�������dS)Nrr�r�r�rkr>)rkr!r!r��r!rkr!�r!r!rkr})
rOr
r�r��hashrWr�rir�r�r�r�r8)rrrJrirs    r>�test_ndarray_hashz$TestBufferProtocol.test_ndarray_hash&s����K��W�W�W�%�%��
�Q�Z�Z�����*�d�B�/�/�/�
�$�u�R�y�y�/�/�"�"��
�T�%��)�)�_�_�R�D�
1�
1�
1������b���4��7�7�+�+�+��T�%��)�)�_�_�Q�q�E�
2�
2�
2������b���4��7�7�+�+�+�
�T�%��)�)�_�_�G�G�G�
4�
4�
4������b���4��7�7�+�+�+�
�)�D��r���O�O�A�a�5�9�9�9�:�:��
�T�%��)�)�_�_�Q�q�E��
D�
D�
D������b���4��7�7�+�+�+��)�D��r���O�O�7�7�7�;�;�;�<�<��
�T�%��)�)�_�_�G�G�G�:�
F�
F�
F������b���4��7�7�+�+�+�
�$�u�R�y�y�/�/�"�"��
�T�%��)�)�_�_�G�G�G�6�
B�
B�
B������b���4��7�7�+�+�+��T�%��)�)�_�_�G�G�G�C�
@�
@�
@������b���4��
�
���#5�#5�6�6�6�6�6r_c��tttttt
ttttttf}|�ttidt
��tdddt ���}dD]@}|D];}t|||��}|�||������<�Atdgdgdt ���}dD].}|D])}t|||��}|�|d	���*�/tt't)d
����gd�dt ���}dD].}|D])}t|||��}|�|d	���*�/dt*fD]�}tdgdgd|t z���}|���}dD].}|D])}t|||��}|�||���*�/tgd
�dgd|t z���}|���}dD].}|D])}t|||��}|�||���*�/��tgd
�dgdgt ���}|���}dD]:}ttfD])}t|||��}|�||���*�;|ddd�}|���}dD]@}|D];}	t|||��}n#t,$rY�!wxYw|�||���<�At't)d����}dt*fD�]�}t|ddg|t z���}t.r*t/t1|��ddgd|dkrdnd���}	|t*kr>tt3|ddg��ddgt ���}
|
���}n|���}|D]�}	t|d|��}n#t,$rY�!wxYw|�||��td�|D��ddgt ���}|�t5|��t5|����t.r*|�||	�d�������|dkr*tt3|ddg��ddgt ���}
nt|ddgt ���}
|
���}tt
tttfD]�}	t|d|��}n#t,$rY�!wxYw|�||��td�|D��ddgt*t z���}|�t5|��t5|����t.r*|�||	�d�������|t*kr.t|ddgt ���}
|
���}n|���}tt
tttfD]�}	t|d|��}n#t,$rY�!wxYw|�||��td�|D��ddg|t z���}|�t5|��t5|����t.r*|�||	�d��������tt't)d����ddgt t8z���}t|dt
��}|�||�����td�|D��ddgt ���}|�t5|��t5|����t|dt
��}tt3|ddg��ddgt ���}
|�||
�����td�|D��ddgt*t z���}|�t5|��t5|����t|dt
��}|�||�����td �|D��ddgt ���}|�t5|��t5|����dS)!Nrzr�r�rr|ryr,rr_r6�r!rr7rr�rkrr!r�r�r�r>r�rr�)r*r�r+r�c��g|]}|��Sr�r�r�s  r>r�zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>����N�N�N�1�Q�N�N�Nr_r�c��g|]}|��Sr�r�r�s  r>r�zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>	r�r_r{c��g|]}|��Sr�r�r�s  r>r�zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>	r�r_c��g|]}|��Sr�r�r�s  r>r�zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>+	���N�N�N�1�Q�N�N�Nr_c��g|]}|��Sr�r�r�s  r>r�zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>2	r�r_c��g|]}|��Sr�r�r�s  r>r�zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>8	r�r_)r�r�r�r�r�r�r�r�r�r�r�r�r�rbr�r
r'r�r8r�rir�r�r/r,r�rQ�tostringr�)
rrr�rir��requestrr�ndbytesrj�nar]r�r�s
             r>�test_py_buffer_to_contiguousz/TestBufferProtocol.test_py_buffer_to_contiguousKs�	��
�M�8�\��
��+��+��/�
��	
���)�%<�b�#�'�	)�	)�	)��Q�b��K�
@�
@�
@��$�	2�	2�E�#�
2�
2��+�B��w�?�?��� � ��B�J�J�L�L�1�1�1�1�
2�
�a�S���C�{�
C�
C�
C��$�	)�	)�E�#�
)�
)��+�B��w�?�?��� � ��C�(�(�(�(�
)��T�%��(�(�^�^�9�9�9�S�&�(�(�(��$�	)�	)�E�#�
)�
)��+�B��w�?�?��� � ��C�(�(�(�(�
)��Z��
	1�
	1�A��!��Q�C��1�[�=�I�I�I�B��j�j�l�l�G�(�
1�
1��'�1�1�G�/��E�7�C�C�A��$�$�Q��0�0�0�0�1�����1�#�c��;��O�O�O�B��j�j�l�l�G�(�
1�
1��'�1�1�G�/��E�7�C�C�A��$�$�Q��0�0�0�0�1�
1��Y�Y�Y�q�c�A�3�k�
J�
J�
J���*�*�,�,��$�	-�	-�E�)�:�6�
-�
-��+�B��w�?�?��� � ��G�,�,�,�,�
-����"��X���*�*�,�,��$�	-�	-�E�#�
-�
-���/��E�7�C�C�A�A��"�����H������ � ��G�,�,�,�,�
-�N�5��9�9�o�o���Z��K	@�K	@�A���Q��F�!�K�-�@�@�@�B��
?� �	�#���()�1�v�S�./�1�f�f�s�s�#�?�?�?��
�J����I�c�A�q�6�2�2�1�a�&�"-�/�/�/���9�9�;�;����:�:�<�<��#�
@�
@���/��C��A�A�A�A��"�����H������ � ��H�-�-�-��N�N��N�N�N�1�a�&��L�L�L��� � ��A���
�2���?�?�?��@��$�$�Q����#��(>�(>�?�?�?���A�v�v��I�c�A�q�6�2�2�1�a�&�"-�/�/�/����C��1�v�[�A�A�A���y�y�{�{�H�&�
�~�)�8�5�
@�
@���/��C��A�A�A�A��"�����H������ � ��H�-�-�-��N�N��N�N�N�1�a�&�
�;�@V�W�W�W��� � ��A���
�2���?�?�?��@��$�$�Q����#��(>�(>�?�?�?���J����C��1�v�[�A�A�A���9�9�;�;����:�:�<�<��&�
�~�)�8�5�
@�
@���/��C��A�A�A�A��"�����H������ � ��H�-�-�-�
�N�N��N�N�N�1�a�&��+�
�N�N�N��� � ��A���
�2���?�?�?��@��$�$�Q����#��(>�(>�?�?�?��!
@�&�T�%��)�)�_�_�Q��F�+�f�:L�
M�
M�
M��
$�B��]�;�;������B�J�J�L�L�)�)�)��N�N��N�N�N�1�a�&��D�D�D������A���
�2���7�7�7�
$�B��]�;�;���I�c�A�q�6�*�*�1�a�&��L�L�L������A�I�I�K�K�(�(�(��N�N��N�N�N�1�a�&�
�;�8N�O�O�O������A���
�2���7�7�7�
$�B��]�;�;������B�J�J�L�L�)�)�)��N�N��N�N�N�1�a�&��D�D�D������A���
�2���7�7�7�7�7sH�$K6�6
L�L�5P�
P�P�2U�
U�U�'Y9�9
Z�Zc�
�dgfgd�dgfttd����gd�fg}|D�]�\}}t||���}t|��}|�|j��|�|j��t|��}t||dd��}t||��}|�
||dd	d
||||��	�	t|��}	|�
|	|dd	d
||||��	�	t|ttz���}
|�
|
jd
��|
���}|�
|ddd	d
||||��	�	t|t ���}
|�
|
jd��|�
|
jd
��|�
|
jd
��|
���}|dkr|gn|}|�
|ddd	d
d|jgd|��	�	���|D]�\}}t||t(���}t|��}|�|j��|�|j��t|��}t||dd��}t-||��}|�
||dd	d
||||��	�	t|��}	|�
|	|dd	d
||||��	�	��|dd�D]�\}}t||t.���}t|��}t|��}t||��}|�
||dd	d
|||j|��	�	t|��}	|�
|	|dd	d
|||j|��	�	��|�t2tdd��|�t2ti��tgd�dg���}t|t ���}
|�t4t|
��t|ttz���}
|�t4t|
��tdgdzdgdzd���}
|�t6t|
��|�t6|
j��|�t6t8|
t:d��|�t6t8|
t:d��|�t6t8|
ddd�t:d��dS)Nr�r�rkrr;r�r,r�rTrr�r�r@r�r,r�rz�9r]r$rr}r�)r�rir
rQr�r�r�rdr�r�r�r�r�r�r�rr�r%r�r6r�r�r�r�r�rbr�r�r�r�)rr�items_shaperxr�r�rHr�r�rjr�ris           r>�test_memoryview_constructionz/TestBufferProtocol.test_memoryview_construction;	s{���2�w����1�#���e�E�l�l�1C�1C�W�W�W�0M�N��(�,	!�,	!�L�E�5���e�,�,�,�B��2���A��O�O�A�N�+�+�+��O�O�A�L�)�)�)��u�:�:�D�(��u�a��=�=�G����&�&�C��K�K��r�!"��d�!����
�
!�
!�
!��A���B��K�K���!"��d�!����
�
!�
!�
!���O�L�$@�A�A�A�B����R�Z��,�,�,��)�)�+�+�A��K�K��t�!"��d�!����
�
!�
!�
!���L�1�1�1�B����R�Y��+�+�+����R�X�r�*�*�*����R�Z��,�,�,��)�)�+�+�A�!�Q�Y�Y�5�'�'�E�C��K�K��t�!"��d��r�y�k�4��
�
!�
!�
!�
!�(�	!�	!�L�E�5���e�:�>�>�>�B��2���A��O�O�A�N�+�+�+��O�O�A�L�)�)�)��u�:�:�D�(��u�a��=�=�G����&�&�C��K�K��r�!"��d�!����
�
!�
!�
!��A���B��K�K���!"��d�!����
�
!�
!�
!�
!�(����O�	!�	!�L�E�5���e�6�:�:�:�B��2���A��u�:�:�D����&�&�C��K�K��r�!"��d�!���
��
�
!�
!�
!��A���B��K�K���!"��d�!���
��
�
!�
!�
!�
!�	
���)�Z��s�;�;�;����)�Z��4�4�4�
�W�W�W�Q�C�
(�
(�
(��
�R��
-�
-�
-�����+�z�2�6�6�6�
�R��� <�
=�
=�
=�����+�z�2�6�6�6��a�S��W�Q�C��G�C�
8�
8�
8�����*�j�"�5�5�5����*�b�&?�@�@�@����*�n�b�*�c�J�J�J����*�n�b�*�c�J�J�J����*�n�b���2��h�
�C�P�P�P�P�Pr_c��gd�}gd�gd�gd�fD]]}t||���}|�|j��t|��}|�t
|jd���^tdd��D]z\}}}td��}|�|��}|�|�	��d��|�|�
��g���{dS)	Nr�rr�r�rr,rQr_)r
r�r�rQr�rbrur�r�r8ra)rrrxr�r��msrcr;rvrHs        r>�test_memoryview_cast_zero_shapez2TestBufferProtocol.test_memoryview_cast_zero_shape�	s���
�����g�g�w�w�w����0�	9�	9�E���e�,�,�,�B��O�O�B�O�,�,�,��b�>�>�D����i���C�8�8�8�8�$�Q��5�5�	-�	-�I�C��A��c�?�?�D��	�	�#���A����Q�Y�Y�[�[�#�.�.�.����Q�X�X�Z�Z��,�,�,�,�		-�	-r_c��|j}tj}d}d}tt	d����}|td��||d|zz����t
|ddgd�	��}|t|��||d|zz����t
|gd
�d�	��}|t|��||d|zz����dS)NzPnin 2P2n2i5P P�3nr6r_r,r!r>rr})r!r!r!rk)�check_sizeofr�calcvobjsizer�rirQr
)rr�check�vsize�base_struct�per_dimrxrJs       r>�test_memoryview_sizeofz)TestBufferProtocol.test_memoryview_sizeof�	s����!���$��'�����U�1�X�X����
��j��o�o�u�u�[�1�w�;�%>�?�?�@�@�@��E�!�Q���4�4�4��
��j��m�m�U�U�;��W��#<�=�=�>�>�>��E����3�7�7�7��
��j��m�m�U�U�;��W��#<�=�=�>�>�>�>�>r_c��Gd�dt��}Gd�dt��}d�}|d��|d��dtd��d	td
d��gd�hd
�ddidddddtddt	d��t	d��dddd|d�g}tdd��D�]a\}}}t
|dg|t���}t
|dg|t���}	t|��}
tj
||	d|��||
d<|�|
d|	d��tj|��}d|vr��|D]�}d}
	tj
||	||��n!#tj
$rtj
}
YnwxYwd}	||
d<n%#ttf$r}|j}Yd}~nd}~wwxYw|
s|r-|�|
d��|�|d����|�|
d|	d������cdS)Nc��eZdZd�Zd�ZdS)�=TestBufferProtocol.test_memoryview_struct_module.<locals>.INTc��||_dSr���val�rrr�s  r>�__init__zFTestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__init__�	�
������r_c��|jSr�r�rqs r>�__int__zETestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__int__�	�	���x�r_N)�__name__�
__module__�__qualname__r�r�r�r_r>�INTr��	�2������
�
�
�
 �
 �
 �
 �
 r_r�c��eZdZd�Zd�ZdS)�=TestBufferProtocol.test_memoryview_struct_module.<locals>.IDXc��||_dSr�r�r�s  r>r�zFTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__init__�	r�r_c��|jSr�r�rqs r>�	__index__zGTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__index__�	r�r_N)r�r�r�r�r�r�r_r>�IDXr��	r�r_r�c��dS)Nr7r�r�r_r>rz;TestBufferProtocol.test_memoryview_struct_module.<locals>.f�	s���r_r�y������@@z-21.1gffffff(@r�r!r�>r>r�r?r7r6r��r�TF�asabcrJ�abcc��|Sr�r�)r]s r>�<lambda>zBTestBufferProtocol.test_memoryview_struct_module.<locals>.<lambda>�	s��q�r_rnrQr|rrr,)�objectr
r�Ellipsisr,r�r
r'rQr8r.r�r�r:rbr�rO�assertIsNot)rrr�r�r�valuesr;rxryr�rirHr�r��
struct_err�mv_errrQs                r>�test_memoryview_struct_modulez0TestBufferProtocol.test_memoryview_struct_module�	s���	 �	 �	 �	 �	 �&�	 �	 �	 �	 �	 �	 �	 �	 �&�	 �	 �	 �	����#�a�&�&�#�#�a�&�&��'�'�*�*�D�(�1�a�.�.��'�'�7�7�7�Q�q�E�2�t���t�X���	�$����6�1B�1B��u�d�F��[�[�
"��!,�B�� =� =�	2�	2��C�����r�d�3�k�J�J�J�B���r�d�3�k�J�J�J�B��2���A���S�"�a��.�.�.��A�a�D����Q�q�T�2�a�5�)�)�)���s�+�+�H��c�z�z���
2�
2��!�
�.��$�S�"�h��:�:�:�:���|�.�.�.�!'��J�J�J�.������)��A�a�D�D��!�:�.�)�)�)��[�F�F�F�F�F�F�����)�����2��2��$�$�Z��6�6�6��$�$�V�T�2�2�2�2��$�$�Q�q�T�2�a�5�1�1�1�1�#
2�	2�	2s*�E&�&F�F�
F�F2�!F-�-F2c���tgd�dgdg���}|�|j��t|��}|�t
|jd��dS)Nr�rkrr�r)r
rlr�rQr�rbru)rrr�r�s   r>�!test_memoryview_cast_zero_stridesz4TestBufferProtocol.test_memoryview_cast_zero_strides	
sa���W�W�W�Q�C�!��
5�
5�
5�������)�)�)��"�~�~�����)�T�Y��4�4�4�4�4r_c	��tD]�}td��rd|zn|}tj|��}tD]�}td��rd|zn|}tj|��}t	tt
d����d|zg|���}t|��}|�t|j
|d|zg������td��D]�\}}	}
t	|	dg|���}t|��}td��D]�\}}
}
t|��s'|�t|j
|d|zg���<t|��s5t|��s&|�t|j
|d|zg������tjd��}tjd��}t	tt
d|z����dd|gd���}t|��}|�t|j
dd|gd���t	tt
d	����gd
����}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��t	ddgdgd���}t|��}
|�t|
jd��|�t|
jdd��|�t|
j��t	tt
d	����gd
����}t|��}
|�t|
j
di���t	tt
d	����d	g���}t|��}
|�t&|
j
ddg���|�t|
j
ddg���|�t|
j
dgd����|�t|
j
dgd����|�t|
j
dgd ����t	td!�t
d"��D����gd#����}t|��}
|�t|
j
d$gd%����t	tt
d&����d&gd$���}t|��}
|�t|
j
d$dgd&z��t	td'�t
d"��D����d"g���}t|��}
|�t|
j
d$gd%����t	td(�t
d"��D����d"g���}t|��}
|�t|
j
dgd%����t	tt
d&����d&gd$���}t|��}t	tt
d&����d&gd���}t|��}t(jd)krn|�t|j
dgd*���|�t|j
dgd+���|�t|j
d$gd,���dS|�t|j
ddd-g��|�t|j
dgd.���|�t|j
d$gd/���dS)0Nr!rAr2r}r,rrr>�xr�r�rk�Xz@Xz@XYz=Bz!Lz<Pz>l�BI�xBIr'r��IIrr6rr+r�)r!rkr>r�r?r7r�)r!rkr>r�r?r7r)r!rkr>r�r?r7r]c��g|]}d��Sr�r�rWs  r>r�zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>^
���6�6�6��1�6�6�6r_i�)rkr�r7r�r)r!rkr>r�r$c��g|]}d��Sr�r�rWs  r>r�zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>h
r�r_c��g|]}d��Sr�r�rWs  r>r�zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>m
r�r_l����)r7r7�Ir/iQiAji��	)�r��r�r6)r�r�r�r�r!��)r�r�r2r2r!)r�r�r2r6r!)�NON_BYTE_FORMATrr8r�r
r�rirQr�rbrur�r�r�r�rcr+r)rar	rf�maxsize)rr�sfmt�sformat�ssize�dfmt�dformat�dsizer�r��sitemsrv�size_h�size_drHrir�r�s                 r>�test_memoryview_cast_invalidz/TestBufferProtocol.test_memoryview_cast_invalid
sN��#�	K�	K�D�$-�a�L�L�:�c�D�j�j�d�G��O�G�,�,�E�'�
K�
K��(1�!���>�#��*�*�$�����0�0���T�%��)�)�_�_�R��Y�K��P�P�P��!�"�~�~���!�!�)�T�Y��r�5�y�k�J�J�J�J�
K� +�1�~�~�
	7�
	7�O�D�&�!����s�4�8�8�8�B��b�>�>�D�)�!�n�n�
7�
7�
��a��+�D�1�1�7��%�%�j�$�)�T�')�5�y�k�3�3�3�3�*�$�/�/�7��t�8L�8L�7��)�)�)�T�Y��+-�u�9�+�7�7�7��

7����%�%�����%�%��
�T�%��F�
�+�+�,�,�Q�q��L��
M�
M�
M���"�~�~�����)�T�Y�q��6�l�3��O�O�O�
�T�%��*�*�%�%�[�[�[�
9�
9�
9���r�N�N��	
���)�Q�V�,�,�,����)�Q�V�Q��1�5�5�5�	
���)�Q�V�R�0�0�0�	
���*�a�f�c�2�2�2����*�a�f�d�3�3�3����*�a�f�e�4�4�4�	
���*�a�f�d�3�3�3����*�a�f�d�3�3�3����*�a�f�d�3�3�3����*�a�f�d�3�3�3����*�a�f�d�3�3�3����*�a�f�e�4�4�4��e�U�^�A�3�t�
<�
<�
<���r�N�N�����-�q�}�a�@�@�@����-�q�}�a��C�C�C����-�q�x�8�8�8��T�%��*�*�%�%�[�[�[�
9�
9�
9���r�N�N�����)�Q�V�S���;�;�;��T�%��*�*�%�%�g�Y�
7�
7�
7���r�N�N�����-����U�G��D�D�D����*�a�f�c�"���>�>�>����*�a�f�c�9I�9I�9I��J�J�J����*�a�f�c�����I�I�I����)�Q�V�S�8I�8I�8I��J�J�J��T�6�6�e�H�o�o�6�6�6�7�7�z�z�z�
J�
J�
J���r�N�N�����)�Q�V�S�	�	�	��B�B�B��T�%��*�*�%�%�c�U�3�
?�
?�
?���r�N�N�����*�a�f�c�A�3�s�7�;�;�;��T�6�6�e�H�o�o�6�6�6�7�7��z�
J�
J�
J���r�N�N�����)�Q�V�S�	�	�	��B�B�B��T�6�6�e�H�o�o�6�6�6�7�7��z�
J�
J�
J���r�N�N�����)�Q�V�S�	�	�	��B�B�B��T�%��*�*�%�%�c�U�3�
?�
?�
?��
��^�^��
�T�%��*�*�%�%�c�U�3�
?�
?�
?��
��^�^���;�'�!�!����i���#�A�A�A�
C�
C�
C����j�"�'�3�@�@�@�
B�
B�
B����j�"�'�3�@�@�@�
B�
B�
B�
B�
B�
���i���#� �*�o�
/�
/�
/����j�"�'�3�>�>�>�
@�
@�
@����j�"�'�3�>�>�>�
@�
@�
@�
@�
@r_c�d���dd�fdd�fdd�ff���fd�}tjd��}td	gd�
��}t|dd��\}}t	|��}|�d��}��||dddd|d
|d��
�
tjd��}td	g|z|gd�
��}t|d|g���\}}t	|��}|�dg���}��|||ddddd|d��
�
tdd��D]8\}	}
}tj|	|
��}t	|��}||||
|	���9tdd��D]<\}	}
}t|
dg|	t���}t	|��}||||
|	���=dS)Nrc�D�t|�����Sr��r�r8�r�s r>r�z9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>�
s��4��
�
���-�-�r_rc�X�d�t|�����D��S)Nc�(�g|]}|dkr|dz
n|��S)r/r#r�r�s  r>r�zMTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>�
s(��P�P�P��Q��W�W�A�c�E�E�!�P�P�Pr_r�r�s r>r�z9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>�
s%��P�P�T�"�*�*�,�,�=O�=O�P�P�P�r_rc�X�d�t|�����D��S)Nc�H�g|]}tt|��d���� S)zlatin-1)rW�chrr�s  r>r�zMTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>�
s(��Q�Q�Q��E�#�a�&�&�)�4�4�Q�Q�Qr_r�r�s r>r�z9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>�
s%��Q�Q�d�2�:�:�<�<�>P�>P�Q�Q�Q�r_c
���tj|��}�
D]�\}}|�|��}||��}��||d|ddd|zgd|d��
�
|�|��}	��|	|��|���}��|	|||dddg|f|d��
�
��dS)Nr,Fr3r�T�	r\r�r;r�r�r�r�rjru)r8r�rur�r�ra)r�rHrxr;�srcsizerR�to_bytelistr�rj�m3�bytespecrrs          ��r>�iter_roundtripz?TestBufferProtocol.test_memoryview_cast.<locals>.iter_roundtrip�
s�����o�c�*�*�G�(0�
0�
0�$����V�V�G�_�_��!�k�"�o�o�����B�B�%&�G�e�!"�2�g�:�,�� #�$��0�0�0�
�W�W�S�\�\��� � ��R�(�(�(��i�i�k�k�����B�B�%,�#��!"�2�$��
� #�$��0�0�0�0�
0�
0r_rr�r}r,Tr�rr�rr�r3rOrQr|)
r8r�r
r<rQrur�r�rOr')
rrrrr��	destitems�	destshaperHr��destsizer;rxrvrs
`           @r>�test_memoryview_castz'TestBufferProtocol.test_memoryview_cast�
s+�����-�-�
.��P�P�
Q��Q�Q�
R�
��	0�	0�	0�	0�	0�	0�(�/�#�&�&��
�Q�b��
-�
-�
-��)�"�c�1�5�5��	�9��r�N�N��
�V�V�C�[�[�����B�B��C�$��)�T�!��	�	.�	.�	.��?�3�'�'��
�a�S��\�(��C�
@�
@�
@��)�"�c�8�2�F�F�F��	�9��r�N�N��
�V�V�C�r�V�
"�
"�����B�B�%�3���"�b�!��	�	.�	.�	.�)��W�5�5�	.�	.�M�C�����S�%�(�(�B��2���A��N�2�q�%��-�-�-�-�)��\�:�:�	.�	.�M�C�����r�d�3�k�J�J�J�B��2���A��N�2�q�%��-�-�-�-�	.�	.r_c�n�t��D�]}tdD�]}|dkr�
dtd��|z}tj|��}t|��|z}t
|��rdnd}t||��D�]�\}}}	tj|��}
|dkr|gng}||
gz}t|||���}
t|
��}t|
|||�	��\}}|�#|�t|j
||����|d
kr��t|||���}|�
||�	��}t|��}|j}|���}|�||
||d||||d��
�
|�
|��}|�
||�	��}t|��}|
j}|
���}|�||
|
|d||||d��
�
|�||
|
|d||||d��
�
�������t$�rGd
�dt$j��}|dd��}t|��}|�
d��}|�|j|��|�|jd��|�|jd��|�|jd��|�|j|jf��|�|jd��|�|jd��t%jd��}t|��}|�
d��}|�|j|��|�|jd��|�|jd��|�|jd��|�|j|jf��|�|jd��|�|jd��dSdS)NrAr)r@rAr!rQrRrr}r�r5Trc�2�eZdZdejfdejfgZdS)�>TestBufferProtocol.test_memoryview_cast_1D_ND.<locals>.BEPointr]r�N)r�r�r��ctypes�c_long�c_double�_fields_r�r_r>�BEPointr�
s&������ �&�-�0�3���2H�I���r_rr�g33333i@rr,Fr�r��333333�?r)rFrVrr8r�r�r�r�r
rQr<r�rbrurdr�rar�r�BigEndianStructurer�r\r�r�r�r�r�r6rer)rr�_tshaper[�tfmt�tsizerr\r;rxrv�sizer��tshaper�rH�titemsrir�r�r�rjr�m4r�pointr�r]s                           r>�test_memoryview_cast_1D_NDz-TestBufferProtocol.test_memoryview_cast_1D_ND�
si��%���5	4�5	4�G����4
4�4
4���3�;�;�� ��1���.��5�����-�-����M�M�E�)��&4�T�&:�&:�I�l�l�	��%0��C�%8�%8�+4�+4�M�C���!�?�3�/�/�D�#$�q�5�5�Q�C�C�b�E�$��v�-�F� ��e�C�@�@�@�B�"�2���A�%/��D�%�v�%N�%N�%N�N�F�F��~��)�)�)�Q�V�T�6�J�J�J� ����� �!��v�d�C�C�C�B�����F��3�3�B��v�;�;�D� �j�G��)�)�+�+�C��K�K���).�D�4�%)���$'�d� �4�4�4�������B�����E��2�2�B��u�:�:�D� �j�G��)�)�+�+�C��K�K���)-�3��%)���$'�d� �4�4�4�
�K�K���)-�3��%)���$'�d� �4�4�4�4�Q+4�4
4�l�	0�
J�
J�
J�
J�
J�&�3�
J�
J�
J��G�C��'�'�E��E�"�"�B�������B����R�V�U�+�+�+����R�[�!�,�,�,��M�M�"�+�u�-�-�-����R�W�a�(�(�(����R�X��	�|�4�4�4����R�Z��.�.�.����R�]�B�/�/�/����$�$�A��A���B�������B����R�V�Q�'�'�'����R�[�!�,�,�,��M�M�"�+�u�-�-�-����R�W�a�(�(�(����R�X��	�|�4�4�4����R�Z��.�.�.����R�]�B�/�/�/�/�/�1	0�	0r_c	�v�tjdttdd������}t|��}|�||��|�|���|�����|ddd�}|ddd�}|�||��|�|���|�����t
ttd����gd�d�	��}t|��}|�|���|�����t
d
dgdgd�	��}t|��}|�t|j��t
d
gdgd�	��}t|��}|�t|j��t
gd�ddgd�	��}t|��}|�t|j��dS)Nrr3r?r!rki	)r�r!r7rkr�rr})r!r�)r7r�r<�12345r,r�)r��b�c�d�e�f)	rOr�rirQr�rar
r�rc)rrrJrHr�s    r>�test_memoryview_tolistz)TestBufferProtocol.test_memoryview_tolists���
�K��T�%��A�,�,�/�/�0�0���q�M�M������A������������Q�X�X�Z�Z�0�0�0�
�a�d��d�G��
�a�d��d�G������A������������Q�X�X�Z�Z�0�0�0�
�T�%�
�+�+�,�,�L�L�L��
M�
M�
M���r�N�N����������R�Y�Y�[�[�1�1�1�
�f�g�&�q�c�$�
?�
?�
?���r�N�N�����-�q�x�8�8�8�
�h�Z��s�3�
7�
7�
7���r�N�N�����-�q�x�8�8�8�
�4�4�4�Q�q�E�#�
N�
N�
N���r�N�N�����-�q�x�8�8�8�8�8r_c�V�ttd����}|���}|�|�d����|���|���}|�|�d����dS)Nr�z<memoryz	<released)rQr,�__repr__r��
startswithr)rrrHr�s   r>�test_memoryview_reprz'TestBufferProtocol.test_memoryview_repr3s~���y��|�|�$�$��
�J�J�L�L��������Y�/�/�0�0�0�	�	�	����
�J�J�L�L��������[�1�1�2�2�2�2�2r_c��dD]z}td��}tj|d|dg��}t|��}|�d|��|�d|��|�d|���{t	dgd���}t|��}|�ttdt����dS)	N)rrg���?g@g"@rr�z9.0 in m)	�floatrOrQ�assertInr
r�rbr?r@)rrr;�infr�rHs     r>�test_memoryview_sequencez+TestBufferProtocol.test_memoryview_sequence<s����	"�	"�C���,�,�C���S�3��S�/�2�2�B��2���A��M�M�#�q�!�!�!��M�M�%��#�#�#��M�M�#�q�!�!�!�!�
�S�"�S�
)�
)�
)���r�N�N�����)�T�:�v�x�x�@�@�@�@�@r_c#��K�|�t��5}dV�ddd��n#1swxYwY|�t|j��d|fz��dS)Nz#index out of bounds on dimension %d)r�r,r��str�	exception)rr�dim�cms   r>�assert_out_of_bounds_errorz-TestBufferProtocol.assert_out_of_bounds_errorJs�����
�
�
�z�
*�
*�	�b��E�E�E�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�����R�\�*�*�>�#��G�	I�	I�	I�	I�	Is�.�2�2c��tdgd���}t|��}|�|dd��|�|d|��|�|d|��|�t|jd��tdgd���}t|��}|�t|jd��tttd	����d	gt�
��}t|��}|�t|jd��|�t|jd��|�t|jd
��|�t|jd��|�t|jd��tttd����ddgt�
��}t|��}|�|dd��|�|dd��|�|dd��|�|dd��|�|dd��dD]:}|�d���5||dfddd��n#1swxYwY�;dD]:}|�d���5|d|fddd��n#1swxYwY�;|�t|jd��|�t|jd��|�t|jd ��|�t|jd!��|�t|jd��|�t|jd��dS)"N�)@rr}r�.rr��iiir7r�r+�@����r6r�rkr>�rr)r!rr�r��r�r�)r�r��rkr�r,�r4�r>rr!�r+rr*�rrr�r;r;)r
rQr�r�rbr+rcr�rir'r,r6)rrr�rH�indexs    r>�test_memoryview_indexz(TestBufferProtocol.test_memoryview_indexQs����T��C�
0�
0�
0���r�N�N������2���%�%�%�����3���#�#�#�����3���$�$�$����)�Q�]�A�6�6�6�
�W�B�u�
5�
5�
5���r�N�N�����-�q�}�b�A�A�A��T�%��(�(�^�^�A�3�k�
B�
B�
B���r�N�N�����*�a�m�U�;�;�;����)�Q�]�C�8�8�8����)�Q�]�C�8�8�8�	
���*�a�m�R�8�8�8����*�a�m�Q�7�7�7��T�%��)�)�_�_�Q�q�E��
E�
E�
E���r�N�N������4��!�$�$�$�����4��!�$�$�$�����4��"�%�%�%�����6��B�'�'�'�����6��A�&�&�&��	�	�E��0�0�Q�0�7�7�
�
��%��(���
�
�
�
�
�
�
�
�
�
�
����
�
�
�
���	�	�E��0�0�Q�0�7�7�
�
��!�U�(���
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�����*�a�m�Z�@�@�@����*�a�m�Z�@�@�@����)�Q�]�I�>�>�>����)�Q�]�J�?�?�?�	
���-�q�}�b�A�A�A����-�q�}�a�@�@�@�@�@s$�'J>�>K	�K	�$K;�;K?	�K?	c�
�tdgdt���}t|��}d|d<|�|dd��d|d<|�|dd��|�t
|jdd	��tttd
����d
g���}t|��}|�t
|jdd
��tttd
����d
gt���}t|��}|�t|jdd��|�t
|jdd
��|�t
|jdd��|�t|jdd��|�t|jdd��tdD]�}|dks|dkr�tgd�dg|t���}t|��}tdd��}d||<|�||d��|�||||����tgd�dgdt���}t|��}d|d<|�|dd��tgd �dgdt���}t|��}d!|d"<|�|d"d!��td#gd"gdt���}t|��}|�t
|jdd$��tttd%����gd&�t���}t|��}td�
��D]�\}}|dkr�|dkr�|�|��}|\}	}
|d'ks|dkrdd(zdd(z}
}	|d)krG|�t|jd|	d"z
��|�t
|jdd*��|�t|jd|
����|�d��}|�t|jdd+��tttd"����d"gd,t���}t|��}|�t |jdd"��td-gd"gd.t���}t|��}|�t |jdd"��tttd/����dd0gt���}t|��}d1|d2<|�|dd"d1��d3|d4<|�|ddd3��d5D]7}|�d"�6��5d||df<ddd��n#1swxYwY�8d7D]7}|�d�6��5d|d|f<ddd��n#1swxYwY�8|�t|jd8d��|�t|jd9d��|�t
|jd:d��|�t
|jd;d��|�t |jdddg��dS)<Nr8rr|g�6@r�g�7@.rg33333�8@r7r�r!rnr�r+r�r:r;r�r<r�r6�rArrr�rkr�)�1�2�3r�)TFTTr,�xr�r�r�rr�rrs���xLr r�r�r>�*)rr,�+r>r?r@rArBr*rCrD)r
r'rQr�r�rbr)r�rir,rVrr�rxrur�rcr6)rrr�rHr;rrir��_ranger��lo�hirEs            r>�test_memoryview_assignz)TestBufferProtocol.test_memoryview_assign�s���T��C�{�
C�
C�
C���r�N�N����"������2���%�%�%���#������2���%�%�%����)�Q�]�A�t�<�<�<��T�%��(�(�^�^�A�3�
/�
/�
/���r�N�N�����)�Q�]�A�r�:�:�:��T�%��(�(�^�^�A�3�k�
B�
B�
B���r�N�N�����*�a�m�U�A�>�>�>����)�Q�]�C��<�<�<����)�Q�]�C��<�<�<�	
���*�a�m�R��<�<�<����*�a�m�Q��;�;�;��3�<�	*�	*�C��c�z�z�S�C�Z�Z��������C�{�K�K�K�B��2���A��"�a� � �A��A�a�D����Q�q�T�1�%�%�%����Q�q�T�2�a�5�)�)�)�)�
�'�'�'��s�3�&�(�(�(���r�N�N����!������1��t�$�$�$�
�(�(�(���C�&�(�(�(���r�N�N����!���
�
�a��d�D�!�!�!��d�V�A�3�s�+�
F�
F�
F���r�N�N�����)�Q�]�A�s�;�;�;�
�T�%��*�*�%�%�[�[�[��
L�
L�
L��
��^�^��"�3�<�-�-�/�/�	A�	A�K�C���s�
�
���c�z�z��������B��F�B���c�z�z�S�C�Z�Z��T�'��1�d�7�B���c�z�z��!�!�*�b�n�a��A��F�F�F��!�!�)�R�^�Q��F�F�F����j�"�.�!�R�@�@�@�@��W�W�S�\�\�����*�b�n�a��E�E�E��T�%��(�(�^�^�A�3�t�;�
O�
O�
O���r�N�N�����-�q�}�a��C�C�C�
�h�Z��s�3�k�
J�
J�
J���r�N�N�����-�q�}�a��C�C�C��T�%��)�)�_�_�Q�q�E��
E�
E�
E���r�N�N����#������A��q��2�&�&�&���%������A��q��2�&�&�&��	 �	 �E��0�0�Q�0�7�7�
 �
 ���%��(��
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 ���	 �	 �E��0�0�Q�0�7�7�
 �
 ���!�U�(��
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �����*�a�m�Z��C�C�C����*�a�m�Z��C�C�C����)�Q�]�I�q�A�A�A����)�Q�]�J��B�B�B�	
���-�q�}�a�!�Q��H�H�H�H�Hs$�4X�X	�X	�.Y�Y	�	Y	c
��tttd����dgt���}t	|��}|�t|jtddd����|�t|j	tddd��tddg����|�t|jd��tttd����dgt���}t	|��}|�t|jtddd��tddd��f��|�t|j	tddd��tddd��ftddg����|�t|jtddd��if��|�t|j	tddd��iftddg����|�t|j	tddd��dg��dtfD�]�}tttd����dgdgdt|z�	��}tttd
����dgdg|���}t	|��}t	|��}|dd�|dd�<|dd�|dd�<|�||��|�||��|dd�ddd�|dd
�ddd�<|dd�ddd�|dd
�ddd�<|�||��|�||��|ddd�ddd�|ddd�ddd�<|ddd�ddd�|ddd�ddd�<|�||��|�||�����dS)Nr�r�rr!r,r�r�r�)r�r�r�r&�r�r�rkr>r�)r
r�rir'rQr�r�r+rr)r,rcrbr�r�)rrr�rHr&r�r�r�r�s        r>�test_memoryview_slicez(TestBufferProtocol.test_memoryview_slice�s���
�T�%��)�)�_�_�R�D��
D�
D�
D���r�N�N��	
���*�a�m�U�1�Q�q�\�\�B�B�B����*�a�m�U�1�Q�q�\�\�#�Q�q�E�*�*�	,�	,�	,�	
���-�q�}�b�A�A�A��T�%��)�)�_�_�R�D��
D�
D�
D���r�N�N�����-�q�}� ��1�Q�<�<��q��1���6�	8�	8�	8����-�q�}� ��1�Q�<�<��q��1���6�	�1�Q�%�8H�8H�	J�	J�	J�	
���)�Q�]�U�1�Q�q�\�\�2�4F�G�G�G����)�Q�]�U�1�Q�q�\�\�2�4F�#�Q�q�E�*�*�	,�	,�	,�	
���)�Q�]�E�!�A�a�L�L�1�#�F�F�F���[�	&�	&�E��$�u�R�y�y�/�/�"���t�B� +�E� 1�3�3�3�C��$�u�R�y�y�/�/�"���s�%�P�P�P�C��C���B��C���B��1�Q�3�x�C��!��H���1��g�B�q��s�G����R��%�%�%����R��%�%�%� ��1��X�c�c��c�]�C��!��H�T�T�r�T�N��q��s�G�C�C�a�C�L�B�q��s�G�D�D�b�D�M����R��%�%�%����R��%�%�%� #�A�a��E�
�3�3�Q�3��C��!�B��K���"���!�!�A�a�%�y���1��~�B�q��2�v�J�t�t��t�����R��%�%�%����R��%�%�%�%�/	&�	&r_c�|�d�}tdd��D�]�}t|d��D�]�\}}}t|��D�]y}t|��D�]e}tj||��}tj||��}	t	|	��}
|�|
|��|�|
���|�����|�|
���|�����|�t|
��t|����||||	|
|��d}d}	||}
||}||||<t|
��t|��k}n#t$r}|j
}Yd}~nd}~wwxYwd}	|
||
|<n#t$r}|j
}Yd}~nd}~wwxYw|r|�|t�����|s|r|�||�����|�|
|��|�|
���|�����|�|
���|�����||||	|
|����g��{������dS)Nc��t|��D]�\}}||}||}|�||��|||<||kr-|�||��|�||��n,|�||��|�||��|||<|�||��|�||��|||<|||<��dSr�)r-r��assertNotEqual)	�testcaserJrrH�
singleitemrrv�ai�mis	         r>�cmptestz9TestBufferProtocol.test_memoryview_array.<locals>.cmptest-s��!�!���
�
���1��q�T���q�T���$�$�R��,�,�,�!��!����#�#��+�+�A�q�1�1�1��+�+�A�q�1�1�1�1��(�(��A�.�.�.��(�(��A�.�.�.�!��!���$�$�Q��*�*�*��$�$�Q��*�*�*���!����!���
�
r_r,r�rO)
rir�rHrOrQr�rar8rdrNrOr�r�)rrr^rr;rxr[rXrPrJrrH�	array_err�have_resize�al�arrQ�m_errs                 r>�test_memoryview_arrayz(TestBufferProtocol.test_memoryview_array+s���	�	�	�$�q�!���(	?�(	?�A�*5�a��*A�*A�'
?�'
?�&��U�J�'��l�l�&?�&?�F�"+�A�,�,�%?�%?��!�K��U�3�3��!�K��U�3�3��&�q�M�M���(�(��A�.�.�.��(�(������Q�X�X�Z�Z�@�@�@��(�(������a�i�i�k�k�B�B�B��(�(��Q����Q���8�8�8����a��A�z�:�:�:�$(�	�&*��4�!"�6��B�!"�6��B�()�&�	�A�f�I�*-�b�'�'�S��W�W�*<�K�K��(�4�4�4�()��I�I�I�I�I�I�����4����!%��0�()�&�	�A�f�I�I��(�0�0�0�$%�K�E�E�E�E�E�E�����0����'�?� �M�M�%��<�<�<�<�"�?�i�?� �M�M�%��;�;�;�;� �,�,�Q��2�2�2� �,�,�Q�X�X�Z�Z������D�D�D� �,�,�Q�Y�Y�[�[�!�)�)�+�+�F�F�F�#�G�D�!�Q��:�>�>�>�>�K%?�&?�'
?�(	?�(	?s0�;F�
F0�F+�+F0�6G�
G�G�Gc���tjdgd���}tjdgd���}t|��}t|��}dD]f}|�t||��|��t��|�t||��|��t���gt|��}|���|�||��|�||��|�||��t|��}t|��}|���|�||��|�||��t|��}|�|gd���tdgdgdt���}d	td
��f|d<|�t|��|��tjdd
��}t|��}|�||��|�||��tr�Gd�dtj��}|dd��}t|��}t|��}|�||��|�||��|�||��|�
t|j��dSdS)Nrr�)r,r!r7)�__lt__�__le__�__gt__�__ge__r=r,zl x d xr|r�r5r�urc�2�eZdZdejfdejfgZdS)�ITestBufferProtocol.test_memoryview_compare_special_cases.<locals>.BEPointr]r�N�r�r�r�rrrr�r_r>rrl��&������ �&�-�0�3��
�2F�G���r_rr�r&)rOrQr��getattrr5rr�rYr
r'r-rrr�rcra)	rrrJrr��w�attrrirrs	         r>�%test_memoryview_compare_special_casesz8TestBufferProtocol.test_memoryview_compare_special_casesis����K��Y�Y�Y�'�'���K��Y�Y�Y�'�'��
�q�M�M���q�M�M��<�	?�	?�D��M�M�*�'�!�T�*�*�1�-�-�~�>�>�>��M�M�*�'�!�T�*�*�1�-�-�~�>�>�>�>�
�q�M�M��	�	�	��������A�������A�q�!�!�!����A�q�!�!�!��q�M�M���q�M�M��	�	�	�������A�q�!�!�!����A�q�!�!�!�
�q�M�M�����A�y�y�y�)�)�)��f�X�a�S��+�
N�
N�
N���U�5�\�\�"��1�����J�r�N�N�B�/�/�/�
�K��U�#�#���q�M�M�����A�q�!�!�!����A�q�!�!�!��
	=�
H�
H�
H�
H�
H�&�3�
H�
H�
H��G�C��%�%�E��5�!�!�A��5�!�!�A�����1�%�%�%�����5�)�)�)�����q�)�)�)����1�1�8�<�<�<�<�<�
	=�
	=r_c���tdgd���}tdgdt���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��|�||��|�|�|����|�|�|����d|d<|�||��|�||��|�||��|�||��|�||��|�||��|�|�|����|�|�|����tttd����dgttz�	��}tttd����dgttz�	��}t|��}|�||��d
|d<|�||��tdgd
���}tdgdt���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��|�||��tdgd
���}tdgdt���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��|�||��|�||��|�||��dS)N��@Lr}rr|i�r�r�r�r�r�)rtrr �Lf5s�hf5s)i?���rr )r
r'rQr�rl�__ne__rYr4r�rir�)rr�nd1�nd2r�rprir�rHs        r>�!test_memoryview_compare_ndim_zeroz4TestBufferProtocol.test_memoryview_compare_ndim_zero�s)���d�"�T�2�2�2���d�"�S��D�D�D���s�O�O���s�O�O������A��������A��������C� � � �����a� � � �����C� � � �����a� � � �������!���%�%�%�������!���%�%�%���"�����A�q�!�!�!����A�q�!�!�!����A�s�#�#�#����C��#�#�#����A�s�#�#�#����C��#�#�#�������!���%�%�%�������!���%�%�%�
�T�%��)�)�_�_�R�D��F�8J�
K�
K�
K��
�T�%��)�)�_�_�R�D��F�8J�
K�
K�
K���r�N�N������B������!�����A�r�"�"�"��+�2�f�E�E�E���+�2�f�'�)�)�)���s�O�O���s�O�O������A��������A��������C� � � �����a� � � �����C� � � �����a� � � ��+�2�f�E�E�E���,�B�v�'�)�)�)���s�O�O���s�O�O�����A�q�!�!�!����A�q�!�!�!����A�s�#�#�#����C��#�#�#����A�s�#�#�#����C��#�#�#�����C� � � �����C� � � � � r_c�^	�tgd�dgd���}tgd�dgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tgd�dgd���}tgd�dgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tgd�d	gd���}tgd�dgd���}t|��}t|��}|�||ddd
���|�|ddd
�|��|�||ddd
���|�|ddd�|ddd���tgd�d	gd
���}tgd�dgd���}t|��}t|��}|�||ddd
���|�|ddd
�|��|�||ddd
���|�|ddd�|ddd���tgd�d	gd���}tgd�dgdt���}t|��}t|��}|�||ddd
���|�|ddd
�|��|�||ddd
���|�|ddd�|ddd���tgd�d	gd���}tgd�dgdt���}t|��}t|��}|�||ddd
���|�|ddd
�|��|�||ddd
���|�|ddd�|ddd���dS)N�����@�����'���r��@hr})r~rr�r�i�z<iz>h)r~r�r�rkr!r�r�z!hz<lr|zh  0cz>  h)r
rQr�rYr��rrryrzr�rps     r>� test_memoryview_compare_ndim_onez3TestBufferProtocol.test_memoryview_compare_ndim_one�s
���2�2�2�1�#�d�K�K�K���1�1�1�!��T�J�J�J���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��2�2�2�1�#�d�K�K�K���1�1�1�!��T�J�J�J���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��(�(�(���D�A�A�A���2�2�2�1�#�d�K�K�K���s�O�O���s�O�O������C���!��H�%�%�%�����3�3�Q�3���%�%�%�����A�c�c��c�F�#�#�#�����4�4�R�4��!�D�D�b�D�'�*�*�*��(�(�(���D�A�A�A���2�2�2�1�#�d�K�K�K���s�O�O���s�O�O������C���!��H�%�%�%�����3�3�Q�3���%�%�%�����A�c�c��c�F�#�#�#�����4�4�R�4��!�D�D�b�D�'�*�*�*��(�(�(���D�A�A�A���2�2�2�1�#�d�"�$�$�$���s�O�O���s�O�O������C���!��H�%�%�%�����3�3�Q�3���%�%�%�����A�c�c��c�F�#�#�#�����4�4�R�4��!�D�D�b�D�'�*�*�*��(�(�(���G�D�D�D���2�2�2�1�#�f�"�$�$�$���s�O�O���s�O�O������C���!��H�%�%�%�����3�3�Q�3���%�%�%�����A�c�c��c�F�#�#�#�����4�4�R�4��!�D�D�b�D�'�*�*�*�*�*r_c���tddgdgd���}tddgdgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tddgdgd���}tddgdgd	���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��dS)
N�rrr�r}i|���i?���z= h0cz@   i�r
rQr�r�s     r>�"test_memoryview_compare_zero_shapez5TestBufferProtocol.test_memoryview_compare_zero_shape%
s|���s�C�j���D�9�9�9���t�T�l�1�#�d�;�;�;���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����s�C�j���G�<�<�<���t�T�l�1�#�g�>�>�>���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����r_c���tgd�dgd���}tdgdgdgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��td	gdzdgd
���}td	gdgdgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��dS)N)r�r�r�r�r>rur}r�rrr�)r�r�z@ Liz!L  hr�r�s     r>�$test_memoryview_compare_zero_stridesz7TestBufferProtocol.test_memoryview_compare_zero_strides?
s����*�*�*�1�#�d�C�C�C���s�e�A�3���C�@�@�@���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����z�l�1�n�Q�C��?�?�?���z�l�1�#��s�7�K�K�K���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����r_c�x�d}tdD]�}t|dd|��\}}}dtfD]k}t||g||���}t	|��}|�||��|ddd�}t	|��}|�||���l��d}t
d��D]�}	t|��\}}}dtfD]k}t||g||���}t	|��}|�||��|ddd�}t	|��}|�||���l��dS)	NrnrIrQrArr|r�r�)rVr|r�r
rQr�ri)
rrrr[r;rxr[r&rirHrvs
          r>�&test_memoryview_compare_random_formatsz9TestBufferProtocol.test_memoryview_compare_random_formatsY
sv��
���D�M�		(�		(�D�%.�q�,��T�%J�%J�"�C��
��V��
(�
(���U�1�#�c��G�G�G���r�N�N��� � ��B�'�'�'����"��X���r�N�N��� � ��B�'�'�'�'�
(�
���s���		(�		(�A�%.�q�\�\�"�C��
��V��
(�
(���U�1�#�c��G�G�G���r�N�N��� � ��B�'�'�'����"��X���r�N�N��� � ��B�'�'�'�'�
(�		(�		(r_c�j�tttdd����gd�d���}tttdd����gd�d���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tdgdzgd�d	���}td
gdzgd�d���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tttd����gd�d
���}tttd����gd�d
���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tdgdzddgd���}tdgdzddgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tttd����gd�d
���}tttd����gd�d���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��dS)N��r5�rkr!r�r�r}rr�rr,r!z=f q xxL)g333333�r,r!z< f 2Qr;r�rkr7z! b B xLz
= Qx l xxLr�r
r�rirQr�rYr�s     r>�"test_memoryview_compare_multidim_cz5TestBufferProtocol.test_memoryview_compare_multidim_cu
s����d�5��b�>�>�*�*�)�)�)�D�I�I�I���d�5��B�<�<�(�(�	�	�	�$�G�G�G���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��y�k�"�n�I�I�I�j�I�I�I���|�n�R�'�y�y�y��J�J�J���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��9�9�o�o�Y�Y�Y�s�C�C�C���d�5��9�9�o�o�Y�Y�Y�s�C�C�C���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��y�k�"�n�Q��F�:�F�F�F���y�k�"�n�Q��F�<�H�H�H���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��9�9�o�o�Y�Y�Y�s�C�C�C���d�5��9�9�o�o�Y�Y�Y�s�C�C�C���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����r_c�B	�tttdd����gd�dt���}tttdd����gd�dt���}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tdgd	zd
dgdt���}td
gd	zd
dgdt���}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tttdd����gd�dt���}tttdd����gd�dt���}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tttdd����gd�dt���}tttdd����gd�dt���}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tttd����gd�dt���}tttd����gd�dt���}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��dS)Nr�r5)r�r!rkr�r|rr�rr�r?r!rk�=Qq)r�rz=qQr;rr��0llrK)r
r�rir�rQr�rYr�s     r>�(test_memoryview_compare_multidim_fortranz;TestBufferProtocol.test_memoryview_compare_multidim_fortran�
sv���d�5��b�>�>�*�*�)�)�)�D�&�(�(�(���d�5��B�<�<�(�(�	�	�	�$�&�(�(�(���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��}�o�a�'��1�v�e�&�(�(�(���}�o�a�'��1�v�e�&�(�(�(���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��b�>�>�*�*�)�)�)�C�&�(�(�(���d�5��b�>�>�*�*�)�)�)�C�&�(�(�(���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��b�>�>�*�*�)�)�)�E�&�(�(�(���d�5��b�>�>�*�*�)�)�)�C�&�(�(�(���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��9�9�o�o�Y�Y�Y�t�&�(�(�(���d�5��9�9�o�o�Y�Y�Y�t�&�(�(�(���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����r_c�j�ttdd����}t|gd���}t|gd�d���}t|gd�dt���}t|��}t|��}|�||��|�||��|�||��dgd	z}d
|d<t|gd���}t|gd�d���}t|gd�d
t���}t|��}t|��}|�||��|�||��|�||��tttd����ddgd���}|ddd�ddd�f}tttd����ddgd���}|ddd�ddd�f}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tdgdzddgd���}|ddd�ddd�f}tdgdzddgd���}|ddd�ddd�f}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tttd	����gd�d���}|dd�ddd�f}tttd	����gd�d���}|dd�ddd�f}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tttd	����gd�d���}|dd�ddd�f}tttd	����gd�d���}|dd�ddd�f}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tdgd	zgd �d!���}|dd�ddd�f}tdgd	zgd �d"���}|dd�ddd�f}t|��}t|��}|�||��|�||��|�||��|�||��|�||��dS)#Nr�r5r��@lr}rr|)gffffff
����rLr)g�������r�rLr�zd b czd h c�(r6�@Irkr,r�r�r)r�r&�r�r!z=iiz>iir;rr)r!r��r�rkr!�b3s�i3s)r�rir�r
r�rQr�rY)	rr�lst1�lst2ryrzr�rpr�r�s	         r>�&test_memoryview_compare_multidim_mixedz9TestBufferProtocol.test_memoryview_compare_multidim_mixed�
sY���E�#�r�N�N�#�#����y�y�y�)�)���d�)�)�)�D�9�9�9���d�)�)�)�C�z�J�J�J���s�O�O���s�O�O������C� � � �����C� � � �����A����"�"�2�%��#��Q����y�y�y�)�)���d�)�)�)�G�<�<�<���d�)�)�)�G�:�N�N�N���s�O�O���s�O�O������C� � � �����C� � � �����A�����d�5��9�9�o�o�a��V�D�A�A�A���!�A�b�&�$�$�B�$�,����d�5��9�9�o�o�a��V�C�@�@�@���!�A�a�%���2��+����s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��(�)�"�,�R��G�E�J�J�J���!�A�b�&�$�$�B�$�,����(�)�"�,�R��G�E�J�J�J���!�A�a�%���2��+����s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����d�5��9�9�o�o�Y�Y�Y�s�C�C�C���!�A�$���"��*�o���d�5��9�9�o�o�Y�Y�Y�s�C�C�C���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��9�9�o�o�Y�Y�Y�s�C�C�C���!�A�$���"��*�o���d�5��9�9�o�o�Y�Y�Y�s�C�C�C���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��{�m�B�&�i�i�i��F�F�F���!�A�$���"��*�o���{�m�B�&�i�i�i��F�F�F���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!�!�!r_c��tttd����gd�d���}tttd����gd�d���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��tttd����gd�d���}tttd����gd�d���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��dS)Nr)rrkr!rr})r�rr!z@ir�r�s     r>�+test_memoryview_compare_multidim_zero_shapez>TestBufferProtocol.test_memoryview_compare_multidim_zero_shape\s����d�5��9�9�o�o�Y�Y�Y�s�C�C�C���d�5��9�9�o�o�Y�Y�Y�t�D�D�D���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��9�9�o�o�Y�Y�Y�s�C�C�C���d�5��9�9�o�o�Y�Y�Y�t�D�D�D���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!�!�!r_c�j�tdgdzgd�d���}tdggd�gd�d���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��|�|���|�����td	gd
zddgd
���}td	gddgddgd���}t|��}t|��}|�||��|�||��|�||��|�||��|�||��dS)Nr�r)r>r�r>rur}rCrr�r'rnr!r�z=lQrz<lQ)r
rQr�rar�s     r>�-test_memoryview_compare_multidim_zero_stridesz@TestBufferProtocol.test_memoryview_compare_multidim_zero_stridesvs����s�e�B�h�i�i�i��=�=�=���s�e�9�9�9�i�i�i��L�L�L���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A������������Q�X�X�Z�Z�0�0�0��v�h�r�k�!�Q���>�>�>���v�h�q�!�f�q�!�f�U�K�K�K���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����r_c�r�tttd����ddgd���}|ddd�ddd	�f}tttd����ddgd
t���}|ddd�ddd	�f}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tdgdzddgd
t���}d|dd<|ddd�ddd	�f}tdgdzddgdttz���}d|dd<|ddd�ddd	�f}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tttd����gd�dt���}|dd�ddd	�f}tttd����gd�d���}|dd�ddd	�f}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tdgdzgd�dttz���}|dd�ddd	�f}tdgdzgd�d���}|dd�ddd	�f}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tttd����gd�dt���}|dd�ddd	�f}tttd����gd�dt���}|dd�ddd	�f}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��tdgdzgd�dttz���}d|ddd<|dd�ddd	�f}tdgdzgd�dttz���}d|ddd<|dd�ddd	�f}t	|��}t	|��}|�||��|�||��|�||��|�||��|�||��ttdd ����}t|gd���}t|gd�d!t���}t|gd�d"ttz���}t	|��}t	|��}|�||��|�||��|�||��d#gdz}d$|d%<t|gd���}t|gd�d&t���}t|gd�d'ttz���}t	|��}t	|��}|�||��|�||��|�||��dS)(Nr�r�r6r�r}rkr,r�r�rr|r�r�)r,r�r!r7z>Qqrr;rr�)rr��Bbr�r)shellor_r,�)rkrkrk�5s0sP)ssushir_r,r�r5r�r)ssashimisslicedg�����4@)sramensspicygfffff�"@r�z
< 10p 9p dz
> 10p 9p d)
r
r�rir�rQr�rYr'r�r�)	rrr�ryr�rzr�rpr�r�s	         r>�+test_memoryview_compare_multidim_suboffsetsz>TestBufferProtocol.test_memoryview_compare_multidim_suboffsets�s����d�5��9�9�o�o�a��V�D�A�A�A���!�A�b�&�$�$�B�$�,����d�5��9�9�o�o�a��V�C�v�N�N�N���!�A�a�%���2��+����s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��}�o�b�(��A��u�'�)�)�)����A��q�	��!�A�b�&�$�$�B�$�,����}�o�b�(��A��u�"�;�.�0�0�0����A��q�	��!�A�a�%���2��+����s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����d�5��9�9�o�o�Y�Y�Y�s�"�$�$�$���!�A�$���"��*�o���d�5��9�9�o�o�Y�Y�Y�s�C�C�C���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��|�n�R�'�y�y�y��"�;�.�0�0�0���!�A�$���"��*�o���|�n�R�'�y�y�y��F�F�F���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��d�5��9�9�o�o�Y�Y�Y�s�&�Q�Q�Q���!�A�$���"��*�o���d�5��9�9�o�o�Y�Y�Y�t�6�R�R�R���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � �����C� � � �����C� � � �����A�����)�*�2�-�Y�Y�Y�w�"�;�.�0�0�0��)��A��q�	�!���!�A�$���"��*�o���)�*�2�-�Y�Y�Y�w�"�;�.�0�0�0��)��A��q�	�!���!�A�$���"��*�o���s�O�O���s�O�O������C� � � �����C� � � ����A�s�#�#�#����A�s�#�#�#����A�q�!�!�!��E�#�r�N�N�#�#����y�y�y�)�)���d�)�)�)�D��G�G�G���d�)�)�)�C�z�&�?P�Q�Q�Q���s�O�O���s�O�O������C� � � �����C� � � �����A����/�/��2��-��R����y�y�y�)�)���d�)�)�)�L��O�O�O���d�)�)�)�L�&�v�-�/�/�/���s�O�O���s�O�O������C� � � �����C� � � �����A�����r_c���dD�]�}tdgdzgd�|dz���}tdgdzgd�|dzttz���}d|d	d
ddd<t|��}t|��}|�||��|�||��|�||��|�||��|�||��tdgdzgd�|dz���}tdgdzgd�|dzttz���}d
|d	d
ddd<t|��}t|��}|�||��|�||��|�||��|�||��|�||�����dS)N)rDrBrCrEr)r�)rkr�r!r!r!rr}r|r,r!rk)r)r'r%�QLH)r,r,r,)r
r'r�rQr�rY)rr�	byteorderr]r�rJrs      r>�!test_memoryview_compare_not_equalz4TestBufferProtocol.test_memoryview_compare_not_equals��.�	&�	&�I������;�;�;�y��}�M�M�M�A������;�;�;�y��}�)�*�4�6�6�6�A� �A�a�D��G�A�J�q�M�!���1�
�
�A��1�
�
�A����Q��"�"�"����Q��"�"�"�����1�%�%�%�����1�%�%�%�����1�%�%�%��.�/��3�;�;�;�(���0�0�0�A��.�/��3�;�;�;�(���k�*�6L�N�N�N�A�(�A�a�D��G�A�J�q�M�!���1�
�
�A��1�
�
�A����Q��"�"�"����Q��"�"�"�����1�%�%�%�����1�%�%�%�����1�%�%�%�%�1	&�	&r_c�0�tjdgd���}t|��}|���|�tt|��|�t|jd��|�tt|��|�t|j��|�t|j��|�ttdt����|�t|jd��|�t|jdd��dD]#}|�t|j
|���$tjdgd���}t|��}t|��}|�||��|���|�||��|�||��|�||��dS)Nr)g�������?g������@gffffff
@rz1.0 in mrr,)r\r6r�r�r%r�r�r�rer�r�r�)rOrQrr�r�rur
rar8r?r@r+r)�__getattribute__r�rY)rrrJrHrqrr�r�s       r>�test_memoryview_check_releasedz1TestBufferProtocol.test_memoryview_check_released/s����K��_�_�_�-�-���q�M�M��	�	�	����	
���*�j�!�4�4�4����*�a�f�c�2�2�2����*�g�q�1�1�1����*�a�h�/�/�/����*�a�i�0�0�0����*�d�J����A�A�A����*�a�m�Q�7�7�7����*�a�m�Q��:�:�:�3�	D�	D�D�
���j�!�*<�d�C�C�C�C�
�K��_�_�_�-�-��
��]�]��
��]�]������R� � � �
�
�
�������B��#�#�#����B��"�"�"�����R� � � � � r_c����d�t�dgd���}t|��}|�||��|�|���|�����t�gdgd���}t|��}|�||��|�|���|�����t�fd�t	d��D��gd	�d
���}t|��}|�||��|�|���|�����t�fd�t	d��D��gd
�d���}t|��}|�||��|�|���|�����t
rjGd�dt
j��}|dd��}t|��}|�|���t|����dSdS)Nr}r�r�r}r,z>hQiLlc���g|]}���Sr�r��r�rvr�s  �r>r�z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>fs���+�+�+�A�a�+�+�+r_r�r�z=hQiLlc���g|]}���Sr�r�r�s  �r>r�z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>ks���,�,�,�A�a�,�,�,r_r�)r�r!r!rkr!z<hQiLlc�2�eZdZdejfdejfgZdS)�;TestBufferProtocol.test_memoryview_tobytes.<locals>.BEPointr]r�Nrmr�r_r>rr�trnr_rr�r&)r
rQr�r8rirrrW)rrrirHrrrJr�s      @r>�test_memoryview_tobytesz*TestBufferProtocol.test_memoryview_tobytesWsR���
)��
�Q�q�c�$�
/�
/�
/���r�N�N������B������������b�j�j�l�l�3�3�3�
�a�S���H�
5�
5�
5���r�N�N������B������������b�j�j�l�l�3�3�3�
�+�+�+�+��r���+�+�+�7�7�7�8�
L�
L�
L���r�N�N������B������������b�j�j�l�l�3�3�3�
�,�,�,�,��s���,�,�,�K�K�K�$�&�&�&���r�N�N������B������������b�j�j�l�l�3�3�3��	8�
H�
H�
H�
H�
H�&�3�
H�
H�
H��G�C��%�%�E��5�!�!�A����Q�Y�Y�[�[�%��,�,�7�7�7�7�7�
	8�	8r_c��|�ttitd��|�ttdt
d��t
gd�dgdg���}|�tt|t
d��t
dd	d
���}dD]J}t|t|��}|�||��|�|d	d���Kt
dd	d
t�
��}dD]J}t|t|��}|�||��|�|d	d���KdD]�}d|d	<t|t
|��}|�||��|�|d	d��d|d	<|�|d	d��|�|d	d����t
dgdgd
t�
��}dD]w}t|t|��}|�t|j
d��|�||��|�|���g���xt
ttd����gd�d
t�
��}dD]O}t|t|��}|�t
|�����ggg���Pt
dgdgdt�
��}dD]h}t|t
|��}|�||��|�|���|������it
gd�dgdt�
��}dD]h}t|t
|��}|�||��|�|���|������it
gd�dgdgt���}dD]�}t|t|��}|�||��|�|���|�����|�t|jdd��|�|dd��|�|dd����|ddd�}dD]�}t|t|��}|�||��|�|���|�����|�t|jdd��|�|dd��|�|dd����t
ttd����ddgt���}dD]_}t|t
|��}|�t
|�����|������`|�tt|t
d��t|t|��}|�t
|�����|�����t
ttd����ddgttz���}dD]_}t|t
|��}|�t
|�����|������`|�tt|t
d��t|t|��}|�t
|�����|�����t
ttd����ddgtt z���}dD]�}|�tt|t
|��t|t|��}|�t
|�����|�������t
gd�dgdg���}t|td��}|�|j��dS)NrzrLr�r�r!r�r{r�r�rr}ryr|rnr,rr6r�rrkrr�r�r�r�r>r�)r�r{)rzr{r�)r�rbr�r�r��PyBUF_WRITEr
r�r'r,r+rar�rir)r�r�r�r�)rrrir�rHs    r>�test_memoryview_get_contiguousz1TestBufferProtocol.test_memoryview_get_contiguouszs��	
���)�^�R��S�I�I�I�	
���+�~�t�[�#�N�N�N��Y�Y�Y�q�c�A�3�
7�
7�
7�����+�~�r�;��L�L�L��Q�b��
-�
-�
-��$�	'�	'�E��r�:�u�5�5�A����Q��#�#�#����Q�r�U�A�&�&�&�&��Q�b��K�
@�
@�
@��$�	'�	'�E��r�:�u�5�5�A����Q��#�#�#����Q�r�U�A�&�&�&�&�%�	)�	)�E��B�r�F��r�;��6�6�A����Q��#�#�#����Q�r�U�A�&�&�&��A�b�E����Q�r�U�B�'�'�'����R��V�R�(�(�(�(��a�S���C�{�
C�
C�
C��$�	-�	-�E��r�:�u�5�5�A����j�!�-��;�;�;����Q��#�#�#����Q�X�X�Z�Z��,�,�,�,�
�T�%��(�(�^�^�9�9�9�S�&�(�(�(��$�	<�	<�E��r�:�u�5�5�A����W�Q�Z�Z�.�.�0�0�2�r�(�;�;�;�;��a�S���C�{�
C�
C�
C��$�	6�	6�E��r�;��6�6�A����Q��#�#�#����Q�X�X�Z�Z������5�5�5�5�
�Y�Y�Y�q�c�#�[�
I�
I�
I��$�	6�	6�E��r�;��6�6�A����Q��#�#�#����Q�X�X�Z�Z������5�5�5�5��Y�Y�Y�q�c�A�3�k�
J�
J�
J��$�	'�	'�E��r�:�u�5�5�A����Q��#�#�#����Q�X�X�Z�Z������5�5�5����i����2�>�>�>����Q�q�T�1�%�%�%����R��U�A�&�&�&�&�
���"��X��$�	'�	'�E��r�:�u�5�5�A����Q��#�#�#����Q�X�X�Z�Z������5�5�5����i����2�>�>�>����Q�q�T�1�%�%�%����R��U�A�&�&�&�&��T�%��)�)�_�_�Q��F�+�
F�
F�
F���	?�	?�E��r�;��6�6�A����W�Q�Z�Z�.�.�0�0�"�)�)�+�+�>�>�>�>����+�~�r�;��L�L�L��2�z�5�1�1���������*�*�,�,�b�i�i�k�k�:�:�:�
�T�%��)�)�_�_�Q��F�&�z�1�3�3�3���	?�	?�E��r�;��6�6�A����W�Q�Z�Z�.�.�0�0�"�)�)�+�+�>�>�>�>����+�~�r�;��L�L�L��2�z�5�1�1���������*�*�,�,�b�i�i�k�k�:�:�:��T�%��)�)�_�_�Q��F�+�f�:L�
M�
M�
M��$�	?�	?�E����k�>�2�{�#�
%�
%�
%��r�:�u�5�5�A����W�Q�Z�Z�.�.�0�0�"�)�)�+�+�>�>�>�>��[�[�[���a�S�
9�
9�
9���2�z�3�/�/�������'�'�'�'�'r_c��tjd��}tjdgd���}t|��}t	j|��}t
d|z��}|�|��|�|�	��|��tjd��}tttd����gd�d���}t|��}t	j|��}t
d|z��}|�|��|�|�	��|��dS)Nrr�r�rr�r�r})
r8r�rOrQ�io�BytesIOr,�readintor�r8r
r�ri)rrrrJrHr0rris       r>�test_memoryview_serializingz.TestBufferProtocol.test_memoryview_serializing�s����s�#�#���K��[�[�[�)�)���q�M�M���j��m�m���a��f�������Q������������a�(�(�(���s�#�#��
�T�%��)�)�_�_�G�G�G�C�
@�
@�
@���r�N�N���j��m�m���e�D�j�!�!�����Q������������a�(�(�(�(�(r_c�	�tttd������}t|��}|�t|��t|����|�dddg���}|�t|��t|����|ddd�}tttd����ddd���}|�t|��t|����tttd����gd�t�	��}t|��}|�t|��t|����tttd����gd����}|ddd
�dd�ddd�f}t|��}|�t|��t|����tttd����gd�t�	��}|ddd
�dd�ddd�f}t|��}|�t|��t|����tttd����dgd
���}t|��}tttd����dgd���}t|��}|�||��|�t|��t|����tttd����gd�d���}t|��}|�
t|j��tttdd����gd�d���}t|��}|�
t|j��tttd����gd�d���}t|��}|�
t|j��tttdd����gd�d���}t|��}|�
t|j��dS)Nr�rrkr>r�r�rr�r�r!r�)r!r�rkrr}rr�rr3r?rz= Lz< h)
rWr�rirQr�r�rur
r�r�r�r��__hash__)	rrrrH�mc�mxrir]rJr�s	         r>�test_memoryview_hashz'TestBufferProtocol.test_memoryview_hash
s���
�$�u�R�y�y�/�/�"�"���q�M�M������a���$�q�'�'�*�*�*��V�V�C��!�u�V�
%�
%������b���4��7�7�+�+�+��t�t��t�W���$�u�R�y�y�/�/�$�$�B�$�'�(�(������b���4��7�7�+�+�+��T�%��)�)�_�_�G�G�G�:�
F�
F�
F���r�N�N������a���$�r�(�(�+�+�+��T�%��)�)�_�_�G�G�G�
4�
4�
4���s�s��s�B�B�B���"��}����q�M�M������a���$�q�'�'�*�*�*��T�%��)�)�_�_�G�G�G�6�
B�
B�
B���s�s��s�B�B�B���"��}����q�M�M������a���$�q�'�'�*�*�*�
�D��r���O�O�B�4��<�<�<���q�M�M���D��r���O�O�B�4��<�<�<���q�M�M������A��������a���$�q�'�'�*�*�*��T�%��)�)�_�_�G�G�G�C�
@�
@�
@���r�N�N�����*�a�j�1�1�1�
�T�%��A�,�,�'�'�w�w�w�s�
C�
C�
C���r�N�N�����*�a�j�1�1�1�
�T�%��)�)�_�_�G�G�G�E�
B�
B�
B���r�N�N�����*�a�j�1�1�1�
�T�%��A�,�,�'�'�w�w�w�u�
E�
E�
E���r�N�N�����*�a�j�1�1�1�1�1r_c
�|�tgd���}t|��}t|��}|�t|j��~|���tgd���}t|��}t|tt���}t|tt���}|�|j	|��|�t|j��~~|���tgd���}t|��}t|��}t|��}|���|�t|j��~|���tgd���}t|��}t|��}t|tt���}t|tt���}|�|j	|��|���|�t|j��~~|���tgd�dgt���}t|��}|�gd�dg���t|��}t|��}|�|�
��|�
����t|��}	|�|	�
��|�
����|�|	�
��|�
����|���|	���|���|�|�
��|�
����~|���|���d�}
td	��}t|��5}|
|��|�|d
td����ddd��n#1swxYwYtt!t#d����gd
�d���}t|tt���}	t|	tt���}|�|j	|��t|��5}|
|��|�|d
d��
��gd�gd�gg��ddd��n#1swxYwYd
tfD�]�}td	��}t|��5}~t|t|���}	t|	��5}~	t|t|���}t|��5}
~|
|
��|
|��|
|��|�|d
td����|�|dtd����|�|
dtd����~
ddd��n#1swxYwY~ddd��n#1swxYwY~ddd��n#1swxYwYtd	��}t|��5}~t|t|���}	t|	��5}~	t|t|���}t|��5}
~|
|��|
|��|
|
��|�|d
td����|�|dtd����|�|
dtd����~~~
ddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwY���td	��}|�t��5t|��5}t|��}|d
td��kddd��n#1swxYwYddd��dS#1swxYwYdS)Nr��r�r&rkr�)r>r�r?r7r6r�r�c�X�t|��5}	ddd��dS#1swxYwYdSr�)rQ)rr�s  r>�catch22z;TestBufferProtocol.test_memoryview_release.<locals>.catch22�sr���A���
�"��
�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
�
s��#�#r�rrIr�r�rr}r,r�)rkr>r�rJr!rK)r,rQr
r�r�rr��ND_REDIRECTr�r\rrr�rar
�ordr�ri)rrrJrHriryrzr�r�r]r�r�rir&rr�s               r>�test_memoryview_releasez*TestBufferProtocol.test_memoryview_releaseIs�	��
�g�g�g�����q�M�M��
�Q�Z�Z�����+�q�y�1�1�1��	�	�	�����g�g�g�����q�M�M���a�
�[�A�A�A���c�-�{�C�C�C���
�
�c�g�q�!�!�!����+�q�y�1�1�1���	�	�	����
�g�g�g����
��]�]��
��^�^��
�R�[�[��
�
�
�������+�r�z�2�2�2��
�
�
�����g�g�g����
��]�]��
��^�^���b��k�B�B�B���c�-�{�C�C�C���
�
�c�g�r�"�"�"�
�
�
�������+�r�z�2�2�2���
�
�
�����W�W�W�Q�C�|�
<�
<�
<��
��^�^��
������A�3��'�'�'�
��^�^���r�N�N����������R�Y�Y�[�[�1�1�1��r�N�N����������R�Y�Y�[�[�1�1�1���������R�Y�Y�[�[�1�1�1�
�
�
����	�	�	����
��������������R�Y�Y�[�[�1�1�1��
�
�
����	�	�	����
	�	�	�
�f����
��]�]�	/�b��G�B�K�K�K����R��U�C��I�I�.�.�.�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/����	/�	/�	/�	/�
�D��r���O�O�7�7�7�3�?�?�?���A�m�;�?�?�?���A�m�;�?�?�?���
�
�a�e�Q����
��]�]�	H�a��G�A�J�J�J����Q�q��s�V�]�]�_�_�	�	�	�9�9�9�/E�.F�G�G�G�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�
��%�#	'�#	'�E��&�!�!�A��A���
�"���B�}�E�B�B�B����]�]��b����=��F�F�F�A�#�A����"���������������������(�(��A���D�	�	�:�:�:��(�(��A���D�	�	�:�:�:��(�(��A���D�	�	�:�:�:����������������������������������������!
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�$�&�!�!�A��A���
'�"���B�}�E�B�B�B����]�]�'�b����=��F�F�F�A�#�A���'�"���������������������(�(��A���D�	�	�:�:�:��(�(��A���D�	�	�:�:�:��(�(��A���D�	�	�:�:�:���B�'�'�'�'�'�'�'�'�'�'�'����'�'�'�'�'�'�'�'�'�'�'�'�'�'�'����'�'�'�'�
'�
'�
'�
'�
'�
'�
'�
'�
'�
'�
'����
'�
'�
'�
'��"
�f����
�
�
�{�
+�
+�	"�	"��A���
"�!��Q�Z�Z���!���D�	�	�!�!�
"�
"�
"�
"�
"�
"�
"�
"�
"�
"�
"����
"�
"�
"�
"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s�?5R�R�R�AU*�*U.�1U.�([
�(Z2�/BZ	�Z2�Z
�Z2�!Z
�"Z2�&[
�2Z6�6[
�9Z6�:[
�
[	�[	�3(`�(`�B!_0	�$`�0_4
�4`�7_4
�8`�;`�`�`�`�`�`"	�%`"	�b1�$)b�
b1�b	�b1� b	�!b1�1b5�8b5c��td�td��D��dgd���}tjdd�td��D����}||fD�]w}t|tt���}t|tt���}t|��}|�|j|��|�|j|��|�|j|��|�||��|�||��|�||��|�|dd�|dd���|�|dd�|dd���|�|dd�|dd���~~|�|dd�|dd�����ydS)	Nc��g|]}d|z��S�r,r�r�s  r>r�z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>�s��1�1�1�!�c�A�g�1�1�1r_r�rr}c��g|]}d|z��Sr�r�r�s  r>r�z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>�s��9�9�9�!�c�A�g�9�9�9r_r�r,rk)	r
rirOr�r�rQr�r\r�)rrrirJr]r�rirHs       r>�test_memoryview_redirectz+TestBufferProtocol.test_memoryview_redirect�s���
�1�1�u�R�y�y�1�1�1�"��c�
J�
J�
J���K��9�9�u�R�y�y�9�9�9�:�:���a��	-�	-�A���-�{�C�C�C�A���-�{�C�C�C�A��1�
�
�A��M�M�!�%��#�#�#��M�M�!�%��#�#�#��M�M�!�%��#�#�#����Q��"�"�"����Q��"�"�"����Q��"�"�"����Q�q��s�V�Q�q��s�V�,�,�,����Q�q��s�V�Q�q��s�V�,�,�,����Q�q��s�V�Q�q��s�V�,�,�,��1����Q�q��s�V�Q�q��s�V�,�,�,�,�#	-�	-r_c�L�d}gd�}|�ttddd��t��}t|��}|�||d|dddgdg|��	�	td��D]}|�|||���~~t��}t|��}~~t��}t|t�	��}t|t�	��}t|��}|�	|j
|��|�	|j
|��|�||d|dddgdg|��	�	~~~~t��}t|tt�
��}t|tt�
��}t|��}|�	|j
|��|�	|j
|��|�	|j
|��|�||d|dddgdg|��	�	~~~~td���}t|��}|�|dd|dddgdg|��	�	td��D]}|�|||���~~td���}t|��}~~td���}t|t�	��}t|t�	��}t|��}|�	|j
d��|�	|j
|��|�||d|dddgdg|��	�	~~~~td���}t|tt�
��}t|tt�
��}t|��}|�	|j
d��|�	|j
|��|�	|j
|��|�||d|dddgdg|��	�	~~~~dS)Nr)rr,r!rkr>r�r?r7r6r�rnr�r,r!rkTr�rr�r�)�legacy_mode)r�rb�staticarrayrQr�rir�r
r�r�r\r�)rrr;rjr]r�rrirHs        r>�$test_memoryview_from_static_exporterz7TestBufferProtocol.test_memoryview_from_static_exporter�sN����)�)�)��	
���)�[�!�Q��:�:�:�
�M�M���q�M�M�����A�1��C�$��2�$����	�	�	�	��r���	&�	&�A����Q�q�T�1�%�%�%�%�
�
��M�M���q�M�M��
�
��M�M���A�m�,�,�,���A�m�,�,�,���q�M�M���
�
�a�e�Q�����
�
�a�e�Q�������A�1��C�$��2�$����	�	�	�	�
�q�!�Q��M�M���A�m�;�?�?�?���A�m�;�?�?�?���q�M�M���
�
�a�e�Q�����
�
�a�e�Q�����
�
�a�e�Q�������A�1��C�$��2�$����	�	�	�	�
�q�!�Q�
�D�)�)�)���q�M�M�����A�4��C�$��2�$����	�	�	�	��r���	&�	&�A����Q�q�T�1�%�%�%�%�
�
��D�)�)�)���q�M�M��
�
��D�)�)�)���A�m�,�,�,���A�m�,�,�,���q�M�M���
�
�a�e�T�"�"�"��
�
�a�e�Q�������A�1��C�$��2�$����	�	�	�	�
�q�!�Q��D�)�)�)���A�m�;�?�?�?���A�m�;�?�?�?���q�M�M��	
�
�
�a�e�T�"�"�"��
�
�a�e�Q�����
�
�a�e�Q�������A�1��C�$��2�$����	�	�	�	�
�q�!�Q�Q�Qr_c��tgd�dgttz���}|�tt
|��dS)Nr�rkr�)r
r��ND_GETBUF_UNDEFINEDr�r�rQr�s  r>�#test_memoryview_getbuffer_undefinedz6TestBufferProtocol.test_memoryview_getbuffer_undefined?sB���W�W�W�q�c��8K�)K�
L�
L�
L�����+�z�2�6�6�6�6�6r_c�|�tgd�dgt���}|�tt|��dS)Nr�rkr�)r
r�r�r�rQ)rrr]s  r>�test_issue_7385z"TestBufferProtocol.test_issue_7385Es:���G�G�G�A�3�n�=�=�=�����+�z�1�5�5�5�5�5r_c��dD]<}|�tj|��tj|�����=dS)N)r@�ii�3s)r��	_testcapi�PyBuffer_SizeFromFormatr8r�)rrr%s  r>�test_pybuffer_size_from_formatz1TestBufferProtocol.test_pybuffer_size_from_formatIsT��'�	6�	6�F����Y�>�v�F�F�#�_�V�4�4�
6�
6�
6�
6�	6�	6r_N�F)Ur�r�r�rsr�r�r�rrrrrrr#r-r/r1r6r9r=rArIrKrTrVr^rarjrnr{r}r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�rrr&r*r0�
contextlib�contextmanagerr6rFrSrVrdrrr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��cpython_onlyr�r�r_r>rmrm�sW������1�1�1�"'�U�H�H�H�H�H�T.,�.,�.,�.,�`g<�g<�g<�R\=�\=�\=�|��� $�$�$�
'�
'�
'�3�3�3�*=�=�=�+)�+)�+)�Z%L�%L�%L�N6�6�6�4E�E�E�..�..�..�`,1�,1�,1�\H�H�H�>-�-�-�&W7�W7�W7�r<�<�<�(D�D�D�@!@�!@�!@�F4/�4/�4/�l>�>�>�B'0�'0�'0�R3�3�3�8<E�<E�<E�|(�(�(�I�I�I�&;�;�;�/�/�/�
$�$�$�>�>�>�2�2�2�
0�
0�
0�#7�#7�#7�Jn8�n8�n8�`sQ�sQ�sQ�j-�-�-�$�'�L�?�?�?�62�62�62�p5�5�5�q@�q@�q@�f:.�:.�:.�xR0�R0�R0�h9�9�9�<3�3�3�A�A�A���I�I���I�3A�3A�3A�jkI�kI�kI�Z6&�6&�6&�p<?�<?�<?�|3=�3=�3=�j=!�=!�=!�~F+�F+�F+�P���4���4(�(�(�8<�<�<�|F�F�F�P_"�_"�_"�B"�"�"�4���6���B&�&�&�:&!�&!�&!�P!8�!8�!8�Fs(�s(�s(�j)�)�)�<:2�:2�:2�x~"�~"�~"�@-�-�-�0\�\�\�|7�7�7�6�6�6�
��6�6���6�6�6r_rm�__main__)r
NN)r�r4r�)r�r4r�r�r�rA)ir��unittest�testr�test.supportr�	itertoolsrr�randomrrr	�warningsrfrOr��os�decimalr
�	fractionsr�_testbuffer�ImportErrorr
r8r�EnvironmentVarGuard�environ�catch_warningsrPr/r��
SHORT_TEST�NATIVEr9r:�STANDARDr?rVr;�copyr��ARRAYr<�BYTEFMTrprrror^rgrkrzr|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
rrr r"r(r1r<rFrHrLrPr�rYr]rjr`rdre�
skipUnless�TestCasermr��mainr�r_r>�<module>rs��� ��������������"�"�"�"�"�"�+�+�+�+�+�+�+�+�,�,�,�,�,�,�,�,�,�,���������������������������������������������G�G�G�������M�M�M�M������
�F�F�F�������M�M�M�M������
�F�F�F������	&��	&�	(�	(�1�B�J�	 ��	 �	"�	"�1�1�0�0�0�0�0�0�1�1�1�1�1�1�1�1�1�1�1����1�1�1�1�1�1�1�1�1�1�1�1�1�1�1����1�1�1�1��������K�K�K�����������������I�I�I������
�	
�q�a�Q�	�q�a�Q�	�q�a�Q�	�q�a�	
�
�����s���s��	�
�
����C��!�!�!���s����s�����<�
�
�
���
����
	�y��y��z��z��z��z��!�T�'�
�A�t�G�4�������*������
���
�3��s�|�3�3��-�-�c�2�2����S���
�[�[�]�]�
����
�
��	���A������!�H��
�+�+�-�-��	���A���:�:��A�J���������
������������
�	����.�.�.�0C�0C�0C�D�����5�����5������5������5����
�
�
� -�-�-�����������0�0�0�0�(�(�(�(�2�2�2�$�$�$�E�D�g�c�l�D�D�D��%�%�%�!�!�!�
�
�
�
�
�
����������
���
���
���
�
�
�0�0�0����C�C�C�I�I�I����,
�
�
�2�2�2�<?�?�?�4���

�
�
����=:�=:�=:�=:�~
�
�
�
*�
*�
*�):�):�):�):�V9�9�9�;�;�;�;�1�1�1�@�@�@�@�B	8�	8�	8� C�C�C����
0�0�0�0�%�%�%�%�
	3�	3�	3�	3�!�!�!�!�
���&�
�	
��
��
� ��J�
�F��H��I�!�N��L����V�D�E�E����W�E�F�F�P96�P96�P96�P96�P96��*�P96�P96�G�F�F�E�P96�fr�z����H�M�O�O�O�O�O��s��A
�
A�A�A � A*�)A*�.A3�3A=�<A=�C�C�%B8�,C�8B<	�<C�?B<	�C�C�C�C�C�C�C%�$C%�)C.�.C8�7C8�D6�6
E�E