
    Џkhnk                     B   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Z	d dl
mZ d dlZd dlZd dlmZ d dlmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ 	 d d	lm Z  d
Z!	 d dl#Z#d
Z$d Z&d Z' ejP                  dd
      d        Z)e$sejP                  d        Z*h dZ+de	iZ, e-       Z. e-       Z/er6	 d dl0Z0e,jc                  de0i        ejd                  e0jf                         ejh                  d      k  r e5d       e0jl                  d       	 d dl7Z7e,jc                  de7i        e7jp                  e       edk7  re.js                  d        ejt                  dd      Z;e;dk(  r e7jx                  e7jz                         ne;dk7  r e>de; d       	 d dl?Z?e,jc                  d!e?i       e.js                  d!        ej                  d"d#eA$       d d%lBmCZC [C	 d dlDZEe,jc                  d&eEj                  i       eEj                  jc                  d'd
       eEj                  jc                  d( eEj                  e      d           edk7  re.js                  d&       e/js                  d&       	 d dlHmIZJ e,jc                  d)eJi       e/js                  d)        eKeeL      r@ ej                         d*vr- e j                  e      ZOeOd+gk7  r	 eOD  ci c]  } | e,|    
 c} Z, e-e,      e+z
  rJ  e-e,      dhz
  ZS ejP                  e,j                         D cg c].  \  }} ej                  ||ej                  j                  .      0 c}}/      d0        ZXej                  j                  ed12      ZZd3 Z[d4ej                  d5ed6   d7dfd8Z]ejP                  d9        ZGej                  j                  ej                  j                   ej                         d:             ej                  j                  d;dd
<       ej                  j                  d=dd
dd
 eQej                        >       ej                  j                  d?d=      Zhej                  j                  eh       e!redNd@       Zjeje _k         e-g dA      e _l        e	jf                  dBk  r#e j                  jc                   e-g dC             g dDe _m        dEdEdFdGdHdIe _n         e-dJg      e _o        dKg dLie _p        d
e _q        e j                  js                  dM       yy# e"$ r dZ!Y w xY w# e%$ r dZ$Y w xY w# e5$ r Y +w xY w# e5$ r Y w xY w# e5$ r Y ww xY w# e5$ r Y w xY w# e5$ r Y w xY wc c} w # eP$ r d, eQe,       d-eO ZR e>eR      w xY wc c}}w )O    N)contextmanager)Literal)get_fpu_mode)SCIPY_ARRAY_APISCIPY_DEVICEarray_namespace
default_xpis_cupyis_daskis_jax)FPUModeChangeWarning)patch_lazy_xp_functions)_pep440)	dt_configTFc                    | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd       	 dd	l}	 ddlm} t
        s7| j                  dd       | j                  dd       | j                  dd       y	y	# t        $ r | j                  dd
       Y bw xY w# t        $ r | j                  dd       Y |w xY w)a  
    Add pytest markers to avoid PytestUnknownMarkWarning

    This needs to contain all markers that are SciPy-specific, as well as
    dummy fallbacks for markers defined in optional test packages.

    Note that we need both the registration here *and* in `pytest.ini`.
    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 platformsz;array_api_backends: test iterates on all array API backendszskip_xp_backends(backends, reason=None, np_only=False, cpu_only=False, eager_only=False, exceptions=None): mark the desired skip configuration for the `skip_xp_backends` fixturezxfail_xp_backends(backends, reason=None, np_only=False, cpu_only=False, eager_only=False, exceptions=None): mark the desired xfail configuration for the `xfail_xp_backends` fixturer   Nz.timeout: mark a test for a non-default timeout)parse_durationz8fail_slow: mark a test for a non-default timeout failurezOparallel_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   s      J/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/conftest.pypytest_configurer   $   s.    I)+
IRT
IBD
IEG
I
.0 I
/1
IS 	4
 "!	" 	F	
 	Q	
 "  IG	II  SQ	SSs$   .B7 3C 7CCC65C6c                 n   | j                  d      }|A	 t        t        j                  j	                  dd            }|st        j                  d       | j                  d      }|Gt        j                  d      j                  dk  r%t        j                  d	|j                  d           t        j                         5 }|j                  t        j                          	 dd
lm} d}|rc	 t        t        j                  d         }t        j*                  d      s1t        j,                         dz  }t/        ||z  d      }	  |d       d d d        y # t
        $ r d}Y *w xY w# t&        $ r d}Y w xY w# t(        $ r Y d d d        y w xY w# t&        $ r Y d d d        y w xY w# 1 sw Y   y xY w)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_workers	            r   pytest_runtest_setuprG   Z   s   ""7+D	BJJNN=#67A KK K L""#34DBGGAJ//!3=diil^LM 
			  C

6::;	&7 $
 
%(4O)P%Q"
 99./%'\\^q%8"%();?Q)QST%U"%&86J5   	A	$  	& %	&  ) $ !  = 67 s   )E  F+$E,,F+/E=;F+
FE)(E),E:7F+9E::F+=	FF+FF+	F(F+'F((F++F4function)scopeautousec              #      K   t               }d t               }||k7  r&t        j                  d|dd|ddt        d       yyw)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_modes      r   check_fpu_moderS      sT     
 ~H	~H8.xm4} M! !3	C s   AAc                       y)Nr&    rU       r   num_parallel_threadsrW      s    rV   >   cupynumpytorcharray_api_strict	jax.numpy
dask.arrayrY   r[   z2.3z'array-api-strict must be >= version 2.3z2024.12)api_versionrZ   cpuSCIPY_DEFAULT_DTYPEfloat64)defaultfloat32zUSCIPY_DEFAULT_DTYPE env var, if set, can only be either 'float64' or 'float32'. Got 'z
' instead.rX   ignorez#cupyx.jit.rawkernel is experimentalrL   )signalr\   jax_enable_x64jax_default_devicer]   )1trueallrk   z!'--array-api-backend' must be in z; got )idmarks)paramsc              #     K   t        | d       t        | d       | j                  }t        |j                  d            }t        r1t        | j                  | |       t        |      5  | ddd       y| y# 1 sw Y   yxY ww)a  Run the test that uses this fixture on each available array API library.

    You can select all and only the tests that use the `xp` fixture by
    passing `-m array_api_backends` to pytest.

    You can select where individual tests run through the `@skip_xp_backends`,
    `@xfail_xp_backends`, and `@skip_xp_invalid_arg` pytest markers.

    Please read: https://docs.scipy.org/doc/scipy/dev/api-dev/array_api.html#adding-tests
    r0   r4   r   )xprP   monkeypatchN)skip_or_xfail_xp_backendsparamr   emptyr   r   r	   )rP   rq   rp   s      r   rp   rp     s}     " gv. gw/	B	!	%B}}g;	
 ^ 	H	 	 	 	s   A(B	*A=/B	=BB	zsTest involves masked arrays, object arrays, or other types that are not valid input when `SCIPY_ARRAY_API` is used.reasonc           	         t        | j                  j                  | d            }t        D ci c]  }|g  }}|D ]  }t	        |j
                        h dz
  }|rt        d|       t	        |j
                  j                  dg             }|t        z
  }t        |t        z
        x}rt        d| dt        t                     |j
                  j                  dd      rB|j
                  j                  d	      xs d
}	t        |z
  D ]  }||   j                  |	        n|j
                  j                  dd      rB|j
                  j                  d	      xs d}	t        |z
  D ]  }||   j                  |	        n]|j
                  j                  dd      rA|j
                  j                  d	      xs d}	t        |z
  D ]  }||   j                  |	        t        |j                        dk(  r|j                  d   }|t        vrt        d| dt        t                     |j
                  j                  d	      xs d| }	||   j                  d|	       dD ]   }
|
|j
                  v st        |
 d|        Rt        |j                        dkD  slt        d|j                          |j!                         D ci c]  \  }}|r||d    c}}S c c}w c c}}w )ztA helper for {skip,xfail}_xp_backends.

    Return dict of {backend to skip/xfail: top reason to skip/xfail it}
    _xp_backends>   rv   np_onlycpu_only
eager_only
exceptionszInvalid kwargs: r|   zUnknown backend(s): z; must be a subset of ry   Frv   z"do not run with non-NumPy backendsrz   zTno array-agnostic implementation or delegation available for this backend and devicer{   z*eager checks not executed on lazy backendsr&   r   zUnknown backend: z; must be one of z#do not run with array API backend: )rz   ry   r{   r|   z is mutually exclusive with z,Please specify only one backend per marker: )listnodeiter_markersxp_known_backendssetkwargs	TypeErrorr-   r.   xp_skip_np_only_backendsappendxp_skip_cpu_only_backendsxp_skip_eager_only_backendslenr5   insertitems)rP   skip_or_xfailr   backendreasonsmarkerinvalid_kwargsr|   invalid_exceptionsrv   kwargbackend_reasonss               r   _backends_kwargs_from_requestr   7  s4   
 7<<,,l-KLMG*;<ww{<G< 1V]]+ /I I.~.>?@@**<<=
'*;;"&z4E'E"FFF34F3G H4489J4K3LN O O ==Y.]]&&x0X4XF3j@ 0 ''/0 ]]z51]]&&x0 /.  5zA 0 ''/0 ]]|U3]]&&x0 >< 6C 0 ''/0 v{{q kk!nG// #4WI >3378I3J2K"M N N]]&&x0 A5gY?  G##Av.L VFMM)$w.J7)%TUUV !>v{{mL _1h -4MMO ( _Q''    k =j s   
K,K1rP   r   )r0   r4   returnc                     | d| j                   vryt        | |      }| j                  }|j                  |v r-||j                     }|sJ t	        t
        |      } ||       yy)aP  
    Helper of the `xp` fixture.
    Skip or xfail based on the ``skip_xp_backends`` or ``xfail_xp_backends`` markers.

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

    Usage
    -----
    ::
        skip_xp_backends = pytest.mark.skip_xp_backends
        xfail_xp_backends = pytest.mark.xfail_xp_backends
        ...

        @skip_xp_backends(backend, *, reason=None)
        @skip_xp_backends(*, cpu_only=True, exceptions=(), reason=None)
        @skip_xp_backends(*, eager_only=True, exceptions=(), reason=None)
        @skip_xp_backends(*, np_only=True, exceptions=(), reason=None)

        @xfail_xp_backends(backend, *, reason=None)
        @xfail_xp_backends(*, cpu_only=True, exceptions=(), reason=None)
        @xfail_xp_backends(*, eager_only=True, exceptions=(), reason=None)
        @xfail_xp_backends(*, np_only=True, exceptions=(), reason=None)

    Parameters
    ----------
    backend : str, optional
        Backend to skip/xfail, e.g. ``"torch"``.
        Mutually exclusive with ``cpu_only``, ``eager_only``, and ``np_only``.
    cpu_only : bool, optional
        When ``True``, the test is skipped/xfailed on non-CPU devices,
        minus exceptions. Mutually exclusive with ``backend``.
    eager_only : bool, optional
        When ``True``, the test is skipped/xfailed for lazy backends, e.g. those
        with major caveats when invoking ``__array__``, ``__bool__``, ``__float__``,
        or ``__complex__``, minus exceptions. Mutually exclusive with ``backend``.
    np_only : bool, optional
        When ``True``, the test is skipped/xfailed for all backends other
        than the default NumPy backend and the exceptions.
        Mutually exclusive with ``backend``. Implies ``cpu_only`` and ``eager_only``.
    reason : str, optional
        A reason for the skip/xfail. If omitted, a default reason is used.
    exceptions : list[str], optional
        A list of exceptions for use with ``cpu_only``, ``eager_only``, or ``np_only``.
        This should be provided when delegation is implemented for some,
        but not all, non-CPU/non-NumPy backends.
    rx   N)r   ru   )keywordsr   rs   __name__getattrr/   )rP   r   skip_xfail_reasonsrp   rv   s        r   rr   rr   w  ss    ` %W-=-==6} 
B	{{((#BKK0v6V$	 )rV   c                     t        |       rt        j                  d       t        |       rddgS t	        |       rt        j                  d       | j                         j                         dgz   S )ao  Fixture that returns a list of all devices for the backend, plus None.
    Used to test input->output device propagation.

    Usage
    -----
    from scipy._lib._array_api import xp_device

    def test_device(xp, devices):
        for d in devices:
            x = xp.asarray(..., device=d)
            y = f(x)
            assert xp_device(y) == xp_device(x)
    zdata-apis/array-api-compat#293ru   r_   Nzjax-ml/jax#26000)r
   r/   r4   r   r   __array_namespace_info__devices)rp   s    r   r   r     s`     r{ 	<=r{t}bz 	./&&(002dV;;rV   z.hypothesisnondeterministic)namedeadline
print_blobdeterministic)r   r   r   databasederandomizesuppress_health_checkSCIPY_HYPOTHESIS_PROFILEc              #   ~  K   t               }ddg}|D ]  }t        t        d      ||<    g d}|D ]  }t        t              ||<    ddlm} d	d
g}|D ]  }t        |j
                  d      ||<    g d}|D ]  }t        t              ||<    t        t        d      t        dt              t        d|j
                        d}|j                  |       t        d      }	ddl
m}
 ddl} |
       5  |j                  j                  d       t        j                          5  | r5| j"                  |v r't        j$                  di || j"                      d n3| r| j"                  |	v rd nt        j&                  dt(               d ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY ww)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)rL   message)zscipy.signal.cwtzscipy.signal.morletzscipy.signal.morlet2zscipy.signal.rickerzscipy.integrate.simpsonzscipy.interpolate.interp2dzscipy.linalg.kronre   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   rL   z"The maximum number of subdivisions)r   z
linalg.rstz	stats.rstscipy.signal.normalize)_fixed_default_rngNerror)rd   )dictRuntimeWarningDeprecationWarningscipyr   IntegrationWarningUserWarningPendingDeprecationWarningupdater   scipy._lib._utilr   rY   randomseedrN   catch_warningsr   filterwarningssimplefilterWarning)testknown_warningsdivide_by_zeror   
deprecatedr   integration_wuser_wdctlegitr   r1   s               r   warnings_errors_and_rngr     s       !?
 # 	BD#'0@$BN4 	B


  	ED#'1C#DN4 	E 	$55
 " 	ND#'1M1M0L$NN4 	N
H 	>D#'#=N4 	> k3HI 979 A'::<

 	c" ,- 	8! 	IINN4 ((* 	DII7++ I.<TYY.GIdii50))'7;		 		 		 	s7   C7F=90F1)A+F%F1	F=%F.	*F11F:6F=)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/interpolate/_rbfinterp_pythran.pyzscipy/_build_utils/tempita.pyzscipy/_lib/array_api_compatzscipy/_lib/highszscipy/_lib/unuranzscipy/_lib/_gcutils.pyzscipy/_lib/doccer.pyzscipy/_lib/_uarrayz+scipy/linalg/_cython_signature_generator.pyzscipy/linalg/_generate_pyx.pyzscipy/linalg/_linalg_pythran.pyz$scipy/linalg/_matfuncs_sqrtm_triu.pyz1scipy/ndimage/utils/generate_label_testvectors.pyz scipy/optimize/_group_columns.pyz$scipy/optimize/_max_len_seq_inner.pyz"scipy/signal/_max_len_seq_inner.pyz%scipy/sparse/_generate_sparsetools.pyzscipy/special/_generate_pyx.pyzscipy/stats/_stats_pythran.pyz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.matz.text()N)sjsonr+   rN   tempfile
contextlibr   typingr   rY   r1   numpy.testingtestingr6   r/   
hypothesisscipy._lib._fpumoder   scipy._lib._array_apir   r   r   r	   r
   r   r   scipy._lib._testutilsr   "scipy._lib.array_api_extra.testingr   
scipy._libr   scipy_doctest.conftestr   
HAVE_SCPDTModuleNotFoundErrorpytest_run_parallelr   r   r   rG   fixturerS   rW   r   xp_available_backendsr   r   r   r[   r   parse__version__VersionImportErrorset_array_api_strict_flagsrZ   set_default_deviceaddr<   rb   set_default_dtypera   r.   rX   r   FutureWarningcupyx.scipyrf   	jax.numpyjaxr   r   
dask.arrayarrayda
isinstancestrlowerloadsSCIPY_ARRAY_API_r;   r}   msgr   r   rs   r@   array_api_backendsrp   skipifskip_xp_invalid_argr   FixtureRequestrr   configurationset_hypothesis_home_dirpathjoin
gettempdirsettingsregister_profileHealthCheckr,   r-   r   load_profiler   user_context_mgrskiplistpytest_extra_ignorepytest_extra_xfail
pseudocodelocal_resourcesstrict_check	stopwords)r   krA   s   000r   <module>r     sr    	   %      ,   7 F 0J#!
3
l.b j$/C 0C ^^ 
#  " E !e 	$$&8:J%KL7==)5569OOGHH333!	
$$gu%56   .5 %))'2 "))19Ei#E##EMM2	!%%,IZ9  	$$fd^4!%%f- 	 ;m	
 	'$$k399%=>

*D1

.L0I!0LM5 %))+6 	$''4$$lB%78 	$''5 	?C(!O!!#+??%4::o6w&& $4) 27;;)% $%(99 9945	A  %++-1 FLLq > >? #	#L kk((I ) K 
= @;%v'<'< ;%-4_-E;%JN;%| < <J    0 0GGLL$$$&6    $ $	dt %     $ $	dTtz556 %  ::>>*D*9;  
      !9 :  O Ob "9I  I( 
~~!!# ' # 	,%I!>  8&><2)>$I   789I 
!I "I H%i y  J  #"#b  &         )  &:456f=M<NP o%&s   T #T- 7A!T; BU  AU %BU 9*U+ U< U7)U< $3V
T*)T*-T87T8;UUUUUUU('U(+U43U47U< <V