Ë
    èÿæiN  ã                   óp  — d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ d dlmZmZmZ e j"                  j$                  Ze j&                  e_        g e_        ej,                  dk(  r<e j.                  j0                  j2                  Ze j6                  ge_        de_        dZnZ e j:                  e j<                  j?                  d«      «      j@                  Ze j6                  ge_        e jB                  e_        dZd	„ Z"d
Z#d„ Z$d„ Z% G d„ de«      Z&e'dk(  r ejP                  «        yy)é    N)Újit)Úerrors)ÚTestCaseÚtagÚskip_if_freethreadingÚnté   Úciè  c                 óP   — |D ]!  }t        dt        z  «       t        «       | |<   Œ# y )Né
   )ÚsleepÚsleep_factorÚPyThread_get_thread_ident©ÚaÚindicesÚidxs      úi/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/numba/tests/test_gil.pyÚfr   "   s'   € ó
 ˆäˆb”<ÑÔ Ü*Ó,ˆˆ#Šñ ó    zvoid(int64[:], intp[:])c                 ód   — t        «        |D ]!  }t        dt        z  «       t        «       | |<   Œ# y)z/
    Same as f(), but inside a lifted loop
    r   N)Úobjectr   r   r   r   s      r   Úlifted_fr   .   s,   € ô „HÛˆäˆb”<ÑÔ Ü*Ó,ˆˆ#Šñ r   c                 ód   — |D ]+  }t        dt        z  «       t        «        t        «       | |<   Œ- y)z)
    Same as f(), but in object mode
    r   N)r   r   r   r   r   s      r   Úobject_fr   8   s,   € ó ˆäˆb”<ÑÔ ÜŒÜ*Ó,ˆˆ#Šñ	 r   c                   ób   — e Zd Zd„ Zd„ Zd„ Zd„ Zed„ «       Zd„ Z	d„ Z
d„ Zd	„ Zed
„ «       Zd„ Zy)ÚTestGILReleasec                 óL   — t        j                  |t         j                  ¬«      S )N©Údtype)ÚnpÚarangeÚint64)ÚselfÚ	n_memberss     r   Úmake_test_arrayzTestGILRelease.make_test_arrayE   s   € Ü�y‰y˜¬"¯(©(Ô3Ð3r   c                 ó  — g } || j                  d«      t        j                  dt        j                  ¬«      «       | j                  d«      }t	        |«      D ]z  }t        j                  |j
                  t        j                  ¬«      }t        j                  j                  |«       t        j                  |||f¬«      }|j                  |«       Œ| |D ]  }|j                  «        Œ |D ]  }|j                  «        Œ |S )Nr	   r   é2   )ÚtargetÚargs)r&   r!   r"   ÚintpÚrangeÚsizeÚrandomÚshuffleÚ	threadingÚThreadÚappendÚstartÚjoin)r$   ÚfuncÚ	n_threadsÚthreadsÚarrÚir   Úts           r   Úrun_in_threadszTestGILRelease.run_in_threadsH   sÇ   € àˆñ 	ˆT×!Ñ! !Ó$¤b§i¡i°¼¿¹Ô&AÔBØ×"Ñ" 2Ó&ˆÜ�yÖ!ˆAô —i‘i §¡´·±Ô8ˆGÜ�I‰I×Ñ˜gÔ&Ü× Ñ ¨°C¸°>ÔBˆAØ�N‰N˜1Õð "ó ˆAØ�G‰G�Ið ãˆAØ�F‰F�Hð àˆ
r   c                 óx   — | j                  |d¬«      }t        |«      }| j                  t        |«      d|«       y )Né   )r6   r	   )r;   ÚsetÚassertEqualÚlen)r$   r5   r8   Údistincts       r   Úcheck_gil_heldzTestGILRelease.check_gil_held\   s6   € Ø×!Ñ! $°!Ð!Ó4ˆÜ�s“8ˆØ×Ñœ˜X›¨¨8Õ4r   c                 óº   — dD ]=  }| j                  ||«      }t        |«      }	 | j                  t        |«      d|«        y  ‚# t        $ r}|}Y d }~ŒRd }~ww xY w)N)r=   é   é    r	   )r;   r>   ÚassertGreaterr@   ÚAssertionError)r$   r5   r6   r8   rA   ÚeÚfailures          r   Úcheck_gil_releasedz!TestGILRelease.check_gil_releaseda   sg   € Û$ˆIð ×%Ñ% d¨IÓ6ˆCÜ˜3“xˆHðØ×"Ñ"¤3 x£=°!°XÔ>ñ ð %ð ˆøô	 "ò Ø•ûðús   ¤AÁ	AÁAÁAc                 ó\   —  t        t        d¬«      t        «      }| j                  |«       y)zu
        Test the GIL is held by default, by checking serialized runs
        produce deterministic results.
        T©ÚnopythonN©r   Úf_sigr   rB   ©r$   Úcfuncs     r   Útest_gil_heldzTestGILRelease.test_gil_heldo   s%   € ð *””E DÔ)¬!Ó,ˆØ×Ñ˜EÕ"r   c                 ó^   —  t        t        dd¬«      t        «      }| j                  |«       y)zj
        Test releasing the GIL, by checking parallel runs produce
        unpredictable results.
        T©rM   ÚnogilN©r   rO   r   rJ   rP   s     r   Útest_gil_releasedz TestGILRelease.test_gil_releasedx   s'   € ð
 6””E D°Ô5´aÓ8ˆØ×Ñ Õ&r   c                 ó^   —  t        t        dd¬«      t        «      }| j                  |«       y)zz
        Test the GIL can by released by a lifted loop even though the
        surrounding code uses object mode.
        T©ÚforceobjrU   N)r   rO   r   rJ   rP   s     r   Ú$test_gil_released_inside_lifted_loopz3TestGILRelease.test_gil_released_inside_lifted_loop€   s'   € ð
 6””E D°Ô5´hÓ?ˆØ×Ñ Õ&r   c                 ó’   ‡—  t        t        d¬«      t        «      Št        t        dd¬«      ˆfd„«       }| j                  |«       y)zh
        Releasing the GIL in the caller is sufficient to have it
        released in a callee.
        TrL   rT   c                 ó   •—  ‰| |«       y ©N© ©r   r9   Ú
compiled_fs     €r   Úcallerz:TestGILRelease.test_gil_released_by_caller.<locals>.callerŽ   ó   ø€ á�q˜!Õr   NrV   ©r$   rb   ra   s     @r   Útest_gil_released_by_callerz*TestGILRelease.test_gil_released_by_callerˆ   sA   ø€ ð
 /”Sœ¨Ô.¬qÓ1ˆ
Ü	ŒU˜T¨Ô	.ó	ó 
/ð	à×Ñ Õ'r   c                 ó”   ‡—  t        t        dd¬«      t        «      Št        t        dd¬«      ˆfd„«       }| j                  |«       y)zR
        Same, but with both caller and callee asking to release the GIL.
        TrT   c                 ó   •—  ‰| |«       y r^   r_   r`   s     €r   rb   zETestGILRelease.test_gil_released_by_caller_and_callee.<locals>.caller˜   rc   r   NrV   rd   s     @r   Ú&test_gil_released_by_caller_and_calleez5TestGILRelease.test_gil_released_by_caller_and_callee“   sC   ø€ ð ;”Sœ¨°TÔ:¼1Ó=ˆ
Ü	ŒU˜T¨Ô	.ó	ó 
/ð	à×Ñ Õ'r   c                 ó’   ‡—  t        t        dd¬«      t        «      Št        t        d¬«      ˆfd„«       }| j                  |«       y)zP
        When only the callee asks to release the GIL, it gets ignored.
        TrT   rL   c                 ó   •—  ‰| |«       y r^   r_   r`   s     €r   rb   z9TestGILRelease.test_gil_ignored_by_callee.<locals>.caller£   rc   r   NrN   rd   s     @r   Útest_gil_ignored_by_calleez)TestGILRelease.test_gil_ignored_by_callee�   sA   ø€ ð
 ;”Sœ¨°TÔ:¼1Ó=ˆ
Ü	ŒU˜TÔ	"ó	ó 
#ð	à×Ñ˜FÕ#r   c                 óB  — t        j                  d¬«      5 }t        j                  dt        j                  «        t        t        dd¬«      t        «      }ddd«       | j                  t        d„ D «       «      |«       | j                  d«       y# 1 sw Y   Œ>xY w)za
        When the function is compiled in object mode, a warning is
        printed out.
        T)ÚrecordÚalwaysrY   Nc              3   ó†   K  — | ]9  }|j                   t        j                  u xr d t        |j                  «      v –— Œ; y­w)z:Code running in object mode won't allow parallel executionN)Úcategoryr   ÚNumbaWarningÚstrÚmessage)Ú.0Úws     r   Ú	<genexpr>z2TestGILRelease.test_object_mode.<locals>.<genexpr>°   sH   è ø€ ð ,á%* ð ŸJ™J¬&×*=Ñ*=Ð=ò oØ \Ô`cÐde×dmÑdmÓ`nÐ nóoá%*ùs   ‚?Aé   )ÚwarningsÚcatch_warningsÚsimplefilterr   rq   r   rO   r   Ú
assertTrueÚanyr;   )r$   ÚwlistrQ   s      r   Útest_object_modezTestGILRelease.test_object_mode¨   s„   € ô
 ×$Ñ$¨DÕ1°UÜ×!Ñ! (¬F×,?Ñ,?Ô@Ø9”Cœ¨°DÔ9¼(ÓCˆE÷ 2ð 	�‰œñ ,á%*ó,ó ,à-2ô	4ð 	×Ñ˜E 1Õ%÷ 2Ð1ús   —ABÂBN)Ú__name__Ú
__module__Ú__qualname__r&   r;   rB   rJ   r   rR   rW   r[   re   rh   rk   r~   r_   r   r   r   r   C   sW   „ ò4òò(5ò
ð ñ#ó ð#ò'ò'ò	(ò(ð ñ$ó ð$ó&r   r   Ú__main__))ÚctypesÚctypes.utilÚosÚsysr0   rx   Únumpyr!   ÚunittestÚnumbar   Ú
numba.corer   Únumba.tests.supportr   r   r   Ú	pythonapir   Úc_longÚrestypeÚargtypesÚnameÚwindllÚkernel32ÚSleepr   Úc_uintr   ÚCDLLÚutilÚfind_libraryÚusleepÚc_intr   rO   r   r   r   r   Úmainr_   r   r   Ú<module>r›      s  ðÛ Û Û 	Û 
Û Û ã ã Ý Ý ß DÑ Dð #×,Ñ,×FÑFÐ Ø$*§M¡MÐ Ô !Ø%'Ð Ô "ð ‡7�7ˆd‚?Ø�M‰M×"Ñ"×(Ñ(€EØ—m‘m�_€E„NØ€E„MØ�LàˆF�K‰K˜Ÿ™×0Ñ0°Ó5Ó6×=Ñ=€EØ—m‘m�_€E„NØ—L‘L€E„MØ€Lò-ð 	"€ò-ò-ôq&�Xô q&ðh ˆzÒØ€H‡M�M…Oð r   