U
    9%eW                     @   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 W/var/www/html/Darija-Ai-API/env/lib/python3.8/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 ]\}}}t ||D ]v\}}tt||}t|sd| |||| | |||| q| t|| | t|| qqd S r   )zipr   r   npisnanassertEqualZpy_func
assertTrue)	selfinputsdtypesvalueZinitial_typeexpectedZ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   Zuint8int8r   r   r   r   r   r   r   test_8_bits$   s
    

zTestViewIntFloat.test_8_bitsc                 C   sJ   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   Zuint32int32Zfloat32nanr   r"   r   r   r   test_32_bits+   s    

zTestViewIntFloat.test_32_bitsc                 C   sJ   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       r   l    r$   )          r)   r$   )r   Zuint64int64Zfloat64r'   r   r"   r   r   r   test_64_bits3   s    

zTestViewIntFloat.test_64_bitsc              	      sV   t tdtjj t fdd}| t}|  W 5 Q R X | 	dt
|j d S )Nzint{}c                     s   d} |    d S )Nr   r   )r   Z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   ZintpZbitwidthr   assertRaisesr   assertInstr	exception)r   r-   er   r,   r   test_python_scalar_exception>   s    z-TestViewIntFloat.test_python_scalar_exceptionc              	   C   sJ   |  t$}tt|d |d }|d W 5 Q R X | dt|j d S )Nr   r   zOChanging the dtype of a 0d array is only supported if the itemsize is unchanged)r0   r   r   r   r1   r2   r3   )r   pairr4   r   r   r   r   do_testing_exceptionsL   s    z&TestViewIntFloat.do_testing_exceptionsc                 C   s,   t jt jft jt jffD ]}| | qd S r   )r   r&   r!   r7   r   r6   r   r   r   test_exceptions32T   s    z"TestViewIntFloat.test_exceptions32c                 C   s,   t jt jft jt jffD ]}| | qd S r   )r   r&   r*   r7   r8   r   r   r   test_exceptions64X   s    z"TestViewIntFloat.test_exceptions64N)__name__
__module____qualname____doc__r   r#   r(   r+   r5   r7   r9   r:   r   r   r   r   r      s   r   )numpyr   Znumbar   Z
numba.corer   Znumba.core.errorsr   Znumba.tests.supportr   r   r   r   r   r   r   <module>   s   