o
    1ήcJ                     @   s  d dl 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Zd dl	m
Z
mZ d dlmZ d dlmZ d dlZd dlmZmZmZmZmZmZmZmZmZ ejejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+ej,gZ-ej./ Z0ej1/ Z2e3 dgZ4ej5ej6ej7ej8ej9ej:ej;ej<ej=ej>ej?ej@ejAgZBG dd dZCejDjEed	d
de
eeBejFeG ddejFeG dddd ZHG dd dZIG dd dZJdd ZKdd ZLG dd dZMG dd dZNG dd dZOG dd dZPesG d d! d!ZQG d"d# d#ZRG d$d% d%ZSG d&d' d'ZTG d(d) d)ZUG d*d+ d+ZVG d,d- d-ZWe jXd.d/ ZYe
ee4eeBee-d0d1 ZZe
ee4eeBee-d2d3 Z[e
eeBee-ee-d4d5 Z\ejD]d6eBd7d8 Z^ejD]d6eBd9d: Z_ejD]d;ej`d< ejDj]d=d>d? d@d? dAd? gg dBdCdDdE ZaejD]d;ej`dF ejDj]d=dGd? dHd? dId? gg dJdCdKdL ZbejD]d;ej`dM ejDjcdNdL ZbejD]d;ej`d< ejDj]d=dOd? dPd? gdQdRgdCdSdT ZddUdVej5dWfdXdYej6dWfdZdZej7dWfd[d[ej8dWfdVdUej:dWfdYdXej9dWfd\d]ej<d^fd_d`ejAd^fdadbej;d^fdcddej=d^fdedfej>d^fdgdhej?d^fdidjej@d^fgZeejD]g dkeeejD]dlejfejgej)gdmdn Zhdodp ZiejD]g dkeeejD]dqejekelejmgdrds ZndS )t    N)_pep440)givensettings)sampled_from)numpy)	assert_assert_equalassert_raisesassert_almost_equalassert_array_equalIS_PYPYsuppress_warnings_gen_alignment_dataassert_warnsc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	TestTypesc                 C   s,   t D ]}|d}t|dkd||f  qd S )N   error with %r: got %r)typesr   )selfatypea r   G/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/tests/test_scalarmath.py
test_types(   s   zTestTypes.test_typesc                 C   s   t tD ]C\}}|d}tjdg|d}t tD ].\}}|d}tjdg|d}|| }	|| }
t|	j|
jd|t|j|t|jf  qqd S )N   dtyper   z$error with types (%d/'%c' + %d/'%c'))	enumerater   nparrayr   r   char)r   kr   a_scalara_arraylbtypeb_scalarb_arrayc_scalarc_arrayr   r   r   test_type_add-   s   
zTestTypes.test_type_addc                 C   s<   t tD ]\}}tg d|}|g d}t|| qd S )Nr      r   )r   r   r   r   r   )r   r!   r   r   br   r   r   test_type_createA   s
   zTestTypes.test_type_createc                 C   s   t dD ]}tdd qd S )Ni@ r   )ranger   add)r   ir   r   r   	test_leakG   s   zTestTypes.test_leakN)__name__
__module____qualname__r   r*   r.   r2   r   r   r   r   r   '   s
    r   i'  i  )max_examplesdeadliner   )r   shapec           	      C   sx  |d }|d }t |tjsJ t |tjsJ |jjdks$|jjdkrAtjtjtjtj	h}| |v rAt
|s<t
|rAtd t m tjddN tdt z| ||}W n. ty } z"tt| | || W d   n1 syw   Y  W Y d}~nd}~ww | ||}t|| W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )z
    This is a thorough test attempting to cover important promotion paths
    and ensuring that arrays and scalars stay as aligned as possible.
    However, if it creates troubles, it should maybe just be removed.
    r   cz3complex comp ufuncs use sort-order, scalars do not.ignoreallerrorN)
isinstancer   genericr   kindoperatorgegtleltisnanpytestxfailwarningscatch_warningserrstatesimplefilterDeprecationWarning	Exceptionraisestyper   )	oparr1arr2scalar1scalar2comp_opsrese
scalar_resr   r   r   #test_array_scalar_ufunc_equivalenceN   s,   


PrZ   c                   @      e Zd Zdd Zdd ZdS )TestBaseMathc              	   C   s  t jdft jdft jdffD ]\}}t|d|dD ]\}}}}t |}t ||d< t ||d< tt ||||d tt |d|d |d tt d|||d t j|||d	 t|||d |d  t j	|j
|d
d 7  < tt |t |||d |t jkrtt |t d||d t ||d< t j|d|d	 t||d |d t ||d< t jd||d	 t||d |d qqd S )N      binary)r   rP   max_size.err_msgr,   r   outr   )r   float32float64int32r   	ones_like
zeros_liker
   r0   arangesizesquaremultiply
reciprocaldivide)r   dtszrd   inp1inp2msgexp1r   r   r   test_blockedr   s:   $
 


zTestBaseMath.test_blockedc                 C   s   t jdt jddd t j}t jdt jddd t j}t|| |d  t j|||d t jt |||d t j|t ||d t t || t |t | d S )N   r      r,   rc   )r   zerosint8viewrf   r
   r0   rh   )r   dor   r   r   test_lower_align   s     zTestBaseMath.test_lower_alignN)r3   r4   r5   rv   r   r   r   r   r   r\   q        r\   c                   @   4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )	TestPowerc                 C   s@   t jt jt jfD ]}|d}|d }t|dkd||f  qd S )Nr   rx   Q   r   )r   r{   int16float16r   r   tr   r-   r   r   r   test_small_types   s
   zTestPower.test_small_typesc                 C   sj   t jt jt jt jt jfD ]&}|d}|d }d||f }t |t jr+t|dk| qt	|d|d qd S )N3   rx   r   i:g ra   )
r   rg   int64re   rf   
longdouble
issubdtypeintegerr   r
   )r   r   r   r-   rt   r   r   r   test_large_types   s   zTestPower.test_large_typesc                 C   sP  dd dD }dd dD }t ||D ]'\}}|jtjkr'tttj|| qt||}t	|jj
tju  t|d qdd dD }t ||D ]'\}}|jtjkr\tttj|| qIt||}t	|jj
tju  t|d qId	d dD }t ||D ]'\}}|jtjkrtttj|| q~t||}t	|jj
tju  t|d
 q~d S )Nc                 S      g | ]
}t d |d qS r   r   r   .0rp   r   r   r   
<listcomp>       zETestPower.test_integers_to_negative_integer_power.<locals>.<listcomp>bhilqc                 S   r   )r   r   r   r   r   r   r   r      r   
bhilqBHILQ      ?c                 S   r   r   r   r   r   r   r   r      r         c                 S   r   )r,   r   r   r   r   r   r   r      r   g      ?)	itertoolsproductr   r   uint64r	   
ValueErrorrA   powr   rP   rf   r
   )r   expbasei1i2rW   r   r   r   'test_integers_to_negative_integer_power   s.   z1TestPower.test_integers_to_negative_integer_powerc              	   C   s   t jt jt jt jt jt jt jt jt jg	}|D ]4}|D ]/}|d}|d}|| }d|||df }t t 	|t j
rBt|dk| qt|d|d qqd S )Nr   r,   z(error with %r and %r:got %r, expected %r	   ra   )r   r{   r   r   re   rf   rg   r   r   r   r   r   r
   )r   typelistt1t2r   r-   resultrt   r   r   r   test_mixed_types   s"   
zTestPower.test_mixed_typesc                 C   sd   d}d}d}t |||}tjtjtjfD ]}tttj |||| tttj t|||| qd S )N   rx   
   )	r   r   rg   re   	complex64r	   	TypeErrorrA   r   )r   r   r-   r9   expectedr   r   r   r   test_modular_power   s   zTestPower.test_modular_powerN)r3   r4   r5   r   r   r   r   r   r   r   r   r   r      s    
$r   c                 C   s   | | | | fS Nr   )xyr   r   r   floordiv_and_mod   s   r   c                 C   s   | t jd v r	dS dS )NUnsignedInteger)r   r   r   )r   	typecodes)rp   r   r   r   _signs   s   r   c                   @   r   )TestModulusc              	   C   s  t jd t jd  }ttfD ]s}t||D ]j\}}tt|t|D ][\}}d}||j||||f }t j|d |dd }	t j|d |dd }
||	|
\}}t	||
 | |	|d |d	krpt
|
|  k ojd
kn  | q$t
|
|  kozd
kn  | q$qqd S )N
AllIntegerFloat*op: %s, dt1: %s, dt2: %s, sg1: %s, sg2: %sG   r   r      ra   r   r   )r   r   r   divmodr   r   r   r3   r   r   r   r   rp   rQ   dt1dt2sg1sg2fmtrt   r   r-   divremr   r   r   test_modulus_basic   s      zTestModulus.test_modulus_basicc                    s8  t tdd}t tdd}|dg | }|| }t t||}t dd |D }tj|tdj\}}tj|tdj\}	}
t	|	dk|dk |dk A @ d	|	}	t	|
dk|dk @ d	|
}
t
tfD ]9 tjd
 D ]1}d j|f }||}||}t fddt||D  \}}t||	|d t||
|d qgq`d S )Nir   r      c                 s   s    | ]}t | V  qd S r   )r   )r   r   r   r   r   	<genexpr>  s    z7TestModulus.test_float_modulus_exact.<locals>.<genexpr>r                  r   zop: %s, dtype: %sc                    s   g | ]	\}} ||qS r   r   )r   a_b_rQ   r   r   r   $  s    z8TestModulus.test_float_modulus_exact.<locals>.<listcomp>ra   )listr/   r   r   r   r   intTfloatwherer   r   r   r3   astypezipr   )r   nlstplstdividenddivisorargtgtr   r-   tgtdivtgtremrp   rt   fafbr   r   r   r   r   test_float_modulus_exact  s(   "

 z$TestModulus.test_float_modulus_exactc              	   C   s   t jd }ttfD ]q}t||D ]h\}}tddD ]]\}}d}||j||||f }t j|d d |dd }	t j|d |dd }
||	|
\}}t||
 | |	|d |d	krit	|
|  k ocd
kn  | qt	|
|  kosd
kn  | qqq	d S )Nr   r   r   N   g+i)+p>r   r   ra   r   r   )
r   r   r   r   r   r   r3   r   r   r   r   r   r   r   test_float_modulus_roundoff(  s    
  z'TestModulus.test_float_modulus_roundoffc                 C   s  t jd D ]6}t jd|d}t t jd|d| }t||}t||kd|  t| | }t|| kd|  qt }|t	d |t	d |t	d |t	d	 |t	d
 t jd D ]l}t jd|d}t jd|d}t jt j
|d}t jt j|d}	t||}tt |d|  t||	}tt |d|  t||}tt |d|  ttfD ]}
|
||\}}tt |ott | qqcW d    d S 1 sw   Y  d S )Nr   r   r   r   zdt: %sz&invalid value encountered in remainderz'divide by zero encountered in remainderz*divide by zero encountered in floor_dividez$divide by zero encountered in divmodz#invalid value encountered in divmod)r   r   r   	nextafterrA   modr   r   filterRuntimeWarninginfnanrF   r   r   isinf)r   rp   r-   r   r   supfonefzerfinffnanrQ   r   r   r   r   r   test_float_modulus_corner_cases:  s>   "z+TestModulus.test_float_modulus_corner_casesc                 C   s`   t ddgt j}t ddgt j}tjtdd || }W d    d S 1 s)w   Y  d S )Nr   r,   z,Cannot cast ufunc 'floor_divide' output frommatch)r   r   r   r   rG   rO   r   )r   r   r-   r   r   r   test_inplace_floordiv_handling]  s   
"z*TestModulus.test_inplace_floordiv_handlingN)r3   r4   r5   r   r   r   r   r   r   r   r   r   r      s    #r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestComplexDivisionc                 C   s  t jddx t jt jfD ]h}|d}|d}tt ||  |tt jt j}tt ||  |tt jt j}tt ||  |tt jt j}tt ||  |tt jt j}tt 	||  |d}tt 	||  qW d    d S 1 sw   Y  d S )Nr:   r;   r   r   )
r   rK   r   
complex128r   r   complexr   r   rF   r   r   r   r   test_zero_divisioni  s"   "z&TestComplexDivision.test_zero_divisionc              	   C   s   t jddK t jt jfD ];}d}|D ]4}|d }|d }|d }|t|d |d |t|d |d  }t|j|d  t|j|d  qqW d    d S 1 sTw   Y  d S )Nr:   r;   ))r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   )r   r   r   r   r   r,   )r   rK   r   r   r   r   realimagr   r   datacasesnr}   exr   r   r   r   test_signed_zerosz  s   
,"z%TestComplexDivision.test_signed_zerosc              	   C   s   t jddV t jt jfD ]F}t }|d |d |D ]4}|d }|d }|d }|t|d |d |t|d |d  }t|j|d  t|j	|d  qqW d    d S 1 s_w   Y  d S )Nr:   r;   )       @r   r	  r   )r   r
  r  r   r   r   r,   )
r   rK   r   r   r   appendr   r   r  r  r  r   r   r   test_branches  s   

,"z!TestComplexDivision.test_branchesN)r3   r4   r5   r   r  r  r   r   r   r   r   h  s    r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zejj	e
 d	d
dd Zejj	eejeejkdd
ejj	e ddd
dd Zdd Zdd Zdd ZdS )TestConversionc                 C   s~   g d}g d}d t jt jfD ]}t j||d}tdd |D | qt j|d d t jd}tdd |D |d d  d S )N)g    .Ag   mBg NgmCg    .g   mg Ngm)i@B l    J)l     NZoil J)l  NZor   c                 S      g | ]}t |qS r   r   r   _mr   r   r   r         z5TestConversion.test_int_from_long.<locals>.<listcomp>r   c                 S   r  r   r  r  r   r   r   r     r  )r   rf   r   r   r   r   )r   r$   lir   r   r   r   r   test_int_from_long  s    z!TestConversion.test_int_from_longc                 C   s   dD ]}t jt |jd |d}t |j}t||k qt jd D ]}t jt |j|d}t |j}t||k q#t jd D ]}t |t |j}t |j}t||k qBd S )NbBhHr   r   r   )	r   r   iinfomaxminr   r   r   rP   )r   coderW   r   r   r   r   test_iinfo_long_values  s   z%TestConversion.test_iinfo_long_valuesc                 C   s2   dd }t jt jt jt jfD ]}tt|| qd S )Nc                 S   s   | t | jd  d S Nr   )r   r  r  r   r   r   r   overflow_error_func  s   zDTestConversion.test_int_raise_behaviour.<locals>.overflow_error_func)r   int_uintlonglong	ulonglongr	   OverflowError)r   r  r  r   r   r   test_int_raise_behaviour  s   z'TestConversion.test_int_raise_behaviourc                 C   sx   t t j}ttt| t #}|t j t 	t j}ttt| t
t|jd W d    d S 1 s5w   Y  d S r  )r   r   r   r	   r"  r   r   recordComplexWarningclongdoubler   lenlogr   r   r   r   r   r   !test_int_from_infinite_longdouble     "z0TestConversion.test_int_from_infinite_longdoublezTest is PyPy only (gh-9972)reasonc                 C   sx   t t j}tt|j t #}|t j t 	t j}tt|j t
t|jd W d    d S 1 s5w   Y  d S r  )r   r   r   r	   r"  __int__r   r$  r%  r&  r   r'  r(  r)  r   r   r   )test_int_from_infinite_longdouble___int__  r+  z8TestConversion.test_int_from_infinite_longdouble___int__zlong double is same as doubleppczIBM double doublec                 C   sP   t t jjd }dt d|  }dd|  }t|t jk tt|| d S )Nr   i	  r,   )	r   finfodoublemaxexpr   r   r   r   r   )r   r   huge_ldhuge_ir   r   r   test_int_from_huge_longdouble  s
   z,TestConversion.test_int_from_huge_longdoublec                 C   s4   t d}tt|d t d}tt|d d S )N      ?r   g      %i)r   r   r   r   )r   r   r   r   r   test_int_from_longdouble  s   

z'TestConversion.test_int_from_longdoublec                 C   s  t jd D ]`}tdt jd|dd kd|f  tdt jd|dd k  d|f  t jd D ]5}tt jd|dd t jd|dd kd||f  tt jd|dd t jd|dd k  d||f  q/qdD ]}td	t jd|dd k d|f  td	t jd|dd k d|f  td	t jd|dd kd|f  d
D ]N}tt jd|dd t jd	|dd kd||f  tt jd|dd t jd	|dd k  d||f  tt jd|dd t jd	|dd kd||f  qqhdt jd  D ]}tdt jd	|dd kd|f  tdt jd	|dd k  d|f  td	t jd	|dd kd|f  dt jd  D ]O}tt jd|dd t jd	|dd kd||f  tt jd|dd t jd	|dd k  d||f  tt jd	|dd t jd	|dd kd||f  q4qd S )Nr   r   r   r   r   ztype %s failedztype %s and %s failedBHILQPr   bhilqpbhlqpr   )r   r   r   r   )r   r   r   r   r   r   &test_numpy_scalar_relational_operators  sT   "$$
&
"$"$
&
$
	"$"$
&
$
z5TestConversion.test_numpy_scalar_relational_operatorsc                 C   s   t jddH}t ddt ttdd k  ttdd k  ttdd k  ttdd k ttdd k ttdd k W d    n1 sQw   Y  tt	|dk tt
tdd  d S )	NT)r$  always r   testNaTr   )rI   rJ   filterwarningsFutureWarningr   r   re   str_
datetime64r'  equal)r   wr   r   r   test_scalar_comparison_to_none"  s   z-TestConversion.test_scalar_comparison_to_noneN)r3   r4   r5   r  r  r#  r*  rG   markskipifr   r/  r   r1  r2  r   platformmachine
startswithr6  r8  r<  rG  r   r   r   r   r    s"    


		)r  c                   @   r[   )TestReprc                 C   s   t |}|j|j }|j}t |jd }dD ]Y}t jdg| t jd}|dkr:|d }d|d  }	d|	> ||< n|dkrO|d }d|d  }	d|	> ||< ntd	|	|d }
t
|
}|t|}|dkrl|
d
k sqt|
| qd S )N   )small denorm
small normr   r   rO  r^   r   rP  hmmg0.++)r   r1  nexpnmantr   itemsizer   uint8r   r|   reprevalr   )r   r   r1  last_fraction_bit_idxlast_exponent_bit_idxstorage_byteswhichconstrbytebytebitvalval_reprval2r   r   r   _test_type_reprB  s,   

zTestRepr._test_type_reprc                 C   s    t jt jfD ]}| | qd S r   )r   re   rf   rb  )r   r   r   r   r   test_float_repr[  s   zTestRepr.test_float_reprN)r3   r4   r5   rb  rc  r   r   r   r   rM  A  s    rM  c                   @   r[   )
TestSizeOfc                 C   s*   t D ]}|d}tt||jk qd S )Nr   )r   r   sys	getsizeofnbytes)r   rP   r   r   r   r   test_equal_nbytesf  s   zTestSizeOf.test_equal_nbytesc                 C   s   t  }tt|jd d S )Nr   )r   re   r	   r   
__sizeof__)r   r}   r   r   r   
test_errork  s   zTestSizeOf.test_errorN)r3   r4   r5   rh  rj  r   r   r   r   rd  d  s    rd  c                   @   r[   )TestMultiplyc                 C   s$  t tjd }dh}t tjd | | }|dh8 }ttfD ]q}|g d}|D ] }t|d}t|| |t|  t|| t||  q(|D ]'}t| }tt	t
tj|||t|  tt	t
tj||t||  qK|D ]}t| }tttj|| tttj|| quqd S )Nr   ?AllVr+   r,   )setr   r   r   tupler   rP   r   r   r   rM   rA   mulr	   r   )r   accepted_typesdeprecated_typesforbidden_typesseq_typeseq
numpy_typer1   r   r   r   test_seq_repeatq  s6   


zTestMultiply.test_seq_repeatc                 C   s   G dd d}|t dtt dfD ]:}t|t d t dd tt d| t dd t|t d t dd tt d| t dd qd S )Nc                   @   r[   )zCTestMultiply.test_no_seq_repeat_basic_array_like.<locals>.ArrayLikec                 S   s
   || _ d S r   arr)r   rz  r   r   r   __init__  s   
zLTestMultiply.test_no_seq_repeat_basic_array_like.<locals>.ArrayLike.__init__c                 S   s   | j S r   ry  )r   r   r   r   	__array__  s   zMTestMultiply.test_no_seq_repeat_basic_array_like.<locals>.ArrayLike.__array__N)r3   r4   r5   r{  r|  r   r   r   r   	ArrayLike  s    r}  r   g      @)r   ones
memoryviewr   re   fullr  )r   r}  arr_liker   r   r   #test_no_seq_repeat_basic_array_like  s    z0TestMultiply.test_no_seq_repeat_basic_array_likeN)r3   r4   r5   rx  r  r   r   r   r   rk  p  r   rk  c                   @   r[   )TestNegativec                 C   s&   t jdt jdd }tttj| d S Nr   r   )r   r~  bool_r	   r   rA   negr   r   r   r   r   test_exceptions  s   zTestNegative.test_exceptionsc                 C   sz   t jd t jd  }t &}|t |D ]}t jd|dd }tt|| d qW d    d S 1 s6w   Y  d S Nr   AllFloatr   r   r   )	r   r   r   r   r   r~  r   rA   r  r   r   r   rp   r   r   r   r   test_result  s   
"zTestNegative.test_resultNr3   r4   r5   r  r  r   r   r   r   r        r  c                   @   r[   )TestSubtractc                 C   s(   t jdt jdd }tttj|| d S r  )r   r~  r  r	   r   rA   subr  r   r   r   r    s   zTestSubtract.test_exceptionsc                 C   sx   t jd t jd  }t %}|t |D ]}t jd|dd }tt||d qW d    d S 1 s5w   Y  d S r  )	r   r   r   r   r   r~  r   rA   r  r  r   r   r   r    s   
"zTestSubtract.test_resultNr  r   r   r   r   r    r  r  c                   @   sH   e Zd Zdd Zejdee dd Z	ejdee dd Z
dS )	TestAbsc                 C   s   |d}t ||d |d}||}t |d |d}||}t |d |t|j}t |||j t }|t |t|j}t |||j W d    n1 sXw   Y  |t|j	}t |||j  d S )Ng      r7  r   r   )
r   r   r1  r  r  r   r   UserWarningtinyr  )r   absfunc
test_dtyper   rW   r   r   r   r   _test_abs_func  s"   


zTestAbs._test_abs_funcr   c                 C   sR   t jdkr!|tjkr!tt dd tdk r!t	j
dd | t| d S Ncygwin-r   z3.3.0z4absl is computed in double precision on cygwin < 3.3r,  re  rJ  r   r&  r   parsereleasesplitVersionrG   rH   r  absr   r   r   r   r   test_builtin_abs  s   zTestAbs.test_builtin_absc                 C   sT   t jdkr!|tjkr!tt dd tdk r!t	j
dd | tj| d S r  r  r  r   r   r   test_numpy_abs  s   zTestAbs.test_numpy_absN)r3   r4   r5   r  rG   rH  parametrizefloating_typescomplex_floating_typesr  r  r   r   r   r   r    s    
r  c                   @   sF   e Zd Zejdejd ejjdej	ej
gddgddd Zd	S )
TestBitShifts	type_coder   rQ   z>>z<<idsc                 C   s   t |}|jd }dD ]L}||d fD ]C}||}||}|||}	|dk r4|tju r4t|	d nt|	d t j|gd |d}
t j|gd |d}||
|}t||	 qqdS )	zA Shifts where the shift amount is the width of the type or wider rN  )r   rx   r   r       r   N)r   r   rT  rP   rA   rshiftr   r   )r   r  rQ   rp   nbitsr_  shiftval_scl	shift_sclres_sclval_arr	shift_arrres_arrr   r   r   test_shift_all_bits  s    






z!TestBitShifts.test_shift_all_bitsN)r3   r4   r5   rG   rH  r  r   r   rA   r  lshiftr  r   r   r   r   r    s    r  c                   @   s`   e Zd Zejdejd dd Zejdejd dd Z	ejdejd d	d
 Z
dS )TestHashr  r   c                 C   s6   t |j}tdD ]}t|t||ksJ q
d S )Nr   )r   r   rP   r/   hash)r   r  scalarr1   r   r   r   test_integer_hashes  s   zTestHash.test_integer_hashesr  c                 C   s   t |j}t jt jddfD ]%}||}|jjdkrt|}nt|}||ks)J t|t|ks3J qttt j	ttt j	krRt|t j	t|t j	ksTJ d S d S )Nr   g      @r9   )
r   r   rP   pir   r@   r   r   r  r   r   r  r  r_  	numpy_valr   r   r   test_float_and_complex_hashes  s   
 z&TestHash.test_float_and_complex_hashesComplexc                 C   sN   t |j}t jd t jd ddfD ]}||}tt|t|ks$J qd S )N              ?y              @y      @      ?)r   r   rP   r  r   r  r   r  r   r   r   test_complex_hashes&  s
   zTestHash.test_complex_hashesN)r3   r4   r5   rG   rH  r  r   r   r  r  r  r   r   r   r   r    s    

r  c              	   c   s8    t  }zt |  d V  W t | d S t | w r   )re  getrecursionlimitsetrecursionlimit)r  r~   r   r   r   recursionlimit/  s   
r  c                 C   sV   z t d || |d W d    W d S 1 sw   Y  W d S  ty*   Y d S w N   r   r  r   r~   rQ   type_r   r   r   test_operator_object_left9     
&r  c                 C   sV   z t d ||d|  W d    W d S 1 sw   Y  W d S  ty*   Y d S w r  r  r  r   r   r   test_operator_object_rightD  r  r  c                 C   s.   z| |d|d W d S  t y   Y d S w r  )r   )rQ   type1type2r   r   r   test_operator_scalarsO  s
   r  rQ   c                 C   sT   z
| t dd  W n	 ty   Y nw z| d t d W d S  ty)   Y d S w )Nr   )r   r   r   r   r   r   r   test_longdouble_inf_loopY  s   r  c                 C   sb   | t jhv r	 z
| tdd  W n	 ty   Y nw z| d td W d S  ty0   Y d S w )NFz)The modulo operator is known to be brokenr   )rA   r   rG   rH   r   r&  r   r   r   r   r   r   test_clongdouble_inf_loope  s   r  r   r   	operationc                 C   s   || S r   r   r  r  r   r   r   <lambda>u      r  c                 C   s   | | S r   r   r  r   r   r   r  v  r  c                 C   s   || S r   r   r  r   r   r   r  w  r  )+r  *r  c                 C   sj   t | j}|t | j}|t | j}tjtdd ||| W d    d S 1 s.w   Y  d S )Noverflow encounteredr   )	r   r   rP   r  r  r  rG   warnsr   )r   r  str  r  r   r   r   &test_scalar_integer_operation_overflows  s   "r  Integerc                 C   s   t | S r   )r  r  neg_1r   r   r   r    r  c                 C   s   | | S r   r   r  r   r   r   r    r  c                 C      | | S r   r   r  r   r   r   r    r  )r  r  //c                 C   sb   t | j}|t | j}|d}tjtdd ||| W d    d S 1 s*w   Y  d S )Nr   r  r   )r   r   rP   r  r  rG   r  r   )r   r  r  r  r  r   r   r   #test_scalar_signed_integer_overflow  s   "r  r   c                 C   sJ   t | d}tjtdd |  W d    d S 1 sw   Y  d S )NrN  r  r   r   r   rP   rG   r  r   )r   r_  r   r   r   r    s   "c                 C   r  r   r   r_  zeror   r   r   r    r  c                 C   s   | | S r   r   r  r   r   r   r    r  r  %c                 C   sZ   t | j}|d}|d}tjtdd ||| W d    d S 1 s&w   Y  d S )Nd   r   zdivide by zeror   r  )r   r  r  r_  r  r   r   r   'test_scalar_integer_operation_divbyzero  s   "r  __lt____gt__T__le____ge____eq____ne____floordiv____rfloordiv__F__truediv____rtruediv____add____radd____mod____rmod____mul____rmul____pow____rpow____sub____rsub__)__op____rop__rQ   cmpsctypec                    s   G dd d| }G dd d| } fdd}fdd}t d	| f ||i}	||d
|d}
t |
| ks?t |
tjks?J ||d
|d|d
dksOJ ||	d
|d ks\J ||d
|	d|d
dkslJ dS )a  
    This test covers scalar subclass deferral.  Note that this is exceedingly
    complicated, especially since it tends to fall back to the array paths and
    these additionally add the "array priority" mechanism.

    The behaviour was modified subtly in 1.22 (to make it closer to how Python
    scalars work).  Due to its complexity and the fact that subclassing NumPy
    scalars is probably a bad idea to begin with.  There is probably room
    for adjustments here.
    c                   @      e Zd ZdS )z+test_subclass_deferral.<locals>.myf_simple1Nr3   r4   r5   r   r   r   r   myf_simple1      r  c                   @   r   )z+test_subclass_deferral.<locals>.myf_simple2Nr  r   r   r   r   myf_simple2  r  r  c                        S r   r   r   otherr  r   r   op_func     z'test_subclass_deferral.<locals>.op_funcc                    r  r   r   r  r  r   r   rop_func  r
  z(test_subclass_deferral.<locals>.rop_funcmyf_opr   r,   N)rP   r   r  )r  r  r  rQ   r  r  r  r	  r  r  rW   r   r  r  r   test_subclass_deferral  s    $r  c                  C   s.   t d} | d dksJ d|  dksJ d S )Nr   r  y      ?      ?)r   r   )r   r   r   r   test_longdouble_complex  s   
r  subtypec           
   	      s   fdd}fdd}t d| f ||dd i}||dtd ks'J |td|dks5J |tjtjhv rC| tkrCd S  krId S t d| f|i}||dtd}|| dtd}	||	kslJ t |t |	ksvJ |td|d}|td| d}	||	ksJ t |t |	ksJ ||dt	d}|| dt	d}	||	ksJ t |t |	ksJ |td|d}|t	d| d}	||	ksJ d S )	Nc                    r  r   r   r  r  r   r   r	    r
  z)test_pyscalar_subclasses.<locals>.op_funcc                    r  r   r   r  r  r   r   r    r
  z*test_pyscalar_subclasses.<locals>.rop_funcmyt__array_ufunc__r   r,   )
rP   r   rf   rA   r   floordivr   r   re   r   )
r  r  r  rQ   r  r	  r  r  rW   r   r   r  r   test_pyscalar_subclasses  s6   r  )o
contextlibre  rI   r   rA   rJ  numpy.compatr   rG   
hypothesisr   r   hypothesis.strategiesr   hypothesis.extrar   hynpr   numpy.testingr   r   r	   r
   r   r   r   r   r   r  r]  ubyteshortushortintcuintcr  r  r   r!  singler2  r   csinglecdoubler&  r   floating__subclasses__r  complexfloatingr  objectobjecty_thingsrE   rD   eqnerB   rC   r0   r  r   rq  r   r  truediv reasonable_operators_for_scalarsr   rH  slowarraysscalar_dtypesrZ   r\   r   r   r   r   r   r  rM  rd  rk  r  r  r  r  r  contextmanagerr  r  r  r  r  r  r  r   r  r  rH   r  ops_with_namesre   rf   r  r  r   r   r   r   r  r   r   r   r   <module>   s    ,


	'
.QmH !33!
	




	

$