
    sh}                     ~    S SK rS SKJr  S SKJrJrJr  S SKJ	r	   " S S\5      r
\S:X  a  \R                  " 5         gg)    N)cuda)unittestxfail_unless_cudasimCUDATestCase)configc                   \   ^  \ rS rSrU 4S jrS rS rS rS rS r	S r
\S	 5       rS
rU =r$ )TestException   c                 D   > [         TU ]  5         U R                  S5        g )Nz!Exceptions not supported with LTO)supersetUpskip_if_lto)self	__class__s    z/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/numba/cuda/tests/cudapy/test_exception.pyr   TestException.setUp	   s     	<=    c                    S n[         R                  " U5      n[         R                  " SSS9" U5      n[        R                  (       d!  US   " [        R
                  " SS/5      5        U R                  [        5       nUS   " [        R
                  " SS/5      5        S S S 5        U R                  S[        WR                  5      5        g ! , (       d  f       N4= f)	Nc                 f    [         R                  R                  nUS:X  a  U R                  U*      g g )N   )r   	threadIdxxshape)aryr   s     r   foo)TestException.test_exception.<locals>.foo   s,      AAv 		1"	 r   TFdebugopt)      r   r    ztuple index out of range)r   jitr   ENABLE_CUDASIMnparrayassertRaises
IndexErrorassertInstr	exception)r   r   
unsafe_foosafe_foocms        r   test_exceptionTestException.test_exception   s    	 XXc]
88$E237$$ tRXXq!f-.z*bTN288QF+, +0#bll2CD +*s    "C
Cc                     [         R                  " SSS9S 5       nUS   " S5        U R                  [        5         US   " S5        S S S 5        g ! , (       d  f       g = f)NTFr   c                     U (       a  [         eg N
ValueError)do_raises    r   r   *TestException.test_user_raise.<locals>.foo%   s       r   r    r    )r   r"   r&   r4   )r   r   s     r   test_user_raiseTestException.test_user_raise$   sR    	%	(	! 
)	! 	D	%z*IdO +**s   A
Ac                    U(       + n[         R                  " XS9S 5       n[         R                  S 5       nSnS[        R                  " U5      S-   -  nS[        R                  " U5      S-   -  nUSU4   " Xg5        S[        R                  " U5      S-   -  nS[        R                  " U5      S-   -  n	USU4   " X5        [        R                  R                  X5        [        R                  R                  X5        g)	zTesting issue #2655.

Exception raising code can cause the compiler to miss location
of unifying branch target and resulting in unexpected warp
divergence.
r   c                 D   [         R                  R                  n[         R                  R                  nUS:  a%  [	        U5       H  nX==   X   X   -  -  ss'   M     [         R
                  " 5         US:  a&  [	        U5       H  nX==   X   X   -  -  ss'   M     g g )N      r   r   r   blockDimrangesyncthreadsr   ytidntidis        r   problematicBTestException.case_raise_causing_warp_diverge.<locals>.problematic7   s    ..""C==??DRxtADADADL(D % RxtADADADL(D % r   c                 l   [         R                  R                  n[         R                  R                  nUS:  a/  [	        U5       H   nX   S:w  d  M  X==   X   X   -  -  ss'   M"     [         R
                  " 5         US:  a0  [	        U5       H   nX   S:w  d  M  X==   X   X   -  -  ss'   M"     g g )Nr<   r   r=   r>   rB   s        r   oracle=TestException.case_raise_causing_warp_diverge.<locals>.oracleE   s    ..""C==??DRxtAtqy, % RxtAtqy, % r       g      ?g{Gz?r    N)r   r"   r$   arangetestingassert_almost_equal)
r   with_debug_modewith_opt_moderG   rJ   ngot_xgot_yexpect_xexpect_ys
             r   case_raise_causing_warp_diverge-TestException.case_raise_causing_warp_diverge.   s     ,+		;	) 
<	) 
	- 
	- biilT)*biilT)*AqD%'1,-1,-q!tX(


&&x7


&&x7r   c                 "    U R                  SS9  g)z#Test case for issue #2655.
        F)rP   N)rW   )r   s    r   test_raise_causing_warp_diverge-TestException.test_raise_causing_warp_divergea   s     	,,U,Cr   c                 P   [         R                  S 5       n[        R                  " S5      n[        R                  " S5      n[        R                  " S5      nUS   " X#U5        U R                  [        R                  " US   5      S5        U R                  US   US   S5        g )Nc                 0    US   US   -  U S'   US   U S'   g Nr   r     rr   rC   s      r   f4TestException.test_no_zero_division_error.<locals>.fm   $    Q4!A$;AaDQ4AaDr   r   r    r7   r   zExpected inf from div by zerozExpected execution to continue)r   r"   r$   zerosones
assertTrueisinfassertEqual)r   rb   ra   r   rC   s        r   test_no_zero_division_error)TestException.test_no_zero_division_errori   s     
	 
	 HHQKHHQKGGAJ	$a1(GH1qt%EFr   c                    [         R                  " SSS9S 5       n[        R                  " S5      n[        R                  " S5      n[        R                  " S5      n[
        R                  (       a  [        nO[        nU R                  U5         US   " X#U5        S S S 5        U R                  US   SS	5        U R                  US   SS
5        g ! , (       d  f       N;= f)NTFr   c                 0    US   US   -  U S'   US   U S'   g r^   r_   r`   s      r   rb   :TestException.test_zero_division_error_in_debug.<locals>.f   rd   r   r   r    r7   r   z Expected result to be left unsetzExpected execution to stop)r   r"   r$   re   rf   r   r#   FloatingPointErrorZeroDivisionErrorr&   ri   )r   rb   ra   r   rC   excs         r   !test_zero_division_error_in_debug/TestException.test_zero_division_error_in_debug{   s     
%	(	 
)	 HHQKHHQKGGAJ   $C#Cs#dGA! $ 	1q"DE1q">?	 $#s   C
C!c                 <  ^^ Sm[         R                  " SS9U4S j5       m[         R                  " SS9U4S j5       nU R                  [        5       nUS   " 5         S S S 5        U R	                  T[        WR                  5      5        g ! , (       d  f       N4= f)NzDevice Function ErrorT)devicec                     > [        T 5      er2   r3   )msgs   r   rb   6TestException.test_raise_in_device_function.<locals>.f   s    S/!r   )r   c                     > T " 5         g r2   r_   )rb   s   r   kernel;TestException.test_raise_in_device_function.<locals>.kernel   s    Cr   r7   )r   r"   r&   r4   r(   r)   r*   )r   rz   raisesrb   rw   s      @@r   test_raise_in_device_function+TestException.test_raise_in_device_function   s    
 &			" 
	" 
		 
	 z*f4LN + 	c3v//01 +*s   B
Br_   )__name__
__module____qualname____firstlineno__r   r.   r8   rW   rZ   rj   rr   r   r}   __static_attributes____classcell__)r   s   @r   r	   r	      s?    >E*18fDG$@: 2 2r   r	   __main__)numpyr$   numbar   numba.cuda.testingr   r   r   
numba.corer   r	   r   mainr_   r   r   <module>r      s;      K K b2L b2J zMMO r   