
    sh                         S SK Jr  S SKJrJr  S SKJrJr  S SKJ	r	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rS SKJrJrJr  S SKr\ " S	 S
5      5       r\" S5       " S S\5      5       r\ S:X  a  \RB                  " 5         gg)    )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                       \ rS rSr% \" \S9r\\   \	S'   \" \S9r
\\   \	S'   \" \S9r\\   \	S'   \" \S9r\\   \	S'   S\S\S	\4S
 jrSrg)FastMathCriterion   )default_factoryfast_expectedfast_unexpectedprec_expectedprec_unexpectedtestfastprecc                 x  ^^ UR                  [        U4S jU R                   5       5      5        UR                  [        U4S jU R                   5       5      5        UR                  [        U4S jU R                   5       5      5        UR                  [        U4S jU R
                   5       5      5        g )Nc              3   ,   >#    U  H	  oT;   v   M     g 7fN .0ir    s     y/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/tests/cudapy/test_fastmath.py	<genexpr>*FastMathCriterion.check.<locals>.<genexpr>        B/A!I/A   c              3   ,   >#    U  H	  oT;  v   M     g 7fr$   r%   r&   s     r)   r*   r+           H3GaTM3Gr-   c              3   ,   >#    U  H	  oT;   v   M     g 7fr$   r%   r'   r(   r!   s     r)   r*   r+      r,   r-   c              3   ,   >#    U  H	  oT;  v   M     g 7fr$   r%   r1   s     r)   r*   r+      r/   r-   )
assertTrueallr   r   r   r   )selfr   r    r!   s     ``r)   checkFastMathCriterion.check   sw    Bt/A/ABBCH43G3GHHIBt/A/ABBCH43G3GHHI    r%   N)__name__
__module____qualname____firstlineno__r   listr   r   str__annotations__r   r   r   r   r6   __static_attributes__r%   r8   r)   r   r      sl    $T:M49:!&t!<OT#Y<$T:M49:!&t!<OT#Y<J, Jc J Jr8   r   z4Fastmath and PTX inspection not available on cudasimc                       \ rS rSrS rS\4S jrS\4S jrS rS r	S r
\S	 5       rS
 rS rS rS rS rS rS rS r\R,                  S 5       rSrg)TestFastMathOption   c                 $   [         R                  " X#SS9" U5      n[         R                  " X#S9" U5      nUR                  XR                  U5      UR                  U5      5        [	        XUSS9u  px[	        XUS9u  pUR                  XU	5        g )NT)devicefastmathrE   )r   jitr6   inspect_asmr   )
r5   pyfuncsigrE   	criterionfastverprecverfastptx_precptxs
             r)   _test_fast_math_common)TestFastMathOption._test_fast_math_common   s     ((3=fE((3.v6%%c*G,?,?,D	

 4

 4

 	w/r8   rL   c                    ^ U4S jnU4S jnU R                  U[        S S S2   [        4SUS9  U R                  U[        4SUS9  g )Nc                    > T" U5      U S'   g Nr   r%   )rxops     r)   kernel8TestFastMathOption._test_fast_math_unary.<locals>.kernel2   s    a5AaDr8   c                    > T" U 5      $ r$   r%   )rX   rY   s    r)   device_functionATestFastMathOption._test_fast_math_unary.<locals>.device_function5   s    a5Lr8      FrE   rL   TrR   r   )r5   rY   rL   rZ   r]   s    `   r)   _test_fast_math_unary(TestFastMathOption._test_fast_math_unary1   sX    		 	##WSqS\7+EY 	$ 	
 	##gZ	 	$ 	
r8   c                    ^ U4S jnU4S jnU R                  U[        S S S2   [        [        4SUS9  U R                  U[        [        4SUS9  g )Nc                    > T" X5      U S'   g rV   r%   )rW   rX   yrY   s      r)   rZ   9TestFastMathOption._test_fast_math_binary.<locals>.kernel@   s    a8AaDr8   c                    > T" X5      $ r$   r%   )rX   rf   rY   s     r)   rE   9TestFastMathOption._test_fast_math_binary.<locals>.deviceC   s    a8Or8   r_   Fr`   Tra   )r5   rY   rL   rZ   rE   s    `   r)   _test_fast_math_binary)TestFastMathOption._test_fast_math_binary?   s^    		 	##SqS\7G,Ui 	$ 	
 	##Wg&ty 	$ 	
r8   c                 D    U R                  [        [        S/S/S95        g )Ncos.approx.ftz.f32 r   r   )rb   r
   r   r5   s    r)   	test_cosfTestFastMathOption.test_cosfN   '    ""45!6 7	
r8   c                 D    U R                  [        [        S/S/S95        g )Nsin.approx.ftz.f32 rn   )rb   r   r   ro   s    r)   	test_sinfTestFastMathOption.test_sinfW   rr   r8   c                 F    U R                  [        [        / SQS/S95        g )N)rt   rm   div.approx.ftz.f32 rt   rn   )rb   r   r   ro   s    r)   	test_tanfTestFastMathOption.test_tanf`   s(    "" - !66	8	
r8   c                 D    U R                  [        [        S/S/S95        g )Ntanh.approx.f32 rn   )rb   r   r   ro   s    r)   
test_tanhfTestFastMathOption.test_tanhfj   s)     	""12!3 4	
r8   c                 b   ^ ^ S mU U4S jnU" S[        S/S/S9S9  U" S[        SS	/S/S9S9  g )
Nc                      [        U5      U S'   g rV   )r   )rW   rX   s     r)   tanh_kernel>TestFastMathOption.test_tanhf_compile_ptx.<locals>.tanh_kernelv   s    7AaDr8   c                    > [        T[        S S S2   [        4SU S9u  p#[        T[        S S S2   [        4U S9u  pCUR                  TX$5        g )Nr_   T)rF   cc)r   )r	   r   r6   )r   rL   rO   rP   rQ   r5   r   s        r)   tanh_common_testCTestFastMathOption.test_tanhf_compile_ptx.<locals>.tanh_common_testy   sS    $[73Q3<2I.2r;JG$[73Q3<2I(*,JGOOD'3r8   )      r|   rn   )r   rL   )r   r   zex2.approx.ftz.f32 zrcp.approx.ftz.f32 )r   )r5   r   r   s   ` @r)   test_tanhf_compile_ptx)TestFastMathOption.test_tanhf_compile_ptxu   sR    		4 	F.?-./0/
 	
 	F#4002/0$2	3r8   c                 D    U R                  [        [        S/S/S95        g )Nzfma.rn.f32 )r   r   )rb   r   r   ro   s    r)   	test_expfTestFastMathOption.test_expf   s%    ""!.,o	
r8   c                 F    U R                  [        [        SS/S/S95        g )Nlg2.approx.ftz.f32 
0f3F317218rn   )rb   r   r   ro   s    r)   	test_logfTestFastMathOption.test_logf   s)    """4lC!6 7	
r8   c                 F    U R                  [        [        SS/S/S95        g )Nr   
0f3E9A209Brn   )rb   r   r   ro   s    r)   test_log10fTestFastMathOption.test_log10f   s)    ""$4lC!6 7	
r8   c                 D    U R                  [        [        S/S/S95        g Nr   rn   )rb   r   r   ro   s    r)   
test_log2fTestFastMathOption.test_log2f   s'    ""#45!6 7	
r8   c                 D    U R                  [        [        S/S/S95        g r   )rj   r   r   ro   s    r)   	test_powfTestFastMathOption.test_powf   s'    ##"45!6 7	
r8   c           
      L    U R                  [        [        S/S/S/S/S95        g )Nrx   
div.rn.f32)r   r   r   r   )rj   r   r   ro   s    r)   	test_divfTestFastMathOption.test_divf   s1    ##&45!-+n!6 7		
r8   c                    U R                  S5        S n[        S S S2   [        [        4n[        R                  " USSS9" U5      n[        R                  " USS9" U5      nSn[        R
                  " U[        R                  S9nU R                  [        5         USU4   " US	S
5        S S S 5         USU4   " US	S
5        g ! , (       d  f       N= f! [         a    U R                  S5         g f = f)Nz!Exceptions not supported with LTOc                     X-  U S'   g rV   r%   )rW   rX   rf   s      r)   f103TestFastMathOption.test_divf_exception.<locals>.f10   s    5AaDr8   r_   T)rF   debug)r   
   )dtypeg      $@g        z5Divide in fastmath should not throw ZeroDivisionError)	skip_if_ltor   r   rH   npemptyassertRaisesZeroDivisionErrorfail)r5   r   rK   rM   rN   nelemarys          r)   test_divf_exception&TestFastMathOption.test_divf_exception   s     	<=	 ss|Wg.((3T:3?((3d+C0hhuBJJ/01AuHc4- 2	OAuHc4-	 21
 ! 	OIIMN	Os   C6C 
CC54C5c                   ^ [         R                  " SSS9S 5       mU4S jn[        S S S2   [        4n[         R                  " USS9" U5      n[         R                  " U5      " U5      nU R                  SUR	                  U5      5        U R                  S	UR	                  U5      5        U R                  SUR	                  U5      5        U R                  S
UR	                  U5      5        g )Nzfloat32(float32, float32)TrG   c                 
    X-  $ r$   r%   )abs     r)   foo@TestFastMathOption.test_device_fastmath_propagation.<locals>.foo   s	    5Lr8   c                 f   > [         R                  " S5      nX R                  :  a  T" X!5      X'   g g )Nr_   )r   gridsize)arrvalr(   r   s      r)   bar@TestFastMathOption.test_device_fastmath_propagation.<locals>.bar   s)    		!A88|Q r8   r_   )rF   zdiv.approx.f32r   zdiv.full.f32)r   rH   r   assertInrI   assertNotIn)r5   r   rK   rM   rN   r   s        @r)    test_device_fastmath_propagation3TestFastMathOption.test_device_fastmath_propagation   s    
 
-d	;	 
<		%
 ss|W%((3.s3((3-$ 	&(;(;C(@A 	lG$7$7$<=)7+>+>s+CD)<)<S)ABr8   r%   N)r9   r:   r;   r<   rR   r   rb   rj   rp   ru   ry   r   r}   r   r   r   r   r   r   r   r   unittestexpectedFailurer   r@   r%   r8   r)   rB   rB      s    0(
3D 

4E 



 
 
3,





O* C Cr8   rB   __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   rB   r9   mainr%   r8   r)   <module>r      s     (  K @ @ @  3 3  
J 
J 
J GHTC TC ITCn zMMO r8   