
    ;e<                    l   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ 	 d dlT n# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY w	  ej                    5 e_         ej                    5  d d	lmZ ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   n# e$ r dZY nw xY w	 d dl Z n# e$ r dZ Y nw xY wd
Z!d d d d d d d d d d d d d d d dZ"ere"d= e"d= er-	  ej#        dd           d e"d<   d e"d<   n# ej$        $ r Y nw xY wdddddddddddddddz   ddz  fdZ%d Z&e"e"e%e%e%e%dZ'ere'd         D ]Z( e&e(          e'd         e(<   e")                                Z*e")                                Z+e"D ]	Z,e,d vre+e,= 
e")                                Z-e"D ]	Z,e,d!vre-e,= 
e*e'd"<   e*e'd#<   e+e'd$<   e-e'd%<   e-e'd&<   d Z.dZ/g dg d'fd$gd(gfd(gd(gfd#d"gd(gfd&d%gd(gfd)Z0d* Z1d+ Z2d, Z3d- Z4dhd/Z5d	d0Z6d	d1Z7d2 Z8d3 Z9d4 e'd         D             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_Z ejd        edc           ejd        edd           G de dfeje                                          Zfegdgk    r ejh                     dS dS )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Pr   r   Q    qr      r      )i   )i    )r   i   )           )r   l        l                     r                    )r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                     | dk    rd}nr| dk    rd}ni| dk    rd}n`| dk    rdd	z   dd	z  f}nNd
D ]4}	 t          j        | d|z  dz
              n# t           j        $ r Y 1w xY w|dz  rd|z   d|z  fndd|z  f}|S )zReturn range of a native type.r   r"   r   r    r   r(   r   r,   r-   )
r$      @   ?                      r   )structpackerror)fmtlhexps      '/usr/lib/python3.11/test/test_buffer.pynative_type_ranger?   _   s    
czz			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                 $   t          t          |          |          }|dk    rt          |g          }|dk    r|dk    rd}|dk    rt          |          }|dk    s|dk    r0t	          j        ||          }t	          j        ||          d         }|S )	zWReturn random item for a type specified by a mode and a single
       format character.r   rP          r   r   r   r   )r   fmtdictbytesboolr8   r9   unpack)modecharobjxs       r>   randrange_fmtr^      s     	74=&'As{{1#JJ'>>a7llAs{{GGs{{dckkKa  M$""1%H    c                     |                      d          \  }}g }|D ]&}|                    t          |||                     't          |          dk    r|d         nt	          |          S )zReturn single random item.#r,   r   )splitappendr^   lentuple)r;   r\   rZ   charsr]   r   s         r>   gen_itemrg      sl    ))C..KD%
A . .	tQ,,----q66Q;;1Q44E!HH,r_   c                     | dk    rt          ||          S dg| z  }t          |           D ]}t          ||          ||<   |S )z,Return a list of random items (or a scalar).r   )rg   range)r   r;   r\   lstr   s        r>   	gen_itemsrk      sU    AvvS!!!#'C1XX $ $#s##AJr_   c                    t          t          |         t                             }|dz   }|                    d          }t	          dd          }t          |          D ]o}t          t          t          |                             }t          t          |         t                             }||t          |r|nd          z  z  }|||z   z  }pt          | ||          }	t          ||          }
||	|
fS )Nra   ambr!   
   r,   )r	   capMODEstripr   ri   re   rV   MULTintrk   rg   )r   r\   rZ   xfmtr;   nmemb_r[   
multiplieritemsitems              r>   struct_itemsrz      s    #c(4.!!D#:D
**U

CaE5\\ # #eGDM**++CHTN++
*;JJ!<<<=
T!"as##ED#Dtr_   r   c                    |%t          t          |         t                             }|'t          t          t          |                             }t          t          |         t
                             }|dz   |t          |r|nd          z  z   }t          | ||          }t          ||          }|	                    d          |z   |z   }|||fS )z"Return random format, items, item.Nra   r,   rm   )
r	   ro   rp   re   rV   rr   rs   rk   rg   rq   )r   r\   rZ   r[   rw   r;   rx   ry   s           r>   	randitemsr|      s    |c#htn%%|eGDM**++C''J
*tc
"A**BBB
BCac""ECD
**U

j
(4
/Ctr_   c              #      K   t           |         t                   D ]&}t          |         D ]}t          | |||          V  'dS )z1Iterate through supported mode/char combinations.N)ro   rp   rV   r|   )r   r\   rZ   r[   s       r>   	iter_moder~      s\      C 0 0DM 	0 	0DAsD$//////	00 0r_   c              #   l   K   t          | |          D ]}|V  |dk    rdS t          | |          V  dS )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       vw''  )
vw
'
''''''r_   c                     d| v pd| v pd| v S )Nr   r   r    )r;   s    r>   is_byte_formatr      s    #:11scz1r_   c                 t    t          |           }|dk    s|dk    o| d         dk    o| |dz
           t          v S )zformat suitable for memoryviewr,   r!   r   rA   )rd   
MEMORYVIEW)r;   r]   s     r>   is_memoryview_formatr      sD    CA!V1Q03q6S= #!H
"$r_   c                 0    g | ]}t          |          |S r   )r   .0r   s     r>   
<listcomp>r      s%    DDD.2C2CD1DDDr_   c                 .    t          | t                     S )z9Tuple items (representing structs) are regarded as atoms.
isinstancelistrj   s    r>   atompr      s    #t$$$$r_   c                 ,    t          | t                    S Nr   r   s    r>   listpr      s    c4   r_   c                 d    t          |           dk    rdS | d         }| dd         D ]}||z  }|S )zProduct of list elements.r   r,   N)rd   )rj   r]   vs      r>   prodr      sF    
3xx1}}qAAW  	QHr_   c                 H   | dk    rdS |dk    rLt          |dd                   |gz   }t          | dz
  dd          D ]}||xx         ||dz            z  cc<   nG|gt          |dd                   z   }t          d|           D ]}||xx         ||dz
           z  cc<   |S )zOCalculate strides of a contiguous array. Layout is 'C' or
       'F' (Fortran).r   r   Cr,   Nr!   )r   ri   )ndimshapeitemsizelayoutstridesr   s         r>   strides_from_shaper     s     qyyr}}uQRRy//XJ.tAvr2&& 	' 	'AAJJJ'!A#,&JJJJ	' *tE#2#J///q$ 	' 	'AAJJJ'!A#,&JJJJNr_   c                 @   t          |           r| S t          |          dk    r| d         S dg|d         z  }|d         rt          |           |d         z  nd}t          |d                   D ]-}||z  }t          | |||z            |dd                   ||<   .|S )zmConvert flat item list to the nested list representation of a
       multidimensional C array with shape 's'.r   r,   N)r   rd   ri   _ca)rx   srj   strider   starts         r>   r   r     s     U|| 
1vv{{Qx#!*C#$Q4.SZZ1Q4QF1Q4[[ 7 7&U5v-.!""66AJr_   c                     t          |           r| S t          |          dk    r| d         S dg|d         z  }|d         }t          |d                   D ]&}t          | |d|         |dd                   ||<   '|S )zsConvert flat item list to the nested list representation of a
       multidimensional Fortran array with shape 's'.r   Nr,   )r   rd   ri   _fa)rx   r   rj   r   r   s        r>   r   r   %  s     U|| 
1vv{{Qx#!*CqTF1Q4[[ . .U19f9%qu--AJr_   c                     t          |           r3d|vr/t          |          t          |           k    rt          d          t	          | |          S Nr   zprod(shape) != len(items))r   r   rd   
ValueErrorr   rx   r   s     r>   carrayr   2  M    U|| 6AJJ4;;#e**+D+D4555uer_   c                     t          |           r3d|vr/t          |          t          |           k    rt          d          t	          | |          S r   )r   r   rd   r   r   r   s     r>   farrayr   7  r   r_   c                 ,    d | D             }t          | S )z(Generate all possible tuples of indices.c                 ,    g | ]}t          |          S r   ri   r   r   s     r>   r   zindices.<locals>.<listcomp>>  s    )))aq)))r_   )r   )r   	iterabless     r>   indicesr   <  s     ))5)))IIr_   c                 V    d}t          |           D ]}|||         ||         z  z  }|S )zAConvert multi-dimensional index to the position in the flat list.r   r   )r   indr   retr   s        r>   getindexr   A  s:    
C4[[ # #wqzCF""Jr_   c                 <   |s| S t          |          }t          ||dd          }t          ||ddd         dd          }dgt          |           z  }t          |          D ]8}t          |||          }t          ||ddd         |          }| |         ||<   9|S )zTranspose 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   )rd   r   r   r   )	srcr   r   sstridesdstridesdestr   frtos	            r>   	transposer   H  s      
u::D!$q#66H!$dddQ<<H3S>Du~~  dC**dC"Ix00r7RKr_   c                     | g k    r| S t          |           r| gS t          | d                   t          | dd                   z   S )zflatten listr   r,   Nr   _flattenr   s    r>   r   r   W  sL    
byy
Szz uCFhs122w////r_   c                 B    t          |           r| S t          |           S )zflatten list or return scalarr   r   s    r>   flattenr   _  s!    Szz 
C==r_   c                     t          |           rg S t          | |d                            gt          | d         |dd                   z   S )zMGet the shape of lst after slicing: slices is a list of slice
       objects.r   r,   N)r   rd   slice_shaperj   slicess     r>   r   r   e  sK     Szz 	F1I ;s1vvabbz#B#BBBr_   c                 Z    t          |           r| S fd| d                  D             S )z=Multi-dimensional slicing: slices is a list of slice objects.c                 @    g | ]}t          |d d                   S r,   N)
multislice)r   sublstr   s     r>   r   zmultislice.<locals>.<listcomp>p  s+    HHHvJvvabbz**HHHr_   r   )r   r   s    `r>   r   r   l  s8    Szz 
HHHHVAYHHHHr_   c                     t          |          r|S fd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          ||d d         d d                   (S r   )m_assign)r   r   rlslicesrslicess      r>   r   zm_assign.<locals>.<listcomp>  sQ     A A A1 Q7122;44 A A Ar_   r   )r   zipllstrlstr   r   s     ``r>   r   r   r  s}     T{{ A A A A AD,d71:.>??A A ADDKr_   c                    t          | |          }t          ||          }t          |          t          |          k    rdS t          t          |                    D ]&}||         ||         k    r dS ||         dk    r dS 'dS )z9Compare the structure of llst[lslices] and rlst[rslices].r   r   )r   rd   ri   )r   r   r   r   lshapershaper   s          r>   cmp_structurer     s    w''Fw''FFs6{{""r3v;;  !9q	!!22!9>>11 1r_   c                 p    t          | |||          dk     rt          d          t          | |||          S )z:Return llst after assigning: llst[lslices] = rlst[rslices]r   z+lvalue and rvalue have different structures)r   r   r   r   s       r>   multislice_assignr     s>    T4'22Q66FGGGD$111r_   c                 p   |z  rdS |dk     s	|z   | k    rdS t          fdD                       rdS |dk    r|dk    o o S dv rdS t          fdt          |          D                       }t          fdt          |          D                       }d||z   k    o||z   z   | k    S )zVerify 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
    Fr   c              3   "   K   | ]	}|z  V  
d S r   r   r   r   r   s     r>   	<genexpr>z#verify_structure.<locals>.<genexpr>  s'      
)
)A1x<
)
)
)
)
)
)r_   Tc              3   X   K   | ]$}|         d k    |         |         dz
  z  V  %dS r   r,   Nr   r   jr   r   s     r>   r   z#verify_structure.<locals>.<genexpr>  sI       # #1!*// qz58A:&!///# #r_   c              3   X   K   | ]$}|         d k    |         |         dz
  z  V  %dS r   r   r   s     r>   r   z#verify_structure.<locals>.<genexpr>  sI       " "1!*q.. qz58A:& ..." "r_   )anysumri   )memlenr   r   r   r   offsetiminimaxs    ` ``   r>   verify_structurer     s0     uzzVH_v--u

)
)
)
)
)
)
))) uqyyqy6Y6w;6Ezzt # # # # #d # # # # #D " " " " "d " " " " "D t>tH 4 >>r_   c                      |D ]
}| |         } | S r   r   )rj   r   r   s      r>   get_itemr     s!      !fJr_   c                 h    |\  }}}}}}|}t          |          D ]}	|||	         | |	         z  z  }|S )z-Location of an item in the underlying memory.r   )
r   r   r   r   r   r   r   r   pr   s
             r>   memory_indexr     sL    562FHdE7FA4[[ # #	WQZ
""Hr_   c                     | \  }}}}}}d|z  }t          |          D ]$}t          ||           }	d|	z  }
||
z  r dS ||
z  }%dS )zThe 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2FHdE7FiGu~~  a  dS= 	4435r_      r4   r   c                 n   st          |dz             }|dk    r?|r| | |dddfS t          dd          }|| z  }t          d          dk    r|  n|}|| |dd|fS d}	t          d          }
|
dk    r|rd}	n|
dk    rd}	dg|z  t          |          D ]}t          |	|dz             |<   nt                    }d	}t          d          }
|
dk    r|
dz  rd
nd}dg|z  | t          | |dz             z  |dz
  <   |s|dz
           dk    r| |dz
  <   t          |dz
  dd          D ]i}||dz            r|dz            ndz  }|r| t          | |dz             z  |<   :dt          d                   | z  t          d|dz             z  |<   jdx}}dvrRt          fdt          |          D                       }t          fdt          |          D                       }||z
  }|r| | z  }||dz   | z  z   }n$| |z   | z  }t          d          dk    r| | z
  n|}|| ||fS )zReturn 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,   r   r      r!   d   _   Z   r   TFr   r,   r   c              3   X   K   | ]$}|         d k    |         |         dz
  z  V  %dS r   r   r   s     r>   r   z!rand_structure.<locals>.<genexpr>  sI       ' 'qajAoo 1:uQxz*%ooo' 'r_   c              3   X   K   | ]$}|         d k    |         |         dz
  z  V  %dS r   r   r   s     r>   r   z!rand_structure.<locals>.<genexpr>  sI       & &qaj1nn 1:uQxz*$nnn& &r_   )r   ri   rd   r   )r   validmaxdimmaxshaper   r   r   r   r   minshaper   r   	maxstridezero_strider   r   r   s       `           @r>   rand_structurer
    s.     ""AII >4R::"1d++(*&/lla&7&7(Vxr2v==cNN77u7HH"WWHd
t 	7 	7A 8A:66E!HH	7 5zzI#Ar''a!e'$$KcDjGI:y{!C!CCGDFO #746?a//"Q462r"" @ @51:4U1Q3ZZ14	 	@!Iyj)A+$F$FFGAJJ 1."#%.q)A+%>%>?GAJJ OD4:: ' ' ' ' 'E$KK ' ' ' ' ' & & & & &E$KK & & & & & D[F A!46X--%$,(*#,Q<<1#4#4$x&8T5'699r_   c                     || z
  }t          |dz             }| r||z
  | z  nd}t          d|dz             }|| |z  z   }t          |||          }t          ||          \  }}}}	|	| k    rt          |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hqj!!E/7>w8++QGQ	""D8d?"DeT4  A$Q00Aq!W(Hr_   c                    dg| z  }dg| z  }t          |           D ]K}||         }|dk    rt          d|dz             nd}t          ||          ||<   t          ||          ||<   Lt          |          t          |          fS )zxCreate two sets of slices for an array x with shape 'shape'
       such that shapeof(x[lslices]) == shapeof(x[rslices]).r   r,   )ri   r   r  re   )r   r   r   r   r   r   r  s          r>   randslice_from_shaper  4  s     cDjGcDjG4[[ : :!H()A9Q!$$$1,Xq99
,Xq99

>>5>>))r_   c                 ~   t          d| dz             }d}t          d          }|dk    rd}n|dk    rd}t          d          dk    rdnd	}dg|z  }dg|z  }dg|z  }dg|z  }	t          |          D ])}t          ||dz             }
t          ||dz             }||
k     r|
|}
}|rxt          |
 |
dz             }t          |
 |
dz             }d
t          d                   t          d|
dz             z  }t          |||          }t          ||
          \  }}}}n+|
dk    rt          d|
dz             nd}t	          ||
          }t	          ||          }t          d          dk    r||
c||<   ||<   ||c|	|<   ||<   |
|c||<   ||<   ||c|	|<   ||<   +||t          |          t          |	          fS )zCreate (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   r   r   P   TFr  )r   ri   r  r  r  re   )r  r  r   r  r   
all_randomr   r   r   r   smallbigr   r  r  s_smallrv   r  s_bigs                      r>   rand_aligned_slicesr   @  s    Qq!!DH#ABww	
b"32--5JSXFDvc$hG1#d(4[[ 4 4(HQJ//(1*--;;C  	?ufeAg..EeVU1W--D)A,,')AuQw*?*??DE4..G -gu = =Aq!XX05		yE!G,,,qH-h>>G (#66Q<<1#& F1Ivay%*G"GAJ

#(# F1Ivay%,e"GAJ

65>>5>>99r_   c                 B    |\  }}}}}}t          ||z  d| z   d          S )zMReturn a list of random items for structure 't' with format
       'fmtchar'.ra   rP   )rk   )r;   r   r   r   rv   s        r>   randitems_from_structurer"  k  s1     $% FHaAqVX%s3w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)
rx   r;   r   r&  r   r   r   r   r   r   s
             r>   ndarray_from_structurer(  q  s=    562FHdE7F5ws E(9; ; ; ;r_   c                     |\  }}}}}}t          |          }	t          |           D ]\  }
}t          j        ||	|
|z  |            t	          |	||||          S )z>Return numpy_array from the tuple returned by rand_structure())bufferr   r   dtyper   )	bytearray	enumerater8   	pack_intonumpy_array)rx   r;   r   r   r   r   r   r   r   bufr   r   s               r>   numpy_array_from_structurer1  w  s|    562FHdE7F
F

C%   2 21c1X:q1111c 1 1 1 1r_   c                    | j         }|rt          |          z  |k    rd|fS n<|g k    r| j        dk    s|k    rd|fS n t          |          \  }}|g}|dk    rd|fS |                                 fdt          dt                              D             }g }|D ]>}	t          j        ||	          d         }
|
|
k    rd|fc S |	                    |
           ?|g k    r||fn	|d         |fS )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).Nr   c                 *    g | ]}||z            S r   r   )r   r   r   mems     r>   r   zcast_items.<locals>.<listcomp>  s&    IIIqQqz\"IIIr_   nan)
nbytesr   r   divmodtobytesri   rd   r8   rY   rc   )exporterr;   r   r   bytelenr   r   	byteitemsrx   r   ry   r4  s     `        @r>   
cast_itemsr<    sN    oG 
;;!W,,; -	"=AW!4!4; "5 gx((166;




CIIIIIE!SXXx,H,HIIIIE  }S!$$Q'4<<%<T"b[[E5>>uQx.??r_   c               #   J  K   t          d          D ]} | gV  t          dd          }t          d          dk    rdndfdt          |          D             V  t          dd          }t          d          dk    rdndfd	t          |          D             V  d
S )z Generate shapes to test casting.r2         r   r  r,   r!   c                 0    g | ]}t          d           S r   r   r   rv   r  s     r>   r   z!gencastshapes.<locals>.<listcomp>  #    
7
7
7a9Xq!!
7
7
7r_   c                 0    g | ]}t          d           S rA  rB  rC  s     r>   r   z!gencastshapes.<locals>.<listcomp>  rD  r_   N)ri   r   )r   r   r  s     @r>   gencastshapesrF    s      2YY  c				Q??DcNNR''qqQH
7
7
7
75;;
7
7
7777Q??DcNNR''qqQH
7
7
7
75;;
7
7
777777r_   c           	          t          t          |  | dz             t          |  | dz             t          |  | dz                       S )z4Generate all possible slices for a single dimension.r,   )r   ri   )r   s    r>   	genslicesrH    s>    5!QqS>>5!QqS>>5!QqS>>BBBr_   c                 L    fdt          |           D             }t          | S )z/Generate all possible slice tuples for 'shape'.c                 :    g | ]}t          |                   S r   )rH  r   r   r   s     r>   r   z"genslices_ndim.<locals>.<listcomp>  s%    :::58$$:::r_   )ri   r   )r   r   r   s    ` r>   genslices_ndimrL    s-    ::::eDkk:::IIr_   Fc                 `    |s| dk    rdnd}t          || dz             }t          ||           S )zGenerate random slice for a single dimension of length n.
       If zero=True, the slices may be empty, otherwise they will
       be non-empty.r   r,   )r   r  )r   allow_emptyminlenr  s       r>   rslicerP    s=     .aQQQF1%%H"8Q///r_   c              #   R   K   t          d          D ]}t          | |          V  dS )z.Generate random slices for a single dimension.r   N)ri   rP  )r   rN  rv   s      r>   r   r     s>      1XX % %Q$$$$$$% %r_   c              #   L  K   t          |          D ],}t          fdt          |           D                       V  -t          |          D ],}t          fdt          |           D                       V  -t          d t          |           D                       V  dS )z)Generate random slice tuples for 'shape'.c              3   B   K   | ]}t          |                   V  d S r   rP  rK  s     r>   r   zrslices_ndim.<locals>.<genexpr>  s/      ::F58$$::::::r_   c              3   F   K   | ]}t          |         d           V  dS )T)rN  NrT  rK  s     r>   r   zrslices_ndim.<locals>.<genexpr>  s4      LL1F58666LLLLLLr_   c              3   8   K   | ]}t          d dd           V  dS r   )r  r   rv   s     r>   r   zrslices_ndim.<locals>.<genexpr>  s,      22a!222222r_   N)ri   re   )r   r   
iterationsrv   s    `  r>   rslices_ndimrY    s       : ; ;::::eDkk:::::::::: M MLLLLdLLLLLLLLL
22eDkk222
2
222222r_   c              #      K   t          |           }|t          |          n|}t          t          ||                    V  d S r   )re   rd   r   )iterabler   pools      r>   rpermutationr]    sF      ??DYD			AA
tQ
 
      r_   c                    	 |                                  }n+# t          t          f$ r |                                 }Y nw xY wt	          | t
                    r| j        }| j        }nd}d}t          d|d| j	        d| j
        d| j        d|d| j        d| j        d	|d
           t          j                                         dS )zPrint ndarray for debugging.unknownzndarray(z, shape=z
, strides=z, suboffsets=z	, offset=z
, format='z', itemsize=z, flags=)N)tolist	TypeErrorNotImplementedErrorr8  r   r   r   r&  printr   r   
suboffsetsr%  r   sysstdoutflush)ndr]   r   r&  s       r>   ndarray_printrj    s    IIKK*+   JJLL"g 	E11bhhh


BMMM666999bkkk555* + + + Js    %??r   rn      r>  z%struct module required for this test.z%ndarray object required for this testc                   (   e Zd Zd ZddddZdQdZd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  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 Z4e5j6        d3             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*jS        dO             ZTdPS )RTestBufferProtocolc                 ,    t                      | _        d S r   )get_sizeof_void_psizeof_void_pselfs    r>   setUpzTestBufferProtocol.setUp   s    .00r_   F)slicedcastc       
         :   	
%&'( rt                    z  'nst          	          'n'd(j        r                     d           d}t	          d          D ]4}|         dk    r n%|         dk    r||          |         dz
  z  z  }5|gd t	          dz
            D             z   ( j        }d         dk     r| }|gt          dd                    z                        j        |            	                    j
        '            	                    j                    	                    j                                        j        |            	                    j                    	                    j        t!                               
r(s( 	                    j        t!                                	                    j        t!          (                     t%          t&                    st)                    r@r                                n                                } 	                    |	           sd S |st/                      }d }t1                    D ]}	 t3          |          }t5          	|          }t%          |t                     rt7          j        g|R  }nt7          j        |          }|                    |           n# t<          $ r d}Y  nw xY w 	                    ||           |s' 	                                                    |           t?                    }d                     d |D                       } 	                    |!                                |           rnd}tE          	          }d	D ]}}|d
k    rItG          d          rtG          d          r(tI          |          }t'          ||tJ                    }n8tG          d          rtG          d
          r|dk    rt'          ||          }tM          tN          |          % 	                    %                                |            (                    tS          %|                     dk    rt          |          }|rdntT          }tW          dtX                    % 	                    t          %          |z             %fdt	          |          D             }t          |d                   dk    rd |D             }t'          ||          }  	                    t?          |           t?                               t?                                                    }! 	                    |!%           t?                                        d           }! 	                    |!%           t?                                        d          }! 	                    |!%           tW          d
tX                    % 	                    t          %          |z             %fdt	          |          D             }t          |d                   dk    rd |D             }t'          ||tJ          z            }  	                    t?          |           t?                               t?                                        d
          }! 	                    |!%           tW          dtX                    % 	                    t          %          |z             %fdt	          |          D             }t          |d                   dk    rd |D             }tG          d
          rtJ          nd}"t'          ||"|z            }  	                    t?          |           t?                               t?                                        d          }! 	                    |!%           t)                    r	 t?                    }n# t<          $ r Y d S w xY wt%          t>                    rj        n&|f&'	 
(fd	}# |#|           |-                                5 }$ |#|$d           d d d            n# 1 swxY w Y   |                                 d S d S )Nr   r   r,   c                     g | ]}d S )r   r   r   s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>  s    (C(C(C(C(C(Cr_   Tr@   c              3       K   | ]	}d |z  V  
dS )z%02xNr   r   s     r>   r   z,TestBufferProtocol.verify.<locals>.<genexpr>U  s&      221FQJ222222r_   r   r   FArz  r{  r   r   r%  r&  r   r%  c                 B    g | ]}t          j        |z            S r   r8   unpack_fromr   r   contigr;   r   s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>  <     6 6 6#$  &1#vqzJJ 6 6 6r_   c                     g | ]
}|d          S r   r   r   s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>      "9"9"9A1Q4"9"9"9r_   r   r&  r%  orderc                 B    g | ]}t          j        |z            S r   r  r  s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>  r  r_   c                     g | ]
}|d          S r  r   r   s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>  r  r_   c                 B    g | ]}t          j        |z            S r   r  r  s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>  r  r_   c                     g | ]
}|d          S r  r   r   s     r>   r   z-TestBufferProtocol.verify.<locals>.<listcomp>  r  r_   c                 d                        | j                                       | j                                       | j                                       | j                                       | j        |                               | j        	                               | j        t                               rs(                    | j
        t                                                   | j        t                               	dk    rdnt                    }                    t          |           |           r
                                n
                                }                    |                               | 
           d S )Nr   r,   )assertIsr\   assertEqualr6  r   r%  readonlyr   r   re   r   re  rd   ra  r8  )rH   expected_readonlyr   repexexpected_lenr;   r   rj   r   resultrr  r   rt  r   re  s       r>   check_memoryviewz3TestBufferProtocol.verify.<locals>.check_memoryview  s   aeR(((  <888  X666  3///  ->???  ...  %,,777 @: @$$QYg???  uZ/@/@AAAAAC  Q+++),Bfmmooo&..2B2B  c***  F+++++r_   )r  ).r   rd   re  assertGreaterri   rp  r   r  r\   r  r6  r   r%  r  r   r   re   r   r   r   r   ra  r8  r,  r   get_pointerr   r8   r9   extendBufferErrorrQ   joinhexr   is_contiguousr   
ND_FORTRANget_contiguous
PyBUF_READ
assertTrue
cmp_contigr'  py_buffer_to_contiguousPyBUF_FULL_RO
toreadonly))rr  r  r\   r   r;   r  r   r   r   rj   rt  ru  
suboffset0r   stride0r  r   buf_errr   item1item2r]   rH   r   ff	flattenedr  expectedtransru   roinitlstycontig_bytesr   r  mmr  r  r  re  s)   `` `` `````                          @@@@r>   verifyzTestBufferProtocol.verify  s
   
  	(;;x/LL ("3xx' 
 	4tQ'''J1d^^ = =8q==E1:??71:+q!"<<J$(C(CU46]](C(C(CCJ (GqzA~~"(i$wqrr{"3"33Gfj#&&&555(333,,,fox000d+++uU||444 	=: 	=V^U7^^<<<*E*,=,=>>>fg&& 	'*>s*C*C 	'%(>&--///fnn.>.>CS#&&& 	F  o	;AGu~~ / /
'44E$S#..E!%// 4"K4e444"KU33HHQKKKK"   "GEE   .... ^;  !1!11555 v&&GG2222222  !,,,  (SSS#CLL	
 - M; M;E%H||,VS99 A(55A %.i$?$?E'.uE"5?(A (A (AH  -VS99 R(55R:?3,,'.yb'Q'Q'QH+FJFFF$$V^^%5%5q999OOJvx$@$@AAAqyy 	NNE&7KB 5VS-PPF$$S[[%(2BCCC6 6 6 6 6 6(-e6 6 6G71:!++"9"9"9"9"9uBsKKKA$$Z]]Jv4F4FGGG#-f#5#5#=#=#?#?L$$\6:::#-f#5#5#=#=D#=#I#IL$$\6:::#-f#5#5#=#=C#=#H#HL$$\6::: 5VS-PPF$$S[[%(2BCCC6 6 6 6 6 6(-e6 6 6G71:!++"9"9"9"9"9uBzM'*, , ,A$$Z]]Jv4F4FGGG#-f#5#5#=#=C#=#H#HL$$\6::: 5VS-PPF$$S[[%(2BCCC6 6 6 6 6 6(-e6 6 6G71:!++"9"9"9"9"9&3FC&@&@G

aAuAbDMMMA$$Z]]Jv4F4FGGG#-f#5#5#=#=C#=#H#HL$$\6::::$$ 	v&&   )&*==I6B6> , , , , , , , , , , , , , , , , ,& Q =2  t<<<<= = = = = = = = = = = = = = =IIKKKKK;	 	s7   A2LLL0b   
bb c::c>c>c                 $   d }|j         r ||t                    s ||t                    r|j        r ||t                    r|j        rj ||t                    r|j        rR ||t                    s|j	        s: ||t                    s|j        r" ||t                    s6 ||t                    r%|                     t          t          ||           d S t!          |t                    st#          |j                  r|                                }n*t          |t(                    }|                                } ||t                    rdn|j         }|j        }	|j        }
|j        } ||t                    sd}	|                                } ||t                    sd} ||t                    r|j        nd} ||t                    r|j        nd}t          ||          }|                     |||
|	||||||
  
         d S )Nc                     | |z  |k    S r   r   )reqflags     r>   matchz/TestBufferProtocol.verify_getbuf.<locals>.match  s    X$&'r_   getbufFr@   r,   r   )	r\   r   r;   r  r   r   r   rj   rt  )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%  ra  r  r   r   r8  r   r   r  )rr  orig_exr  r  rt  r  rj   ri  r  r;   r   r   r   r   s                 r>   verify_getbufz TestBufferProtocol.verify_getbuf  s|   	( 	( 	( [	"U377	 U3*++	 57O	 U3*++		 57O		
 U3,--	
 79m	 sN++	 13	 sM**	 46?	 sH%%	 +0%\*B*B	 k7BsCCCFb'"" 	&:29&E&E 	))++CCM222B))++C eC00AUUbki;wuS,'' 	$ C//##CuS(## 	D!&sH!5!5=2%*U3%>%>F'//BR$$$BB%3UGF 	 	, 	, 	, 	, 	,r_   c                 	   t           t          t          t          t          t
          t          t          t          t          t          t          t          t          t          f}d t          d          D             dfg ddfg ddfd t          d          D             dff}g g d	fg d
g d	fdgg d	fdgdgdfdgdgd	fdgdgdfddgg d	fddgddgdfddgddgdfddgddgdff
}d	t           t"          t"          t           z  t$          t$          t           z  f}d	t&          t(          t&          t(          z  f}|D ]x\  }}t+          j        |          |D ]Z\  }}	}
fd|	D             }	|
z  }
|D ]<}|	r|t"          z  r|s|t$          z  r|r|n|d	         }t/          |||||	|
          }|r|d d d         nd }t1          |          }|rt1          |          }|j        d	k    s|j        dk    r|r|	r|                     ||           |r%|j        dk    r|r|	r|                     ||           |D ]u}|D ]p}|                     ||||z             |                     ||||z             |r8|                     ||||z  d           |                     ||||z  d           qv>\zg d}t/          |dgt8                    }|                     t<          t.          |           t/          dgdg          }t/          |t                    }|                     t<          t.          |t&                     |                     t<          t.          |t                     |                     t<          t.          |t                     |                     t<          t.          |t                     |                     t<          t.          |t
                     |                     t<          t.          |t                     t/          |t                    }g dg dfD ]}d	t"          fD ]}t/          |||t           z            }|                     tA          |d                     |                     tA          |d                     |D ]Y}t/          ||          }|                     tA          |d                     |                     tA          |d                     Zd S ) Nc                      g | ]}|d z  rdndS )r!   TFr   r   r]   s     r>   r   z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>  s%    :::1a!e&dd:::r_      r   r,   r!   rk  r>  r   r?  r7   r6   	   rn      r  r   r   c                 ,    g | ]}|d z  rd|z
  nd|z   S )r!   r'   r&   r   r  s     r>   r   z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>  s-    DDDQ1q50uQwwvaxDDDr_   r   r   )r,   rk  r,   r   r  r?  r!   rk  r>  r,   r6   c                     g | ]}|z  S r   r   r   s     r>   r   z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>)  s    999A1x<999r_   )r%  r&  r   r   r   T)rt  r   r&  r  r  )r,   r  r,   )r7   r   r7   rz  r   )!r  r  r  PyBUF_SIMPLEr  r  r  
PyBUF_FULLr  PyBUF_RECORDSPyBUF_RECORDS_ROPyBUF_STRIDEDPyBUF_STRIDED_ROPyBUF_CONTIGPyBUF_CONTIG_ROri   r'  r  ND_PILr  r  r8   calcsizer   rQ   r   r  r  ND_GETBUF_FAILr  r  r  r  )rr  requests	items_fmt	structurendflags
real_flagsrx   r;   r   r   r   r&  _itemsex1ex2m1m2r  bitsr  baseri  r  r   s                          @r>   test_ndarray_getbufz&TestBufferProtocol.test_ndarray_getbuf  s    M8\ 24H++/	
 ;:b		:::C@)))3/)))3/DD%))DDDcJ	
	 QKWWb!T2qMTB4S1#qMS2$OVROVb"Xr"VaVQVb"Xq!
	 {J
;(>F;&

 $\13
 $ !	@ !	@JE3s++H*3 @ @&w9999999("$ @ @E !E*$4 !   !eFl ! &+9UUqF!&E(-wvO O OC',6#ddd))$C#CB -'__x1}}Q5W((S111 2sx1}}}7}((S111' @ @$. @ @D ..sCTBBB ..sBDAAA" @ $ 2 23SX:> !3 !@ !@ !@ $ 2 23CH:> !3 !@ !@ !@@@)@@B -,, U2$n===+w333 sQC  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--- XXwww& 		< 		<EJ < <U%u[7HIIIb# 6 6777b# 6 6777% < <E E222BOOM"c$:$:;;;OOM"c$:$:;;;;<<		< 		<r_   c           	         t          dgdg          }t          dgdgt                    }t           |j        |j        fD ]}|                     t          |h d           |                     t          |g d           |                     t          |g d           |                     t          |g ddh	           |                     t          |g ddgdh
           |                     t          |g ddgg            |                     t          |dgdgi            |                     t          |dgdgi            |                     t          |dgdgi            |                     t          |dgdgdgt
                     |                     t          |dgg t                     |                     t          |g dg	           |                     t          |dgdgd           |                     t          j	        |dgdgd           |                     t          |ddgdgd           |                     t          |g ddgd           t          dz   }|                     t          |dg|z  dg|z  	           |                     t          |dgdg	           |                     t          |g ddg	           |                     t          |dgddz  g	           |                     t          |g dddgd           |                     t          |g ddgdg
           |                     t          |dgdgddz  g
           |                     t          |ddgddgdg
           |                     t          |g ddgdgd           |                     t          |g ddgd           |                     t          |g ddgdd           |                     t          |g ddgd            |                     t          j	        |dgdgd!           g d"}|                     t          ||ddgd#d$gd%&           |                     t          |t                      d'(           |                     t          |dgdgt                     |                     t          |dg           |                     t          t           d)t          *           t          dgdgt                    }|                     t          |j        dgdgt                     t          d)          }|                     t          |j        dgdg           |                     t          |j                   t          dgdg          }|                    dgdg           t#          |          }|                     t          |j        dgdg           |                     t          |j                   |                                 |                                 |                     t          |j                   ~|                     t          t&          i g d           |                     t          t&          d)i            t          t)          t+          d+                    dgd+z  	          }|                     t          t&          |d%g           t          t)          t+          d,                    ddg	          }|                     t          t&          |g d-           |                     t          t&          |ddg           |                     t          t&          |d#dg           |                     t          t&          |d.dg           t          g ddgd          }t          |t,          *          }|                     t          |j                   t          g ddgd          }t          |          }	t          |	          }|                     t          |j                   t          d/gdgd0          }|                     t          |j                   t          }t          t)          t+          |                    dg|z  	          }|                     t          |j                   t          dgdg	          }|                     t          t2          ddddd%           |                     t          t2          |d1d2           |                     t          t2          |d.d2           |                     t          t2          |t4          d3           |                     t6          t2          |t4          d4           |                     t          t2          |t4          d5           |                     t          t2          |d6d7           t          dgdg	          }|                     t          t8          ddddd%           |                     t          t8          i |           |                     t          t8          |i            t          dgdg	          }|                     t          t:          ddddd%           |                     t          t:          i d7           |                     t          t:          |d8           d S )9Nr  r,   r&  >   r,   r!   rk  )r,   r!   rN   )r,   r!   rk  r>  r,   r!   rk  rk  r   r   r   r   r   r}  r  )r   r  r   r   r&  XXXr   i  r   r!   rk  r!   QLr   rN   r$   r,   r!   rk  r>  r   rL   r,   r!   rk  r>  r   r   r%  r>  )r   r   r%  r@   z@#$)
r,   r!   rk  r>  r   r?  r7   r6   r  rn   r  r   )r   r   r   r   r%     123r  r   r  )r!   rk  r>  r+   )r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   r,   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  rb  r  r  r   r8   r:   ND_MAX_NDIMOverflowErrorr,  r  r  r  poprQ   releaser  r   ri   r  ra  memoryview_from_bufferr  r  UnicodeEncodeErrorr  r  )
rr  ri  ndmr   r   rx   rH   r  r  r  s
             r>   test_ndarray_exceptionsz*TestBufferProtocol.test_ndarray_exceptionsg  sy
   aS1#qcA3l333 27CH- G	1 G	1AiGGG444iIII666iKKK888iGGGA3???iGGGA3LLLiGGGA3rJJJiQCs2FFFiQCs"EEEiQCs2FFF iQCsQC$.  0 0 0 iQCrHHH j!Rs;;;j!eWQCLLLflAvaSMMMj!aYqc#NNNj!WWWQCMMM AAj!aSU1#a%@@@ j!aS===j!WWWSEBBBmQAsF8DDDj![[[1aPPP j!WWWQC#OOOmQA3'(#vh  0 0 0 j!aU1Q%!MMMj!YYYqcA3%(  * * * j!WWWQCJJJj!WWWQC%(  * * * j!WWWQCKKKflAy%*  , , , +**Ej!U1Q%')2hq  : : : iIKKDDD iQCs:NNN iQC0000 	+w~NNN aS1#\222*bgsQC|LLL V__+rwaS999+rv... aS1#
aSrNN+rwaS999+rv...			
 	+rv... 	)["ggg>>>)[&"===T%**%%aSW555*k2s;;;T%))__QqE222*k2www???*k2!u===*k21v>>>-b5)DDD WWWQC444R---*bi000 gggaS555cllS\\)R%>???hZs7;;;)R%>???T%((^^A3q5111*b&?@@@ aS$$$)^Q1aCCC)^RDDD-UCHHH)^RSIII,nb*"	$ 	$ 	$*nb*cJJJ*nb#sCCC aS$$$)ZAq!Q???)ZR888)ZR888 aS$$$)]Aq!QBBB)]B<<<)]B<<<<<r_   c                    t          t          d                    D ]}dgdz  }t          g ddgt                    }t	          |          |d<   t          dd          D ].}|                    g ddg           t	          |          ||<   /t          d          D ]"}|||                                                   #|                     t          |j	                   ~d S )Nr   r   r  rk  r  r,   r  )
r   ri   r   r  rQ   r  r  r  r  r
  )rr  permrH   ri  r   s        r>   test_ndarray_linked_listz+TestBufferProtocol.test_ndarray_linked_list  s     q** 	 	DAA<@@@Bb>>AaD1a[[ & &s+++!"~~!1XX % %$q'
""$$$$k26222	 	r_   c                     t          d          D ]J\  }}}t          j        |          }t          |d|          }|                     |d ||dddd|	  	         Kd S )Nr   r   r}  Tr\   r   r;   r  r   r   r   rj   )r   r8   r  r   r  )rr  r;   scalarrv   r   ri  s         r>   test_ndarray_format_scalarz-TestBufferProtocol.test_ndarray_format_scalar  s    )!nn 	$ 	$NCs++Hr#666BKK!)sTb""  $ $ $ $	$ 	$r_   c                     t          dd          }t          |          D ]Z\  }}}t          j        |          }dt          fD ]6}t          ||g||          }|                     |d ||dd|f|f|	  	         7[d S )Nr,   rn   r   r|  Tr  )r   r   r8   r  r  r   r  )rr  r   r;   rx   rv   r   r&  ri  s           r>   test_ndarray_format_shapez,TestBufferProtocol.test_ndarray_format_shape  s    Ar""(00 	' 	'MCs++HV ' 'U6(3eLLLBD%-3!"6)h[ %  ' ' ' ''	' 	'r_   c                    t          dd          }t          |          D ]\  }}}t          j        |          }t	          dd          D ]}|dk    r	t          |d d |                   g}||z  g}|dk     r||dz
  z  nd}	dt          fD ]>}
t          |||||	|
          }|                     |d ||dd|||d d |         	  	         ?d S )	Nr,      r   r   r$  Tr  )	r   r   r8   r  ri   rd   r  r   r  )rr  r   r;   rx   rv   r   r  r   r   r   r&  ri  s               r>   test_ndarray_format_stridesz.TestBufferProtocol.test_ndarray_format_strides+  s*   1b!!(00 	3 	3MCs++Hb! 3 3199U66T6]++,=/04q6!8,,a[ 3 3E eW(+F%I I IBKK)1sT%&eW$)&&D&M   3 3 3 333	3 	3r_   c                     g d}t          |dd          }t          |t          t          z            }|                     |                                t          |d                     d S )Nr  r  )r,   rk  r  r  )r   r  r  r  ra  r   )rr  rx   r  ri  s       r>   test_ndarray_fortranz'TestBufferProtocol.test_ndarray_fortran@  sg    ,,,U&&999R 2< ?@@@fUF&;&;<<<<<r_   c                    t          d          D ]}d t          |          D             }t          |          }t          |          D ]}t          |          \  }}}t	          j        |          }dt          fD ]R}	|dk    r|	t          k    rt          ||||	          }
t          |||d          }t          ||          }| 
                    |
d ||d||||	  	         t          |          rt          |||          }t          |t          t          z  	          }
|                     |
j        d
k               |
                                }| 
                    |d ||d||||	  	         t          ||||	t"          z            }
t          |||d          }t%          ||          }| 
                    |
d ||d||||	  	         Td S )Nr   c                 .    g | ]}t          d d          S )r!   rn   rB  rW  s     r>   r   z<TestBufferProtocol.test_ndarray_multidim.<locals>.<listcomp>H  s"    ===AyB''===r_   r   r|  r   Tr  r}  r  r   rz  )ri   r   r   r|   r8   r  r  r   r   r   r  r   r  r  r  r   r  r  r   )rr  r   shape_tr   r   r;   rx   rv   r   r&  ri  r   rj   r  mvs                  r>   test_ndarray_multidimz(TestBufferProtocol.test_ndarray_multidimF  s-   !HH *	) *	)D==t===G']]F%g.. ') ') )& 1 1UA!?3//[ ") ")EqyyUf__  !eCuMMMB0uhLLG ..CKK)1sT%)$'   ) ) )
 ,C00 	-$U%DDD$R0LMMM
b(89996688BD-53)-UG(+ $ - - - !eC',Z'79 9 9B 1uhLLG ..CKK)1sT%)$'   ) ) ) )?")')*	) *	)r_   c                 $   t          dgdg          }|                     t          |j        dd           t	          |          }|                     ||           |                     t          |j        dd           t          dgdgt                    }|                     t          |j        d           t	          |          }|                     ||           |                     t          |j        d           t          dgdgt                    }|                     t          |j	        d           |                     t          |j        dd           t	          |          }|                     ||           |                     t          |j	        d           |                     t          |j        dd           g d}t          |t          |          gdt                    }|                     t          j        |j        d	d
           |                     t          |j        dd           t	          |          }|                     ||           |                     t          |j        d	d
           |                     t          |j        dd           g d}t          |t          |          gdt                    }|                     t          |j        d	d
           |                     t          j        |j        dd           d S )Nr,   r  r6   r  r+   r,   r!   rk  r>  r   r?  r7   r6   r   r|  r!   i,  )r      )r,   r!   r  )r   r?  LQ)s    1r&  )r   r  rb  __setitem__rQ   r  r'  __delitem__r	  __getitem__
IndexErrorrd   r8   r:   r   )rr  ri  r"  rx   s       r>   test_ndarray_index_invalidz-TestBufferProtocol.test_ndarray_index_invalids  s   aS$$$)R^Q:::^^R   )R^Q::: aS;777)R^Q777^^R   )R^Q777 aS;777-???-BBB^^R   *bne<<<*bneQ??? "!!U3u::,s+NNN&,3???*bnaDDD^^R   *bna===)R^Q
CCC%%%U3u::,t;OOO*bna===&,?KKKKKr_   c                    t          ddt                    }t          |          }|                     ||           |d         }|                     |d           |d         }|                     |                                |                                           |d         }|                     |d           |d         }|                     |                                |                                           |                     t          |j        d           |                     t          |j        d           |                     t          |j        dd           |                     t          |j        dd           |                     |                                d           |                     |                                d           d|d<   |                     |                                d           d|d<   |                     |                                d           d|d<   |                     |                                d           d|d<   |                     |                                d           d S )	Nr,   r   r  .r   r6   r  r   )	r   r'  rQ   r  ra  r  rb  r+  r)  )rr  ri  r"  r]   s       r>   test_ndarray_index_scalarz,TestBufferProtocol.test_ndarray_index_scalar  s   Qb444^^R   rFT%%a+++sGT%%ahhjj"))++>>>rFT%%a+++sGT%%ahhjj"))++>>>)R^Q777)R^Q777)R^Q:::)R^Q:::a(((a(((2D$$RYY[[!4442D$$RYY[[!4443T%%biikk15553T%%biikk155555r_   c           	      :   t          t          t          d                    ddgt                    }t          |t                    }|                     t          |j        d           |                     t          |j        t          ddd                     d S )	Nr6   r!   r>  r  r  r,   rk  r   )	r   r   ri   r'  r  r  r  r+  r  )rr  r  ri  s      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~uQq||DDDDDr_   c                 4   t          d          D ]<\  }}}t          |dg|          }t          dd          D ]$}|                     ||         ||                    %|                     t
          |j        d           |                     t
          |j        d           t          |          rt          |          }|                     ||           t          dd          D ]$}|                     ||         ||                    %|                     t
          |j        d           |                     t
          |j        d           >t          d          D ]\  }}}t          |dgt          |          }t          |t          t          z            }t          dd          D ]$}|                     ||         ||                    %t          |          rw|                                }|                     |                    |          t                     t          dd          D ]$}|                     ||         ||                    %g d}t          |dg          }t          |t                     }t          dd          D ]$}|                     ||         ||                    %g d}t          |dg          }t          |t"                    }t          dd          D ]$}|                     ||         ||                    %d S )	Nr   r}  r  r  r  r  r  )r   r   ri   r  r  r,  r+  r   rQ   r'  r  r  r  r  __eq__NotImplementedr  r  )rr  r;   rx   rv   ri  r   r"  r  s           r>   !test_ndarray_index_getitem_singlez4TestBufferProtocol.test_ndarray_index_getitem_single  s   (^^ 	A 	AMCqc#666B2q\\ 2 2  Aa1111j"."===j".!<<<#C(( A^^  R(((r1 6 6A$$RUE!H5555!!*bnbAAA!!*bna@@@ )^^ 	6 	6MCqcSIIIBL$=>>>B2q\\ 2 2  Aa1111#C(( 6..00biimm^<<<r1 6 6A$$RUE!H5555 U1#&&&R000r1 	. 	.ARUE!H---- U1#&&&R---r1 	. 	.ARUE!H----	. 	.r_   c                 ~   t          d          D ]~\  }}}t          |dg|t                    }t          d          D ]}|||<   |||<   |                     |                                |           |                     t          |j        d|           |                     t          |j        d|           t          |          st          |dg|t                    }t          |          }|                     ||           t          d          D ]}|||<   |||<   |                     |                                |           |                     t          |j        d|           |                     t          |j        d|           t          d          D ]\  }}}t          |dg|t                    }t          dd          D ]}||dz            ||<   ||dz            ||<   |                     |                                |           t          |          st          |dg|t                    }t          |          }|                     ||           t          dd          D ]}||dz            ||<   ||dz            ||<   |                     |                                |           d S )Nr   r|  r3  r  r>  r,   )r   r   r'  ri   r  ra  r  r,  r)  r   rQ   )rr  r;   rx   single_itemri  r   r"  s          r>   !test_ndarray_index_setitem_singlez4TestBufferProtocol.test_ndarray_index_setitem_single  s   '21~~ 	J 	J#Cqc#[IIIB1XX $ $&a#1RYY[[%000j"."kJJJj".![III',, qc#[IIIBBBR$$$1XX $ $&a#1RYY[[%000j"."kJJJj".![IIII (31~~ 	1 	1#Cqc#[IIIB2q\\     1:a1Q31RYY[[%000',, qc#[IIIBBBR$$$2q\\     1:a1Q31RYY[[%0000!	1 	1r_   c           
      d   d}t          |          }t          |          D ]}t          |          \  }}}dt          fD ]l}t	          ||||          }t          ||          }	t          |d          |d                   D ]}
|                     |	|
         ||
                                                    t          |d          |d                   D ]}|                     |	|
         |         ||
         |                                                    t          |d          |d                   D ]<}|                     |	|
         |         |         ||
         |         |                    =t	          ||||t          z            }t          ||          }	t          |d          |d                   D ]}
|                     |	|
         ||
                                                    t          |d          |d                   D ]}|                     |	|
         |         ||
         |                                                    t          |d         |d                   D ]<}|                     |	|
         |         |         ||
         |         |                    =nd S )Nr!   rk  r   r   r|  r,   r!   )r   r   r|   r  r   r   ri   r  ra  r  r   )rr  r!  r   r   r;   rx   rv   r&  ri  rj   r   r   ks                r>   #test_ndarray_index_getitem_multidimz6TestBufferProtocol.test_ndarray_index_getitem_multidim  s   g!'** 	H 	HE%f--MCV H HU%5IIIUE**ay%(33 H HA$$SVRU\\^^<<<"E!H9eAh77 H H((QBqE!HOO4E4EFFF!&ay%(!;!; H HA ,,SVAYq\2a58A;GGGGHH U%#(#35 5 5UE**ay%(33 H HA$$SVRU\\^^<<<"E!H9eAh77 H H((QBqE!HOO4E4EFFF!&uQxq!:!: H HA ,,SVAYq\2a58A;GGGGHHH#H		H 	Hr_   c                    t          dd          }|                     t          t          dt	                                 t          |          }|                     ||           |                     t          t          dt	                                 t          d          D ]\  }}}t          |dg|          }t          |          D ]8\  }}|                     |||                    | 	                    ||v            9t          |          rWt          |          }t          |          D ]8\  }}|                     |||                    | 	                    ||v            9d S )Nr,   r   r  z1 in ndz1 in mvr   r}  )r   r  rb  evallocalsrQ   r  r   r-  r  r   )rr  ri  r"  r;   rx   rv   r   r   s           r>   test_ndarray_sequencez(TestBufferProtocol.test_ndarray_sequence:  s`   Qb!!!)T9fhh???^^R   )T9fhh???(^^ 
	- 
	-MCqc#666B!" ) )1  E!H---R((((#C(( -^^%bMM - -DAq$$Qa111OOAG,,,,
	- 
	-r_   c           
      l   g d}t          |dgt                    }t          |          }|                     t          |j        t          ddd          |           |                     t          |j        t          ddd          |           t          |dgt                    }t          |dgt                    }t          |t                    }|                     t          |j        t          ddd          |           t          |dgdt                    }t          |          }|                     t          |j
        t          ddd                     |                     t          |j
        t          ddd                     t          |d	d
gdt                    }t          |          }|                     t          |j
        t          ddd          t          ddd          f           |                     t          |j
        t          ddd          t          ddd          f           |                     t          |j
        d           |                     t          |j
        dt          ddd          f           |                     t          |j
        t          ddd          i f           |                     t          |j
        t          ddd          t          ddd          f           |                     t          |j
        d           t          |dgdt                    }t          |dgd          }t          |          }t          |          }|                     t          |j        t          ddd          |dd                    |                     |                                |           |                     t          |j        t          ddd          |dd                    |                     |                                |           t          |dgdt                    }t          |dgd          }	t          |          }t          |          }|                     t          |j        t          ddd          |dd                    |                     |                                |           |                     t          |j        t          ddd          |dd                    |                     |                                |           t          |d	d
gdt                    }t          |dgd          }t          |          }t          |          }|                     t          |j        t          ddd          |dd                    |                     |                                g dg dg           |                     t          |j        t          ddd          |dd                    t          |dgdt                    }t          |dgd          }t          |          }t          |          }|                     t          |j        t          dd	d          |dd                    |                     |                                |           |                     t          |j        t          dd	d          |dd                    |                     |                                |           |                     t          t          t          ddd	          i            |                     t          t          dd           |                     t          t          t          ddd          d
           t          |dgdt                    }
|                     t          |
j                   t          |dgd          }t          |t"                    }
|                     t          |
j                   d S )Nr%  r6   r  r   r,   r  r   r|  r!   r>  z@%$r   r   r}  r7   r  )r   r?  r7   r6   z###########)r   r'  rQ   r  rb  r)  r  r  r  r   r+  rc  r  ra  r  r  add_suboffsetsr  )rr  rx   xlmlr  xrri  r"  mryrr]   s              r>   test_ndarray_slice_invalidz-TestBufferProtocol.test_ndarray_slice_invalidM  s   !!! U1#[999^^)R^U1Qq\\5III)R^U1Qq\\5III U1#[999U1#[999R)))+r~uQq||RHHH U1#cEEE^^*bneAallCCC*bneAallCCCU1Q%;GGG^^*bn 1Q<<q16	8 	8 	8*bn 1Q<<q16	8 	8 	8)R^U;;;)R^eU1Qq\\5JKKK)R^eAallB5GHHH 	-r~ 1Q<<q16	8 	8 	8)R^U;;; U1#cEEEU1#c222^^^^*bneAallBqsGLLLe,,,*bneAallBqsGLLLe,,, U1#cEEEU1#c222^^^^*bneAallBqsGLLLe,,,*bneAallBqsGLLLe,,, U1a&KHHHU1#c222^^^^*bneAallBqsGLLLyyy)))&<===-r~uQq||QqS'	# 	# 	# U1#cEEEU1#c222^^^^*bneAallBqsGLLLe,,,*bneAallBqsGLLLe,,, 	)]E!AaLL"EEE)]M1EEE*mU1Qq\\1EEEE!S???)Q%5666U1#c222B|,,,)Q%566666r_   c                    g d}t          |dgdt                    }t          |dgd          }|dd         |dd<   |                     |                                |           t	          |          }t	          |          }|                     ||           |                     ||           |dd         |dd<   |                     |                                |           t          |ddgdt                    }t          |ddgd          }|d	d
ddf         |d	d
d
d
f<   |                     |                                t          |ddg                     d S )Nr  r  r   r|  r}  r  r>  rk  r,   r!   )r   r'  r  ra  rQ   r   )rr  rx   r]   r  rE  rG  s         r>   test_ndarray_slice_zero_shapez0TestBufferProtocol.test_ndarray_slice_zero_shape  sl   ,,,E"cEEEE"c2221Q3!A#U+++]]]]QQQqS'1Q3e,,,E!Q;GGGE!Q444!QqSk!A#qs(VEAq6%:%:;;;;;r_   c                 ~   d}t          |          }t          |          }t          |          D ]}t          |          \  }}}t	          j        |          }dt          fD ]}	t          ||||	          }
t          ||          }t          ||          D ]}d }	 t          ||          }n# t          $ r}|j        }Y d }~nd }~ww xY wd }	 |
|         }n# t          $ r}|j        }Y d }~nd }~ww xY w|s|r|                     ||           y|                     |                                |           ؐd S Nr;  r   r|  )rd   r   r   r|   r8   r  r  r   r   rY  r   	Exception	__class__r  r  ra  )rr  r!  r   r   r   r;   rx   rv   r   r&  ri  rj   r   listerrrt  enderrndsliceds                     r>   test_ndarray_slice_multidimz.TestBufferProtocol.test_ndarray_slice_multidim  s   7||g!'** 	D 	DE%f--MCs++HV D DU%5IIIUE***477 D DF"G.!+C!8!8$ . . ."#+. !E,#%f:$ , , , !,  D DeW5555(():):FCCCC#D	D	D 	Ds0   B..
C		8C	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        }Y d }~nd }~ww xY wd }	 |	|         }n# t          $ r}|j        }Y d }~nd }~ww xY w|s|r|                     ||           y|                     |                                |           Id S )N)r!   rk  r   r!   r}  )rd   r   r   r|   r8   r  r   rC  rQ   r   rY  r   rN  rO  r  r  ra  )rr  r!  r   r   r   r;   rx   rv   r   ri  r  r"  rj   r   rP  rt  rQ  rR  rS  s                      r>   'test_ndarray_slice_redundant_suboffsetsz:TestBufferProtocol.test_ndarray_slice_redundant_suboffsets  s   7||g!'** 	@ 	@E%f--MCs++HeC888BeC888BBB&&C&tU33 @ @*'V44FF  * * *kGGGGGG* (!&zHH  ( ( (KEEEEEE(  @G @MM%1111$$X__%6%6????#@	@ 	@s0   C++
D5DDD
D0D++D0c                    t          d          D ]e\  }}}t          d          D ]M}t          d          D ]9}dt          fD ]+}|t          z  }t	          |dg||          }t	          |dg||          }	t          |	          }
d }d }|d d          }	 ||         }||         }||         ||<   t          |          t          |          k    }n# t          $ r}|j        }Y d }~nd }~ww xY wd }	 ||         ||<   n# t          $ r}|j        }Y d }~nd }~ww xY w|r| 	                    |t                     n>|                     |                                |           | 	                    ||           t          |          sGd }	 |
|         |
|<   n# t          $ r}|j        }Y d }~nd }~ww xY w|r| 	                    |t                     |                     |
                                |           |                     |
|           | 	                    ||           |                     |
|	|j        |d|j        |j        |j        |                                	  	         -;Ogd S )Nr   r   r|  Fr  )r   rH  r  r'  r   rQ   rd   rN  rO  r  r   r  ra  r   r  r   r   r   r   )rr  r;   rx   rv   lslicerP  r&  r   ri  r  r"  lsterrdiff_structurerj   lvalrvalrQ  rR  mverrs                      r>    test_ndarray_slice_assign_singlez3TestBufferProtocol.test_ndarray_slice_assign_single  s   (^^ 3	/ 3	/MC#A,, 2/ 2/'ll 1/ 1/F"#V 0/ 0/!+-$U1#cKKK$U1#cKKK'^^!%)-#AAAh1#&v;D#&v;D*-f+CK-0YY#d))-CNN( 1 1 1%&[FFFFFF1 !%0)+FBvJJ( 0 0 0$%KEEEEEE0 * 9 MM%<<<< ,,RYY[[#>>> MM%8883C88 %$ $0)+FBvJJ( 0 0 0$%KEEEEEE0 * 	/ MM%<<<< ,,RYY[[#>>> ,,R444 MM%888 KK'){e#%7"(BJ"$))++ ( / / / /[0/1/2/3	/ 3	/sH   ;C
C.C))C.4D  
D
DDF
F5$F00F5c           
         d}t          |          }t          |          }t          |          D ]}t          |          \  }}}dt          fD ]}t          t                    D ]}t          ||          \  }	}
t          ||||t          z            }t          ||          }d }	 t          |||	|
          }n# t          $ r}|j        }Y d }~nd }~ww xY wd }	 ||
         ||	<   n# t          $ r}|j        }Y d }~nd }~ww xY w|s|r|                     ||           |                     |                                |           d S rM  )rd   r   r   r|   r  ri   
ITERATIONSr  r   r'  r   r   rN  rO  r  r  ra  )rr  r!  r   r   r   r;   rx   rv   r&  r   r   ri  rj   rP  r  rQ  rR  s                    r>   "test_ndarray_slice_assign_multidimz5TestBufferProtocol.test_ndarray_slice_assign_multidim3  s   7||g!'** 	> 	>E%f--MCV > >z** > >A';D%'H'H$GW eC',['8: : :B ..C"G.!23Wg!N!N$ . . ."#+. !E,&(k7$ , , , !,  > >eW5555((f====->>		> 	>s0   (B;;
C	C	C	C((
D	2C>	>D	c                    t          t                    D ]}t          d         D ]}t          j        |          }t          |dt          t                    }|                     t          |            t          ||          }t          |||          }|                                }t          |          }t          |          r*|                                }	|                     |	|           |d         dk    rt          |||t                     }
|
                                }|                     ||           t          |
          }t          |          r@|                     ||
           |                                }	|                     |	|           t"          rc|d         }d|v rt%          |||          }|                     |d |j        |d|j        |j        |j        |                                		  	         d S )
NrA   Tr  r  r!   r   r  rk  Fr  )ri   r`  rV   r8   r  r
  MAXDIMMAXSHAPEr  r   r"  r(  ra  rQ   r   r  r  r/  r1  r  r   r   r   r   )rr  rv   r;   r   r   rx   r]   xlistr"  mvlistr  ylistr   zs                 r>   test_ndarray_randomz&TestBufferProtocol.test_ndarray_randomT  s   z"" %	0 %	0As| $0 $0!?3//"8T&,46 6 6 0! 45550a88*5#q99

]]',, 4YY[[F$$VU333Q4!88.uc1FKKKAHHJJE$$UE222#AB+C00 8((Q///!#((777 0aDEEzz 25#qAAAKKt)*u%&V17AI$%HHJJ   0 0 0C$0%	0 %	0r_   c                    t          t                    D ]}t          d         D ]}t          j        |          }t          |dt          t                    }|                     t          |            t          ||          }d}	 t          |||          }n# t          $ r}|j        }Y d }~nd }~ww xY w|                     |           t          r4d}		 t!          |||          }
n# t          $ r}|j        }	Y d }~nd }~ww xY w	 d S )NrA   Frc  )ri   r`  rV   r8   r  r
  rd  re  assertFalser   r"  r(  rN  rO  r  r/  r1  )rr  rv   r;   r   r   rx   rR  r]   rQ  	numpy_errr  s              r>   test_ndarray_random_invalidz.TestBufferProtocol.test_ndarray_random_invalid}  sJ   z"" 	3 	3As| 3 3!?3//"8U6,46 6 6  !11!56660a88(.uc1==AA  ( ( (KEEEEEE(&&& 3 %I06uc1EE$ 0 0 0$%K						03-3	3 	3s0   B
B3"B..B3C''
D1C==Dc                 6   t          t                    D ]}t          d         D ]p}t          j        |          }t          t          t                    \  }}}}t          |d|          }t          |d|          }	| 	                    t          |            | 	                    t          |	            t          ||          }
t          ||	          }t          |
||          }t          |||	          }||         ||<   |                                }|                                }t          |          }t          |          }|                     |                                |           |                     |                                |           |d         dk    r	|	d         dk    rt          |
||t                     }t          |||	t                     }||         ||<   |                                }|                                }|                     ||           |                     ||           t          |          }t          |          }|                     |                                |           |                     |                                |           t"          rd|v sd|v rt%          |
||          }t%          |||	          }||         ||<   t'          |          sSt'          |	          sD|                     |d |j        |d|j        |j        |j        |                                		  	         |                     |d |j        |d|j        |j        |j        |                                		  	         rd S )
NrA   rc  Tr  r!   r   r  Fr  )ri   r`  rV   r8   r  r   rd  re  r
  r  r   r"  r(  ra  rQ   r  r  r/  r1  r   r  r   r   r   r   )rr  rv   r;   r   r   r   r   r   tltrlitemsritemsrD  rF  xllistxrlistrE  rG  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#Hd&AAA#Hd&AAA 0" 5666 0" 56661#r::1#r::+FC<<+FC<< k7^^^^  f555  f555a5199A/RvNNNB/RvNNNB"$W+BwKYY[[FYY[[F$$VV444$$VV444#BB#BB$$RYY[[&999$$RYY[[&999 EF{{a6kk 3FCDDB3FCDDB"$W+BwK)"-- InR6H6H I BD-/[cE)+,.JBIIKK $ I I I
 KK)+#%'WBH(*
		   E E Em9E:	E :	Er_   c                    g d}t          |ddgt                    }t          |          }|                     |j        t          z             |                     |j        |           |                     |j        d           |                     |j	                   |                     |j
                   |                     |j                   d S )Nr  rk  r>  r  )r   r   )r   r  r  r&  r  r\   r  re  rl  r  r  r  )rr  rx   ri  r  s       r>   test_ndarray_re_exportz)TestBufferProtocol.test_ndarray_re_export  s    ,,,U1Q%v666R[[6)***bfb!!!000))))))'''''r_   c           	         dt           fD ]V}t          g ddg|          }t          |          }|                     ||           |                     |                                g            |                     |                                g            t          g dg d|          }|                     |                                g            t          g dg d|          }|                     |                                g g g g           t          g dg d|          }|                     |                                g g g gg g g gg g g gg           Xd S )Nr   r  r  r   rk  rk  rk  r   rk  )rk  rk  r   r  r   rQ   r  ra  rr  r&  ri  r"  s       r>   test_ndarray_zero_shapez*TestBufferProtocol.test_ndarray_zero_shape  sw   [ 	I 	IE5999BBBR$$$RYY[["---RYY[["---u===BRYY[["---u===BRYY[[2r2,777u===BRYY[[!2rlRRL2r2,GI I I I	I 	Ir_   c                 <   dt           fD ]}t          dgdgdg|          }t          |          }|                     ||           |                     |                                g d           |                     |                                g d           d S )Nr   r,   r   r  )r,   r,   r,   r,   r,   r  r  s       r>   test_ndarray_zero_stridesz,TestBufferProtocol.test_ndarray_zero_strides  s    [ 	; 	;E!QC!EBBBBBBR$$$RYY[[///:::RYY[[///::::	; 	;r_   c                     t          t          t          d                    dgd          }|                     |j        d           |                     |                                g d           d S )N   rk  r7   r  )r7   r6   r  )r   r   ri   r  r   ra  rr  ri  s     r>   test_ndarray_offsetz&TestBufferProtocol.test_ndarray_offset   sd    T%))__QC:::A&&&ggg.....r_   c                     dt           fD ]Y}t          t          t          d                    dg|          }|                                }|                     ||           Zd S Nr   rk  r  )r  r   r   ri   r  r  )rr  r&  ri  rH   s       r>   #test_ndarray_memoryview_from_bufferz6TestBufferProtocol.test_ndarray_memoryview_from_buffer  sk    [ 	$ 	$EeAhhs%@@@B))++AQ####	$ 	$r_   c           	          dt           fD ]l}t          t          t          d                    dg|          }t          d          D ]-}|                     ||         t          ||g                     .md S r  )r  r   r   ri   r  r  )rr  r&  ri  r   s       r>   test_ndarray_get_pointerz+TestBufferProtocol.test_ndarray_get_pointer  s    [ 	> 	>EeAhhs%@@@B1XX > >  AB(<(<====>	> 	>r_   c                    t          t          t          d                    g d          }t          |t          t          z            }|                     |                                |                                           t          |          }|                     |                                |                                           d S )Nr  )r!   r!   r   r  r  )r   r   ri   r  r  r  ra  rQ   )rr  r  ri  rH   s       r>    test_ndarray_tolist_null_stridesz3TestBufferProtocol.test_ndarray_tolist_null_strides  s    T%))__GGG444R 5666biikk222rNNRYY[[11111r_   c                    |                      t          dd                     t          t          t	          d                    ddg          }t          t          t	          d                    ddg          }|                      t          ||                     t          dgdgd	          }|                     t          |d
                     |                     t          d
|                     d S )Nr  s   456r  rk  r>  r  r,   r   r}  rU   )rl  r  r   r   ri   r  )rr  r]   r  s      r>   test_ndarray_cmp_contigz*TestBufferProtocol.test_ndarray_cmp_contig  s    FF33444DrOOAa5111DrOOAa5111Aq))***QCs3///
1g..///
7A../////r_   c           	      ~   t          j         dg d          }t          |          }|                     t          t          |           t          t          t          d                              }t          t          t          d                    dg          }|                     t	          |          t	          |                     t          t          t          d                    ddg          }|                     t	          |          t	          |                     t          t          t          d                    g d          }|                     t	          |          t	          |                     t          t          t          t          d                    ddg                    }t          t          t          d                    ddgt                    }|                     t	          |          t	          |                     t          t          t          t          d                    g d	                    }t          t          t          d                    g d	t                    }|                     t	          |          t	          |                     t          t          t          d                              }t          t          t          d                    g d
t                    }|                     t	          |          t	          |                     t          t          t          d                    g d
d          }|                     t	          |          t	          |                                                     d S )Nr   r  r  r  rk  r>  )rk  r!   r!   r  r!   rk  r!   r!   r!   rk  r}  )rO   r   r  r   hashrW   r   ri   r  r   r  r  r8  )rr  rJ   ri  r   s       r>   test_ndarray_hashz$TestBufferProtocol.test_ndarray_hash&  s   KWWW%%QZZ*dB/// $uRyy//""T%))__RD111b477+++ T%))__QqE222b477+++T%))__GGG444b477+++ )DrOOAa5999::T%))__QqEDDDb477+++)DrOO777;;;<<T%))__GGG:FFFb477+++ $uRyy//""T%))__GGG6BBBb477+++ T%))__GGGC@@@b4

#5#566666r_   c                    t           t          t          t          t          t
          t          t          t          t          t          t          f}|                     t          t          i dt
                     t          dddt                     }dD ]@}|D ];}t          |||          }|                     ||                                           <At          dgdgdt                     }dD ].}|D ])}t          |||          }|                     |d	           */t          t'          t)          d
                    g ddt                     }dD ].}|D ])}t          |||          }|                     |d	           */dt*          fD ]}t          dgdgd|t           z            }|                                }dD ].}|D ])}t          |||          }|                     ||           */t          g ddgd|t           z            }|                                }dD ].}|D ])}t          |||          }|                     ||           */t          g ddgdgt                     }|                                }dD ]:}t          t          fD ])}t          |||          }|                     ||           *;|d d d         }|                                }dD ]@}|D ];}	 t          |||          }n# t,          $ r Y !w xY w|                     ||           <At'          t)          d                    }dt*          fD ]}t          |ddg|t           z            }t.          r*t/          t1          |          ddgd|dk    rdnd          }	|t*          k    r>t          t3          |ddg          ddgt                     }
|
                                }n|                                }|D ]}	 t          |d|          }n# t,          $ r Y !w xY w|                     ||           t          d |D             ddgt                     }|                     t5          |          t5          |                     t.          r*|                     ||	                    d                     |dk    r*t          t3          |ddg          ddgt                     }
nt          |ddgt                     }
|
                                }t          t
          t           t          t          fD ]}	 t          |d|          }n# t,          $ r Y !w xY w|                     ||           t          d |D             ddgt*          t           z            }|                     t5          |          t5          |                     t.          r*|                     ||	                    d                     |t*          k    r.t          |ddgt                     }
|
                                }n|                                }t          t
          t           t          t          fD ]}	 t          |d|          }n# t,          $ r Y !w xY w|                     ||           t          d |D             ddg|t           z            }|                     t5          |          t5          |                     t.          r*|                     ||	                    d                     Ðt          t'          t)          d                    ddgt           t8          z            }t          |dt
                    }|                     ||                                           t          d |D             ddgt                     }|                     t5          |          t5          |                     t          |dt
                    }t          t3          |ddg          ddgt                     }
|                     ||
                                           t          d |D             ddgt*          t           z            }|                     t5          |          t5          |                     t          |dt
                    }|                     ||                                           t          d  |D             ddgt                     }|                     t5          |          t5          |                     d S )!Nrz  r  r   r   r|  ry  r,   r   r_   r6   r!   r   r7   r   r  rk  r   r!   r  r   r  r>  r  r   r   )r*  r   r+  r  c                     g | ]}|S r   r   r   s     r>   r   zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>      NNN1QNNNr_   r  c                     g | ]}|S r   r   r   s     r>   r   zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>	  r  r_   r{  c                     g | ]}|S r   r   r   s     r>   r   zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>	  r  r_   c                     g | ]}|S r   r   r   s     r>   r   zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>+	      NNN1QNNNr_   c                     g | ]}|S r   r   r   s     r>   r   zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>2	  r  r_   c                     g | ]}|S r   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  rb  r  r   r'  r  r8  r   ri   r  r  r/  r,  r   rQ   tostringr  )rr  r  ri  r  requestr   r   ndbytesrj   nar]   r  r  s                r>   test_py_buffer_to_contiguousz/TestBufferProtocol.test_py_buffer_to_contiguousK  s	    M8\++/
 	)%<b#'	) 	) 	) QbK@@@$ 	2 	2E# 2 2+Bw??  BJJLL11112
 aSC{CCC$ 	) 	)E# ) )+Bw??  C(((() T%((^^999S&( ( ($ 	) 	)E# ) )+Bw??  C(((() Z 	1 	1A!QC1[=IIIBjjllG( 1 1' 1 1G/E7CCA$$Q00001 1#c;OOOBjjllG( 1 1' 1 1G/E7CCA$$Q000011 YYYqcA3kJJJ**,,$ 	- 	-E):6 - -+Bw??  G,,,,- "X**,,$ 	- 	-E# - -/E7CCAA"   H  G,,,,-N 599ooZ K	@ K	@AQF!K-@@@B ? 	#()1vS./1ffss#? ? ?
 JIcAq6221a&"-/ / /99;;::<<# @ @/CAAAA"   H   H--- NNNNN1a&LLL  A
2??? @$$Q#(>(>??? AvvIcAq6221a&"-/ / / C1v[AAAyy{{H&~)85 @ @/CAAAA"   H  H--- NNNNN1a&
;@VWWW  A
2??? @$$Q#(>(>??? JC1v[AAA99;;::<<&~)85 @ @/CAAAA"   H   H---
 NNNNN1a&+NNN  A
2??? @$$Q#(>(>???!@& T%))__QF+f:LMMM $B];;BJJLL)))NNNNN1a&DDDA
2777 $B];;IcAq6**1a&LLLAIIKK(((NNNNN1a&
;8NOOOA
2777 $B];;BJJLL)))NNNNN1a&DDDA
277777sH   $K66
LL5P
PP2U
UU'Y99
ZZc                 
   dg fg ddgft          t          d                    g dfg}|D ]\  }}t          ||          }t          |          }|                     |j                   |                     |j                   t          |          }t          ||dd          }t          ||          }| 
                    ||dd	d
||||	  	         t          |          }	| 
                    |	|dd	d
||||	  	         t          |t          t          z            }
|                     |
j        d           |
                                }| 
                    |d dd	d
||||	  	         t          |t                     }
|                     |
j        d           |                     |
j        d           |                     |
j        d           |
                                }|dk    r|gn|}| 
                    |d dd	d
d|j        gd|	  	         |D ]\  }}t          ||t(                    }t          |          }|                     |j                   |                     |j                   t          |          }t          ||dd          }t-          ||          }| 
                    ||dd	d
||||	  	         t          |          }	| 
                    |	|dd	d
||||	  	         |dd          D ]\  }}t          ||t.                    }t          |          }t          |          }t          ||          }| 
                    ||dd	d
|||j        |	  	         t          |          }	| 
                    |	|dd	d
|||j        |	  	         |                     t2          t          dd           |                     t2          t          i            t          g ddg          }t          |t                     }
|                     t4          t          |
           t          |t          t          z            }
|                     t4          t          |
           t          dgdz  dgdz  d          }
|                     t6          t          |
           |                     t6          |
j                   |                     t6          t8          |
t:          d           |                     t6          t8          |
t:          d           |                     t6          t8          |
d d d         t:          d           d S )Nr  r  rk  r  r;  r  r,   r   r   Tr  r  r   r@   r   r,   r  rz     9r]   r$   r   r}  r   )r   ri   r   rQ   r  r  r  rd   r   r   r  r  r  r  r   r  r  r%  r   r6  r  r  r   r  r  rb  r  r   r  r  )rr  items_shaperx   r   r  rH   r   r   rj   r  ri  s              r>   test_memoryview_constructionz/TestBufferProtocol.test_memoryview_construction;	  s{   2w1#eEll1C1CWWW0MN ( ,	! ,	!LE5 e,,,B2AOOAN+++OOAL)))u::D(ua==G&&CKKr!"d!  ! ! ! ABKK!"d!  ! ! ! OL$@AAABRZ,,,))++AKKt!"d!  ! ! ! L111BRY+++RXr***RZ,,,))++A!QYY5''ECKKt!"dryk4  ! ! ! ! ( 	! 	!LE5 e:>>>B2AOOAN+++OOAL)))u::D(ua==G&&CKKr!"d!  ! ! ! ABKK!"d!  ! ! ! ! (O 	! 	!LE5 e6:::B2Au::D&&CKKr!"d!
  ! ! ! ABKK!"d!
  ! ! ! ! 	)Zs;;;)Z444WWWQC(((R---+z2666R <===+z2666 aSWQCGC888*j"555*b&?@@@*nb*cJJJ*nb*cJJJ*nb2h
CPPPPPr_   c                    g d}g dg dg dfD ]]}t          ||          }|                     |j                   t          |          }|                     t
          |j        d           ^t          dd          D ]z\  }}}t          d          }|                    |          }|                     |	                                d           |                     |
                                g            {d S )	Nr  r  r  r  r   r,   rQ   r_   )r   r  r  rQ   r  rb  ru  r   r  r8  ra  )rr  rx   r   r  msrcr;   rv   rH   s           r>   test_memoryview_cast_zero_shapez2TestBufferProtocol.test_memoryview_cast_zero_shape	  s    
 ggwww0 	9 	9Ee,,,BOOBO,,,b>>DiC8888$Q55 	- 	-ICAc??D		#AQYY[[#...QXXZZ,,,,		- 	-r_   c                    | j         }t          j        }d}d}t          t	          d                    } |t          d           ||d|z  z                        t          |ddgd	          } |t          |           ||d|z  z                        t          |g d
d	          } |t          |           ||d|z  z                        d S )NzPnin 2P2n2i5P P3nr6   r_   r,   r!   r>  r   r}  )r!   r!   r!   rk  )check_sizeofr   calcvobjsizer   ri   rQ   r   )rr  checkvsizebase_structper_dimrx   rJ   s          r>   test_memoryview_sizeofz)TestBufferProtocol.test_memoryview_sizeof	  s    !$'U1XXjoouu[1w;%>??@@@E!Q444jmmUU;W#<==>>>E3777jmmUU;W#<==>>>>>r_   c                     G d dt                     } G d dt                     }d } |d           |d          dt          d          d	t          d
d          g dh dddiddddd t          ddt	          d          t	          d          dddd|d g}t          dd          D ]a\  }}}t          |dg|t                    }t          |dg|t                    }	t          |          }
t          j
        ||	d|           ||
d<   |                     |
d         |	d                    t          j        |          }d|v r|D ]}d }	 t          j
        ||	||           n!# t          j        $ r t          j        }Y nw xY wd }	 ||
d<   n%# t          t          f$ r}|j        }Y d }~nd }~ww xY w|s|r-|                     |d            |                     |d            |                     |
d         |	d                    cd S )Nc                       e Zd Zd Zd ZdS )=TestBufferProtocol.test_memoryview_struct_module.<locals>.INTc                     || _         d S r   valrr  r  s     r>   __init__zFTestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__init__	      r_   c                     | j         S r   r  rq  s    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                       e Zd Zd Zd ZdS )=TestBufferProtocol.test_memoryview_struct_module.<locals>.IDXc                     || _         d S r   r  r  s     r>   r  zFTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__init__	  r  r_   c                     | j         S r   r  rq  s    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                      dS )Nr7   r   r   r_   r>   r   z;TestBufferProtocol.test_memoryview_struct_module.<locals>.f	  s    r_   r  y@      @z-21.1gffffff(@r   r!   r  >   r>  r   r?  r7   r6   r   r  TF   as   abcrJ   abcc                     | S r   r   )r]   s    r>   <lambda>zBTestBufferProtocol.test_memoryview_struct_module.<locals>.<lambda>	  s    q r_   rn   rQ   r|  r   r   r,   )objectr
   r   Ellipsisr,  r   r   r'  rQ   r8   r.  r  r  r:   rb  r   rO  assertIsNot)rr  r  r  r   valuesr;   rx   ry   r  ri  rH   r   r   
struct_errmv_errrQ  s                   r>   test_memoryview_struct_modulez0TestBufferProtocol.test_memoryview_struct_module	  s   	  	  	  	  	 & 	  	  	 	  	  	  	  	 & 	  	  	  	#a&&##a&&''**D(1a..''777QqE2ttX	$61B1BudF[[" !,B = = 	2 	2Crd3kJJJBrd3kJJJB2AS"a...AaDQqT2a5)))s++Hczz 2 2!
.$S"h::::| . . .!'JJJ. )AaDD!:. ) ) )[FFFFFF)  2 2$$Z666$$VT2222$$QqT2a51111#2	2 	2s*   E&&FF
FF2!F--F2c                     t          g ddgdg          }|                     |j                   t          |          }|                     t
          |j        d           d S )Nr  rk  r   r  r   )r   rl  r  rQ   r  rb  ru  )rr  r  r  s      r>   !test_memoryview_cast_zero_stridesz4TestBufferProtocol.test_memoryview_cast_zero_strides	
  sa     WWWQC!555)))"~~)TY44444r_   c           	         t           D ]}t          d          rd|z   n|}t          j        |          }t           D ]}t          d          rd|z   n|}t          j        |          }t	          t          t          d                    d|z  g|          }t          |          }|                     t          |j
        |d|z  g           t          d          D ]\  }}	}
t	          |	dg|          }t          |          }t          d          D ]\  }}
}
t          |          s'|                     t          |j
        |d|z  g           <t          |          s5t          |          s&|                     t          |j
        |d|z  g           t          j        d          }t          j        d          }t	          t          t          d|z                      dd|gd          }t          |          }|                     t          |j
        dd|gd           t	          t          t          d	                    g d
          }t          |          }|                     t          |j
                   |                     t          |j
        ddd           |                     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	          ddgdgd          }t          |          }|                     t          |j        d           |                     t          |j        dd           |                     t          |j                   t	          t          t          d	                    g d
          }t          |          }|                     t          |j
        di            t	          t          t          d	                    d	g          }t          |          }|                     t&          |j
        ddg           |                     t          |j
        ddg           |                     t          |j
        dg d           |                     t          |j
        dg d           |                     t          |j
        dg d            t	          t          d! t          d"          D                       g d#          }t          |          }|                     t          |j
        d$g d%           t	          t          t          d&                    d&gd$          }t          |          }|                     t          |j
        d$dgd&z             t	          t          d' t          d"          D                       d"g          }t          |          }|                     t          |j
        d$g d%           t	          t          d( t          d"          D                       d"g          }t          |          }|                     t          |j
        dg d%           t	          t          t          d&                    d&gd$          }t          |          }t	          t          t          d&                    d&gd          }t          |          }t(          j        d)k    rn|                     t          |j
        dg d*           |                     t          |j
        dg d+           |                     t          |j
        d$g d,           d S |                     t          |j
        ddd-g           |                     t          |j
        dg d.           |                     t          |j
        d$g d/           d S )0Nr!   rA   r2   r}  r,   r   r   r>  x   r  r  rk  Xz@Xz@XYz=Bz!Lz<Pz>lBIxBIr'  r  IIr   r6   r   r+   r   )r!   rk  r>  r   r?  r7   r   )r!   rk  r>  r   r?  r7   r   )r!   rk  r>  r   r?  r7   r]   c                     g | ]}d S r  r   rW  s     r>   r   zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>^
      6661666r_   i  )rk  r   r7   r  r   )r!   rk  r>  r   r$   c                     g | ]}d S r  r   rW  s     r>   r   zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>h
  r  r_   c                     g | ]}d S r  r   rW  s     r>   r   zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>m
  r  r_   l    )r7   r7   I   r/   iQ  iAj i	 )   r     r  r6   )r  r  r  r  r!   )r  r  r2   r2   r!   )r  r  r2   r6   r!   )NON_BYTE_FORMATr   r8   r  r   r   ri   rQ   r  rb  ru  r   r   r   r   rc  r+  r)  ra  r	  rf  maxsize)rr  sfmtsformatssizedfmtdformatdsizer  r  sitemsrv   size_hsize_drH   ri  r  r  s                    r>   test_memoryview_cast_invalidz/TestBufferProtocol.test_memoryview_cast_invalid
  sN   # 	K 	KD$-aLL:cDjjdGOG,,E' K K(1!>#**$00T%))__RYKPPP!"~~!!)TYr5ykJJJJK  +1~~ 
	7 
	7OD&!s4888Bb>>D)!nn 7 7
a+D11 7%%j$)T')5yk3 3 3 3 *$// 7t8L8L 7)))TY+-u9+7 7 77 %%%%T%F
++,,QqLMMM"~~)TYq6l3OOOT%**%%[[[999rNN 	)QV,,,)QVQ1555 	)QVR000 	*afc222*afd333*afe444 	*afd333*afd333*afd333*afd333*afd333*afe444 eU^A3t<<<rNN-q}a@@@-q}aCCC-qx888 T%**%%[[[999rNN)QVS;;; T%**%%gY777rNN-UGDDD*afc">>>*afc9I9I9IJJJ*afcIII)QVS8I8I8IJJJ T66eHoo66677zzzJJJrNN)QVS			BBB T%**%%cU3???rNN*afcA3s7;;; T66eHoo66677zJJJrNN)QVS			BBB T66eHoo66677zJJJrNN)QVS			BBB T%**%%cU3???^^T%**%%cU3???^^;'!!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    dd fdd fdd ff fd}t          j        d          }t          d	g d
          }t          |dd          \  }}t	          |          }|                    d          }                     ||dddd|d|d
  
         t          j        d          }t          d	g|z  |gd
          }t          |d|g           \  }}t	          |          }|                    dg           }                     |||ddddd|d
  
         t          dd          D ]8\  }	}
}t          j        |	|
          }t	          |          } ||||
|	           9t          dd          D ]<\  }	}
}t          |
dg|	t                    }t	          |          } ||||
|	           =d S )Nr   c                 D    t          |                                           S r   r   r8  r  s    r>   r  z9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>
  s    4

-- r_   r   c                 X    d t          |                                           D             S )Nc                 (    g | ]}|d k    r|dz
  n|S )r/   r#   r   r  s     r>   r   zMTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>
  s(    PPPQWWAcEE!PPPr_   r  r  s    r>   r  z9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>
  s%    PPT"**,,=O=OPPP r_   r   c                 X    d t          |                                           D             S )Nc                 H    g | ]}t          t          |          d            S )zlatin-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Qd2::<<>P>PQQQ r_   c                    t          j        |          }
D ]\  }}|                    |          } ||           }                    || d|ddd|z  gd|d
  
         |                    |          }	                    |	|            |                                 }                    |	| ||dddg|f|d
  
         d S )Nr,   Fr3   r  T	r\   r   r;   r  r   r   r   rj   ru  )r8   r  ru  r  r  ra  )r  rH   rx   r;   srcsizerR   to_bytelistr  rj   m3bytespecrr  s             r>   iter_roundtripz?TestBufferProtocol.test_memoryview_cast.<locals>.iter_roundtrip
  s    oc**G(0 0 0$VVG__!k"ooBB%&Ge!"2g:, #$  0 0 0
 WWS\\  R(((iikkBB%,#!"2$
 #$  0 0 0 00 0r_   r   r  r}  r,   Tr  r  r  r   r   r3   rO   rQ   r|  )
r8   r  r   r<  rQ   ru  r  r   rO   r'  )rr  r  r  r  	destitems	destshaperH   r  destsizer;   rx   rv   r  s   `           @r>   test_memoryview_castz'TestBufferProtocol.test_memoryview_cast
  s+   --
.PP
QQQ
R
	0 	0 	0 	0 	0 	0( /#&&Qb---)"c155	9rNNVVC[[BBC$)T! 	 	. 	. 	. ?3''aS\(C@@@)"c82FFF	9rNNVVCrV""BB%3"b! 	 	. 	. 	. )W55 	. 	.MCS%((B2AN2q%---- )\:: 	. 	.MCrd3kJJJB2AN2q%----	. 	.r_   c                 n   t                      D ]}t          d         D ]}|dk    r
dt          d                   |z   }t          j        |          }t          |          |z  }t          |          rdnd}t          ||          D ]\  }}}	t          j        |          }
|dk    r|gng }||
gz   }t          |||          }t          |          }t          ||||	          \  }}|#|                     t          |j        ||           |d
k    rt          |||          }|                    ||	          }t          |          }|j        }|                                }|                     ||||d||||d
  
         |                    |          }|                    ||	          }t          |          }|j        }|                                }|                     |||
|d||||d
  
         |                     |||
|d||||d
  
         t$          r G d dt$          j                  } |dd          }t          |          }|                    d          }|                     |j        |           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        |j        f           |                     |j        d           |                     |j        d           t%          j        d          }t          |          }|                    d          }|                     |j        |           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        |j        f           |                     |j        d           |                     |j        d           d S d S )NrA   r   )r@   rA   r!   rQ   rR   r   r}  r  r5  Tr  c                   2    e Zd Zdej        fdej        fgZdS )>TestBufferProtocol.test_memoryview_cast_1D_ND.<locals>.BEPointr]   r  N)r  r  r  ctypesc_longc_double_fields_r   r_   r>   BEPointr  
  s&         &-032HIr_   r  r   g33333i@r   r,   Fr  r   333333?r   )rF  rV   r   r8   r  r   r   r   r   rQ   r<  r  rb  ru  rd   r   ra  r  r  BigEndianStructurer  r\   r   r  r  r   r   r6  re  r  )rr  _tshaper[   tfmttsizer   r\   r;   rx   rv   sizer   tshaper  rH   titemsri  r  r   r   rj   r  m4r  pointr  r]   s                              r>   test_memoryview_cast_1D_NDz-TestBufferProtocol.test_memoryview_cast_1D_ND
  si    % 5	4 5	4G 44 44 3;; 1.5--MME)&4T&:&:Ill	%0C%8%8 +4 +4MC!?3//D#$q55QCCbE$v-F eC@@@B"2A%/D%v%N%N%NNFF~)))QVT6JJJ   !vdCCCBF33Bv;;D jG))++CKK).D4%)$'d   4 4 4 BE22Bu::D jG))++CKK)-3%)$'d   4 4 4
 KK)-3%)$'d   4 4 4 4Q+444l  	0J J J J J&3 J J JGC''EE""BBRVU+++R[!,,,MM"+u---RWa(((RX	|444RZ...R]B///$$AABBRVQ'''R[!,,,MM"+u---RWa(((RX	|444RZ...R]B/////1	0 	0r_   c           	      v   t          j         dt          t          dd                              }t          |          }|                     ||           |                     |                                |                                           |dd d         }|dd d         }|                     ||           |                     |                                |                                           t          t          t          d                    g dd	          }t          |          }|                     |                                |                                           t          d
dgdgd	          }t          |          }|                     t          |j                   t          dgdgd	          }t          |          }|                     t          |j                   t          g dddgd	          }t          |          }|                     t          |j                   d S )Nr   r3  r?  r!   rk  i	  )r  r!   r7   rk  r   r   r}  )r!   r   )r7   r  r<      12345r,   r   )r     b   c   d   e   f)	rO   r   ri   rQ   r  ra  r   r  rc  )rr  rJ   rH   r  s       r>   test_memoryview_tolistz)TestBufferProtocol.test_memoryview_tolist  s    KT%A,,//00qMMAQXXZZ000addGaddGAQXXZZ000T%
++,,LLLMMMrNNRYY[[111fg&qc$???rNN-qx888hZs3777rNN-qx888444QqE#NNNrNN-qx88888r_   c                 V   t          t          d                    }|                                }|                     |                    d                     |                                 |                                }|                     |                    d                     d S )Nr  z<memoryz	<released)rQ   r,  __repr__r  
startswithr  )rr  rH   r   s      r>   test_memoryview_reprz'TestBufferProtocol.test_memoryview_repr3  s~    y||$$JJLLY//000			JJLL[1122222r_   c                    dD ]z}t          d          }t          j        |d|dg          }t          |          }|                     d|           |                     d|           |                     d|           {t	          dg d          }t          |          }|                     t          t          dt                                 d S )	N)r   r   g            ?g      @g      "@r   r  z9.0 in m)	floatrO   rQ   assertInr   r  rb  r?  r@  )rr  r;   infr  rH   s        r>   test_memoryview_sequencez+TestBufferProtocol.test_memoryview_sequence<  s     	" 	"C,,CS3S/22B2AMM#q!!!MM%###MM#q!!!!S"S)))rNN)T:vxx@@@@@r_   c              #      K   |                      t                    5 }d V  d d d            n# 1 swxY w Y   |                     t          |j                  d|fz             d S )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_errorJ  s      z** 	bEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	R\**>#G	I 	I 	I 	I 	Is   .22c                    t          dg d          }t          |          }|                     |d         d           |                     |d         |           |                     |d         |           |                     t          |j        d           t          dg d          }t          |          }|                     t          |j        d           t          t          t          d	                    d	gt          
          }t          |          }|                     t          |j        d           |                     t          |j        d           |                     t          |j        d           |                     t          |j        d           |                     t          |j        d           t          t          t          d                    ddgt          
          }t          |          }|                     |d         d           |                     |d         d           |                     |d         d           |                     |d         d           |                     |d         d           dD ]:}|                     d          5  ||df          d d d            n# 1 swxY w Y   ;dD ]:}|                     d          5  |d|f          d d d            n# 1 swxY w Y   ;|                     t          |j        d           |                     t          |j        d           |                     t          |j        d            |                     t          |j        d!           |                     t          |j        d           |                     t          |j        d           d S )"N      )@r   r}  r   .r   r  iiir7   r  r+          @        r6   r  rk  r>  r   r   )r!   r   r  r  r   r   )r  r  rk  r  r,   r4  r>  r  r!   r+   r   r*   r   r   r   r;  r;  )r   rQ   r  r  rb  r+  rc  r   ri   r'  r,  r6  )rr  r  rH   indexs       r>   test_memoryview_indexz(TestBufferProtocol.test_memoryview_indexQ  s    TC000rNN2%%%3###3$$$)Q]A666WBu555rNN-q}bAAA T%((^^A3kBBBrNN*amU;;;)Q]C888)Q]C888 	*amR888*amQ777 T%))__QqEEEErNN4!$$$4!$$$4"%%%6B'''6A&&&  	 	E00Q077  %(               	 	E00Q077  !U(              *amZ@@@*amZ@@@)Q]I>>>)Q]J??? 	-q}bAAA-q}a@@@@@s$   'J>>K	K	$K;;K?	K?	c                    t          dg dt                    }t          |          }d|d<   |                     |d         d           d|d<   |                     |d         d           |                     t
          |j        dd	           t          t          t          d
                    d
g          }t          |          }|                     t
          |j        dd           t          t          t          d
                    d
gt                    }t          |          }|                     t          |j        dd           |                     t
          |j        dd           |                     t
          |j        dd           |                     t          |j        dd           |                     t          |j        dd           t          d         D ]}|dk    s|dk    rt          g ddg|t                    }t          |          }t          dd          }d||<   |                     ||         d           |                     ||         ||                    t          g ddgdt                    }t          |          }d|d<   |                     |d         d           t          g d dgdt                    }t          |          }d!|d"<   |                     |d"         d!           t          d#gd"gdt                    }t          |          }|                     t
          |j        dd$           t          t          t          d%                    g d&t                    }t          |          }t          d                                         D ]\  }}|dk    r|dk    r|                    |          }|\  }	}
|d'k    s|dk    rdd(z   dd(z  }
}	|d)k    rG|                     t          |j        d|	d"z
             |                     t
          |j        dd*           |                     t          |j        d|
           |                    d          }|                     t          |j        dd+           t          t          t          d"                    d"gd,t                    }t          |          }|                     t           |j        dd"           t          d-gd"gd.t                    }t          |          }|                     t           |j        dd"           t          t          t          d/                    dd0gt                    }t          |          }d1|d2<   |                     |d         d"         d1           d3|d4<   |                     |d         d         d3           d5D ]7}|                     d"6          5  d||df<   d d d            n# 1 swxY w Y   8d7D ]7}|                     d6          5  d|d|f<   d d d            n# 1 swxY w Y   8|                     t          |j        d8d           |                     t          |j        d9d           |                     t
          |j        d:d           |                     t
          |j        d;d           |                     t           |j        dddg           d S )<Nr8  r   r|  g     6@r   g     7@.r   g333338@r7   r  r!   rn   r  r+   r  r:  r;  r  r<  r  r6      rA   r   r   r  rk  r  )   1   2   3r  )TFTTr,      xr   r  r  r   r  r   r  s   xLr   r   r  r>  *   )r   r,   +   r>  r?  r@  rA  rB  r*   rC  rD  )r   r'  rQ   r  r  rb  r)  r   ri   r,  rV   r   r  rx   ru  r   rc  r6  )rr  r  rH   r;   r   ri  r  _ranger  lohirE  s               r>   test_memoryview_assignz)TestBufferProtocol.test_memoryview_assign  s    TC{CCCrNN"2%%%#2%%%)Q]At<<< T%((^^A3///rNN)Q]Ar::: T%((^^A3kBBBrNN*amUA>>>)Q]C<<<)Q]C<<< 	*amR<<<*amQ;;; 3< 	* 	*CczzSCZZC{KKKB2A"a  AAaDQqT1%%%QqT2a5))))'''s3&( ( (rNN!1t$$$(((C&( ( (rNN!adD!!! dVA3s+FFFrNN)Q]As;;;T%**%%[[[LLL^^"3<--// 	A 	AKCs

czzBFBczzSCZZT'1d7Bczz!!*bnaAFFF!!)R^QFFFj".!R@@@@ WWS\\*bnaEEE T%((^^A3t;OOOrNN-q}aCCChZs3kJJJrNN-q}aCCC T%))__QqEEEErNN#Aq2&&&%Aq2&&& 	  	 E00Q077    %(                              	  	 E00Q077    !U(                             *amZCCC*amZCCC)Q]IqAAA)Q]JBBB 	-q}a!QHHHHHs$   4XX	X	.YY		Y	c           
         t          t          t          d                    dgt                    }t	          |          }|                     t          |j        t          ddd                     |                     t          |j	        t          ddd          t          ddg                     |                     t          |j        d           t          t          t          d                    dgt                    }t	          |          }|                     t          |j        t          ddd          t          ddd          f           |                     t          |j	        t          ddd          t          ddd          ft          ddg                     |                     t          |j        t          ddd          i f           |                     t          |j	        t          ddd          i ft          ddg                     |                     t          |j	        t          ddd          dg           dt          fD ]}t          t          t          d                    dgdgdt          |z  	          }t          t          t          d
                    dgdg|          }t	          |          }t	          |          }|dd         |dd<   |dd         |dd<   |                     ||           |                     ||           |dd         d d d         |dd         d d d<   |dd         d d d         |dd         d d d<   |                     ||           |                     ||           |ddd         d d d         |ddd         d d d<   |ddd         d d d         |ddd         d d d<   |                     ||           |                     ||           d S )Nr  r  r   r!   r,   r   r   r  )r   r   r   r&     r  r   rk  r>  r  )r   r   ri   r'  rQ   r  r   r+  r  r)  r,  rc  rb  r  r  )rr  r  rH   r&  r  r  r  r  s           r>   test_memoryview_slicez(TestBufferProtocol.test_memoryview_slice  s   T%))__RDDDDrNN 	*amU1Qq\\BBB*amU1Qq\\#QqE**	, 	, 	, 	-q}bAAA T%))__RDDDDrNN-q} 1Q<<q16	8 	8 	8-q} 1Q<<q16	1Q%8H8H	J 	J 	J 	)Q]U1Qq\\24FGGG)Q]U1Qq\\24F#QqE**	, 	, 	, 	)Q]E!AaLL1#FFF [ 	& 	&E$uRyy//"tB +E 13 3 3C$uRyy//"s%PPPCCBCB1Q3xC!H1gBqsGR%%%R%%% 1Xccc]C!HTTrTNqsGCCaCLBqsGDDbDMR%%%R%%% #AaE
33Q3C!BK"!!Aa%y1~Bq2vJtttR%%%R%%%%/	& 	&r_   c                 |   d }t          dd          D ]}t          |d          D ]\  }}}t          |          D ]y}t          |          D ]e}t          j        ||          }t          j        ||          }	t	          |	          }
|                     |
|           |                     |
                                |                                           |                     |
                                |                                           |                     t          |
          t          |                      || ||	|
|           d }d }	 ||         }||         }||         ||<   t          |          t          |          k    }n# t          $ r}|j
        }Y d }~nd }~ww xY wd }	 |
|         |
|<   n# t          $ r}|j
        }Y d }~nd }~ww xY w|r|                     |t                     |s|r|                     ||           |                     |
|           |                     |
                                |                                           |                     |
                                |                                            || ||	|
|           g{d S )Nc                    t          |          D ]\  }}||         }||         }|                     ||           |||<   ||k    r-|                     ||           |                     ||           n,|                     ||           |                     ||           |||<   |                     ||           |                     ||           |||<   |||<   d S r   )r-  r  assertNotEqual)	testcaserJ   r   rH   
singleitemr   rv   aimis	            r>   cmptestz9TestBufferProtocol.test_memoryview_array.<locals>.cmptest-  s   !!  1qTqT$$R,,,!!##++Aq111++Aq1111((A...((A...!!$$Q***$$Q***!! r_   r,   r   rO   )ri   r   rH  rO   rQ   r  ra  r8  rd   rN  rO  r  r   )rr  r^  r   r;   rx   r[  rX  rP  rJ   r   rH   	array_errhave_resizealarrQ  m_errs                    r>   test_memoryview_arrayz(TestBufferProtocol.test_memoryview_array+  s   	 	 	$ q! (	? (	?A*5a*A*A '? '?&UJ'll &? &?F"+A,, %? %?!KU33!KU33&qMM((A...((QXXZZ@@@((aiikkBBB((QQ888aAz:::$(	&*4!"6B!"6B()&	AfI*-b''SWW*<KK( 4 4 4()IIIIII4 !%0()&	AfII( 0 0 0$%KEEEEEE0 ' ? MM%<<<<" ?i ? MM%;;;; ,,Q222 ,,QXXZZDDD ,,QYY[[!))++FFF#GD!Q:>>>>K%?&?'?(	? (	?s0   ;F
F0F++F06G
GGGc                    t          j         dg d          }t          j         dg d          }t          |          }t          |          }dD ]f}|                      t          ||          |          t                     |                      t          ||          |          t                     gt          |          }|                                 |                     ||           |                     ||           |                     ||           t          |          }t          |          }|                                 |                     ||           |                     ||           t          |          }|                     |g d           t          dgdgdt                    }d	t          d
          f|d<   |                     t          |          |           t          j         dd          }t          |          }|                     ||           |                     ||           t          r G d dt          j                  } |dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     t          |j                   d S d S )Nr   r  )r,   r!   r7   )__lt____le____gt____ge__r=  r,   zl x d xr|  r   r5  r   ur  c                   2    e Zd Zdej        fdej        fgZdS )ITestBufferProtocol.test_memoryview_compare_special_cases.<locals>.BEPointr]   r  Nr  r  r  r  r  r  r   r_   r>   r  rl    &         &-032FGr_   r  r   r&  )rO   rQ   r  getattrr5  r  r  rY  r   r'  r-  r  r  r  rc  ra  )	rr  rJ   r   r   wattrri  r  r  s	            r>   %test_memoryview_compare_special_casesz8TestBufferProtocol.test_memoryview_compare_special_casesi  s   KYYY''KYYY'' qMMqMM< 	? 	?DMM*'!T**1--~>>>MM*'!T**1--~>>>> qMM			AAq!!!Aq!!!qMMqMM			Aq!!!Aq!!! qMMAyyy))) fXaS+NNNU5\\"1JrNNB/// KU##qMMAq!!!Aq!!!  
	=H H H H H&3 H H HGC%%E5!!A5!!A1%%%5)))q)))118<<<<<
	= 
	=r_   c                    t          dg d          }t          dg dt                    }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     |                    |                     |                     |                    |                     d|d<   |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     |                    |                     |                     |                    |                     t          t          t          d                    dgt          t          z  	          }t          t          t          d                    dgt          t          z  	          }t          |          }|                     ||           d
|d<   |                     ||           t          dg d          }t          dg dt                    }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dg d          }t          dg dt                    }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )N  @Lr}  r   r|  i  r   r  r  r   r  )rt  r  r   Lf5shf5s)i?r  r   )r   r'  rQ   r  rl  __ne__rY  r4  r   ri   r  )rr  nd1nd2r   rp  ri  r  rH   s           r>   !test_memoryview_compare_ndim_zeroz4TestBufferProtocol.test_memoryview_compare_ndim_zero  s)   d"T222d"SDDDsOOsOOAAC   a   C   a   !%%%!%%%"Aq!!!Aq!!!As###C###As###C###!%%%!%%%T%))__RDF8JKKKT%))__RDF8JKKKrNNB!Ar""" +2fEEE+2f') ) )sOOsOOAAC   a   C   a    +2fEEE,Bv') ) )sOOsOOAq!!!Aq!!!As###C###As###C###C   C     r_   c                 ^	   t          g ddgd          }t          g ddgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          g ddgd          }t          g ddgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          g dd	gd          }t          g ddgd          }t          |          }t          |          }|                     ||d d d
                    |                     |d d d
         |           |                     ||d d d
                    |                     |d d d         |d d d                    t          g dd	gd          }t          g ddgd          }t          |          }t          |          }|                     ||d d d
                    |                     |d d d
         |           |                     ||d d d
                    |                     |d d d         |d d d                    t          g dd	gd          }t          g ddgdt                    }t          |          }t          |          }|                     ||d d d
                    |                     |d d d
         |           |                     ||d d d
                    |                     |d d d         |d d d                    t          g dd	gd          }t          g ddgdt                    }t          |          }t          |          }|                     ||d d d
                    |                     |d d d
         |           |                     ||d d d
                    |                     |d d d         |d d d                    d S )N@    'r   @hr}  )r~  r  r  r  i  z<iz>h)r~  r  r  rk  r!   r   r  z!hz<lr|  zh  0cz>  h)r   rQ   r  rY  r  rr  ry  rz  r   rp  s        r>    test_memoryview_compare_ndim_onez3TestBufferProtocol.test_memoryview_compare_ndim_one  s
    2221#dKKK111!TJJJsOOsOOC   C   As###As###Aq!!! 2221#dKKK111!TJJJsOOsOOC   C   As###As###Aq!!! (((DAAA2221#dKKKsOOsOOC!H%%%33Q3%%%AcccF###44R4!DDbD'*** (((DAAA2221#dKKKsOOsOOC!H%%%33Q3%%%AcccF###44R4!DDbD'*** (((DAAA2221#d"$ $ $sOOsOOC!H%%%33Q3%%%AcccF###44R4!DDbD'*** (((GDDD2221#f"$ $ $sOOsOOC!H%%%33Q3%%%AcccF###44R4!DDbD'*****r_   c                    t          ddgdgd          }t          ddgdgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          ddgdgd          }t          ddgdgd	          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )
N  r  r   r  r}  i|i?z= h0cz@   ir   rQ   r  r  s        r>   "test_memoryview_compare_zero_shapez5TestBufferProtocol.test_memoryview_compare_zero_shape%  s|    sCjD999tTl1#d;;;sOOsOOC   C   C   C   A sCjG<<<tTl1#g>>>sOOsOOC   C   C   C   Ar_   c                    t          g ddgd          }t          dgdgdgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          d	gdz  dgd
          }t          d	gdgdgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )N)r  r  r  r  r>  ru  r}  r  r   r   r  )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seA3C@@@sOOsOOC   C   C   C   A zl1nQC???zl1#s7KKKsOOsOOC   C   C   C   Ar_   c                 x   d}t           d         D ]}t          |dd|          \  }}}dt          fD ]k}t          ||g||          }t	          |          }|                     ||           |d d d         }t	          |          }|                     ||           ld}t          d          D ]}	t          |          \  }}}dt          fD ]k}t          ||g||          }t	          |          }|                     ||           |d d d         }t	          |          }|                     ||           ld S )	Nrn   rI   rQ   rA   r   r|  r  r   )rV   r|   r  r   rQ   r  ri   )
rr  r   r[   r;   rx   r[  r&  ri  rH   rv   s
             r>   &test_memoryview_compare_random_formatsz9TestBufferProtocol.test_memoryview_compare_random_formatsY  sv    DM 		( 		(D%.q,T%J%J"C
V ( (U1#cGGGrNN  B'''"XrNN  B''''( s 		( 		(A%.q\\"C
V ( (U1#cGGGrNN  B'''"XrNN  B''''(		( 		(r_   c                 j   t          t          t          dd                    g dd          }t          t          t          dd                    g dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  g dd	          }t          d
gdz  g dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d                    g dd          }t          t          t          d                    g dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  ddgd          }t          dgdz  ddgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d                    g dd          }t          t          t          d                    g dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )Nr5   rk  r!   r   r  r}  r   r  r   r,   r!   z=f q xxL)g333333r,   r!   z< f 2Qr;  r      rk  r7   z! b B xLz
= Qx l xxLr   r   r   ri   rQ   r  rY  r  s        r>   "test_memoryview_compare_multidim_cz5TestBufferProtocol.test_memoryview_compare_multidim_cu  s    d5b>>**)))DIIId5B<<((			$GGGsOOsOOC   C   As###As###Aq!!! yk"nIIIjIII|nR'yyyJJJsOOsOOC   C   As###As###Aq!!! d599ooYYYsCCCd599ooYYYsCCCsOOsOOC   C   As###As###Aq!!! yk"nQF:FFFyk"nQF<HHHsOOsOOC   C   As###As###Aq!!! d599ooYYYsCCCd599ooYYYsCCCsOOsOOC   C   C   C   Ar_   c                 B	   t          t          t          dd                    g ddt                    }t          t          t          dd                    g ddt                    }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgd	z  d
dgdt                    }t          dgd	z  d
dgdt                    }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          dd                    g ddt                    }t          t          t          dd                    g ddt                    }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          dd                    g ddt                    }t          t          t          dd                    g ddt                    }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d                    g ddt                    }t          t          t          d                    g ddt                    }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )Nr  r5   )r   r!   rk  r  r|  r   r  r   r   r?  r!   rk  =Qq)r   r   z=qQr;  r   r  0llrK   )r   r   ri   r  rQ   r  rY  r  s        r>   (test_memoryview_compare_multidim_fortranz;TestBufferProtocol.test_memoryview_compare_multidim_fortran  sv    d5b>>**)))D&( ( (d5B<<((			$&( ( (sOOsOOC   C   As###As###Aq!!! }oa'1ve&( ( (}oa'1ve&( ( (sOOsOOC   C   As###As###Aq!!! d5b>>**)))C&( ( (d5b>>**)))C&( ( (sOOsOOC   C   As###As###Aq!!! d5b>>**)))E&( ( (d5b>>**)))C&( ( (sOOsOOC   C   As###As###Aq!!! d599ooYYYt&( ( (d599ooYYYt&( ( (sOOsOOC   C   C   C   Ar_   c                 j   t          t          dd                    }t          |g d          }t          |g dd          }t          |g ddt                    }t          |          }t          |          }|                     ||           |                     ||           |                     ||           dgd	z  }d
|d<   t          |g d          }t          |g dd          }t          |g ddt                    }t          |          }t          |          }|                     ||           |                     ||           |                     ||           t          t          t          d                    ddgd          }|dddd d df         }t          t          t          d                    ddgd          }|dddd d df         }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  ddgd          }|dddd d df         }t          dgdz  ddgd          }|dddd d df         }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d	                    g dd          }|ddd d df         }t          t          t          d	                    g dd          }|ddd d df         }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d	                    g dd          }|ddd d df         }t          t          t          d	                    g dd          }|ddd d df         }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgd	z  g d d!          }|ddd d df         }t          dgd	z  g d d"          }|ddd d df         }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )#Nr  r5   r  @lr}  r   r|  )gffffff
rL  r  )gr  rL  r   zd b czd h c(   r6   @Irk  r,   r   r  r   )r  r&      r  r!   z=iiz>iir;  r   r   )r!   r  r   rk  r!   b3si3s)r   ri   r   r   r  rQ   r  rY  )	rr  lst1lst2ry  rz  r   rp  r  r  s	            r>   &test_memoryview_compare_multidim_mixedz9TestBufferProtocol.test_memoryview_compare_multidim_mixed  sY    E#rNN##yyy))d)))D999d)))CzJJJsOOsOOC   C   A ""2%#Qyyy))d)))G<<<d)))G:NNNsOOsOOC   C   A d599ooaVDAAA!Ab&$$B$,d599ooaVC@@@!Aa%2+sOOsOOC   C   As###As###Aq!!! ()",RGEJJJ!Ab&$$B$,()",RGEJJJ!Aa%2+sOOsOOC   C   C   C   A d599ooYYYsCCC!A$"*od599ooYYYsCCC!A$"*osOOsOOC   C   As###As###Aq!!! d599ooYYYsCCC!A$"*od599ooYYYsCCC!A$"*osOOsOOC   C   As###As###Aq!!! {mB&iiiFFF!A$"*o{mB&iiiFFF!A$"*osOOsOOC   C   As###As###Aq!!!!!r_   c                    t          t          t          d                    g dd          }t          t          t          d                    g dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d                    g dd          }t          t          t          d                    g dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )Nr  )r   rk  r!   r   r}  )r   r   r!   z@ir  r  s        r>   +test_memoryview_compare_multidim_zero_shapez>TestBufferProtocol.test_memoryview_compare_multidim_zero_shape\  s    d599ooYYYsCCCd599ooYYYtDDDsOOsOOC   C   As###As###Aq!!! d599ooYYYsCCCd599ooYYYtDDDsOOsOOC   C   As###As###Aq!!!!!r_   c                 j   t          dgdz  g dd          }t          dgg dg dd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           |                     |                                |                                           t          d	gd
z  ddgd          }t          d	gddgddgd          }t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )Nr  r  )r>  r   r>  ru  r}  rC  r   r  r'  rn   r!   r   z=lQr   z<lQ)r   rQ   r  ra  r  s        r>   -test_memoryview_compare_multidim_zero_stridesz@TestBufferProtocol.test_memoryview_compare_multidim_zero_stridesv  s    seBhiii===se999iiiLLLsOOsOOC   C   C   C   AQXXZZ000 vhrk!Q>>>vhq!fq!fUKKKsOOsOOC   C   C   C   Ar_   c                 r   t          t          t          d                    ddgd          }|dddd d d	f         }t          t          t          d                    ddgd
t                    }|dddd d d	f         }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  ddgdt                    }d|d         d<   |dddd d d	f         }t          dgdz  ddgdt          t          z            }d|d         d<   |dddd d d	f         }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d                    g ddt                    }|ddd d d	f         }t          t          t          d                    g dd          }|ddd d d	f         }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  g ddt          t          z            }|ddd d d	f         }t          dgdz  g dd          }|ddd d d	f         }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          t          d                    g ddt                    }|ddd d d	f         }t          t          t          d                    g ddt                    }|ddd d d	f         }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  g ddt          t          z            }d|d         d         d<   |ddd d d	f         }t          dgdz  g ddt          t          z            }d|d         d         d<   |ddd d d	f         }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          t          dd                     }t          |g d          }t          |g dd!t                    }t          |g dd"t          t          z            }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           d#gdz  }d$|d%<   t          |g d          }t          |g dd&t                    }t          |g dd't          t          z            }t	          |          }t	          |          }|                     ||           |                     ||           |                     ||           d S )(Nr  r   r6   r  r}  rk  r,   r   r  r   r|  r  r  )r,   r  r!   r7   z>Qqr  r;  r   r  )r  r   Bbr  r   )s   hellor_   r,      )rk  rk  rk  5s0sP)s   sushir_   r,   r  r5   r  r   )s   sashimis   slicedg4@)s   ramens   spicygfffff"@r  z
< 10p 9p dz
> 10p 9p d)
r   r   ri   r  rQ   r  rY  r'  r   r  )	rr  r  ry  r  rz  r   rp  r  r  s	            r>   +test_memoryview_compare_multidim_suboffsetsz>TestBufferProtocol.test_memoryview_compare_multidim_suboffsets  s    d599ooaVDAAA!Ab&$$B$,d599ooaVCvNNN!Aa%2+sOOsOOC   C   As###As###Aq!!! }ob(Au') ) )Aq	!Ab&$$B$,}ob(Au";.0 0 0Aq	!Aa%2+sOOsOOC   C   C   C   A d599ooYYYs"$ $ $!A$"*od599ooYYYsCCC!A$"*osOOsOOC   C   As###As###Aq!!! |nR'yyy";.0 0 0!A$"*o|nR'yyyFFF!A$"*osOOsOOC   C   As###As###Aq!!! d599ooYYYs&QQQ!A$"*od599ooYYYt6RRR!A$"*osOOsOOC   C   C   C   A )*2-YYYw";.0 0 0)Aq	!!A$"*o)*2-YYYw";.0 0 0)Aq	!!A$"*osOOsOOC   C   As###As###Aq!!! E#rNN##yyy))d)))DGGGd)))Cz&?PQQQsOOsOOC   C   A //2-Ryyy))d)))LOOOd)))L&v-/ / /sOOsOOC   C   Ar_   c                    dD ]}t          dgdz  g d|dz             }t          dgdz  g d|dz   t          t          z            }d|d	         d
         d         d         d<   t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           t          dgdz  g d|dz             }t          dgdz  g d|dz   t          t          z            }d|d	         d
         d         d         d<   t          |          }t          |          }|                     ||           |                     ||           |                     ||           |                     ||           |                     ||           d S )N)rD   rB   rC   rE   r)   r  )rk  r   r!   r!   r!   r   r}  r|  r,   r!   rk  )r)   r'   r%   QLH)r,   r,   r,   )r   r'  r  rQ   r  rY  )rr  	byteorderr]   r  rJ   r   s         r>   !test_memoryview_compare_not_equalz4TestBufferProtocol.test_memoryview_compare_not_equal  s    . 	& 	&I;;;y}MMMA;;;y})*46 6 6A AaDGAJqM!1A1AQ"""Q"""1%%%1%%%1%%%./3;;;(0 0 0A./3;;;(k*6LN N NA(AaDGAJqM!1A1AQ"""Q"""1%%%1%%%1%%%%1	& 	&r_   c                 0   t          j         dg d          }t          |          }|                                 |                     t          t          |           |                     t          |j        d           |                     t          t          |           |                     t          |j                   |                     t          |j                   |                     t          t          dt                                 |                     t          |j        d           |                     t          |j        dd           dD ]#}|                     t          |j        |           $t          j         dg d          }t          |          }t          |          }|                     ||           |                                 |                     ||           |                     ||           |                     ||           d S )Nr   )g?g@gffffff
@r   z1.0 in mr   r,   )r\   r6  r  r   r%  r   r   r   re  r  r  r  )rO   rQ   r  r  r   ru  r   ra  r8  r?  r@  r+  r)  __getattribute__r  rY  )rr  rJ   rH   rq  r   r  r  s          r>   test_memoryview_check_releasedz1TestBufferProtocol.test_memoryview_check_released/  s   K___--qMM			 	*j!444*afc222*gq111*ah///*ai000*dJAAA*amQ777*amQ:::3 	D 	DD j!*<dCCCC K___--]]]]R   


B###B"""R     r_   c                    dt          dgd          }t          |          }|                     ||           |                     |                                |                                           t          gdgd          }t          |          }|                     ||           |                     |                                |                                           t          fdt	          d          D             g d	d
          }t          |          }|                     ||           |                     |                                |                                           t          fdt	          d          D             g dd          }t          |          }|                     ||           |                     |                                |                                           t
          rj G d dt
          j                  } |dd          }t          |          }|                     |                                t          |                     d S d S )Nr}  r   r  r}  r,   z>hQiLlc                     g | ]}S r   r   r   rv   r   s     r>   r   z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>f  s    +++Aa+++r_   r  r  z=hQiLlc                     g | ]}S r   r   r  s     r>   r   z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>k  s    ,,,Aa,,,r_   r  )r   r!   r!   rk  r!   z<hQiLlc                   2    e Zd Zdej        fdej        fgZdS );TestBufferProtocol.test_memoryview_tobytes.<locals>.BEPointr]   r  Nrm  r   r_   r>   r  r  t  rn  r_   r  r   r&  )r   rQ   r  r8  ri   r  r  rW   )rr  ri  rH   r  r  rJ   r   s         @r>   test_memoryview_tobytesz*TestBufferProtocol.test_memoryview_tobytesW  sR    )Qqc$///rNNBbjjll333aSH555rNNBbjjll333++++r+++7778LLLrNNBbjjll333,,,,s,,,KKK$& & &rNNBbjjll333  	8H H H H H&3 H H HGC%%E5!!AQYY[[%,,77777	8 	8r_   c                    |                      t          t          i t          d           |                      t          t          dt
          d           t          g ddgdg          }|                      t          t          |t
          d           t          dd	d
          }dD ]J}t          |t          |          }|                     ||           |                     |d	         d           Kt          dd	d
t                    }dD ]J}t          |t          |          }|                     ||           |                     |d	         d           KdD ]}d|d	<   t          |t
          |          }|                     ||           |                     |d	         d           d|d	<   |                     |d	         d           |                     |d	         d           t          dgdgd
t                    }dD ]w}t          |t          |          }|                      t          |j
        d           |                     ||           |                     |                                g            xt          t          t          d                    g dd
t                    }dD ]O}t          |t          |          }|                     t          |                                          g g g           Pt          dgdgdt                    }dD ]h}t          |t
          |          }|                     ||           |                     |                                |                                           it          g ddgdt                    }dD ]h}t          |t
          |          }|                     ||           |                     |                                |                                           it          g ddgdgt                    }dD ]}t          |t          |          }|                     ||           |                     |                                |                                           |                      t          |j        dd           |                     |d         d           |                     |d         d           |d d d         }dD ]}t          |t          |          }|                     ||           |                     |                                |                                           |                      t          |j        dd           |                     |d         d           |                     |d         d           t          t          t          d                    ddgt                    }dD ]_}t          |t
          |          }|                     t          |                                          |                                           `|                      t          t          |t
          d           t          |t          |          }|                     t          |                                          |                                           t          t          t          d                    ddgt          t          z            }dD ]_}t          |t
          |          }|                     t          |                                          |                                           `|                      t          t          |t
          d           t          |t          |          }|                     t          |                                          |                                           t          t          t          d                    ddgt          t           z            }dD ]}|                      t          t          |t
          |           t          |t          |          }|                     t          |                                          |                                           t          g ddgdg          }t          |t          d          }|                     |j                   d S )Nrz  rL  r   r  r!   r  r{  r  r   r   r}  ry  r|  rn   r,   r   r6   r  r   rk  r   r  r  r   r  r>  r  )r   r{  )rz  r{  r  )r  rb  r  r  r  PyBUF_WRITEr   r  r'  r,  r+  ra  r   ri   r)  r  r  r  r  )rr  ri  r  rH   s       r>   test_memoryview_get_contiguousz1TestBufferProtocol.test_memoryview_get_contiguousz  s    	)^RSIII 	+~t[#NNN YYYqcA3777+~r;LLL Qb---$ 	' 	'Er:u55AQ###QrUA&&&& QbK@@@$ 	' 	'Er:u55AQ###QrUA&&&& % 	) 	)EBrFr;66AQ###QrUA&&&AbEQrUB'''RVR(((( aSC{CCC$ 	- 	-Er:u55Aj!-;;;Q###QXXZZ,,,,T%((^^999S&( ( ($ 	< 	<Er:u55AWQZZ..002r(;;;; aSC{CCC$ 	6 	6Er;66AQ###QXXZZ5555YYYqc#[III$ 	6 	6Er;66AQ###QXXZZ5555 YYYqcA3kJJJ$ 	' 	'Er:u55AQ###QXXZZ555i2>>>QqT1%%%RUA&&&&"X$ 	' 	'Er:u55AQ###QXXZZ555i2>>>QqT1%%%RUA&&&& T%))__QF+FFF 	? 	?Er;66AWQZZ..00"))++>>>>+~r;LLL2z511**,,biikk:::T%))__QF&z13 3 3 	? 	?Er;66AWQZZ..00"))++>>>>+~r;LLL2z511**,,biikk::: T%))__QF+f:LMMM$ 	? 	?Ek>2{#% % %r:u55AWQZZ..00"))++>>>> [[[aS9992z3//'''''r_   c                    t          j        d          }t          j        dg d          }t          |          }t	          j        |          }t          d|z            }|                    |           |                     |	                                |           t          j        d          }t          t          t          d                    g dd          }t          |          }t	          j        |          }t          d|z            }|                    |           |                     |	                                |           d S )Nr   r  r   r   r  r  r}  )r8   r  rO   rQ   ioBytesIOr,  readintor  r8  r   r   ri   )rr  r  rJ   rH   r0  r   ri  s          r>   test_memoryview_serializingz.TestBufferProtocol.test_memoryview_serializing  s    s##K[[[))qMMjmmafQa((( s##T%))__GGGC@@@rNNjmmeDj!!Qa(((((r_   c                 	   t          t          t          d                              }t          |          }|                     t          |          t          |                     |                    dddg          }|                     t          |          t          |                     |d d d         }t          t          t          d                    d d d                   }|                     t          |          t          |                     t          t          t          d                    g dt          	          }t          |          }|                     t          |          t          |                     t          t          t          d                    g d          }|d d d
d d d d df         }t          |          }|                     t          |          t          |                     t          t          t          d                    g dt          	          }|d d d
d d d d df         }t          |          }|                     t          |          t          |                     t          t          t          d                    dgd          }t          |          }t          t          t          d                    dgd          }t          |          }|                     ||           |                     t          |          t          |                     t          t          t          d                    g dd          }t          |          }| 
                    t          |j                   t          t          t          dd                    g dd          }t          |          }| 
                    t          |j                   t          t          t          d                    g dd          }t          |          }| 
                    t          |j                   t          t          t          dd                    g dd          }t          |          }| 
                    t          |j                   d S )Nr  r   rk  r>  r  r  r  r  r  r!   r   )r!   r   rk  r   r}  r   r  r   r3  r?  r   z= Lz< h)rW   r   ri   rQ   r  r  ru  r   r  r  r  r   __hash__)	rr  r   rH   mcmxri  r]   rJ   r  s	            r>   test_memoryview_hashz'TestBufferProtocol.test_memoryview_hash  s    $uRyy//""qMMa$q''*** VVC!uV%%b477+++ tttW$uRyy//$$B$'((b477+++ T%))__GGG:FFFrNNa$r((+++ T%))__GGG444sssBBB"}qMMa$q''*** T%))__GGG6BBBsssBBB"}qMMa$q''*** DrOOB4<<<qMMDrOOB4<<<qMMAa$q''*** T%))__GGGC@@@rNN*aj111T%A,,''wwwsCCCrNN*aj111T%))__GGGEBBBrNN*aj111T%A,,''wwwuEEErNN*aj11111r_   c           
      |   t          g d          }t          |          }t          |          }|                     t          |j                   ~|                                 t          g d          }t          |          }t          |t          t                    }t          |t          t                    }|                     |j	        |           |                     t          |j                   ~~|                                 t          g d          }t          |          }t          |          }t          |          }|                                 |                     t          |j                   ~|                                 t          g d          }t          |          }t          |          }t          |t          t                    }t          |t          t                    }|                     |j	        |           |                                 |                     t          |j                   ~~|                                 t          g ddgt                    }t          |          }|                    g ddg           t          |          }t          |          }|                     |                                |                                           t          |          }	|                     |	                                |                                           |                     |	                                |                                           |                                 |	                                 |                                 |                     |                                |                                           ~|                                 |                                 d }
t          d	          }t          |          5 } |
|           |                     |d
         t          d                     d d d            n# 1 swxY w Y   t          t!          t#          d                    g dd          }t          |t          t                    }	t          |	t          t                    }|                     |j	        |           t          |          5 } |
|           |                     |d
d                                         g dg dgg           d d d            n# 1 swxY w Y   d
t          fD ]}t          d	          }t          |          5 }~t          |t          |          }	t          |	          5 }~	t          |t          |          }t          |          5 }~ |
|            |
|            |
|           |                     |d
         t          d                     |                     |d         t          d                     |                     |d         t          d                     ~d d d            n# 1 swxY w Y   ~d d d            n# 1 swxY w Y   ~d d d            n# 1 swxY w Y   t          d	          }t          |          5 }~t          |t          |          }	t          |	          5 }~	t          |t          |          }t          |          5 }~ |
|            |
|            |
|           |                     |d
         t          d                     |                     |d         t          d                     |                     |d         t          d                     ~~~d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          d	          }|                     t                    5  t          |          5 }t          |          }|d
         t          d          k     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  r  r&  rk  r  )r>  r   r?  r7   r6   r   r  c                 X    t          |           5 }	 d d d            d S # 1 swxY w Y   d S r   )rQ   )r   r  s     r>   catch22z;TestBufferProtocol.test_memoryview_release.<locals>.catch22  sr    A "                 s   ##r  r   rI  r  r  r   r}  r,   r  )rk  r>  r   rJ  r!   rK  )r,  rQ   r   r  r  r  r  ND_REDIRECTr  r\   r  r  r  ra  r
  ordr   ri   )rr  rJ   rH   ri  ry  rz  r  r  r]   r  r  ri  r&  r  r  s                  r>   test_memoryview_releasez*TestBufferProtocol.test_memoryview_releaseI  s	    gggqMMQZZ+qy111			gggqMMa[AAAc-{CCCcgq!!!+qy111			 ggg]]^^R[[


+rz222


ggg]]^^bkBBBc-{CCCcgr"""


+rz222


 WWWQC|<<<^^
A3'''^^rNNRYY[[111rNNRYY[[111RYY[[111


			
RYY[[111


			
	 	 	 f]] 	/bGBKKKRUCII...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ DrOO7773???Am;???Am;???aeQ]] 	HaGAJJJQqsV]]__			999/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FA#A "((AD		:::((AD		:::((AD		:::                              !              $ &!!AA '"B}EBBB]] 'b=FFFA#A '"((AD		:::((AD		:::((AD		:::B' ' ' ' ' ' ' ' ' ' ' ' ' ' '' ' ' ' ' ' ' ' ' ' ' ' ' ' '' ' ' ' ' ' ' ' ' ' ' ' ' ' '" f{++ 	" 	"A "!QZZ!D		!!" " " " " " " " " " " " " " "	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s  ?5R  RRAU**U.1U.([
(Z2/BZ	Z2ZZ2!Z"Z2&[
2Z66[
9Z6:[

[	[	3(`(`B!_0	$`0_44`7_48`;``````"	%`"	b1$)bb1b	b1 b	!b11b58b5c                    t          d t          d          D             dgd          }t          j        dd t          d          D                       }||fD ]w}t          |t          t                    }t          |t          t                    }t          |          }|                     |j        |           |                     |j        |           |                     |j        |           |                     ||           |                     ||           |                     ||           |                     |dd         |dd                    |                     |dd         |dd                    |                     |dd         |dd                    ~~|                     |dd         |dd                    yd S )	Nc                     g | ]}d |z  S r,  r   r  s     r>   r   z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>  s    111!cAg111r_   r  r   r}  c                     g | ]}d |z  S r  r   r  s     r>   r   z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>  s    999!cAg999r_   r  r,   rk  )	r   ri   rO   r  r  rQ   r  r\   r  )rr  ri  rJ   r]   r  ri  rH   s          r>   test_memoryview_redirectz+TestBufferProtocol.test_memoryview_redirect  s   11uRyy111"cJJJK99uRyy999::a 	- 	-A-{CCCA-{CCCA1AMM!%###MM!%###MM!%###Q"""Q"""Q"""QqsVQqsV,,,QqsVQqsV,,,QqsVQqsV,,,1QqsVQqsV,,,,#	- 	-r_   c                 L   d}g d}|                      t          t          ddd           t                      }t          |          }|                     ||d|dddgdg|	  	         t          d          D ]}|                     ||         |           ~~t                      }t          |          }~~t                      }t          |t          	          }t          |t          	          }t          |          }| 	                    |j
        |           | 	                    |j
        |           |                     ||d|dddgdg|	  	         ~~~~t                      }t          |t          t          
          }t          |t          t          
          }t          |          }| 	                    |j
        |           | 	                    |j
        |           | 	                    |j
        |           |                     ||d|dddgdg|	  	         ~~~~t          d          }t          |          }|                     |d d|dddgdg|	  	         t          d          D ]}|                     ||         |           ~~t          d          }t          |          }~~t          d          }t          |t          	          }t          |t          	          }t          |          }| 	                    |j
        d            | 	                    |j
        |           |                     ||d|dddgdg|	  	         ~~~~t          d          }t          |t          t          
          }t          |t          t          
          }t          |          }| 	                    |j
        d            | 	                    |j
        |           | 	                    |j
        |           |                     ||d|dddgdg|	  	         ~~~~d S )Nr   )r   r,   r!   rk  r>  r   r?  r7   r6   r  rn   r  r,   r!   rk  Tr  r  r  r  )legacy_mode)r  rb  staticarrayrQ   r  ri   r  r   r  r  r\   r  )rr  r;   rj   r]   r  r   ri  rH   s           r>   $test_memoryview_from_static_exporterz7TestBufferProtocol.test_memoryview_from_static_exporter  sN   ))) 	)[!Q::: MMqMMA1C$2$ 	 	 	 	 r 	& 	&AQqT1%%%%MMqMMMMAm,,,Am,,,qMMaeQaeQA1C$2$ 	 	 	 	 q!QMMAm;???Am;???qMMaeQaeQaeQA1C$2$ 	 	 	 	 q!Q D)))qMMA4C$2$ 	 	 	 	 r 	& 	&AQqT1%%%%D)))qMMD)))Am,,,Am,,,qMMaeT"""aeQA1C$2$ 	 	 	 	 q!QD)))Am;???Am;???qMM 	aeT"""aeQaeQA1C$2$ 	 	 	 	 q!QQQr_   c                     t          g ddgt          t          z            }|                     t          t
          |           d S )Nr  rk  r  )r   r  ND_GETBUF_UNDEFINEDr  r  rQ   r  s     r>   #test_memoryview_getbuffer_undefinedz6TestBufferProtocol.test_memoryview_getbuffer_undefined?  sB     WWWqc8K)KLLL+z266666r_   c                 |    t          g ddgt                    }|                     t          t          |           d S )Nr  rk  r  )r   r  r  r  rQ   )rr  r]   s     r>   test_issue_7385z"TestBufferProtocol.test_issue_7385E  s:    GGGA3n===+z155555r_   c                     dD ]<}|                      t          j        |          t          j        |                     =d S )N)r@   ii3s)r  	_testcapiPyBuffer_SizeFromFormatr8   r  )rr  r%  s     r>   test_pybuffer_size_from_formatz1TestBufferProtocol.test_pybuffer_size_from_formatI  sT     ' 	6 	6FY>vFF#_V446 6 6 6	6 	6r_   NF)Ur  r  r  rs  r  r  r  r  r  r  r  r  r  r#  r-  r/  r1  r6  r9  r=  rA  rI  rK  rT  rV  r^  ra  rj  rn  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r&  r*  r0  
contextlibcontextmanagerr6  rF  rS  rV  rd  rr  r{  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>   rm  rm    sW       1 1 1 "'UH H H H HT., ., ., .,`g< g< g<R\= \= \=|   $ $ $
' 
' 
'3 3 3*= = =+) +) +)Z%L %L %LN6 6 64E E E.. .. ..`,1 ,1 ,1\H H H>- - -&W7 W7 W7r< < <(D D D@!@ !@ !@F4/ 4/ 4/l> > >B'0 '0 '0R3 3 38<E <E <E|( ( (I I I&; ; ;/ / /
$ $ $> > >2 2 2
0 
0 
0#7 #7 #7Jn8 n8 n8`sQ sQ sQj- - -$ 'L? ? ?62 62 62p5 5 5q@ q@ q@f:. :. :.xR0 R0 R0h9 9 9<3 3 3A A A I I I3A 3A 3AjkI kI kIZ6& 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 !8Fs( s( s(j) ) )<:2 :2 :2x~" ~" ~"@- - -0\ \ \|7 7 76 6 6 6 6 6 6 6r_   rm  __main__)r   NN)r   r4   r   )r   r4   r  r   r  rA  )ir  unittesttestr   test.supportr   	itertoolsr   r   randomr   r   r	   warningsrf  rO   r  osdecimalr
   	fractionsr   _testbufferImportErrorr   r8   r  EnvironmentVarGuardenvironcatch_warningsrP   r/  r  
SHORT_TESTNATIVEr9   r:   STANDARDr?   rV   r;   copyr   ARRAYr<  BYTEFMTrp   rr   ro   r^   rg   rk   rz   r|   r~   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  r  r   r"  r(  r1  r<  rF  rH  rL  rP  r   rY  r]  rj  r`  rd  re  
skipUnlessTestCaserm  r  mainr   r_   r>   <module>r     s               " " " " " " + + + + + + + + , , , , , , , , , ,                                GGGMMMM   FFFMMMM   FFF	&	&	(	( 1BJ	 	 	"	"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    KKK   III 
 	
qaQ	qaQ	qaQ	qa	
 
  ss	 C!!!ss<   
 	yyzzzz!T'
AtG4   *   
 3s| 3 3--c22S[[]]
	  A!H
++--	  A::AJ 	...0C0C0CD5555    - - -       0 0 0 0( ( ( (2 2 2$ $ $ EDgclDDD% % %! ! !          
  
  
    0 0 0  C C CI I I  ,  2 2 2<? ? ?4  
    =: =: =: =:~  
* 
* 
*): ): ): ):V9 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P96 P96 P96 P96 P96* P96 P96 GF FEP96fr zHMOOOOO s   A AAA   A*)A*.A3 3A=<A=C C%B8,C8B<	<C?B<	 CC CC CC C%$C%)C. .C87C8D6 6
EE