o
    i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)Zaddinivalue_linepytest_timeout	ExceptionZpytest_fail_slowr
   PARALLEL_RUN_AVAILABLE)configr   r
    r   H/home/kim/smarthome/.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 )NZxslowZSCIPY_XSLOW0Fz@very slow test; set environment variable SCIPY_XSLOW=1 to run itZxfail_on_32bitr      z&Fails on our 32-bit test platform(s): )threadpool_limitsTZPYTEST_XDIST_WORKER_COUNTZOMP_NUM_THREADS      Zblas)Zuser_api)Zget_closest_markerintosenvironget
ValueErrorpytestskipnpZintpitemsizexfailargsnptZsuppress_warningsfilterZ PytestUnraisableExceptionWarningZthreadpoolctlr   r   KeyErrorgetenv	cpu_countmax)	itemmarkvsupr   ZHAS_THREADPOOLCTLZxdist_worker_countZmax_openmp_threadsZthreads_per_workerr   r   r   pytest_runtest_setupI   sT   




"r,   function)scopeZ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   )requestZold_modeZnew_moder   r   r   check_fpu_modez   s   
r4   c                   C   s   dS )Nr   r   r   r   r   r   num_parallel_threads   s   r5   numpyarray_api_strictz2.0z'array-api-strict must be >= version 2.0z2023.12)api_versiontorchcupy	jax.numpyZjax_enable_x64Zjax_default_device)1trueallc                 C   s   i | ]}|t | qS r   )xp_available_backends).0backendr   r   r   
<dictcomp>   s    rB   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_backendsZ_xp_backendsr   zmultiple backends: np_onlyT
exceptionscpu_onlyr   Nr   )keywordsr!   lenr   listnodeZiter_markerskwargsr   appendupdate)r3   skip_or_xfailZargs_r	   backendsrN   markerrA   r   r   r   _backends_kwargs_from_request   s(   


rT   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   rQ   rJ   rT   skip_or_xfail_xp_backendsrD   r3   rR   rN   r   r   r   rV      s   
rV   c                 C   rU   )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    rW   rX   rZ   r   r   r   r[     s   
r[   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.
    rG   FrI   rH   reasonsz.provide a single `reason=` kwarg; got reasons=z insteadz<`exceptions` is only valid alongside `cpu_only` or `np_only`rF   z#do not run with non-NumPy backends.r   z8please provide a singleton `reason` when using `np_only`r6   rE   NzTno array-agnostic implementation or delegation available for this backend and devicecpur:   r9   r   r;   z#do not run with array API backend: )getattrr   r   r   
isinstancestrrK   __name__r   r   emptyZdevicetypedevicesZdevice_kind	enumerate)rD   rR   rN   rQ   rG   rI   rH   r\   rF   dirA   r   r   r   rY     sT   
#






rY   z.hypothesisZnondeterministic)namedeadline
print_blobZdeterministic)rh   ri   rj   ZdatabaseZderandomizeZ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)r/   message)zscipy.signal.cwtzscipy.signal.morletzscipy.signal.morlet2zscipy.signal.rickerzscipy.integrate.simpsonzscipy.interpolate.interp2dzscipy.linalg.kron)r/   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)rl   r/   z"The maximum number of subdivisions)rn   z
linalg.rstz	stats.rstscipy.signal.normalize)_fixed_default_rngNignoreerror)rq   )dictRuntimeWarningDeprecationWarningZscipyrm   ZIntegrationWarningUserWarningPendingDeprecationWarningrP   setZscipy._lib._utilrp   r6   randomseedr1   catch_warningsrh   filterwarningssimplefilterWarning)testZknown_warningsZdivide_by_zerorh   
deprecatedrm   Zintegration_wZuser_wdctZlegitrp   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_optionsro   rn   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   r1   tempfile
contextlibr   r6   r   Znumpy.testingZtestingr"   r   Z
hypothesisZscipy._lib._fpumoder   Zscipy._lib._testutilsr   Zscipy._lib._array_apir   r   Z
scipy._libr   Zscipy_doctest.conftestr   Z
HAVE_SCPDTModuleNotFoundErrorZpytest_run_parallelr   r   r   r,   Zfixturer4   r5   r?   r_   r`   r7   rP   parse__version__VersionImportErrorZset_array_api_strict_flagsr9   Zset_default_devicer:   Z	jax.numpyZjaxr   rd   lowerloadsZSCIPY_ARRAY_API_r$   keysmsgr   r)   ZparametrizevaluesZarray_api_compatibleZskipifZskip_xp_invalid_argrT   rV   r[   rY   configurationZset_hypothesis_home_dirpathjoin
gettempdirsettingsZregister_profilerL   ZHealthCheckr   r   rk   Zload_profiler   Zuser_context_mgrrx   ZskiplistZpytest_extra_ignoreZpytest_extra_xfailZ
pseudocodeZlocal_resourcesZstrict_checkr   r   r   r   <module>   s   *1









VQ


 