o
    ۾iW                     @   sT   d dl Zd dlmZ d dlmZ d dlmZ d dlm	Z	 dd Z
G dd	 d	e	ZdS )
    N)njit)types)TypingError)TestCasec                    s    fdd}|S )Nc                    s    |  S Nview)xab L/home/ubuntu/.local/lib/python3.10/site-packages/numba/tests/test_numbers.pyimpl   s   zgen_view.<locals>.implr   )r   r   r   r   r
   r   gen_view   s   r   c                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )TestViewIntFloatz0 This tests the 'view' method on NumPy scalars. c           	   	   C   s   |D ]F\}}}t ||D ];\}}tt||}t|s2| |||| | |||| q| t|| | t|| qqd S r   )zipr   r   npisnanassertEqualpy_func
assertTrue)	selfinputsdtypesvalueinitial_typeexpectedtarget_typeresultr   r   r   r   
do_testing   s   

zTestViewIntFloat.do_testingc                 C   s4   t jt jf}dt jdfdt jdff}| || d S )N   )r!   r!   )   r"   )r   uint8int8r    r   r   r   r   r   r   test_8_bits$   s
   

zTestViewIntFloat.test_8_bitsc                 C   J   t jt jt jf}dt jdfdt jddt jffdt jdff}| || d S )Nr!   )r!   r!   g      6r"   l          ?)  ?r*   r)   )r   uint32int32float32nanr    r&   r   r   r   test_32_bits+   s   

zTestViewIntFloat.test_32_bitsc                 C   r(   )Nr!   )r!   r!   g       r"   l    r)   )          r0   r)   )r   uint64int64float64r.   r    r&   r   r   r   test_64_bits3   s   

zTestViewIntFloat.test_64_bitsc                    sj   t tdtjj t fdd}| t}|  W d    n1 s%w   Y  | 	dt
|j d S )Nzint{}c                     s   d} |    d S )Nr!   r   )r   inttyr   r   myviewA   s   z=TestViewIntFloat.test_python_scalar_exception.<locals>.myviewz\'view' can only be called on NumPy dtypes, try wrapping the variable 'a' with 'np.<dtype>()')getattrr   formatr   intpbitwidthr   assertRaisesr   assertInstr	exception)r   r7   er   r5   r   test_python_scalar_exception>   s   z-TestViewIntFloat.test_python_scalar_exceptionc                 C   s^   |  t}tt|d |d }|d W d    n1 sw   Y  | dt|j d S )Nr   r!   zOChanging the dtype of a 0d array is only supported if the itemsize is unchanged)r<   r   r   r   r=   r>   r?   )r   pairr@   r   r   r   r   do_testing_exceptionsL   s   
z&TestViewIntFloat.do_testing_exceptionsc                 C   ,   t jt jft jt jffD ]}| | qd S r   )r   r,   r%   rC   r   rB   r   r   r   test_exceptions32T      z"TestViewIntFloat.test_exceptions32c                 C   rD   r   )r   r,   r2   rC   rE   r   r   r   test_exceptions64X   rG   z"TestViewIntFloat.test_exceptions64N)__name__
__module____qualname____doc__r    r'   r/   r4   rA   rC   rF   rH   r   r   r   r   r      s    r   )numpyr   numbar   
numba.corer   numba.core.errorsr   numba.tests.supportr   r   r   r   r   r   r   <module>   s   