
    xKgI                         d dl 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 Z
d Zd Zd Zd	 Z G d
 de	j                        Zedk(  r e	j$                          yy)    N)TypingError)njit)typesc                 ,    t        j                  |       S N)r   int32xs    \/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_casting.pyfloat_to_intr   	   s    ;;q>    c                 2    t        j                  |       dz  S )N   )r   float64r	   s    r   int_to_floatr      s    ==ar   c                 ,    t        j                  |       S r   )r   uint32r	   s    r   float_to_unsignedr      s    <<?r   c                 ,    t        j                  |       S r   )r   
complex128r	   s    r   float_to_complexr      s    Ar   c                  T    t        j                  t        j                  d             y )N)   )npr   zeros r   r   numpy_scalar_cast_errorr      s    HHRXXd^r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestCastingc                    t         } t        t        j                  f      |      }| j	                  |j
                  d   j                  t        j                         | j	                   |d       |d             | j	                   |d      t        d             | j	                   |d       |d             | j	                   |d      t        d             y )Nr   皙(@g()	r   r   r   float32assertEqualnopython_signaturesreturn_typer   intselfpyfunccfuncs      r   test_float_to_intzTestCasting.test_float_to_int   s    &emm%&v.2215AA5;;OtfTl3tc$i0uve}5us5z2r   c                 *   t         } t        t        j                  f      |      }| j	                  |j
                  d   j                  t        j                         | j	                   |d       |d             | j	                   |d      d       y )Nr   iA  g     d@)r   r   r   int64r#   r$   r%   r   r'   s      r   test_int_to_floatzTestCasting.test_int_to_float'   sr    $ekk^$V,2215AA	(sVC[1sX.r   c           
         t         } t        t        j                  f      |      }| j	                  |j
                  d   j                  t        j                         | j	                   |d       |d             | j	                   |d      t        j                  dt        j                  dd            d          y )Nr   gGz	@Ii   )r   r   r   r"   r#   r$   r%   r   structunpackpackr'   s      r   test_float_to_unsignedz"TestCasting.test_float_to_unsigned0   s    "&emm%&v.2215AA5<<PtfTl3tfmmCSFG:I 'JJK'M 	Nr   c                 *   t         } t        t        j                  f      |      }| j	                  |j
                  d   j                  t        j                         | j	                   |d       |d             | j	                   |d      d       y )Nr   gGz	yGz	        )r   r   r   r   r#   r$   r%   r   r'   s      r   test_float_to_complexz!TestCasting.test_float_to_complex9   su    !&emm%&v.2215AA))	+uve}5uz2r   c                 :   t        d      d        j                          t        d      fd       }t        j                  dgt        j                        }| j                   ||      |d          | j                  t        j                        d       y	)
z<Make sure this compiles.

        Cast C to A array
        z	f8(f8[:])c                     | d   S )Nr   r   r	   s    r   innerz.TestCasting.test_array_to_array.<locals>.innerF   s    Q4Kr   zf8(f8[::1])c                      |       S r   r   )r
   r;   s    r   driverz/TestCasting.test_array_to_array.<locals>.driverL   s    8Or   i  dtyper      N)r   disable_compiler   arrayr   r#   len	overloads)r(   r=   r
   r;   s      @r   test_array_to_arrayzTestCasting.test_array_to_arrayA   s    
 
k		 
	 		m		 
	 HHdV2::.AaD)U__-q1r   c                    t         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        j                  dd      ft        j                  t        j                  d      fd	g	}|D ]7  \  }}t        j                  ||
      }| j                   ||      |d          9 y )Nc                 8    | j                   j                  |       S r   )r?   typer	   s    r   r;   z-TestCasting.test_0darrayT_to_T.<locals>.innerU   s    77<<?"r   Tr!      y      @       @r2   hz
2016-01-01)z<U3ABCr>   r   )r   r   bool_r"   r   r-   	complex64r   timedelta64
datetime64rB   r#   )r(   r;   inputsTinpr
   s         r   test_0darrayT_to_TzTestCasting.test_0darrayT_to_TT   s    		# 
	# XXtZZZZXXrN\\4 ]]D!^^R^^As34]]BMM,78

 HQA&AU1Xqu- r   c                     | j                  t              5 } t        d      t               ddd       | j	                  dt        j                               y# 1 sw Y   /xY w)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   assertInstr	exception)r(   raisess     r   test_array_to_scalarz TestCasting.test_array_to_scalari   sP     {+vDH,- , 	W&**+	- ,+s   AA#c                     t        j                  t         j                        }t        j                  t         j                        } ||      }t	        |      d        }| j                   |d      d       | j                   |d             y)z
        Test error due mishandling of Optional to Optional casting

        Related issue: https://github.com/numba/numba/issues/1718
        c                     | S r   r   )as    r   fooz2TestCasting.test_optional_to_optional.<locals>.foo   s    Hr   r   N)r   Optionalintpr   r   r#   assertIsNone)r(   opt_intopt_fltsigr^   s        r   test_optional_to_optionalz%TestCasting.test_optional_to_optionalu   sp     ..,../g	c	 
	 	Q##d)$r   N)__name__
__module____qualname__r+   r.   r6   r8   rE   rS   rZ   re   r   r   r   r   r      s+    3/N32&.*
-%r   r   __main__)numpyr   numba.core.errorsr   numbar   
numba.corer   r3   unittestr   r   r   r   r   TestCaser   rf   mainr   r   r   <module>rq      s_     )     i%(## i%X zHMMO r   