
    xKg                         d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	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Zd dlmZmZmZ d dlZe G d	 d
             Z ed       G d de             Ze dk(  r ejB                          yy)    )List)	dataclassfield)cudafloat32)compile_ptx_for_current_devicecompile_ptx)	cossintanexploglog10log2powtanh)truedivN)CUDATestCaseskip_on_cudasimskip_unless_cc_75c                       e Zd ZU  ee      Zee   ed<    ee      Z	ee   ed<    ee      Z
ee   ed<    ee      Zee   ed<   dededefd	Zy
)FastMathCriterion)default_factoryfast_expectedfast_unexpectedprec_expectedprec_unexpectedtestfastprecc                 p   |j                  t        fd| j                  D                     |j                  t        fd| j                  D                     |j                  t        fd| j                  D                     |j                  t        fd| j
                  D                     y )Nc              3   &   K   | ]  }|v  
 y wN .0ir   s     i/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/cuda/tests/cudapy/test_fastmath.py	<genexpr>z*FastMathCriterion.check.<locals>.<genexpr>        B/A!AI/A   c              3   &   K   | ]  }|v 
 y wr#   r$   r%   s     r(   r)   z*FastMathCriterion.check.<locals>.<genexpr>        H3GaATM3Gr+   c              3   &   K   | ]  }|v  
 y wr#   r$   r&   r'   r    s     r(   r)   z*FastMathCriterion.check.<locals>.<genexpr>   r*   r+   c              3   &   K   | ]  }|v 
 y wr#   r$   r/   s     r(   r)   z*FastMathCriterion.check.<locals>.<genexpr>   r-   r+   )
assertTrueallr   r   r   r   )selfr   r   r    s     ``r(   checkzFastMathCriterion.check   sw    Bt/A/ABBCH43G3GHHIBt/A/ABBCH43G3GHHI    N)__name__
__module____qualname__r   listr   r   str__annotations__r   r   r   r   r4   r$   r5   r(   r   r      sl    $T:M49:!&t!<OT#Y<$T:M49:!&t!<OT#Y<J, Jc J Jr5   r   z4Fastmath and PTX inspection not available on cudasimc                       e Zd Zd ZdefdZdefdZd Zd Zd Z	e
d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zej*                  d        Zy)TestFastMathOptionc                 H    t        j                  ||d      |      } t        j                  ||      |      }|j                  | |j                  |      |j                  |             t	        |||d      \  }}t	        |||      \  }	}|j                  | ||	       y )NT)devicefastmathr?   )r   jitr4   inspect_asmr   )
r3   pyfuncsigr?   	criterionfastverprecverfastptx_precptxs
             r(   _test_fast_math_commonz)TestFastMathOption._test_fast_math_common   s     >$((3v=fE.$((3v.v6'%%c*G,?,?,D	

 4C

 4C

 	gw/r5   rF   c                     fd}fd}| j                  |t        d d d   t        fd|       | j                  |t        fd|       y )Nc                      |      | d<   y Nr   r$   )rxops     r(   kernelz8TestFastMathOption._test_fast_math_unary.<locals>.kernel2   s    a5AaDr5   c                      |       S r#   r$   )rQ   rR   s    r(   device_functionzATestFastMathOption._test_fast_math_unary.<locals>.device_function5   s    a5Lr5      Fr?   rF   TrL   r   )r3   rR   rF   rS   rU   s    `   r(   _test_fast_math_unaryz(TestFastMathOption._test_fast_math_unary1   sX    		 	##WSqS\7+EY 	$ 	
 	##gZ	 	$ 	
r5   c                     fd}fd}| j                  |t        d d d   t        t        fd|       | j                  |t        t        fd|       y )Nc                      ||      | d<   y rO   r$   )rP   rQ   yrR   s      r(   rS   z9TestFastMathOption._test_fast_math_binary.<locals>.kernel@   s    a8AaDr5   c                      | |      S r#   r$   )rQ   r\   rR   s     r(   r?   z9TestFastMathOption._test_fast_math_binary.<locals>.deviceC   s    a8Or5   rV   FrW   TrX   )r3   rR   rF   rS   r?   s    `   r(   _test_fast_math_binaryz)TestFastMathOption._test_fast_math_binary?   s^    		 	##SqS\7G,Ui 	$ 	
 	##Wg&ty 	$ 	
r5   c                 J    | j                  t        t        dgdg             y )Ncos.approx.ftz.f32 r   r   )rY   r
   r   r3   s    r(   	test_cosfzTestFastMathOption.test_cosfN   '    ""45!6 7	
r5   c                 J    | j                  t        t        dgdg             y )Nsin.approx.ftz.f32 ra   )rY   r   r   rb   s    r(   	test_sinfzTestFastMathOption.test_sinfW   rd   r5   c                 L    | j                  t        t        g ddg             y )N)rf   r`   div.approx.ftz.f32 rf   ra   )rY   r   r   rb   s    r(   	test_tanfzTestFastMathOption.test_tanf`   s(    "" - !66	8	
r5   c                 J    | j                  t        t        dgdg             y )Ntanh.approx.f32 ra   )rY   r   r   rb   s    r(   
test_tanhfzTestFastMathOption.test_tanhfj   s)     	""12!3 4	
r5   c                 x     d  fd} |dt        dgdg              |dt        dd	gdg             y )
Nc                      t        |      | d<   y rO   )r   )rP   rQ   s     r(   tanh_kernelz>TestFastMathOption.test_tanhf_compile_ptx.<locals>.tanh_kernelv   s    7AaDr5   c                     t        t        d d d   t        fd|       \  }}t        t        d d d   t        f|       \  }}|j                  ||       y )NrV   T)r@   cc)rr   )r	   r   r4   )rr   rF   rI   rJ   rK   r3   rp   s        r(   tanh_common_testzCTestFastMathOption.test_tanhf_compile_ptx.<locals>.tanh_common_testy   sY    $[73Q3<2I.2r;JGQ$[73Q3<2I(*,JGQOOD'73r5   )      rl   ra   )rr   rF   )rt   r   zex2.approx.ftz.f32 zrcp.approx.ftz.f32 )r   )r3   rs   rp   s   ` @r(   test_tanhf_compile_ptxz)TestFastMathOption.test_tanhf_compile_ptxu   sR    		4 	F.?-./0/
 	
 	F#4002/0$2	3r5   c                 J    | j                  t        t        dgdg             y )Nzfma.rn.f32 )r   r   )rY   r   r   rb   s    r(   	test_expfzTestFastMathOption.test_expf   s%    ""!.,o	
r5   c                 L    | j                  t        t        ddgdg             y )Nlg2.approx.ftz.f32 
0f3F317218ra   )rY   r   r   rb   s    r(   	test_logfzTestFastMathOption.test_logf   s)    """4lC!6 7	
r5   c                 L    | j                  t        t        ddgdg             y )Nrz   
0f3E9A209Bra   )rY   r   r   rb   s    r(   test_log10fzTestFastMathOption.test_log10f   s)    ""$4lC!6 7	
r5   c                 J    | j                  t        t        dgdg             y Nrz   ra   )rY   r   r   rb   s    r(   
test_log2fzTestFastMathOption.test_log2f   s'    ""#45!6 7	
r5   c                 J    | j                  t        t        dgdg             y r   )r^   r   r   rb   s    r(   	test_powfzTestFastMathOption.test_powf   s'    ##"45!6 7	
r5   c           	      R    | j                  t        t        dgdgdgdg             y )Nri   
div.rn.f32)r   r   r   r   )r^   r   r   rb   s    r(   	test_divfzTestFastMathOption.test_divf   s1    ##&45!-+n!6 7		
r5   c                    | j                  d       d }t        d d d   t        t        f} t        j                  |dd      |      } t        j                  |d      |      }d}t	        j
                  |t        j                        }| j                  t              5   |d|f   |d	d
       d d d        	  |d|f   |d	d
       y # 1 sw Y   xY w# t        $ r | j                  d       Y y w xY w)Nz!Exceptions not supported with LTOc                     ||z  | d<   y rO   r$   )rP   rQ   r\   s      r(   f10z3TestFastMathOption.test_divf_exception.<locals>.f10   s    q5AaDr5   rV   T)r@   debug)r   
   )dtypeg      $@g        z5Divide in fastmath should not throw ZeroDivisionError)	skip_if_ltor   r   rB   npemptyassertRaisesZeroDivisionErrorfail)r3   r   rE   rG   rH   nelemarys          r(   test_divf_exceptionz&TestFastMathOption.test_divf_exception   s     	<=	 ss|Wg.:$((3T:3?+$((3d+C0hhuBJJ/01GAuHc4- 2	OGAuHc4-	 21
 ! 	OIIMN	Os   #C<C CC54C5c                    t        j                  dd      d        fd}t        d d d   t        f} t        j                  |d      |      } t        j                  |      |      }| j                  d|j	                  |             | j                  d	|j	                  |             | j                  d|j	                  |             | j                  d
|j	                  |             y )Nzfloat32(float32, float32)TrA   c                     | |z  S r#   r$   )abs     r(   fooz@TestFastMathOption.test_device_fastmath_propagation.<locals>.foo   s    q5Lr5   c                 h    t        j                  d      }|| j                  k  r ||      | |<   y y )NrV   )r   gridsize)arrvalr'   r   s      r(   barz@TestFastMathOption.test_device_fastmath_propagation.<locals>.bar   s/    		!A388|QA r5   rV   )r@   zdiv.approx.f32r   zdiv.full.f32)r   rB   r   assertInrC   assertNotIn)r3   r   rE   rG   rH   r   s        @r(    test_device_fastmath_propagationz3TestFastMathOption.test_device_fastmath_propagation   s    
 
-d	;	 
<		%
 ss|W%.$((3.s3$((3-$ 	&(;(;C(@A 	lG$7$7$<=)7+>+>s+CD)<)<S)ABr5   N)r6   r7   r8   rL   r   rY   r^   rc   rg   rj   r   rm   rv   rx   r|   r   r   r   r   r   unittestexpectedFailurer   r$   r5   r(   r=   r=      s    0(
3D 

4E 



 
 
3,





O* C Cr5   r=   __main__)"typingr   dataclassesr   r   numbar   r   numba.cuda.compilerr   r	   mathr
   r   r   r   r   r   r   r   r   operatorr   numpyr   numba.cuda.testingr   r   r   r   r   r=   r6   mainr$   r5   r(   <module>r      s     (  K @ @ @  3 3  
J 
J 
J GHTC TC ITCn zHMMO r5   