
    xKgb"                     @   d dl Zd dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZmZ d dlZd dlZd Zd	 Zd
 Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z, G d de      Z-e.dk(  r ej^                          yy)    N)compile_ptx)	f2i1i2i4i8u1u2u4u8)cuda)types)CUDATestCaseskip_on_cudasimskip_unless_cc_53)float16float32c                     t        |       S N)floatxs    h/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/cuda/tests/cudapy/test_casting.pynative_castr      s    8O    c                 ,    t        j                  |       S r   )npint8r   s    r   to_int8r      s    771:r   c                 ,    t        j                  |       S r   )r   int16r   s    r   to_int16r"          88A;r   c                 ,    t        j                  |       S r   )r   int32r   s    r   to_int32r&      r#   r   c                 ,    t        j                  |       S r   )r   int64r   s    r   to_int64r)      r#   r   c                 ,    t        j                  |       S r   )r   uint8r   s    r   to_uint8r,   "   r#   r   c                 ,    t        j                  |       S r   )r   uint16r   s    r   	to_uint16r/   &   s    99Q<r   c                 ,    t        j                  |       S r   )r   uint32r   s    r   	to_uint32r2   *       <<?r   c                 ,    t        j                  |       S r   )r   uint64r   s    r   	to_uint64r6   .   r3   r   c                 X    t        j                  |       t        j                  d      z  S )Ng      ?r   r   r   s    r   
to_float16r9   2   s     JJqMBJJsO+,r   c                 X    t        j                  |       t        j                  d      z  S N   )r   r   r   s    r   
to_float32r=   8       ::a=2::a=((r   c                 X    t        j                  |       t        j                  d      z  S r;   )r   float64r   s    r   
to_float64rA   <   r>   r   c                 ,    t        j                  |       S r   )r   	complex64r   s    r   to_complex64rD   @   s    <<?r   c                 ,    t        j                  |       S r   )r   
complex128r   s    r   to_complex128rG   D   s    ==r   c                 h    t         j                  j                  t        j                  |       d      S r;   r   fp16hmulr   r   r   s    r   cuda_int_literal_to_float16rL   O   s!     99>>"**Q-++r   c                 X    t        j                  |       t        j                  d      z  S r;   r8   r   s    r    reference_int_literal_to_float16rN   U   r>   r   c                 h    t         j                  j                  t        j                  |       d      S Ng      @rI   r   s    r   cuda_float_literal_to_float16rQ   Y   s!     99>>"**Q---r   c                 X    t        j                  |       t        j                  d      z  S rP   r8   r   s    r   "reference_float_literal_to_float16rS   _   s    ::a=2::c?**r   c                      e Zd Zd Zed        Z ed      d        Zed        Z ed      d        Z	ed        Z
ed        Z ed      d	        Z ed      d
        Zed        Z ed      d        Zed        Z ed      d        Zy)TestCastingc                      t        j                  d      |      t         j                  fd       fd}|S )NTdevicec                 "     | d         |d<   y )Nr    )argreswrapped_funcs     r   cuda_wrapper_fnz4TestCasting._create_wrapped.<locals>.cuda_wrapper_fng   s    !#a&)CFr   c                     t        j                  d      }| |d<   t        j                  d      } d   ||       |d   S )N   )dtyper   )r`   r`   )r   zeros)r[   argarrayresarrayr^   intypeouttypes      r   
wrapper_fnz/TestCasting._create_wrapped.<locals>.wrapper_fnk   sG    xx0HHQKxx1H!OD!(H5A;r   )r   jit)selfpyfuncre   rf   rg   r^   r]   s     `` @@r   _create_wrappedzTestCasting._create_wrappedd   s;    ,txxt,V4		* 
	*	 r   c           	         t         t        t        t        f}t        j
                  t        j                  t        j                  t        j                  f}t        j                  t        j                  t        j                  f}t        ||      D ]  \  }}|D ]  }| j                  ||      5  | j                  |||      }| j                   |d       |d             | j                   |d      t!        d             | j                   |d       |d             | j                   |d      t!        d             d d d          y # 1 sw Y   xY w)Nfromtytoty皙(@皙()r   r"   r&   r)   r   r   r!   r%   r(   r   r   r@   zipsubTestrk   assertEqualintri   pyfuncstotysfromtysrj   ro   rn   cfuncs           r   test_float_to_intzTestCasting.test_float_to_intt   s    Hh9"((BHHbhh7::rzz2::6/LFD!\\d\; 00FE$$U4[&,?$$U4[#d)<$$U5\6%=A$$U5\3u:> <; " 0;;s   .BEEz(Compilation unsupported in the simulatorc                     t         t        t        t        f}d}t	        ||      D ]1  \  }}t        |t        fd      \  }}| j                  d| d|       3 y )N          @   TrW   z	cvt.rni.s.f16)r   r"   r&   r)   rr   r   r   assertInri   rw   sizesrj   sizeptx_s          r   test_float16_to_int_ptxz#TestCasting.test_float16_to_int_ptx   sU    Hh9/LFD "t<FCMMIdV40#6 0r   c           	      4   t         t        t        t        f}t        j
                  t        j                  t        j                  t        j                  f}t        j                  t        j                  t        j                  f}t        ||      D ]z  \  }}|D ]p  }| j                  ||      5  | j                  |||      }| j                   |d       |d             | j                   |d      t!        d             d d d        r | y # 1 sw Y   xY w)Nrm   rp   )r   r"   r&   r)   r   r+   r.   r1   r5   r   r   r@   rr   rs   rk   rt   ru   rv   s           r   test_float_to_uintzTestCasting.test_float_to_uint   s    Hh9299bii;::rzz2::6/LFD!\\d\; 00FE$$U4[&,?$$U4[#d)< <; " 0;;s   .ADDc                     t         t        t        t        f}d}t	        ||      D ]1  \  }}t        |t        fd      \  }}| j                  d| d|       3 y )Nr}   TrW   z	cvt.rni.ur   )r,   r/   r2   r6   rr   r   r   r   r   s          r   test_float16_to_uint_ptxz$TestCasting.test_float16_to_uint_ptx   sU    Y	9=/LFD "t<FCMMIdV40#6 0r   c                 x   t         t        t        f}t        j                  t        j
                  t        j                  f}t        ||      D ]_  \  }}| j                  |      5  | j                  |t        j                  |      }| j                   |d       |d             d d d        a y # 1 sw Y   lxY w)N)ro   A  )r9   r=   rA   r   r   r   r@   rr   rs   rk   r(   rt   )ri   rw   rx   rj   ro   rz   s         r   test_int_to_floatzTestCasting.test_int_to_float   s    z:6RZZ4/LFD4(,,VRXXtD  sVC[9 )( 0((s   %A B00B9	c                 D   t         t        f}t        t        f}t	        ||      D ]m  \  }}| j                  |      5  | j                  |t        j                  t        j                        }| j                   |d       |d             d d d        o y # 1 sw Y   zxY w)N)funcr   )
rL   rQ   rN   rS   rr   rs   rk   r   r   rt   )ri   	cudafuncs	hostfuncscudafunchostfuncrz   s         r   test_literal_to_float16z#TestCasting.test_literal_to_float16   s    024	579	 #&i";Hh8,,,Xrzz2::N  sXc]; -, #<,,s   ABB	c                     t         t        t        t        f}d}t	        ||      D ]0  \  }}t        t        |fd      \  }}| j                  d| |       2 y )Nr}   TrW   zcvt.rn.f16.s)r   r   r   r   rr   r   r9   r   ri   ry   r   tyr   r   r   s          r   test_int_to_float16_ptxz#TestCasting.test_int_to_float16_ptx   S    r2r"GU+HB bU4@FCMML/5 ,r   c                     t         t        t        t        f}d}t	        ||      D ]0  \  }}t        t        |fd      \  }}| j                  d| |       2 y )Nr}   TrW   zcvt.rn.f16.u)r	   r
   r   r   rr   r   r9   r   r   s          r   test_uint_to_float16_ptxz$TestCasting.test_uint_to_float16_ptx   r   r   c           	      ,   t         t        t        f}t        j                  t        j
                  t        j                  f}t        j                  t        ||      |      D ]  \  \  }}}| j                  ||      5  | j                  |||      }t        j                  j                   |d       |d       |d      z  d       t        j                  j                   |d       |d       |d      z  d       d d d         y # 1 sw Y   xY w)Nrm   rp   r<   ga2U0*3?)rtolrq   )r9   r=   rA   r   r   r   r@   	itertoolsproductrr   rs   rk   testingassert_allclose)ri   rw   tysrj   rn   ro   rz   s          r   test_float_to_floatzTestCasting.test_float_to_float   s    z:6zz2::rzz2&/&7&7GS8I3&O"VVdV$7,,VVTB
 

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

**5<+/;a+@v + O 87 'P77s   =BD

D	c                     t         t        f}d}t        ||      D ]1  \  }}t        |t        fd      \  }}| j                  d| d|       3 y )N)f32f64TrW   zcvt.r   )r=   rA   rr   r   r   r   )ri   rw   	postfixesrj   postfixr   r   s          r   test_float16_to_float_ptxz%TestCasting.test_float16_to_float_ptx   sQ    z*"	"7I6OFG "t<FCMMD	.4  7r   c                 4   t         t        f}t        j                  t        j                  f}t        j
                  t        j                  t        j                  f}t        ||      D ]  \  }}|D ]  }| j                  ||      5  | j                  |||      }t        j                  j                   |d       | |d                   t        j                  j                   |d       | |d            dz          d d d          y # 1 sw Y   xY w)Nrm   gGz	@gGz	y                )rD   rG   r   rC   rF   r   r   r@   rr   rs   rk   r   r   rv   s           r   test_float_to_complexz!TestCasting.test_float_to_complex   s    /r}}-::rzz2::6/LFD!\\d\; 00FE
 JJ..uT{/5fTl/CEJJ..uU|/5fUm/Dr/IK <; " 0;;s   A;DDc                     t        j                  t        t        fd      \  }}| j	                  d|       t        j                  t        t
        fd      \  }}| j	                  d|       y )NTrW   zst.f32zst.u16)r   r   r   r   r   r   )ri   float32_ptxr   float16_ptxs       r   test_native_castzTestCasting.test_native_cast   sR    ))+z$OQh,))+z$OQh,r   N)__name__
__module____qualname__rk   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   rZ   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   mainrZ   r   r   <module>r      s     " ? ? ?  3 3 (  -)),).+Z-, Z-z zHMMO r   