Ë
    çÿæi÷/  ã                   óÀ  — d 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Zddl	m
Z
mZ ddlZddlZ	 ddlZddlmZ ddlmZ dZ ej,                  e«       ej.                  e«      k  rdZ	 g d¢ZdZ ej6                  d	«      xs d
Zdev rdZdej:                  d   v Z G d„ de«      Z  G d„ d«      Z! G d„ d«      Z"d„ Z#d„ Z$d„ Z%d„ Z&d„ Z'd„ Z(y# e$ r dZY Œnw xY w)z
Generic test utilities.

é    N)Úmodule_from_specÚspec_from_file_location)Úversion)Ú_pep440z3.0.8)ÚPytestTesterÚcheck_free_memoryÚ_TestPythranFuncÚIS_MUSLFÚHOST_GNU_TYPEÚ ÚmuslTÚeditablec                   ó   — e Zd ZdZy)ÚFPUModeChangeWarningzWarning about FPU mode changeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    új/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/scipy/_lib/_testutils.pyr   r   3   s   „ Ù'Ør   r   c                   ó"   — e Zd ZdZd„ Z	 	 dd„Zy)r   a"  
    Run tests for this namespace

    ``scipy.test()`` runs tests for all of SciPy, with the default settings.
    When used from a submodule (e.g., ``scipy.cluster.test()``, only the tests
    for that namespace are run.

    Parameters
    ----------
    label : {'fast', 'full'}, optional
        Whether to run only the fast tests, or also those marked as slow.
        Default is 'fast'.
    verbose : int, optional
        Test output verbosity. Default is 1.
    extra_argv : list, optional
        Arguments to pass through to Pytest.
    doctests : bool, optional
        Whether to run doctests or not. Default is False.
    coverage : bool, optional
        Whether to run tests with code coverage measurements enabled.
        Default is False.
    tests : list of str, optional
        List of module names to run tests for. By default, uses the module
        from which the ``test`` function is called.
    parallel : int, optional
        Run tests in parallel with pytest-xdist, if number given is larger than
        1. Default is 1.

    c                 ó   — || _         y ©N)Úmodule_name)Úselfr   s     r   Ú__init__zPytestTester.__init__V   s
   € Ø&ˆÕr   Nc                 ó¶  — dd l }t        j                  | j                     }	t        j
                  j                  |	j                  d   «      }
ddg}|€g }||z  }t        d„ |D «       «      rt        d«      ‚|r&t        |«      dkD  r|ddt        |«      dz
  z  z   gz  }|r	|d	|
z   gz  }|d
k(  r|ddgz  }n|dk7  r|d|gz  }|€| j                  g}|�7|dkD  r2t        «       r|dt        |«      gz  }ndd l}|j                  dd¬«       |dgt        |«      z   z  }	 |j!                  |«      }|dk(  S # t"        $ r}|j$                  }Y d }~|dk(  S d }~ww xY w)Nr   z--showlocalsz
--tb=shortc              3   ó4   K  — | ]  }|d k(  xs |dk(  –— Œ y­w)ú-mz	--markersNr   )Ú.0Úargs     r   Ú	<genexpr>z(PytestTester.__call__.<locals>.<genexpr>e   s"   è ø€ ÐG¹J°Sˆs�d‰{Ò0˜c [Ñ0Ó0¹Jùs   ‚zMust specify -m before --é   Ú-Úvz--cov=Úfastr    znot slowÚfullz-nzMCould not run tests in parallel because pytest-xdist plugin is not available.é   )Ú
stacklevelz--pyargs)ÚpytestÚsysÚmodulesr   ÚosÚpathÚabspathÚ__path__ÚanyÚ
ValueErrorÚintÚ_pytest_has_xdistÚstrÚwarningsÚwarnÚlistÚmainÚ
SystemExitÚcode)r   ÚlabelÚverboseÚ
extra_argvÚdoctestsÚcoverageÚtestsÚparallelr+   ÚmoduleÚmodule_pathÚpytest_argsr7   r<   Úexcs                  r   Ú__call__zPytestTester.__call__Y   sŠ  € ãä—‘˜T×-Ñ-Ñ.ˆÜ—g‘g—o‘o f§o¡o°aÑ&8Ó9ˆà% |Ð4ˆàÐØˆJØ�zÑ!ˆÜÑG¹JÓGÔGäÐ8Ó9Ð9á”s˜7“| aÒ'Ø˜C #¤s¨7£|°A¡~Ñ"6Ñ6Ð7Ñ7ˆKáØ˜H {Ñ2Ð3Ñ3ˆKà�FŠ?Ø˜D *Ð-Ñ-‰KØ�fŠ_Ø˜D %˜=Ñ(ˆKàˆ=Ø×%Ñ%Ð&ˆEàÐ H¨q¢LÜ Ô"Ø ¤c¨(£mÐ4Ñ4‘ãØ—‘ð Fà)*ð ô ,ð 	˜
�|¤d¨5£kÑ1Ñ1ˆð	Ø—;‘;˜{Ó+ˆDð ˜‘	Ðøô ò 	Ø—8‘8ŒDà˜‘	Ðûð	ús   ÄD5 Ä5	EÄ>EÅE)r'   r$   NFFNN)r   r   r   r   r   rH   r   r   r   r   r   8   s   „ ñò:'ð KPØ6:ô.r   r   c                   ó"  — e Zd ZdZej
                  ej                  ej                  ej                  ej                  ej                  gZej                  ej                  gZej                  ej                   gZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy	)
r	   aL  
    These are situations that can be tested in our pythran tests:
    - A function with multiple array arguments and then
      other positional and keyword arguments.
    - A function with array-like keywords (e.g. `def somefunc(x0, x1=None)`.
    Note: list/tuple input is not yet tested!

    `self.arguments`: A dictionary which key is the index of the argument,
                      value is tuple(array value, all supported dtypes)
    `self.partialfunc`: A function used to freeze some non-array argument
                        that of no interests in the original function
    c                 ó.   — i | _         d | _        d | _        y r   )Ú	argumentsÚpartialfuncÚexpected)r   s    r   Úsetup_methodz_TestPythranFunc.setup_method›   s   € ØˆŒØˆÔØˆ�r   c                 óä   — t        j                  |«      }i }|j                  j                  «       D ];  \  }}|j                  t         j
                  j                  usŒ-|j                  ||<   Œ= |S r   )ÚinspectÚ	signatureÚ
parametersÚitemsÚdefaultÚ	ParameterÚempty)r   ÚfuncrQ   Úoptional_argsÚkr&   s         r   Úget_optional_argsz"_TestPythranFunc.get_optional_args    sd   € ô ×%Ñ% dÓ+ˆ	ØˆØ×(Ñ(×.Ñ.Ö0‰DˆAˆqØ�y‰y¤× 1Ñ 1× 7Ñ 7Ò7Ø#$§9¡9�˜aÒ ð 1ð Ðr   c                 ór   — d}| j                   D ]%  }t        | j                   |   d   «      }||kD  sŒ$|}Œ' |S )Nr   r$   )rK   Úlen)r   Úmax_lenÚarg_idxÚcur_lens       r   Úget_max_dtype_list_lengthz*_TestPythranFunc.get_max_dtype_list_lengthª   sA   € àˆØ—~”~ˆGÜ˜$Ÿ.™.¨Ñ1°!Ñ4Ó5ˆGØ˜Ó Ø!‘ð &ð ˆr   c                 ó8   — |t        |«      dz
  kD  r|d   S ||   S )Nr$   éÿÿÿÿ)r\   )r   Ú
dtype_listÚ	dtype_idxs      r   Ú	get_dtypez_TestPythranFunc.get_dtype³   s*   € ð ”s˜:“ qÑ(Ò(Ø˜b‘>Ð!à˜iÑ(Ð(r   c                 ó(  — t        | j                  «       «      D ]v  }g }| j                  D ]T  }| j                  | j                  |   d   |«      }|j	                  | j                  |   d   j                  |«      «       ŒV  | j                  |Ž  Œx y )Nr$   r   )Úranger`   rK   re   ÚappendÚastypeÚpythranfunc)r   Útype_idxÚ
args_arrayr^   Ú	new_dtypes        r   Útest_all_dtypesz _TestPythranFunc.test_all_dtypes»   sˆ   € Ü˜d×<Ñ<Ó>Ö?ˆHØˆJØŸ>œ>�Ø ŸN™N¨4¯>©>¸'Ñ+BÀ1Ñ+EØ+3ó5�	à×!Ñ! $§.¡.°Ñ"9¸!Ñ"<×"CÑ"CÀIÓ"NÕOð *ð ˆD×Ñ˜jÒ)ñ @r   c                 ó¢   — g }| j                   D ]/  }|j                  | j                   |   d   d d d…   d d d…   «       Œ1  | j                  |Ž  y )Nr   rb   )rK   rh   rj   ©r   rl   r^   s      r   Ú
test_viewsz_TestPythranFunc.test_viewsÄ   sS   € Øˆ
Ø—~”~ˆGØ×Ñ˜dŸn™n¨WÑ5°aÑ8¹¸2¸Ñ>¹tÀ¸tÑDÕEð &àˆ×Ñ˜*Ò%r   c                 óÂ   — g }| j                   D ]?  }|j                  t        j                  | j                   |   d   dd¬«      d d d…   «       ŒA  | j                  |Ž  y )Nr   r)   )Úaxis)rK   rh   ÚnpÚrepeatrj   rp   s      r   Útest_stridedz_TestPythranFunc.test_stridedÊ   sa   € Øˆ
Ø—~”~ˆGØ×ÑœbŸi™i¨¯©°wÑ(?ÀÑ(BØ()°ô3Ù36°Q°3ñ8õ 9ð &ð 	ˆ×Ñ˜*Ò%r   N)r   r   r   r   rt   Úint8Úint16Úint32Úint64ÚintcÚintpÚALL_INTEGERÚfloat32Úfloat64Ú	ALL_FLOATÚ	complex64Ú
complex128ÚALL_COMPLEXrN   rZ   r`   re   rn   rq   rv   r   r   r   r	   r	   Š   sz   „ ñð —7‘7˜BŸH™H b§h¡h°·±¸"¿'¹'À2Ç7Á7ÐK€KØ—‘˜RŸZ™ZÐ(€IØ—<‘< §¡Ð/€Kòò
òò)ò*ò&ó&r   r	   c                  ó"   — ddl m}   | d«      duS )zQ
    Check if the pytest-xdist plugin is installed, providing parallel tests
    r   ©Ú	find_specÚxdistN)Úimportlib.utilr†   r…   s    r   r5   r5   Ò   s   € õ
 )Ù�WÓ TÐ)Ð)r   c                 ó.  — ddl }	 t        t        j                  d   «      }dj	                  | t        j                  d   «      }|| dz  k  r|j                  |«       yy# t
        $ r+ t        «       }|€|j                  d«       | › d|dz  › d�}Y ŒNw xY w)	zJ
    Check *free_mb* of memory is available, otherwise do pytest.skip
    r   NÚSCIPY_AVAILABLE_MEMz={} MB memory required, but environment SCIPY_AVAILABLE_MEM={}zlCould not determine available memory; set SCIPY_AVAILABLE_MEM variable to free memory in MB to run the test.z MB memory required, but ç    €„.Az MB available)r+   Ú_parse_sizer.   ÚenvironÚformatÚKeyErrorÚ_get_mem_availableÚskip)Úfree_mbr+   Úmem_freeÚmsgs       r   r   r   Û   sª   € ó ð	OÜœrŸz™zÐ*?Ñ@ÓAˆØM×TÑTØ”R—Z‘ZÐ 5Ñ6ó8ˆð �'˜C‘-ÒØ�‰�CÕð  øô ò OÜ%Ó'ˆØÐØ�K‰Kð Iô Jà�	Ð2°8¸C±<°.ÀÐNŠðOús   †?A  Á 1BÂBc                 ód  — dddddddddddddd	d
œ}t        j                  dj                  dj                  |j	                  «       «      «      | t         j
                  «      }|r|j                  d«      |vrt        d«      ‚t        |j                  d«      «      ||j                  d«         z  S )Nr‹   g      ð?ç     @�@g    eÍÍAg   ¢”mBg      �@g      0Ag      ÐAg      pB)r   ÚbrY   ÚMÚGÚTÚkbÚMbÚGbÚTbÚkibÚMibÚGibÚTibz^\s*(\d+)\s*({})\s*$Ú|r)   zInvalid size stringr$   )	ÚreÚmatchrŽ   ÚjoinÚkeysÚIÚgroupr3   Úfloat)Úsize_strÚsuffixesÚms      r   rŒ   rŒ   ð   s§   € ØØØ˜s¨°4Ø ¨C°tØ i¸	È)ñ	U€Hô
 	�‰Ð(×/Ñ/°·±¸¿¹»Ó0IÓJØÜ—‘ó	€Añ �—‘˜“
 (Ñ*ÜÐ.Ó/Ð/ä�—‘˜“Ó˜x¨¯©°«
Ñ3Ñ3Ð3r   c                  ó°  — 	 ddl } | j                  «       j                  S # t        t        f$ r Y nw xY wt
        j                  j                  d«      rƒi }t        d«      5 }|D ]F  }|j                  «       }t        |d   «      dz  ||d   j                  d«      j                  «       <   ŒH 	 ddd«       n# 1 sw Y   nxY wd|v r|d   S |d	   |d
   z   S y)zD
    Get information about memory available, not counting swap.
    r   NÚlinuxz/proc/meminfor$   r–   Ú:ÚmemavailableÚmemfreeÚcached)ÚpsutilÚvirtual_memoryÚ	availableÚImportErrorÚAttributeErrorr,   ÚplatformÚ
startswithÚopenÚsplitrª   ÚstripÚlower)r´   ÚinfoÚfÚlineÚps        r   r�   r�   ÿ   sÑ   € ðÛØ×$Ñ$Ó&×0Ñ0Ð0øÜœÐ(ò Ùðúô ‡|�|×Ñ˜wÔ'ØˆÜ�/Ô" aÛ�Ø—J‘J“L�Ü05°a¸±d³¸cÑ0A��Q�q‘T—Z‘Z “_×*Ñ*Ó,Ò-ñ ÷ #×"Ñ"úð
 ˜TÑ!à˜Ñ'Ð'à˜	‘? T¨(¡^Ñ3Ð3às   ‚   2±2Á!AB7Â7C c                 ó’  ‡‡	— ddl }	 t        j                  ddg«       | t        t        j                  «       «      z  } t        j                  j                  |«      d   }t        j                  || |z  «       | |z  dz  dz  }|d	z  Š	t        j                  ‰	d
¬«       t        |dz  «      }t        |d«      5 }|j                  d«       |j                  dt         j"                  › d�«       ddd«       t         j$                  dk(  r(t        j                  dddd|dt        |«      g‰	¬«       n%t        j                  ddd|t        |«      g‰	¬«       t        j                  g d¢‰	¬«       t'        j(                  d«      Šˆˆ	fd„} |d«       |d«      fS # t        $ r |j	                  d«       Y �Œšw xY w# 1 sw Y   ŒÎxY w)z•
    Helper function to test building and importing Cython modules that
    make use of the Cython APIs for BLAS, LAPACK, optimize, and special.
    r   NÚmesonz	--versionzNo usable 'meson' foundr$   rB   Ú_cython_examplesÚbuildT)Úexist_okzinterpreter-native-file.iniÚwz[binaries]
z
python = 'Ú'Úwin32Úsetupz--buildtype=releasez--native-filez--vsenv)Úcwd)rÄ   Úcompilez-vvÚ
EXT_SUFFIXc                 ó”   •— ‰| z  j                  ‰«      }t        | |«      }t        |«      }|j                  j	                  |«       |S r   )Úwith_suffixr   r   ÚloaderÚexec_module)ÚmodnameÚsoÚspecÚmodÚsuffixÚ
target_dirs       €€r   Úloadz$_test_cython_extension.<locals>.loadE  sE   ø€ Ø˜7Ñ"×/Ñ/°Ó7ˆÜ& w°Ó3ˆÜ˜tÓ$ˆØ�‰×Ñ Ô$Øˆ
r   Ú	extendingÚextending_cpp)r+   Ú
subprocessÚ
check_callÚFileNotFoundErrorr‘   r6   Ú	threadingÚ	get_identr.   r/   r¼   ÚshutilÚcopytreeÚmakedirsr»   Úwriter,   Ú
executabler¹   Ú	sysconfigÚget_config_var)
Útmp_pathÚsrcdirr+   Úmod_nameÚ	build_dirÚnative_filerÀ   rÙ   r×   rØ   s
           @@r   Ú_test_cython_extensionrí     s¨  ù€ ó
 ð/Ü×Ñ˜w¨Ð4Ô5ð
 œ#œi×1Ñ1Ó3Ó4Ñ4€Hô �w‰w�}‰}˜VÓ$ QÑ'€HÜ
‡O�O�F˜H xÑ/Ô0Ø˜8Ñ# gÑ-Ð0BÑB€IØ˜WÑ$€JÜ‡K�K�
 TÕ*ô �iÐ"?Ñ?Ó@€KÜ	ˆk˜3Ô	 1Ø	�‰�ÔØ	�‰�*œSŸ^™^Ð,¨AÐ.Ô/÷ 
 ô ‡|�|�wÒÜ×Ñ˜w¨Ø4Ø.°Ø(¬#¨i«.ð:ð #-ö		 ô 	×Ñ˜w¨Ø.°¼SÀ»^ðMà",õ	 ô ×ÑÒ5¸:ÕFô ×%Ñ% lÓ3€Fõñ �Ó™d ?Ó3Ð3Ð3øô[ ò /Ø�‰Ð-×.ð/ú÷  
 Ð	ús   ˆF Â;5F=ÆF:Æ9F:Æ=Gc                 ó  ‡‡— t        j                  | «      Šˆˆfd„}g }t        d| «      D ]-  }|j                  t        j                  ||f|z   |¬«      «       Œ/ |D ]  }|j                  «        Œ |D ]  }|j                  «        Œ y)aÍ  
    Run a given function concurrently across a given number of threads.

    This is equivalent to using a ThreadPoolExecutor, but using the threading
    primitives instead. This function ensures that the closure passed by
    parameter gets called concurrently by setting up a barrier before it gets
    called before any of the threads.

    Arguments
    ---------
    n_workers: int
        Number of concurrent threads to spawn.
    fn: callable
        Function closure to execute concurrently. Its first argument will
        be the thread id.
    *args: tuple
        Variable number of positional arguments to pass to the function.
    **kwargs: dict
        Keyword arguments to pass to the function.
    c                 ó>   •— ‰j                  «         ‰| g|¢­i |¤Ž y r   )Úwait)ÚiÚargsÚkwargsÚbarrierÚfns      €€r   Úclosurez(_run_concurrent_barrier.<locals>.closureg  s   ø€ Ø�‰ŒÙ
ˆ1ÐˆtÒ�vÓr   r   )Útargetrò   ró   N)rß   ÚBarrierrg   rh   ÚThreadÚstartr¦   )	Ú	n_workersrõ   rò   ró   rö   Úworkersrñ   Úworkerrô   s	    `      @r   Ú_run_concurrent_barrierrþ   P  sƒ   ù€ ô* ×Ñ 	Ó*€Gõð €GÜ�1�iÖ ˆØ�‰”y×'Ñ'ØØ�˜‘ Vô-õ 	.ð !ó
 ˆØ�‰�ð ó ˆØ�‰�ñ r   ))r   rP   r.   r¤   rá   rÜ   r,   ræ   rß   rˆ   r   r   Únumpyrt   ÚscipyÚcythonÚCython.Compiler.Versionr   Úcython_versionÚ
scipy._libr   Úrequired_versionÚparseÚVersionr·   Ú__all__r
   rç   Ú_vr1   ÚIS_EDITABLEÚRuntimeWarningr   r   r	   r5   r   rŒ   r�   rí   rþ   r   r   r   Ú<module>r     s  ðñó
 Û 	Û 	Û Û Û 
Û Û ß Dã Û ðãõõ #ØÐØ€w‡}�}�^Ó$  w§¡Ð7GÓ'HÒHà‰ò O€ð €ð
 €Y×Ñ˜oÓ.Ò4°"€Ø	ˆR�<Ø€Gð ˜EŸN™N¨1Ñ-Ð-€ô	˜>ô 	÷
Oñ O÷dE&ñ E&òP*òò*4òò254óp%øðo	 ò Ø‚Fðús   ´
C ÃCÃC