
    shI                         S SK rS SKJr  S SKJr  S SKJr  S SKrS SK	r	S r
S rS rS rS	 r " S
 S\	R                  5      r\S:X  a  \	R$                  " 5         gg)    N)TypingError)njit)typesc                 .    [         R                  " U 5      $ N)r   int32xs    l/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/tests/test_casting.pyfloat_to_intr   	   s    ;;q>    c                 4    [         R                  " U 5      S-  $ )N   )r   float64r	   s    r   int_to_floatr      s    ==ar   c                 .    [         R                  " U 5      $ r   )r   uint32r	   s    r   float_to_unsignedr      s    <<?r   c                 .    [         R                  " U 5      $ r   )r   
complex128r	   s    r   float_to_complexr      s    Ar   c                  X    [         R                  " [         R                  " S5      5        g )N)   )npr   zeros r   r   numpy_scalar_cast_errorr      s    HHRXXd^r   c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)TestCasting   c                    [         n[        [        R                  45      " U5      nU R	                  UR
                  S   R                  [        R                  5        U R	                  U" S5      U" S5      5        U R	                  U" S5      [        S5      5        U R	                  U" S5      U" S5      5        U R	                  U" S5      [        S5      5        g )Nr   皙(@g()	r   r   r   float32assertEqualnopython_signaturesreturn_typer   intselfpyfunccfuncs      r   test_float_to_int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                 *   [         n[        [        R                  45      " U5      nU R	                  UR
                  S   R                  [        R                  5        U R	                  U" S5      U" S5      5        U R	                  U" S5      S5        g )Nr   iA  g     d@)r   r   r   int64r$   r%   r&   r   r(   s      r   test_int_to_floatTestCasting.test_int_to_float'   sp    ekk^$V,2215AA	(sVC[1sX.r   c           
         [         n[        [        R                  45      " U5      nU R	                  UR
                  S   R                  [        R                  5        U R	                  U" S5      U" S5      5        U R	                  U" S5      [        R                  " S[        R                  " SS5      5      S   5        g )Nr   gGz	@Ii   )r   r   r   r#   r$   r%   r&   r   structunpackpackr(   s      r   test_float_to_unsigned"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                 *   [         n[        [        R                  45      " U5      nU R	                  UR
                  S   R                  [        R                  5        U R	                  U" S5      U" S5      5        U R	                  U" S5      S5        g )Nr   gGz	yGz	        )r   r   r   r   r$   r%   r&   r   r(   s      r   test_float_to_complex!TestCasting.test_float_to_complex9   ss    !emm%&v.2215AA))	+uve}5uz2r   c                 8  ^ [        S5      S 5       mTR                  5         [        S5      U4S j5       n[        R                  " S/[        R                  S9nU R                  U" U5      US   5        U R                  [        TR                  5      S5        g	)
z,Make sure this compiles.

Cast C to A array
z	f8(f8[:])c                     U S   $ )Nr   r   r	   s    r   inner.TestCasting.test_array_to_array.<locals>.innerF   s    Q4Kr   zf8(f8[::1])c                    > T" U 5      $ r   r   )r
   r@   s    r   driver/TestCasting.test_array_to_array.<locals>.driverL   s    8Or   i  dtyper      N)r   disable_compiler   arrayr   r$   len	overloads)r)   rC   r
   r@   s      @r   test_array_to_arrayTestCasting.test_array_to_arrayA   s    
 
k		 
	 		m		 
	 HHdV2::.AaD)U__-q1r   c                    [         S 5       n[        R                  S4[        R                  S4[        R                  S4[        R
                  S4[        R                  S4[        R                  S4[        R                  [        R                  " SS5      4[        R                  [        R                  " S5      4S	/	nU H4  u  p4[        R                  " XCS
9nU R                  U" U5      US   5        M6     g )Nc                 8    U R                   R                  U 5      $ r   )rF   typer	   s    r   r@   -TestCasting.test_0darrayT_to_T.<locals>.innerU   s    77<<?"r   Tr"      y      @       @r5   hz
2016-01-01)z<U3ABCrE   r   )r   r   bool_r#   r   r/   	complex64r   timedelta64
datetime64rI   r$   )r)   r@   inputsTinpr
   s         r   test_0darrayT_to_TTestCasting.test_0darrayT_to_TT   s    		# 
	# XXtZZZZXXrN\\4 ]]D!^^R^^As34]]BMM,78

 HQ&AU1Xqu- r   c                     U R                  [        5       n[        S5      " [        5        SSS5        U R	                  S[        WR                  5      5        g! , (       d  f       N4= f)z^
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_scalar TestCasting.test_array_to_scalari   sN     {+vH,- , 	W&**+	- ,+s   A
A(c                 $   [         R                  " [         R                  5      n[         R                  " [         R                  5      nU" U5      n[	        U5      S 5       nU R                  U" S5      S5        U R                  U" S5      5        g)zw
Test error due mishandling of Optional to Optional casting

Related issue: https://github.com/numba/numba/issues/1718
c                     U $ r   r   )as    r   foo2TestCasting.test_optional_to_optional.<locals>.foo   s    Hr   r   N)r   Optionalintpr   r   r$   assertIsNone)r)   opt_intopt_fltsigri   s        r   test_optional_to_optional%TestCasting.test_optional_to_optionalu   sp     ..,../g	c	 
	 	Q##d)$r   r   N)__name__
__module____qualname____firstlineno__r,   r0   r9   r<   rL   r\   rd   rq   __static_attributes__r   r   r   r   r      s+    3/N32&.*
-%r   r   __main__)numpyr   numba.core.errorsr   numbar   
numba.corer   r6   unittestr   r   r   r   r   TestCaser   rs   mainr   r   r   <module>r      s]     )     i%(## i%X zMMO r   