U
    #c                     @   s   d Z ddlZddlZddlZddlZddlmZmZ ddlZddl	Z
ddlmZmZ G dd dZG dd dZejjejd	k d
dG dd dZejjejd	kddejde
je
je
jgee
j ddddZG dd dZdS )z;
Test the scalar constructors, which also do type-coercion
    N)AnyType)assert_equalassert_raisesc                   @   sl  e Zd Zejdejejej	ej
gejdddddgdd Zejdejejej	ej
gd	d
 Zejdejejej	ej
gdd Zdd Zejdejdddddgdddddgfejdddddgdddddgfej	dd d!d"d#gdd$d%d&d'gfejej
dd(d)d*d+gdd,d-d.d/gejjeej	eej
kd0d1ejje d2d3d1gd4gd5d6 Zd7S )8TestAsIntegerRatioftypezf, ratio)g      ?)      )g      )ir	   )        )r      )g      '@)      c                 C   s   t || | d S N)r   as_integer_ratio)selfr   fZratio r   H/tmp/pip-unpacked-wheel-b2rbor69/numpy/core/tests/test_scalar_methods.py
test_small   s    	zTestAsIntegerRatio.test_smallc                 C   sz   t j}t|dd||d   t|dd||d   t|dd||d   t|dd||d	   d S )
Nr   r   r
      r   g      @g      ?ig     h)	fractionsFractionr   r   )r   r   Rr   r   r   test_simple_fractions   s    



z(TestAsIntegerRatio.test_simple_fractionsc                 C   s4   t t|dj t t|dj t t|dj d S )Ninfz-infnan)r   OverflowErrorr   
ValueError)r   r   r   r   r   test_errors+   s    zTestAsIntegerRatio.test_errorsc                 C   s   t j}t|dd|td   t|dd|td   t|dd|td   t|dd|td   t|d	d
|td   t|dd
|td   d S )Ni3  i   g @ig i33C i    i̼l   L33 l         @ lL33 )r   r   r   nphalfr   singledouble)r   r   r   r   r   test_against_known_values2   s&    





z,TestAsIntegerRatio.test_against_known_valueszftype, frac_vals, exp_valsr
   gu?gi(?g1?g_?r   r   i   g%?g?g1,B?gJfu?
      igB П?gɱk?gu&>L?gFO?i3      isgMJ ;?gޫ_?gКAQ?g8O?ii7  irizlong double is same as doublereasonppczIBM double double)Zmarksc              
   C   s   t ||D ]\}}t|||}|j|ks0t| \}}zt|}	t|}
W n" ttfk
rv   t	
d Y nX t|	|
 |d|| q
d S )Nz%longdouble too small on this platformz{}/{})zipr   ldexpdtypeAssertionErrorr   
longdoubler   RuntimeWarningpytestskipr   format)r   r   Z	frac_valsZexp_valsfracexpr   ndnfZdfr   r   r   test_roundtripB   s    
z!TestAsIntegerRatio.test_roundtripN)__name__
__module____qualname__r2   markparametrizer   r    r!   r"   r0   r   r   r   r#   paramskipifZfinfoplatformmachine
startswithr:   r   r   r   r   r      s         
   

 
 
 r   c                   @   s   e Zd Zejdddgejdejd eedddd	Z	ejdejd ejd
  eddddZ
ejdejd eddddZdS )TestIsInteger	str_valuer   r   codeZFloatN)rG   rF   returnc                 C   s$   t |j}||}| r td S r   )r   r.   type
is_integerr/   )r   rG   rF   clsvaluer   r   r   test_specialn   s    zTestIsInteger.test_specialZ
AllIntegerrG   rH   c                 C   s,   t dd|}|D ]}| stqd S )Nr   r   ZarangeZastyperJ   r/   r   rG   Zfloat_arrayrL   r   r   r   	test_trueu   s    zTestIsInteger.test_truec                 C   s>   t dd|}|d9 }|D ]}|dkr,q| rtqd S )NrO   r   g?r   rP   rQ   r   r   r   
test_false}   s    zTestIsInteger.test_false)r;   r<   r=   r2   r>   r?   r   	typecodesstrrM   rR   rS   r   r   r   r   rE   m   s    rE   )   	   zRequires python 3.9r)   c                	   @   s   e Zd Zejdejejej	ej
ejejgeej ddddZddddZejd	ed
eddddZejdejejejgeej ddddZejdejd eddddZejd	ed
eddddZddddZdS )TestClassGetItemrK   NrK   rH   c                 C   s*   |t  }t|tjst|j|ks&td S r   )r   
isinstancetypesGenericAliasr/   
__origin__)r   rK   aliasr   r   r   test_abc   s    	zTestClassGetItem.test_abc)rH   c                 C   s2   t jttf }t|tjst|jt jks.td S r   )r   complexfloatingr   rZ   r[   r\   r/   r]   )r   r^   r   r   r   test_abc_complexfloating   s    z)TestClassGetItem.test_abc_complexfloatingarg_len   )rb   rH   c              	   C   sb   t f| }|dkr"tj| s^tn<d|dkr0dnd d}tjt|d tj|  W 5 Q R X d S )N)r   r   zToo r   fewmanyz
 argumentsmatch)r   r   r`   r/   r2   raises	TypeError)r   rb   arg_tuprg   r   r   r   (test_abc_complexfloating_subscript_tuple   s    
z9TestClassGetItem.test_abc_complexfloating_subscript_tuplec              	   C   s"   t t |t  W 5 Q R X d S r   r2   rh   ri   r   )r   rK   r   r   r   test_abc_non_numeric   s    z%TestClassGetItem.test_abc_non_numericrG   ZAllrN   c              	   C   s.   t |j}tt |t  W 5 Q R X d S r   )r   r.   rI   r2   rh   ri   r   )r   rG   rK   r   r   r   test_concrete   s    zTestClassGetItem.test_concretec              	   C   sF   t f| }|dkr"tj| sBtn tt tj|  W 5 Q R X d S )Nr   )r   r   numberr/   r2   rh   ri   )r   rb   rj   r   r   r   test_subscript_tuple   s
    
z%TestClassGetItem.test_subscript_tuplec                 C   s   t jt std S r   )r   ro   r   r/   )r   r   r   r   test_subscript_scalar   s    z&TestClassGetItem.test_subscript_scalar)r;   r<   r=   r2   r>   r?   r   ro   integerZinexactZunsignedintegerZsignedintegerZfloatingr   r_   ra   rangeintrk   ZgenericZflexible	characterrm   rT   rU   rn   rp   rq   r   r   r   r   rX      s&   	rX   zRequires python 3.8rK   rY   c              	   C   s*   d}t jt|d | t  W 5 Q R X d S )Nz(Type subscription requires python >= 3.9rf   rl   )rK   rg   r   r   r   test_class_getitem_38   s    rv   c                   @   s:   e Zd Zejdejd ejd  dd Zdd Z	dS )	TestBitCountitypert   Zuintc                 C   sV   t tt|jddD ]8}d| d| d}|| t|dkst|qd S )Nr      zSmoke test for (z).bit_count()1)	rs   maxr   Ziinfomin	bit_countbincountr/   )r   rx   amsgr   r   r   r      s    zTestBitCount.test_smallc                 C   s   dD ]x}d| }t | dks&tt |d  |ks@tt |dA  dksZtt |d dA  |d kstqd S )N)r%   r&   ?   r   r   r   r   i  r	   )r   Zuint64r~   r/   )r   r6   r   r   r   r   test_bit_count   s    zTestBitCount.test_bit_countN)
r;   r<   r=   r2   r>   r?   r   Zsctypesr   r   r   r   r   r   rw      s   
rw   )__doc__sysr   rB   r[   typingr   r   r2   Znumpyr   Znumpy.testingr   r   r   rE   r>   rA   version_inforX   r?   ro   r`   Zint64rv   rw   r   r   r   r   <module>   s    ]5