o
    eRhV                     @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlm	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 d dlmZ z
d dlmZ dZW n eyW   d	ZY nw zd dlZdZW n eyk   d	ZY nw d
d Zdd Zejddddd Z esejdd Z!deiZ"erOe#ee$rOz"d dl%Z%e"&de%i e'e%j(e)dk re*de%j+dd W n	 e*y   Y nw zd dl,Z,e"&de,i e,-e W n	 e*y   Y nw zd dl.Z.e"&de.i W n	 e*y   Y nw z!d dl/Z0e"&de0ji e0j1&dd e0j1&de02ed   W n
 e*y   Y nw e3 dvrOe 4eZ5d e5v r2nz	d!d" e5D Z"W n e6yN   d#e"7  Z8e9e8w de"v rVd$Zej:;d%e"< Z=ej:j>ed&d'Z?d(d) Z@ejd*d+ ZAejd,d- ZBdEd/d0ZCejDEejFGeH d1 ejIjJd2ddd3 ejIjJd4ddddeKejLd5 ejMNd6d4ZOejIPeO eredFd7d8ZQeQe_ReSg d9e_Tej(d:k rejT&eSg d; g d<e_Ud=d=d>d?d@dAe_VeSdBge_WdCg dDie_Xde_YdS dS )G    N)contextmanager)get_fpu_mode)FPUModeChangeWarning)SCIPY_ARRAY_APISCIPY_DEVICE)_pep440)	dt_configTFc                 C   s   |  dd |  dd |  dd zdd l}W n ty'   |  dd Y nw zddlm} W n ty?   |  dd Y nw |  dd	 |  dd
 tsb|  dd |  dd |  dd d S d S )Nmarkerszslow: Tests that are very slow.zHxslow: mark test as extremely slow (not run unless explicitly requested)z8xfail_on_32bit: mark test as failing on 32-bit platformsr   z.timeout: mark a test for a non-default timeout)parse_durationz8fail_slow: mark a test for a non-default timeout failurezskip_xp_backends(backends, reason=None, np_only=False, cpu_only=False, exceptions=None): mark the desired skip configuration for the `skip_xp_backends` fixture.zxfail_xp_backends(backends, reason=None, np_only=False, cpu_only=False, exceptions=None): mark the desired xfail configuration for the `xfail_xp_backends` fixture.zOparallel_threads(n): run the given test function in parallel using `n` threads.z8thread_unsafe: mark the test function as single-threadedzCiterations(n): run the given test function `n` times in each thread)addinivalue_linepytest_timeout	Exceptionpytest_fail_slowr
   PARALLEL_RUN_AVAILABLE)configr   r
    r   P/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/scipy/conftest.pypytest_configure   sV   r   c           	   	   C   s  |  d}|d ur'zttjdd}W n ty   d}Y nw |s'td |  d}|d urCt	dj
dk rCtd	|jd   t |}|tj z
dd
lm} d}W n tyc   d}Y nw |rz	ttjd }W n ty   Y W d    d S w tdst d }t|| d}z||dd W n  ty   Y W d    d S w W d    d S W d    d S W d    d S 1 sw   Y  d S )NxslowSCIPY_XSLOW0Fz@very slow test; set environment variable SCIPY_XSLOW=1 to run itxfail_on_32bitr      z&Fails on our 32-bit test platform(s): )threadpool_limitsTPYTEST_XDIST_WORKER_COUNTOMP_NUM_THREADS      blas)user_api)get_closest_markerintosenvironget
ValueErrorpytestskipnpintpitemsizexfailargsnptsuppress_warningsfilter PytestUnraisableExceptionWarningthreadpoolctlr   r   KeyErrorgetenv	cpu_countmax)	itemmarkvsupr   HAS_THREADPOOLCTLxdist_worker_countmax_openmp_threadsthreads_per_workerr   r   r   pytest_runtest_setupI   sT   




"r>   function)scopeautousec                 c   sF    t  }dV  t  }||kr!tjd|dd|ddtdd dS dS )z9
    Check FPU mode was not changed during the test.
    NzFPU mode changed from z#xz to z during the testr   )category
stacklevel)r   warningswarnr   )requestold_modenew_moder   r   r   check_fpu_modez   s   
rI   c                   C   s   dS )Nr   r   r   r   r   r   num_parallel_threads   s   rJ   numpyarray_api_strictz2.0z'array-api-strict must be >= version 2.0z2023.12)api_versiontorchcupy	jax.numpyjax_enable_x64jax_default_device)1trueallc                 C   s   i | ]}|t | qS r   )xp_available_backends).0backendr   r   r   
<dictcomp>   s    rY   z!'--array-api-backend' must be in cudaxpzsTest involves masked arrays, object arrays, or other types that are not valid input when `SCIPY_ARRAY_API` is used.reasonc                 C   s   | j | d j}t|dkrtd| t| j| d}g }i }|D ]J}|jdr=d|d< |jdg |d< n|jdrU|dsUd|d< |jdg |d< t|jdkrq|jd }|	| |j
d
i ||ji q'||fS )z%A helper for {skip,xfail}_xp_backends_xp_backendsr   zmultiple backends: np_onlyT
exceptionscpu_onlyr   Nr   )keywordsr,   lenr%   listnodeiter_markerskwargsr$   appendupdate)rF   skip_or_xfailargs_r	   backendsrg   markerrX   r   r   r   _backends_kwargs_from_request   s(   


rn   c                 C   2   d|j vrdS t|dd\}}t| ||dd dS )a  skip_xp_backends(backend=None, reason=None, np_only=False, cpu_only=False, exceptions=None)

    Skip a decorated test for the provided backend, or skip a category of backends.

    See ``skip_or_xfail_backends`` docstring for details. Note that, contrary to
    ``skip_or_xfail_backends``, the ``backend`` and ``reason`` arguments are optional
    single strings: this function only skips a single backend at a time.
    To skip multiple backends, provide multiple decorators.
    skip_xp_backendsNr'   rj   rb   rn   skip_or_xfail_xp_backendsr[   rF   rl   rg   r   r   r   rp      s   
rp   c                 C   ro   )a  xfail_xp_backends(backend=None, reason=None, np_only=False, cpu_only=False, exceptions=None)

    xfail a decorated test for the provided backend, or xfail a category of backends.

    See ``skip_or_xfail_backends`` docstring for details. Note that, contrary to
    ``skip_or_xfail_backends``, the ``backend`` and ``reason`` arguments are optional
    single strings: this function only xfails a single backend at a time.
    To xfail multiple backends, provide multiple decorators.
    xfail_xp_backendsNr+   rq   rr   rt   r   r   r   ru     s   
ru   r'   c                 C   s  t t|}|dd}|dd}|dg }|d }r&td|d|r,|r,d}|r6|s6|s6td|r^|d	d
}t|tsMt|dkrMtd| jdkr\| j|vr\||d dS |rd}|du rhg n|}trt	dkr| jdkrd|vr||d n5| jdkrd|vrd| 
djjvr||d n| jdkrd|vr| 
d D ]}	d|	jvr||d q|durt|D ]\}
}| j|kr|| d	}|sd| }||d qdS dS )an  
    Skip based on the ``skip_xp_backends`` or ``xfail_xp_backends`` marker.

    See the "Support for the array API standard" docs page for usage examples.

    Parameters
    ----------
    backends : tuple
        Backends to skip/xfail, e.g. ``("array_api_strict", "torch")``.
        These are overriden when ``np_only`` is ``True``, and are not
        necessary to provide for non-CPU backends when ``cpu_only`` is ``True``.
        For a custom reason to apply, you should pass a dict ``{'reason': '...'}``
        to a keyword matching the name of the backend.
    reason : str, optional
        A reason for the skip/xfail in the case of ``np_only=True``.
        If unprovided, a default reason is used. Note that it is not possible
        to specify a custom reason with ``cpu_only``.
    np_only : bool, optional
        When ``True``, the test is skipped/xfailed for all backends other
        than the default NumPy backend. There is no need to provide
        any ``backends`` in this case. To specify a reason, pass a
        value to ``reason``. Default: ``False``.
    cpu_only : bool, optional
        When ``True``, the test is skipped/xfailed on non-CPU devices.
        There is no need to provide any ``backends`` in this case,
        but any ``backends`` will also be skipped on the CPU.
        Default: ``False``.
    exceptions : list, optional
        A list of exceptions for use with ``cpu_only`` or ``np_only``.
        This should be provided when delegation is implemented for some,
        but not all, non-CPU/non-NumPy backends.
    skip_or_xfail : str
        ``'skip'`` to skip, ``'xfail'`` to xfail.
    r_   Fra   r`   reasonsz.provide a single `reason=` kwarg; got reasons=z insteadz<`exceptions` is only valid alongside `cpu_only` or `np_only`r]   z#do not run with non-NumPy backends.r   z8please provide a singleton `reason` when using `np_only`rK   r\   NzTno array-agnostic implementation or delegation available for this backend and devicecpurO   rN   r   rP   z#do not run with array API backend: )getattrr&   r$   r%   
isinstancestrrc   __name__r   r   emptydevicetypedevicesdevice_kind	enumerate)r[   rl   rg   rj   r_   ra   r`   rv   r]   dirX   r   r   r   rs     sT   
#






rs   z.hypothesisnondeterministic)namedeadline
print_blobdeterministic)r   r   r   databasederandomizesuppress_health_checkSCIPY_HYPOTHESIS_PROFILEc              	   c   s   t  }ddg}|D ]
}t tdd||< q
g d}|D ]	}t td||< qddlm} d	d
g}|D ]}t |jdd||< q1g d}|D ]	}t td||< qCt tddt dtdt d|jdd}|| t	d}	ddl
m}
 ddl}|
 U |jd t 2 | r| j|v rtjdi || j  dV  n| r| j|	v rdV  n	tdt dV  W d   n1 sw   Y  W d   dS W d   dS 1 sw   Y  dS )zmTemporarily turn (almost) all warnings to errors.

        Filter out known warnings which we allow.
        zscipy.linalg.normzscipy.ndimage.center_of_masszdivide by zero)rB   message)zscipy.signal.cwtzscipy.signal.morletzscipy.signal.morlet2zscipy.signal.rickerzscipy.integrate.simpsonzscipy.interpolate.interp2dzscipy.linalg.kron)rB   r   )	integratezscipy.special.ellip_normalzscipy.special.ellip_harm_2zThe occurrence of roundoff)zscipy.stats.anderson_ksampzscipy.stats.kurtosistestzscipy.stats.normaltestscipy.sparse.linalg.normzExited at iterationzthe matrix subclass is not)r   rB   z"The maximum number of subdivisions)r   z
linalg.rstz	stats.rstscipy.signal.normalize)_fixed_default_rngNignoreerror)r   )dictRuntimeWarningDeprecationWarningscipyr   IntegrationWarningUserWarningPendingDeprecationWarningri   setscipy._lib._utilr   rK   randomseedrD   catch_warningsr   filterwarningssimplefilterWarning)testknown_warningsdivide_by_zeror   
deprecatedr   integration_wuser_wdctlegitr   r(   r   r   r   warnings_errors_and_rng  sf   



"r   )zscipy.linalg.LinAlgErrorzscipy.fftpack.fftshiftzscipy.fftpack.ifftshiftzscipy.fftpack.fftfreqzscipy.special.sinczscipy.optimize.show_optionsr   r   z$scipy.io.matlab.MatlabObject.stridesz"scipy.io.matlab.MatlabObject.dtypez"scipy.io.matlab.MatlabOpaque.dtypez$scipy.io.matlab.MatlabOpaque.stridesz&scipy.io.matlab.MatlabFunction.stridesz$scipy.io.matlab.MatlabFunction.dtype2)zscipy.io.hb_readzscipy.io.hb_writez)scipy.sparse.csgraph.connected_componentsz&scipy.sparse.csgraph.depth_first_orderz"scipy.sparse.csgraph.shortest_pathz#scipy.sparse.csgraph.floyd_warshallzscipy.sparse.csgraph.dijkstraz!scipy.sparse.csgraph.bellman_fordzscipy.sparse.csgraph.johnsonzscipy.sparse.csgraph.yenz(scipy.sparse.csgraph.breadth_first_orderz*scipy.sparse.csgraph.reverse_cuthill_mckeez$scipy.sparse.csgraph.structural_rankz*scipy.sparse.csgraph.construct_dist_matrixz%scipy.sparse.csgraph.reconstruct_pathzscipy.ndimage.value_indiceszscipy.stats.mstats.describe)zscipy.stats.distributionszscipy.optimize.cython_optimizez
scipy.testzscipy.show_configzscipy/special/_precomputez#scipy/interpolate/_interpnd_info.pyzscipy/_lib/array_api_compatzscipy/_lib/highszscipy/_lib/unuranzscipy/_lib/_gcutils.pyzscipy/_lib/doccer.pyzscipy/_lib/_uarrayzReST parser limitationz__cinit__ unexpected argumentznan in scalar_powerzintegration warning)zND_regular_grid.rstzextrapolation_examples.rstzsampling_pinv.rstzsampling_srou.rstzprobability_distributions.rstzintegrate.nquad(func,zio.rst)zoctave_a.matzoctave_cells.matzoctave_struct.mat)r'   )N)Zjsonr"   rD   tempfile
contextlibr   rK   r(   numpy.testingtestingr-   r&   
hypothesisscipy._lib._fpumoder   scipy._lib._testutilsr   scipy._lib._array_apir   r   
scipy._libr   scipy_doctest.conftestr   
HAVE_SCPDTModuleNotFoundErrorpytest_run_parallelr   r   r   r>   fixturerI   rJ   rV   ry   rz   rL   ri   parse__version__VersionImportErrorset_array_api_strict_flagsrN   set_default_devicerO   	jax.numpyjaxr   r   lowerloadsSCIPY_ARRAY_API_r2   keysmsgr%   r7   parametrizevaluesarray_api_compatibleskipifskip_xp_invalid_argrn   rp   ru   rs   configurationset_hypothesis_home_dirpathjoin
gettempdirsettingsregister_profilerd   HealthCheckr#   r$   r   load_profiler   user_context_mgrr   skiplistpytest_extra_ignorepytest_extra_xfail
pseudocodelocal_resourcesstrict_checkr   r   r   r   <module>   s   *1









VQ


 