
    shb"                     B   S SK rS SKJr  S SKJrJrJrJrJ	r	J
r
JrJrJr  S SKJr  S SKJr  S SKJrJrJr  S SKJrJr  S SKrS SKrS rS	 rS
 rS rS rS r S r!S r"S r#S r$S r%S r&S r'S r(S r)S r*S r+S r, " S S\5      r-\.S:X  a  \R^                  " 5         gg)    N)compile_ptx)	f2i1i2i4i8u1u2u4u8)cuda)types)CUDATestCaseskip_on_cudasimskip_unless_cc_53)float16float32c                     [        U 5      $ N)floatxs    x/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/tests/cudapy/test_casting.pynative_castr      s    8O    c                 .    [         R                  " U 5      $ r   )npint8r   s    r   to_int8r      s    771:r   c                 .    [         R                  " U 5      $ r   )r   int16r   s    r   to_int16r"          88A;r   c                 .    [         R                  " U 5      $ r   )r   int32r   s    r   to_int32r&      r#   r   c                 .    [         R                  " U 5      $ r   )r   int64r   s    r   to_int64r)      r#   r   c                 .    [         R                  " U 5      $ r   )r   uint8r   s    r   to_uint8r,   "   r#   r   c                 .    [         R                  " U 5      $ r   )r   uint16r   s    r   	to_uint16r/   &   s    99Q<r   c                 .    [         R                  " U 5      $ r   )r   uint32r   s    r   	to_uint32r2   *       <<?r   c                 .    [         R                  " U 5      $ r   )r   uint64r   s    r   	to_uint64r6   .   r3   r   c                 \    [         R                  " U 5      [         R                  " S5      -  $ )Ng      ?r   r   r   s    r   
to_float16r9   2   s     JJqMBJJsO+,r   c                 \    [         R                  " U 5      [         R                  " S5      -  $ N   )r   r   r   s    r   
to_float32r=   8       ::a=2::a=((r   c                 \    [         R                  " U 5      [         R                  " S5      -  $ r;   )r   float64r   s    r   
to_float64rA   <   r>   r   c                 .    [         R                  " U 5      $ r   )r   	complex64r   s    r   to_complex64rD   @   s    <<?r   c                 .    [         R                  " U 5      $ r   )r   
complex128r   s    r   to_complex128rG   D   s    ==r   c                 j    [         R                  R                  [        R                  " U 5      S5      $ r;   r   fp16hmulr   r   r   s    r   cuda_int_literal_to_float16rL   O   s!     99>>"**Q-++r   c                 \    [         R                  " U 5      [         R                  " S5      -  $ r;   r8   r   s    r    reference_int_literal_to_float16rN   U   r>   r   c                 j    [         R                  R                  [        R                  " U 5      S5      $ Ng      @rI   r   s    r   cuda_float_literal_to_float16rQ   Y   s!     99>>"**Q---r   c                 \    [         R                  " U 5      [         R                  " S5      -  $ rP   r8   r   s    r   "reference_float_literal_to_float16rS   _   s    ::a=2::c?**r   c                   "   \ rS rSrS r\S 5       r\" S5      S 5       r\S 5       r	\" S5      S 5       r
\S 5       r\S	 5       r\" S5      S
 5       r\" S5      S 5       r\S 5       r\" S5      S 5       r\S 5       r\" S5      S 5       rSrg)TestCastingc   c                    ^^^^ [         R                  " SS9" U5      m[         R                  U4S j5       mUUU4S jnU$ )NTdevicec                 "   > T" U S   5      US'   g )Nr    )argreswrapped_funcs     r   cuda_wrapper_fn4TestCasting._create_wrapped.<locals>.cuda_wrapper_fng   s    !#a&)CFr   c                    > [         R                  " STS9nXS'   [         R                  " STS9nTS   " X5        US   $ )N   )dtyper   )rb   rb   )r   zeros)r\   argarrayresarrayr_   intypeouttypes      r   
wrapper_fn/TestCasting._create_wrapped.<locals>.wrapper_fnk   sA    xx0HQKxx1HD!(5A;r   )r   jit)selfpyfuncrg   rh   ri   r_   r^   s     `` @@r   _create_wrappedTestCasting._create_wrappedd   s9    xxt,V4		* 
	*	 r   c           	         [         [        [        [        4n[        R
                  [        R                  [        R                  [        R                  4n[        R                  [        R                  [        R                  4n[        X5       H  u  pEU H  nU R                  XeS9   U R                  XFU5      n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        S S S 5        M     M     g ! , (       d  f       M  = f)Nfromtytoty皙(@皙()r   r"   r&   r)   r   r   r!   r%   r(   r   r   r@   zipsubTestrn   assertEqualintrl   pyfuncstotysfromtysrm   rs   rr   cfuncs           r   test_float_to_intTestCasting.test_float_to_intt   s    Hh9"((BHHbhh7::rzz2::6/LF!\\\; 00FE$$U4[&,?$$U4[#d)<$$U5\6%=A$$U5\3u:> <; " 0;;s   (BE


Ez(Compilation unsupported in the simulatorc                     [         [        [        [        4nSn[	        X5       H-  u  p4[        U[        4SS9u  pVU R                  SU S3U5        M/     g )N          @   TrX   z	cvt.rni.s.f16)r   r"   r&   r)   rv   r   r   assertInrl   r{   sizesrm   sizeptx_s          r   test_float16_to_int_ptx#TestCasting.test_float16_to_int_ptx   sO    Hh9/LF "t<FCMMIdV40#6 0r   c           	      :   [         [        [        [        4n[        R
                  [        R                  [        R                  [        R                  4n[        R                  [        R                  [        R                  4n[        X5       Hw  u  pEU Hl  nU R                  XeS9   U R                  XFU5      nU R                  U" S5      U" S5      5        U R                  U" S5      [!        S5      5        S S S 5        Mn     My     g ! , (       d  f       M  = f)Nrq   rt   )r   r"   r&   r)   r   r+   r.   r1   r5   r   r   r@   rv   rw   rn   rx   ry   rz   s           r   test_float_to_uintTestCasting.test_float_to_uint   s    Hh9299bii;::rzz2::6/LF!\\\; 00FE$$U4[&,?$$U4[#d)< <; " 0;;s   (AD
Dc                     [         [        [        [        4nSn[	        X5       H-  u  p4[        U[        4SS9u  pVU R                  SU S3U5        M/     g )Nr   TrX   z	cvt.rni.ur   )r,   r/   r2   r6   rv   r   r   r   r   s          r   test_float16_to_uint_ptx$TestCasting.test_float16_to_uint_ptx   sO    Y	9=/LF "t<FCMMIdV40#6 0r   c                 ~   [         [        [        4n[        R                  [        R
                  [        R                  4n[        X5       H\  u  p4U R                  US9   U R                  U[        R                  U5      nU R                  U" S5      U" S5      5        S S S 5        M^     g ! , (       d  f       Mp  = f)N)rs   A  )r9   r=   rA   r   r   r   r@   rv   rw   rn   r(   rx   )rl   r{   r|   rm   rs   r~   s         r   test_int_to_floatTestCasting.test_int_to_float   s    z:6RZZ4/LF4(,,VRXXtD  sVC[9 )( 0((s    A B--
B<	c                 J   [         [        4n[        [        4n[	        X5       Hj  u  p4U R                  US9   U R                  U[        R                  [        R                  5      nU R                  U" S5      U" S5      5        S S S 5        Ml     g ! , (       d  f       M~  = f)N)funcr   )
rL   rQ   rN   rS   rv   rw   rn   r   r   rx   )rl   	cudafuncs	hostfuncscudafunchostfuncr~   s         r   test_literal_to_float16#TestCasting.test_literal_to_float16   s    024	579	 #&i";H8,,,Xrzz2::N  sXc]; -, #<,,s   AB
B"	c                     [         [        [        [        4nSn[	        X5       H,  u  p4[        [        U4SS9u  pVU R                  SU 3U5        M.     g )Nr   TrX   zcvt.rn.f16.s)r   r   r   r   rv   r   r9   r   rl   r}   r   tyr   r   r   s          r   test_int_to_float16_ptx#TestCasting.test_int_to_float16_ptx   M    r2r"G+HB bU4@FCMML/5 ,r   c                     [         [        [        [        4nSn[	        X5       H,  u  p4[        [        U4SS9u  pVU R                  SU 3U5        M.     g )Nr   TrX   zcvt.rn.f16.u)r	   r
   r   r   rv   r   r9   r   r   s          r   test_uint_to_float16_ptx$TestCasting.test_uint_to_float16_ptx   r   r   c           	      $   [         [        [        4n[        R                  [        R
                  [        R                  4n[        R                  " [        X5      U5       H  u  u  p4nU R                  XES9   U R                  X4U5      n[        R                  R                  U" S5      U" S5      U" S5      -  SS9  [        R                  R                  U" S5      U" S5      U" S5      -  SS9  S S S 5        M     g ! , (       d  f       M  = f)Nrq   rt   r<   ga2U0*3?)rtolru   )r9   r=   rA   r   r   r   r@   	itertoolsproductrv   rw   rn   testingassert_allclose)rl   r{   tysrm   rr   rs   r~   s          r   test_float_to_floatTestCasting.test_float_to_float   s    z:6zz2::rzz2&/&7&7G8I3&O"VdV7,,VTB
 

**5;+/:Q+?f + N

**5<+/;a+@v + O 87 'P77s   8A;D  
D	c                     [         [        4nSn[        X5       H-  u  p4[        U[        4SS9u  pVU R                  SU S3U5        M/     g )N)f32f64TrX   zcvt.r   )r=   rA   rv   r   r   r   )rl   r{   	postfixesrm   postfixr   r   s          r   test_float16_to_float_ptx%TestCasting.test_float16_to_float_ptx   sK    z*"	"76OF "t<FCMMD	.4  7r   c                 :   [         [        4n[        R                  [        R                  4n[        R
                  [        R                  [        R                  4n[        X5       H  u  pEU H  nU R                  XeS9   U R                  XFU5      n[        R                  R                  U" S5      U" U" S5      5      5        [        R                  R                  U" S5      U" U" S5      5      S-   5        S S S 5        M     M     g ! , (       d  f       M  = f)Nrq   gGz	@gGz	y                )rD   rG   r   rC   rF   r   r   r@   rv   rw   rn   r   r   rz   s           r   test_float_to_complex!TestCasting.test_float_to_complex   s    /r}}-::rzz2::6/LF!\\\; 00FE
 JJ..uT{/5fTl/CEJJ..uU|/5fUm/Dr/IK <; " 0;;s    A:D
Dc                     [         R                  " [        [        4SS9u  pU R	                  SU5        [         R                  " [        [
        4SS9u  p2U R	                  SU5        g )NTrX   zst.f32zst.u16)r   r   r   r   r   r   )rl   float32_ptxr   float16_ptxs       r   test_native_castTestCasting.test_native_cast   sN    ))+z$Oh,))+z$Oh,r   r[   N)__name__
__module____qualname____firstlineno__rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__r[   r   r   rU   rU   c   s%     ? ? ?@7 A7 
= 
= ?@7 A7 : : 	< 	< ?@6 A6 ?@6 A6 O O  ?@5 A5 K K$ ?@- A-r   rU   __main__)0numpyr   
numba.cudar   numba.core.typesr   r   r   r   r   r	   r
   r   r   numbar   
numba.corer   numba.cuda.testingr   r   r   numba.typesr   r   r   unittestr   r   r"   r&   r)   r,   r/   r2   r6   r9   r=   rA   rD   rG   rL   rN   rQ   rS   rU   r   mainr[   r   r   <module>r      s     " ? ? ?  3 3 (  -)),).+Z-, Z-z zMMO r   