
    J/Ph                      4   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j!                     dS dS )    )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d
S )FastMathCriterion)default_factoryfast_expectedfast_unexpectedprec_expectedprec_unexpectedtestfastprecc                    |                     t          fd| j        D                                  |                     t          fd| j        D                                  |                     t          fd| j        D                                  |                     t          fd| j        D                                  d S )Nc              3       K   | ]}|v V  	d S N .0ir   s     e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/cuda/tests/cudapy/test_fastmath.py	<genexpr>z*FastMathCriterion.check.<locals>.<genexpr>   '      BB!AIBBBBBB    c              3       K   | ]}|vV  	d S r#   r$   r%   s     r(   r)   z*FastMathCriterion.check.<locals>.<genexpr>   '      HHaATMHHHHHHr+   c              3       K   | ]}|v V  	d S r#   r$   r&   r'   r    s     r(   r)   z*FastMathCriterion.check.<locals>.<genexpr>   r*   r+   c              3       K   | ]}|vV  	d S 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   s    BBBBt/ABBBBBCCCHHHH43GHHHHHIIIBBBBt/ABBBBBCCCHHHH43GHHHHHIIIIIr+   N)__name__
__module____qualname__r   listr   r   str__annotations__r   r   r   r   r4   r$   r+   r(   r   r      s         $uT:::M49:::!&t!<!<!<OT#Y<<<$uT:::M49:::!&t!<!<!<OT#Y<<<J, Jc J J J J J J Jr+   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dS )TestFastMathOptionc                     t          j        ||d          |          } t          j        ||          |          }|                    | |                    |          |                    |                     t	          |||d          \  }}t	          |||          \  }	}|                    | ||	           d S )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E.$(3v...v66'%%c**G,?,?,D,D	
 	
 	

 4C
 
 

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

 	gw/////r+   rE   c                     fd}fd}|                      |t          d d d         t          fd|           |                      |t          fd|           d S )Nc                 $     |          | d<   d S Nr   r$   )rxops     r(   kernelz8TestFastMathOption._test_fast_math_unary.<locals>.kernel2   s    2a55AaDDDr+   c                      |           S r#   r$   )rP   rQ   s    r(   device_functionzATestFastMathOption._test_fast_math_unary.<locals>.device_function5   s    2a55Lr+      Fr>   rE   TrK   r   )r3   rQ   rE   rR   rT   s    `   r(   _test_fast_math_unaryz(TestFastMathOption._test_fast_math_unary1   s    	 	 	 	 		 	 	 	 	 	##WSSqS\7+EY 	$ 	
 	
 	
 	##gZ	 	$ 	
 	
 	
 	
 	
r+   c                     fd}fd}|                      |t          d d d         t          t          fd|           |                      |t          t          fd|           d S )Nc                 &     ||          | d<   d S rN   r$   )rO   rP   yrQ   s      r(   rR   z9TestFastMathOption._test_fast_math_binary.<locals>.kernel@   s    2a88AaDDDr+   c                      | |          S r#   r$   )rP   r[   rQ   s     r(   r>   z9TestFastMathOption._test_fast_math_binary.<locals>.deviceC   s    2a88Or+   rU   FrV   TrW   )r3   rQ   rE   rR   r>   s    `   r(   _test_fast_math_binaryz)TestFastMathOption._test_fast_math_binary?   s    	 	 	 	 		 	 	 	 	 	##SSqS\7G,Ui 	$ 	
 	
 	
 	##Wg&ty 	$ 	
 	
 	
 	
 	
r+   c                 ^    |                      t          t          dgdg                     d S )Ncos.approx.ftz.f32 r   r   )rX   r
   r   r3   s    r(   	test_cosfzTestFastMathOption.test_cosfN   E    ""45!6 7  	
 	
 	
 	
 	
r+   c                 ^    |                      t          t          dgdg                     d S )Nsin.approx.ftz.f32 r`   )rX   r   r   ra   s    r(   	test_sinfzTestFastMathOption.test_sinfW   rc   r+   c                 `    |                      t          t          g ddg                     d S )N)re   r_   div.approx.ftz.f32 re   r`   )rX   r   r   ra   s    r(   	test_tanfzTestFastMathOption.test_tanf`   sP    "" - - - !66	8 8 8	
 	
 	
 	
 	
r+   c                 ^    |                      t          t          dgdg                     d S )Ntanh.approx.f32 r`   )rX   r   r   ra   s    r(   
test_tanhfzTestFastMathOption.test_tanhfj   sG     	""12!3 4  	
 	
 	
 	
 	
r+   c                      d  fd} |dt          dgdg                      |dt          dd	gdg                     d S )
Nc                 *    t          |          | d<   d S rN   )r   )rO   rP   s     r(   tanh_kernelz>TestFastMathOption.test_tanhf_compile_ptx.<locals>.tanh_kernelv   s    77AaDDDr+   c                     t          t          d d d         t          fd|           \  }}t          t          d d d         t          f|           \  }}|                    ||           d S )NrU   T)r?   cc)rq   )r	   r   r4   )rq   rE   rH   rI   rJ   r3   ro   s        r(   tanh_common_testzCTestFastMathOption.test_tanhf_compile_ptx.<locals>.tanh_common_testy   s}    $[733Q3<2I.2r; ; ;JGQ$[733Q3<2I(*, , ,JGQOOD'733333r+   )      rk   r`   )rq   rE   )rs   r   zex2.approx.ftz.f32 zrcp.approx.ftz.f32 )r   )r3   rr   ro   s   ` @r(   test_tanhf_compile_ptxz)TestFastMathOption.test_tanhf_compile_ptxu   s    	 	 		4 	4 	4 	4 	4 	4 	F.?-./0/
 /
 /
 	 	 	 	
 	F#4002/0$2 $2 $2	3 	3 	3 	3 	3 	3r+   c                 ^    |                      t          t          dgdg                     d S )Nzfma.rn.f32 )r   r   )rX   r   r   ra   s    r(   	test_expfzTestFastMathOption.test_expf   sC    ""!.,o  	
 	
 	
 	
 	
r+   c                 `    |                      t          t          ddgdg                     d S )Nlg2.approx.ftz.f32 
0f3F317218r`   )rX   r   r   ra   s    r(   	test_logfzTestFastMathOption.test_logf   sG    """4lC!6 7  	
 	
 	
 	
 	
r+   c                 `    |                      t          t          ddgdg                     d S )Nry   
0f3E9A209Br`   )rX   r   r   ra   s    r(   test_log10fzTestFastMathOption.test_log10f   sG    ""$4lC!6 7  	
 	
 	
 	
 	
r+   c                 ^    |                      t          t          dgdg                     d S Nry   r`   )rX   r   r   ra   s    r(   
test_log2fzTestFastMathOption.test_log2f   sE    ""#45!6 7  	
 	
 	
 	
 	
r+   c                 ^    |                      t          t          dgdg                     d S r   )r]   r   r   ra   s    r(   	test_powfzTestFastMathOption.test_powf   sE    ##"45!6 7  	
 	
 	
 	
 	
r+   c           	      f    |                      t          t          dgdgdgdg                     d S )Nrh   
div.rn.f32)r   r   r   r   )r]   r   r   ra   s    r(   	test_divfzTestFastMathOption.test_divf   sO    ##&45!-+n!6 7	  	
 	
 	
 	
 	
r+   c                 8   |                      d           d }t          d d d         t          t          f} t          j        |dd          |          } t          j        |d          |          }d}t	          j        |t          j                  }|                     t                    5   |d|f         |d	d
           d d d            n# 1 swxY w Y   	  |d|f         |d	d
           d S # t          $ r |                     d           Y d S w xY w)Nz!Exceptions not supported with LTOc                     ||z  | d<   d S rN   r$   )rO   rP   r[   s      r(   f10z3TestFastMathOption.test_divf_exception.<locals>.f10   s    q5AaDDDr+   rU   T)r?   debug)r   
   )dtypeg      $@g        z5Divide in fastmath should not throw ZeroDivisionError)	skip_if_ltor   r   rA   npemptyassertRaisesZeroDivisionErrorfail)r3   r   rD   rF   rG   nelemarys          r(   test_divf_exceptionz&TestFastMathOption.test_divf_exception   s    	<===	 	 	 sss|Wg.:$(3T:::3??+$(3d+++C00huBJ///011 	. 	.GAuHc4---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.	OGAuHc4-----  	O 	O 	OIIMNNNNNN	Os$   1CCCC6 6DDc                 >   t          j        dd          d             fd}t          d d d         t          f} t          j        |d          |          } t          j        |          |          }|                     d|                    |                     |                     d	|                    |                     |                     d|                    |                     |                     d
|                    |                     d S )Nzfloat32(float32, float32)Tr@   c                     | |z  S r#   r$   )abs     r(   fooz@TestFastMathOption.test_device_fastmath_propagation.<locals>.foo   s    q5Lr+   c                 h    t          j        d          }|| j        k     r ||          | |<   d S d S )NrU   )r   gridsize)arrvalr'   r   s      r(   barz@TestFastMathOption.test_device_fastmath_propagation.<locals>.bar   s9    	!A38||QA |r+   rU   )r?   zdiv.approx.f32r   zdiv.full.f32)r   rA   r   assertInrB   assertNotIn)r3   r   rD   rF   rG   r   s        @r(    test_device_fastmath_propagationz3TestFastMathOption.test_device_fastmath_propagation   s+   
 
-d	;	;	;	 	 
<	;		% 	% 	% 	% 	%
 sss|W%.$(3...s33$(3--$$ 	&(;(;C(@(@AAA 	lG$7$7$<$<===)7+>+>s+C+CDDD)<)<S)A)ABBBBBr+   N)r5   r6   r7   rK   r   rX   r]   rb   rf   ri   r   rl   ru   rw   r{   r~   r   r   r   r   unittestexpectedFailurer   r$   r+   r(   r<   r<      sC       0 0 0(
3D 
 
 
 

4E 
 
 
 

 
 

 
 

 
 
 
 
 
3 3 3,
 
 

 
 

 
 

 
 

 
 

 
 
O O O* C C C C Cr+   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<   r5   mainr$   r+   r(   <module>r      s         ( ( ( ( ( ( ( (         K K K K K K K K @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @          3 3 3 3 3 3 3 3 3 3  
J 
J 
J 
J 
J 
J 
J 
J GHHTC TC TC TC TC TC TC IHTCn zHMOOOOO r+   