o
    i                     @   s   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l
Z
d dlZdd Zdd	 Zd
d Zdd Zdd ZG dd dejZedkrKe  dS dS )    N)compile_isolated)TypingError)njit)typesc                 C   
   t | S N)r   int32x r   g/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/numba/tests/test_casting.pyfloat_to_int
      
r   c                 C   s   t | d S )N   )r   float64r	   r   r   r   int_to_float   s   r   c                 C   r   r   )r   uint32r	   r   r   r   float_to_unsigned   r   r   c                 C   r   r   )r   
complex128r	   r   r   r   float_to_complex   r   r   c                   C   s   t t d d S )N)   )npr   Zzerosr   r   r   r   numpy_scalar_cast_error   s   r   c                   @   sL   e 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 )TestCastingc                 C   s~   t }t|tjg}|j}| |jjtj | |d|d | |dt	d | |d|d | |dt	d d S )N皙(@g()
r   r   r   float32entry_pointassertEqual	signaturereturn_typer   intselfZpyfunccrZcfuncr   r   r   test_float_to_int   s   zTestCasting.test_float_to_intc                 C   R   t }t|tjg}|j}| |jjtj | |d|d | |dd d S )NiA  g     d@)	r   r   r   int64r   r   r   r   r   r!   r   r   r   test_int_to_float)   s   zTestCasting.test_int_to_floatc              
   C   sf   t }t|tjg}|j}| |jjtj | |d|d | |dt	
dt	ddd  d S )NgGz	@Ii   r   )r   r   r   r   r   r   r   r   r   structunpackpackr!   r   r   r   test_float_to_unsigned2   s   
z"TestCasting.test_float_to_unsignedc                 C   r%   )NgGz	yGz	        )	r   r   r   r   r   r   r   r   r   r!   r   r   r   test_float_to_complex<   s   z!TestCasting.test_float_to_complexc                    sh   t ddd     t d fdd}tjdgtjd}| |||d	  | t jd
 dS )z<Make sure this compiles.

        Cast C to A array
        z	f8(f8[:])c                 S   s   | d S )Nr   r   r	   r   r   r   innerI      z.TestCasting.test_array_to_array.<locals>.innerzf8(f8[::1])c                    s    | S r   r   r	   r0   r   r   driverO   r1   z/TestCasting.test_array_to_array.<locals>.driveri  dtyper      N)r   Zdisable_compiler   arrayr   r   lenZ	overloads)r"   r3   r
   r   r2   r   test_array_to_arrayD   s   
zTestCasting.test_array_to_arrayc                 C   s   t dd }tjdftjdftjdftjdftjdftjdftjtddftj	t	d	fd
g	}|D ]\}}tj
||d}| |||d  q2d S )Nc                 S   s   | j | S r   )r5   typer	   r   r   r   r0   X   s   z-TestCasting.test_0darrayT_to_T.<locals>.innerTr      y      @       @r*   hz
2016-01-01)z<U3ABCr4   r   )r   r   Zbool_r   r   r&   Z	complex64r   Ztimedelta64Z
datetime64r7   r   )r"   r0   ZinputsTinpr
   r   r   r   test_0darrayT_to_TW   s    
zTestCasting.test_0darrayT_to_Tc                 C   sJ   |  t}ttd W d   n1 sw   Y  | dt|j dS )zv
        Ensure that a TypingError exception is raised if
        user tries to convert numpy array to scalar
        r   Nz?Casting array(float64, 1d, C) to int32 directly is unsupported.)assertRaisesr   r   r   ZassertInstr	exception)r"   Zraisesr   r   r   test_array_to_scalarl   s   z TestCasting.test_array_to_scalarc                 C   sR   t t j}t t j}||}t|dd }| |dd | |d dS )z
        Test error due mishandling of Optional to Optional casting

        Related issue: https://github.com/numba/numba/issues/1718
        c                 S   s   | S r   r   )ar   r   r   foo   s   z2TestCasting.test_optional_to_optional.<locals>.foor   N)r   OptionalZintpr   r   r   ZassertIsNone)r"   Zopt_intZopt_fltsigrF   r   r   r   test_optional_to_optionalx   s   
z%TestCasting.test_optional_to_optionalN)__name__
__module____qualname__r$   r'   r.   r/   r9   r@   rD   rI   r   r   r   r   r      s    	
r   __main__)numpyr   Znumba.core.compilerr   Znumba.core.errorsr   Znumbar   Z
numba.corer   r+   Zunittestr   r   r   r   r   ZTestCaser   rJ   mainr   r   r   r   <module>   s     n