B
     \a                 @   s~   d dl mZ d dlZd dlmZ d dl mZmZ d dl	Z	dd Z
dd Zd	d
 Zdd ZG dd dejZedkrze  dS )    )unittest_supportN)compile_isolated)typesnjitc             C   s
   t | S )N)r   int32)x r   7lib/python3.7/site-packages/numba/tests/test_casting.pyfloat_to_int   s    r
   c             C   s   t | d S )N   )r   float64)r   r   r   r	   int_to_float   s    r   c             C   s
   t | S )N)r   uint32)r   r   r   r	   float_to_unsigned   s    r   c             C   s
   t | S )N)r   
complex128)r   r   r   r	   float_to_complex   s    r   c               @   s<   e Z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 )Ng(@g()
r
   r   r   float32entry_pointassertEqual	signaturereturn_typer   int)selfpyfunccrcfuncr   r   r	   test_float_to_int   s    zTestCasting.test_float_to_intc             C   sR   t }t|tjg}|j}| |jjtj | |d|d | |dd d S )NiA  g     d@)	r   r   r   Zint64r   r   r   r   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   structZunpackZpack)r   r   r   r   r   r   r	   test_float_to_unsigned-   s    z"TestCasting.test_float_to_unsignedc             C   sR   t }t|tjg}|j}| |jjtj | |d|d | |dd d S )NgGz	yGz	        )	r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r	   test_float_to_complex7   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	   innerD   s    z.TestCasting.test_array_to_array.<locals>.innerzf8(f8[::1])c                s    | S )Nr   )r   )r%   r   r	   driverJ   s    z/TestCasting.test_array_to_array.<locals>.driveri  )Zdtyper      N)r   Zdisable_compilenpZarrayr   r   lenZ	overloads)r   r&   r   r   )r%   r	   test_array_to_array?   s    zTestCasting.test_array_to_arrayc             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 )Nr   )ar   r   r	   foo]   s    z2TestCasting.test_optional_to_optional.<locals>.foor   N)r   ZOptionalZintpr   r   r   ZassertIsNone)r   Zopt_intZopt_fltZsigr,   r   r   r	   test_optional_to_optionalR   s    z%TestCasting.test_optional_to_optionalN)	__name__
__module____qualname__r   r   r#   r$   r*   r-   r   r   r   r	   r      s   	
r   __main__)Znumbar   ZunittestZnumpyr(   Znumba.compilerr   r   r   r"   r
   r   r   r   ZTestCaser   r.   mainr   r   r   r	   <module>   s   M