
    doi                        % S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJrJrJr  SSKJr  SSKrSSKJr  SS	KJrJrJrJrJrJrJrJrJr J!r"J#r$J%r&J'r(J)r*J+r,J-r.  SS
K/J0r0  SSK1J2r2  SSK3J4r4J5r5J6r6  SSK7J8r8  SSK9J:r;  / SQr<\r=\\>S'   \=\R~                  -  r?\\>S'   S\=S\SS4S jr@   S%SSSS.S\?S\S\S   S-  S\AS-  S\S-  S\AS\AS\=4S jjjrBSS.S \=S\S-  S\=4S! jjrCS \=S\R                  4S" jrE\
" S#5      rF\
\   \>S$'   \S\S\S%   4S& j5       rGSS'.S( jrHS)S)S)S)S*.S+ jrIS, rJS)S)S)S)S-SS..S/ jrKSSS)S)S)S)S-SS0.S1 jrLS2S)S)S)S)S-SS3.S4 jrMS)S)S)S)S-S)SS5.S6 jrNSbS7 jrOScS8 jrPS9\S\Q4S: jrRS \=S\S\A4S; jrSS\S\Q4S< jrTS\S\S-  4S= jrUSSS>SS?.S \=S@\V\W\V   -  S-  SA\ASB\V\X-  S\S-  S\=4SC jjrYSS.S \=S\S-  S\=4SD jjrZSdSE jr[SSF.SG jr\SSSH.SI jr]SdSJ\=S\S-  S\=4SK jjr^SL r_SM r`S\S-  SN\\?   S\=4SO jraSP rbSeSQ jrcSR rd\R                  " SSS9 " ST SU5      5       rf     SfSW jrgSdSX jrhSSVSVSSSSSVSVSS)SSY.SZ jriSS[.S\ jrjSS[.S] jrkSS[.S^ jrl0 rmS_\=S\S`   4Sa jrng)ga6  Utility functions to use Python Array API compatible libraries.

For the context about the Array API see:
https://data-apis.org/array-api/latest/purpose_and_scope.html

The SciPy use case of the Array API is described on the following page:
https://data-apis.org/array-api/latest/use_cases.html#use-case-scipy
    N)	Generator)contextmanager)
ContextVar)
ModuleType)AnyLiteral	TypeAlias)Iterable)is_array_api_objis_lazy_arrayis_numpy_arrayis_cupy_arrayis_torch_arrayis_jax_arrayis_dask_arraysizenumpydeviceis_numpy_namespaceis_cupy_namespaceis_torch_namespaceis_jax_namespaceis_dask_namespaceis_array_api_strict_namespace)_compat_module_name)lazy_xp_function)array_namespaceSCIPY_ARRAY_APISCIPY_DEVICE)FunctionDoc)array_api_extra)"_asarrayr   assert_almost_equalassert_array_almost_equal
default_xpeager_warnsr   	is_marrayis_array_api_strict
is_complexis_cupyis_jaxis_numpyis_torch	np_compatget_native_namespace_namer   r   scipy_namespace_forxp_assert_closexp_assert_equalxp_assert_lessxp_copy	xp_devicexp_ravelxp_sizexp_unsupported_param_msgxp_vector_normxp_capabilitiesxp_result_type
xp_promotemake_xp_test_casemake_xp_pytest_marksmake_xp_pytest_paramArray	ArrayLikearrayxpreturnc                 h    UR                  UR                  U 5      5      (       d  Sn[        U5      eg)zCheck for NaNs or Infs.z#array must not contain infs or NaNsN)allisfinite
ValueError)rB   rC   msgs      Q/var/www/html/land-ocr/venv/lib/python3.13/site-packages/scipy/_lib/_array_api.py_check_finiterK   E   s.    66"++e$%%3o &    F)rC   check_finitesubokdtypeorder)KACFcopyrM   rN   c                   Uc  [        U 5      n[        U5      (       aN  USL a  [        R                  " XXS9n ODU(       a  [        R                  " XUS9n O'[        R
                  " XUS9n O UR                  XUS9n U(       a  [        X5        U $ ! [         a-    [        UR                  S5      5      nUR                  XUS9n  NJf = f)a8  SciPy-specific replacement for `np.asarray` with `order`, `check_finite`, and
`subok`.

Memory layout parameter `order` is not exposed in the Array API standard.
`order` is only enforced if the input array implementation
is NumPy based, otherwise `order` is just silently ignored.

`check_finite` is also not a keyword in the array API standard; included
here for convenience rather than that having to be a separate function
call inside SciPy functions.

`subok` is included to allow this function to preserve the behaviour of
`np.asanyarray` for NumPy based inputs.
T)rP   rO   rN   )rP   rO   )rO   rU      )r   r,   nprB   
asanyarrayasarray	TypeErrorrK   )rB   rO   rP   rU   rC   rM   rN   
coerced_xps           rJ   r"   r"   K   s    0 
zU#||4<HHUuJEMM%EBEJJu?E	FJJuJ=E
 e L  	F(A7J&&u&EE	Fs   .B 4C	C	rC   xc                4    Uc  [        U 5      n[        U SUS9$ )z
Copies an array.

Parameters
----------
x : array

xp : array_namespace

Returns
-------
copy : array
    Copied array

Notes
-----
This copy function does not offer all the semantics of `np.copy`, i.e. the
`subok` and `order` keywords are not used.
T)rU   rC   )r   r"   r^   rC   s     rJ   r4   r4   z   s"    , 
zQADR((rL   c                    [        U 5      n[        U5      (       a  U R                  5       $ [        U5      (       a  U R	                  5       $ [        U5      (       a  U R                  5       R                  5       $ [        U5      (       a1  [        R                  " UR                  XR                  S5      S9SS9$ [        R                  " U SS9$ )aI  Copies a possibly on device array to a NumPy array.

This function is intended only for converting alternative backend
arrays to numpy arrays within test code, to make it easier for use
of the alternative backend to be isolated only to the function being
tested. `_xp_copy_to_numpy` should NEVER be used except in test code
for the specific purpose mentioned above. In production code, attempts
to copy device arrays to NumPy arrays should fail, or else functions
may appear to be working on the GPU when they actually aren't.

Parameters
----------
x : array

Returns
-------
ndarray

CPU_DEVICE)r   T)rU   )r   r,   rU   r*   getr-   cpur   r(   rX   rZ   Devicer`   s     rJ   _xp_copy_to_numpyrf      s    & 
	B||vvxr{{uuw||uuw}}2 zzJJq<!8J9
 	
 ::ad##rL   _default_xp_default_xp_ctxvar)NNNc              #      #    [         R                  U 5      n Sv   [         R                  U5        g! [         R                  U5        f = f7f)a  In all ``xp_assert_*`` and ``assert_*`` function calls executed within this
context manager, test by default that the array namespace is
the provided across all arrays, unless one explicitly passes the ``xp=``
parameter or ``check_namespace=False``.

Without this context manager, the default value for `xp` is the namespace
for the desired array (the second parameter of the tests).
N)rh   setreset)rC   tokens     rJ   r%   r%      s<      ""2&E(  '  's   A3 AA

Amatchc                    SSK nSSKJn  [        U5      (       d   [	        U5      (       d  [        U5      (       a  UR                  XS9$ U" Xc  SS9$ US9$ )zpytest.warns context manager if arrays of specified namespace are always eager.

Otherwise, context manager that *ignores* specified warning.
r   N)ignore_warnsrm    )pytestscipy._lib._utilrp   r,   r(   r*   warns)warning_typern   rC   rr   rp   s        rJ   r&   r&      sN    
 -||*2..'"++||L|66-BKKUKKrL   Tcheck_namespacecheck_dtypecheck_shapecheck_0dc                   SnUc   [         R                  5       nU(       a  [	        XU5        [        U5      (       a  U(       ay  S[        U 5       S[        U5       3nUR                  U 5      (       a  UR                  U5      (       d3  UR                  U 5      (       d  UR                  U5      (       a   U5       eUR                  U 5      n UR                  U5      nU(       a=  SU R                   SUR                   3nU R                  UR                  :X  d   U5       eU(       am  [        U5      (       a   U R                  5         UR                  5         SU R                   SUR                   3nU R                  UR                  :X  d   U5       eUR                  XR                  5      nXU4$ ! [         a    [        U5      n GNf = f)NTz$Array-ness does not match:
 Actual: z
 Desired: zdtypes do not match.
Actual: 

Desired: zShapes do not match.
Actual: )rh   rc   LookupErrorr   _assert_matching_namespacer,   typeisscalarrZ   rO   is_daskcompute_chunk_sizesshapebroadcast_to)	actualdesiredrC   rw   rx   ry   rz   __tracebackhide___msgs	            rJ   _strict_checkr      s    	z	*#'')B "6B7 ||7<.T']O=V$$W)=)=F++BKK4H4H	QLP	Q J ZZFjj!G/~[X||w}},2d2,2;;&&('')/~[X||w}},2d2,oog||4GB;  	* )B	*s   F7 7GGc                     Sn[        U5      nSUR                   SUR                   3nXB:X  d   U5       e[        U 5      nSUR                   SUR                   3nXb:X  d   U5       eg )NTzNamespace of desired array does not match expectations set by the `default_xp` context manager or by the `xp`pytest fixture.
Desired array's space: z
Expected namespace: z=Namespace of actual and desired arrays do not match.
Actual: r|   )r   __name__)r   r   rC   r   desired_arr_spacer   actual_arr_spaces          rJ   r~   r~     s    '0& '8&@&@%A B##%;;-	1D
 "(D("&v.'001 2}&D !'4'!rL   rq   )rw   rx   ry   rz   err_msgrC   c          
      $   Sn[        XXrX4US9u  pn[        U5      (       a  UR                  R                  XUS9$ [	        U5      (       a(  US:X  a  S OUnUR                  R                  XSSSSUS9$ [        R                  R                  XUS9$ )NTrv   )r   rq   r   Frtolatol	equal_nanrx   rI   )r   r*   testingassert_array_equalr-   assert_closerX   )	r   r   rw   rx   ry   rz   r   rC   r   s	            rJ   r2   r2     s    'FR r{{zz,,Vg,NN	" "R-$Wzz&&vQQRV38g ' G 	G ::(('(JJrL   )r   r   rw   rx   ry   rz   r   rC   c          
         Sn
[        XU	XEXgS9u  pn	U	R                  U R                  S5      nUc3  U(       a,  U	R                  U R                  5      R                  S-  S-  nOUc  Sn[        U	5      (       a  U	R                  R                  XUX8S9$ [        U	5      (       a'  US:X  a  S OUnU	R                  R                  XX#SS	US
9$ [        R                  R                  XUX8S9$ )NTrv   real floatingcomplex floating      ?   gHz>)r   r   r   rq   Fr   )r   isdtyperO   finfoepsr*   r   assert_allcloser-   r   rX   )r   r   r   r   rw   rx   ry   rz   r   rC   r   floatings               rJ   r1   r1   .  s    ''FR zz&,,(MNH| xx%))3.2	r{{zz))&/3 * F 	F	"!R-$Wzz&&vT155g ' W 	W ::%%fD+/ & B BrL      )nulprw   rx   ry   rz   r   rC   c          
          Sn	[        XUX4XVS9u  pn[        [        X45      u  p[        R                  R                  XUS9$ )NTrv   )r   )r   maprf   rX   r   assert_array_almost_equal_nulp)
r   r   r   rw   rx   ry   rz   r   rC   r   s
             rJ   xp_assert_close_nulpr   N  sR     ''FR +f->?OF::44V44PPrL   )rw   rx   ry   rz   r   verboserC   c          
      |   Sn	[        XXX4US9u  pn[        U5      (       a  UR                  R                  XXgS9$ [	        U5      (       aT  U R
                  R                  S:w  a  U R                  5       n UR
                  R                  S:w  a  UR                  5       n[        R                  R                  XXgS9$ )NTrv   )r   r   rd   )	r   r*   r   assert_array_lessr-   r   r   rd   rX   )
r   r   rw   rx   ry   rz   r   r   rC   r   s
             rJ   r3   r3   ]  s    'FR r{{zz++F4; , N 	N	"==&ZZ\F>>%'kkmG::''07 ( J JrL   c                 <    SSSU* -  -  pe[        X/UQ7XeSSS.UD6$ zPBackwards compatible replacement. In new code, use xp_assert_close instead.
    r   g      ?
   F)r   r   rx   ry   r1   r   r   decimalargskwdsr   r   s          rJ   r$   r$   t  B     CgX&$6 * * $UPU*$(* *rL   c                 <    SSSU* -  -  pe[        X/UQ7XeSSS.UD6$ r   r   r   s          rJ   r#   r#   }  r   rL   paramc                     SU < S3$ )Nz
Providing z$ is only supported for numpy arrays. )r   s    rJ   r8   r8     s    y DEErL   c                 :    UR                  U R                  S5      $ )Nr   )r   rO   r`   s     rJ   r)   r)     s    ::agg122rL   c                 R    U R                   nUR                  [        5        S35      $ )zCReturn name for native namespace (without array_api_compat prefix)..)r   removeprefixr   )rC   names     rJ   r/   r/     s(    ;;D 3 56a899rL   c                     [        U 5      (       a  SSKnUR                  $ [        U 5      (       a  SSKnUR                  $ [        U 5      (       a  U $ g)a   Return the `scipy`-like namespace of a non-NumPy backend

That is, return the namespace corresponding with backend `xp` that contains
`scipy` sub-namespaces like `linalg` and `special`. If no such namespace
exists, return ``None``. Useful for dispatching.
r   N)r*   cupyxscipyr+   jaxr-   )rC   r   r   s      rJ   r0   r0     sA     r{{{{bzzyy||	rL      )axiskeepdimsordrC   r   r   r   c               6   Uc  [        U 5      OUn[        (       aa  [        US5      (       a  UR                  R	                  XX#S9$ US:w  a  [        S5      eUR                  UR                  U 5      U -  XS9S-  $ [        R                  R                  XXS9$ )Nlinalg)r   r   r   r   zonly the Euclidean norm (`ord=2`) is currently supported in `xp_vector_norm` for backends not implementing the `linalg` extension.r   r   r   )r   r   r   )
r   r   hasattrr   vector_normrH   sumconjrX   norm)r^   r   r   r   rC   s        rJ   r9   r9     s    
  "z	rB2x  99(((RRax !  66"''!*q.t6GLL yy~~at~GGrL   c               F    Uc  [        U 5      OUnUR                  U S5      $ )N))r   reshaper`   s     rJ   r6   r6     s%      "z	rB::arL   c                     Uc  [        U 5      OUn[        [        U R                  5      5      nXB   XA   sXA'   XB'   UR	                  X5      n U $ N)r   listrangendimpermute_dims)aaxis1axis2rC   axess        rJ   xp_swapaxesr     sK    !z	rBaffD#{DKDK
 AHrL   )force_floatingc           	      2   U Vs/ s H;  n[        U5      (       d  [        R                  " U5      (       a  [        USUS9OUPM=     nnU Vs/ s H	  o3c  M  UPM     nnU (       a  UR	                  S5        [        U5      (       aN  UR                  S:  a>  U Vs/ s H"  n[        USS5      S:X  a  UR                  OUPM$     nnUR                  " U6 $  UR                  " U6 $ s  snf s  snf s  snf ! [         a    U (       d  e / nU Hh  n[        R                  " U5      (       a  UR                  U5      OUn[        USU5      nUR                  US	5      (       d  MW  UR	                  U5        Mj     UR                  " / UQ[        U5      P76 s $ f = f)
a  
Returns the dtype that results from applying type promotion rules
(see Array API Standard Type Promotion Rules) to the arguments. Augments
standard `result_type` in a few ways:

- There is a `force_floating` argument that ensures that the result type
  is floating point, even when all args are integer.
- When a TypeError is raised (e.g. due to an unsupported promotion)
  and `force_floating=True`, we define a custom rule: use the result type
  of the default float and any other floats passed. See
  https://github.com/scipy/scipy/pull/22695/files#r1997905891
  for rationale.
- This function accepts array-like iterables, which are immediately converted
  to the namespace's arrays before result type calculation. Consequently, the
  result dtype may be different when an argument is `1.` vs `[1.]`.

Typically, this function will be called shortly after `array_namespace`
on a subset of the arguments passed to `array_namespace`.
TrN   rC   g      ?z2.0r   r   r   rO   r   )r   rX   iterabler"   appendr,   __version__getattrrO   result_typer[   r   rZ   r   xp_default_dtype)r   rC   r   argargs_not_none
float_args	arg_arrayrO   s           rJ   r;   r;     s   0 "&'!%# 2@1D1DTWHXHXXc"-!% 	 '$(<DSSDM<S!||. %23$1S '.c61&=&BK$1 	 3~~}--A~~}--'<3  A
 
 C+-;;s+;+;

3IIw4Ezz%!FGG!!#&	 !
 ~~@z@+;B+?@@As1   AC%C*C*)C/C4 4A)F!2FF)	broadcastr   c           
         U(       d  U$ U Vs/ s H;  n[        U5      (       d  [        R                  " U5      (       a  [        USUS9OUPM=     nn[	        X1US.6nU Vs/ s H  nUb  [        XESUS9OUPM     nnU (       d  [        U5      S:X  a  US   $ [        U5      $ U Vs/ s H	  oDc  M  UPM     nnU Vs1 s H  oDR                  iM     nn [        U5      S:w  a  [        R                  " U6 OUS   R                  n/ nU H  nUc  UR                  U5        M  UR                  U:w  a)  [        U5      (       a  S	S0O0 nUR                  " XH40 UD6nUR                  U:w  a  UR                  XE5      nUR                  U5        M     [        U5      S:X  a  US   $ [        U5      $ s  snf s  snf s  snf s  snf ! [         a  n	Sn
[        U
5      U	eSn	A	ff = f)
aw  
Promotes elements of *args to result dtype, ignoring `None`s.
Includes options for forcing promotion to floating point and
broadcasting the arrays, again ignoring `None`s.
Type promotion rules follow `xp_result_type` instead of `xp.result_type`.

Typically, this function will be called shortly after `array_namespace`
on a subset of the arguments passed to `array_namespace`.

This function accepts array-like iterables, which are immediately converted
to the namespace's arrays before result type calculation. Consequently, the
result dtype may be different when an argument is `1.` vs `[1.]`.

See Also
--------
xp_result_type
Tr   )r   rC   N)rO   rN   rC   r   r   z/Array shapes are incompatible for broadcasting.rN   )r   rX   r   r"   r;   lentupler   broadcast_shapesrH   r   r,   r   rO   astype)r   r   rC   r   r   rO   r   shapesr   emessageoutkwargss                rJ   r<   r<     s   $  "&'!%# 2@1D1DTWHXHXXc"-!% 	 ' DBGE  ?BoXcdr:SVV 	  d)Q,tAw7E$K7$(<DSSDM< $11=Cii=F1)14V1A$$f-#A&,, 	 C;JJsO
 99(0gt_"F//#77C 99))C'C

3! $ Xq[3q60eCj0S'
 = 2  )C!q()s6   AF1!F6'F;1F;=G 1G 
G"GG"arrc                    Uc  [        U 5      OUnU R                  nUR                  X!R                  5      (       a  UR	                  XR
                  5      n U $ UR                  US5      (       a  UR	                  XR                  5      n U $ )Nr   )r   rO   r   float32r   	complex64
complex128)r   rC   	arr_dtypes      rJ   xp_float_to_complexr   P  ss    !#	B		I 
zz)ZZ((ii\\* J 
I	/	/ii]]+JrL   c                 Z    [        U 5      (       a  U R                  5       $ U R                  $ )z@Query the namespace-dependent default floating-point dtype.
    )r-   get_default_dtypefloat64r]   s    rJ   r   r   ^  s(     ||##%% zzrL   c                  P    U  H   n[        U5      (       d  M  [        U5      s  $    g)zReturn the device of an array in `args`, for the purpose of
input-output device propagation.
If there are multiple devices, return an arbitrary one.
If there are no arrays, return None (this typically happens only on NumPy).
N)r   r5   )r   r   s     rJ   xp_result_devicer   j  s*      C  S>!	 
 rL   arraysc           	          U Vs/ s H(  n[         R                  " U R                  U5      SU S9PM*     nnU R                  U5      $ s  snf )zWA replacement for `np.r_` as `xp.concat` does not accept python scalars
or 0-D arrays.
r   )r   rC   )xpx
atleast_ndrZ   concat)rC   r   r   aryss       rJ   	concat_1dr  y  sC     CII&QCNN2::a=qR8&DI99T? Js   /Ac                      SU R                   ;   $ )z=Returns True if `xp` is an MArray namespace; False otherwise.marray)r   r]   s    rJ   r'   r'     s    r{{""rL   c                    Uc  [        U 5      OUn[        U5      (       aR  [        R                  " U5      (       a  Sn[	        U5      eUR                  UR                  XUS9U R                  5      $ Uc  [        U 5      $ [        [        R                  " [        R                  " U R                  5      [        R                  " U5         5      5      $ )Nz8`axis` must be an integer or None for use with `MArray`.r   )r   r'   rX   r   NotImplementedErrorr   countrO   r7   intprodrZ   r   )r^   r   r   rC   r   s        rJ   _length_nonmaskedr    s    !z	rB}};;tPG%g..yy!BAGGLL,GAJ A

177+BJJt,<=>?ArL   c                    [        U 5      (       aU  [        R                  " [        R                  S U 5       5      nU Vs/ s H  o0R                  UR                  US9PM     nn[        U5      S:X  a  US   $ U$ s  snf )Nc              3   8   #    U  H  oR                   v   M     g 7fr   mask).0r   s     rJ   	<genexpr>_share_masks.<locals>.<genexpr>  s     .H4Cxx4s   r  r   r   )r'   	functoolsreduceoperatoror_rZ   datar   )rC   r   r  r   s       rJ   _share_masksr    si    }}.H4.HI;?@4C

388$
/4@$i1n47.$. As   #A<)reprc                   r    \ rS rSr% \S-  \S'   \S-  \S'   \R                  " \S9r	\\
   \S'   S rS rS	rg)
_XPSphinxCapabilityi  Nrd   gpu)default_factorywarningsc                     Uc  gU(       d  gU R                   (       a6  SSR                  U R                   5      -   n[        U5      S::  d   S5       eU$ g)Nzn/au   ⛔u   ⚠️ z;    zWarnings too longu   ✅)r   joinr   )selfvalueress      rJ   _render_XPSphinxCapability._render  sL    ===dii66Cs8r>6#66>JrL   c                     U R                  U R                  5      nU R                  U R                  5      nUS SUS 3$ )N20z  )r'  rd   r  )r$  rd   r  s      rJ   __str___XPSphinxCapability.__str__  s;    ll488$ll488$bC8$$rL   r   )r   
__module____qualname____firstlineno__bool__annotations__dataclassesfieldr   r   strr'  r+  __static_attributes__r   rL   rJ   r  r    s9    		%++DAHd3iA	%rL   r  r   c
                    U(       a  SS0$ [        U5      n[        SS S9[        SS S9[        S SS9[        SSS9[        SSU(       a  / OS/S9[        SS U(       a  S/O/ S9S.n
[        U 5      [        U5      -    H3  u  pX   nUR                  b  SUl        UR                  c  M,  SUl        M5     U
R                  5        Hg  u  pU(       a5  XS	1-  ;  a,  UR                  b  SUl        UR                  b	  SUl        M?  MA  U(       d  MJ  X;  d  MQ  UR                  c  M`  SUl        Mi     U H$  u  pX   nUR                  R                  U5        M&     U
$ )
Nout_of_scopeT)rd   r  zno JIT)rd   r  r   zcomputes graph)r   array_api_strictcupytorch	jax.numpy
dask.arrayFr   )rj   r  r   rd   r  itemsr   r   )skip_backendsxfail_backendscpu_onlynp_onlyr7  
exceptionsallow_dask_computejax_jitr   reasoncapabilitiesmodule_backendwarnings                  rJ   _make_sphinx_capabilitiesrK    s\    %%ZJ %48/DdC#$7$48(Tt"R
4 *d+=&'2G
L -(4+??	&;;"GK;;"GK @ (--/v7)%;;{{&#{{&# 'X&2w{{7NGK 0 $&( $ rL   c                     SU;   a  SU  S3n[         R                  " U5      $ SU  SUS    SUS    S	US
    SUS    SUS    S3U=(       d    S-   S-   n[         R                  " U5      $ )Nr7  z2
        **Array API Standard Support**

        `z` is not in-scope for support of Python Array API Standard compatible
        backends other than NumPy.

        See :ref:`dev-arrayapi` for more information.
        z*
    **Array API Standard Support**

    `aG  ` has experimental support for Python Array API Standard compatible
    backends in addition to NumPy. Please consider testing these features
    by setting an environment variable ``SCIPY_ARRAY_API=1`` and providing
    CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following
    combinations of backend and device (or other capability) are supported.

    ====================  ====================  ====================
    Library               CPU                   GPU
    ====================  ====================  ====================
    NumPy                 r   z
    CuPy                  r9  z
    PyTorch               r:  z
    JAX                   r;  z
    Dask                  r<  zK
    ====================  ====================  ====================

    rq   z1    See :ref:`dev-arrayapi` for more information.)textwrapdedent)fun_namerF  
extra_notenotes       rJ   _make_capabilities_noterR    s    %
  	 t$$ Z 	 (0D E'/D E'0D E'4D E'5D E!& '&  S'SD* ??4  rL   )capabilities_tabler>  r?  r@  rA  rE  r7  rB  r   rC  rD  rP  c                    ^ ^^^ T c  [         OT m U(       a  Sn[        UUUUUUUU	U
US9
m[        S0 TD6mUU UU4S jnU$ )aE  Decorator for a function that states its support among various
Array API compatible backends.

This decorator has two effects:
1. It allows tagging tests with ``@make_xp_test_case`` or
   ``make_xp_pytest_param`` (see below) to automatically generate
   SKIP/XFAIL markers and perform additional backend-specific
   testing, such as extra validation for Dask and JAX;
2. It automatically adds a note to the function's docstring, containing
   a table matching what has been tested.

See Also
--------
make_xp_test_case
make_xp_pytest_param
array_api_extra.testing.lazy_xp_function
T)
r>  r?  r@  rA  r7  rE  rB  rC  rD  r   c                   > TTU '   [        U R                  TT5      n[        U 5      nUS   R                  U5        [	        U5      R                  SS5      S   R                  S5      n X l        U $ ! [         a     U $ f = f)NNotes
r   z 
)	rR  r   r    r   r4  splitlstrip__doc__AttributeError)frQ  docrF  rS  rP  sphinx_capabilitiess      rJ   	decorator"xp_capabilities.<locals>.decoratorH  s     !-1&qzz3F
S!nGD!#hnnT1%a(//6	I   	 	s   +A3 3
B Br   )xp_capabilities_tabledictrK  )rS  r>  r?  r@  rA  rE  r7  rB  r   rC  rD  rP  r_  rF  r^  s   `          ` @@rJ   r:   r:     sl    H 4F3M/1  #%!-L 4ClC   rL   rS  c                 >   ^ U c  [         OU n  [        USU 06mU4S j$ )NrS  c                 6   > [         R                  " S TU 5      $ )Nc                     U" U 5      $ r   r   )r\  gs     rJ   <lambda>5make_xp_test_case.<locals>.<lambda>.<locals>.<lambda>  s    adrL   )r  r  )funcmarkss    rJ   rh  #make_xp_test_case.<locals>.<lambda>  s    	(():E4HrL   )ra  r>   )rS  funcsrk  s     @rJ   r=   r=   [  s2    3E3M/1 *V !%O<NOEHHrL   c                \    SSK n[        XS9nUR                  " U /UQ7X@R                  S.6$ )a  Variant of ``make_xp_test_case`` that returns a pytest.param for a function,
with all necessary skip_xp_backends and xfail_xp_backends marks applied::

    @pytest.mark.parametrize(
        "func", [make_xp_pytest_param(f1), make_xp_pytest_param(f2)]
    )
    def test(func, xp):
        ...

The above is equivalent to::

    @pytest.mark.parametrize(
        "func", [
            pytest.param(f1, marks=[
                pytest.mark.skip_xp_backends(...),
                pytest.mark.xfail_xp_backends(...), ...]),
            pytest.param(f2, marks=[
                pytest.mark.skip_xp_backends(...),
                pytest.mark.xfail_xp_backends(...), ...]),
    )
    def test(func, xp):
        ...

Parameters
----------
func : Callable
    Function to be tested. It must be decorated with ``@xp_capabilities``.
*args : Any, optional
    Extra pytest parameters for the use case, e.g.::

    @pytest.mark.parametrize("func,verb", [
        make_xp_pytest_param(f1, "hello"),
        make_xp_pytest_param(f2, "world")])
    def test(func, verb, xp):
        # iterates on (func=f1, verb="hello")
        # and (func=f2, verb="world")

See Also
--------
xp_capabilities
make_xp_test_case
make_xp_pytest_marks
array_api_extra.testing.lazy_xp_function
r   Nrc  )rk  id)rr   r>   r   r   )rj  rS  r   rr   rk  s        rJ   r?   r?     s/    Z  ME<<CtC5]]CCrL   c           	      J   U c  [         OU n SSKn/ nU GH  nX   nUS   nUS   nUS   (       a)  UR                  UR                  R	                  SXgS95        US   (       a)  UR                  UR                  R	                  SXgS	95        US
    H-  u  pUR                  UR                  R	                  XS95        M/     US    H-  u  pUR                  UR                  R                  XS95        M/     S V	s0 s H  n	XU	   _M
     n
n	[        U40 U
D6  GM     U$ s  sn	f )a  Variant of ``make_xp_test_case`` that returns a list of pytest marks,
which can be used with the module-level `pytestmark = ...` variable::

    pytestmark = make_xp_pytest_marks(f1, f2)

    def test(xp):
        ...

In this example, the whole test module is dedicated to testing `f1` or `f2`,
and the two functions have the same capabilities, so it's unnecessary to
cherry-pick which test tests which function.
The above is equivalent to::

    pytestmark = [
        pytest.mark.skip_xp_backends(...),
        pytest.mark.xfail_xp_backends(...), ...]),
    ]

    def test(xp):
        ...

See Also
--------
xp_capabilities
make_xp_test_case
make_xp_pytest_param
array_api_extra.testing.lazy_xp_function
Nr   rB  rE  r@  T)r@  rB  rE  rA  )rA  rB  rE  r>  )rE  r?  )rC  rD  )ra  rr   r   markskip_xp_backendsxfail_xp_backendsr   )rS  rm  rr   rk  rj  rF  rB  rE  mod_nameklazy_kwargss              rJ   r>   r>     sO   : 4F3M/1 E)/!,/
h'
#LL55* 6 E F	"LL55 6 D E !-_ =HLL55h5NO !> ,-= >HLL66x6OP !? !BC A1 q/) A 	 C--' * L	Cs   <D r   )rd   cudaNc                 >   [        U 5      (       a  g[        U 5      (       a  g[        U 5      (       a  U R                  R                  $ [        U 5      (       a   U R                  R                  =nS:X  a  S$ U$ [        U 5      (       a  [        U R                  5      $ g )Nrd   rw  r  )
r   r   r   r   r   r   platformr   xp_device_type_meta)r   ps     rJ   rz  rz    s~    aQaxx}}A xx000!U:vAAQagg&&rL   )   )   r   )FN)
r   r   FFFr   FTr   N)orZ  r  r2  r  rM  collections.abcr   
contextlibr   contextvarsr   typesr   typingr   r   r	   r
   r   rX   numpy.typingnptscipy._lib.array_api_compatr   r   r   r   r   r   r   r   r7   r.   r   r5   r   r,   r   r*   r   r-   r   r+   r   r   r   r(   +scipy._lib.array_api_compat.common._helpersr   "scipy._lib.array_api_extra.testingr   scipy._lib._array_api_overrider   r   r   scipy._lib._docscraper    
scipy._libr!   r  __all__r@   r1  rA   rK   r0  r"   r4   ndarrayrf   rh   r%   r&   r   r~   r2   r1   r   r3   r$   r#   r4  r8   r)   r/   r0   r  r   floatr9   r6   r   r;   r<   r   r   r   r  r'   r  r  	dataclassr  rK  rR  r:   r=   r?   r>   ra  rz  r   rL   rJ   <module>r     sC       % % "  * * $      $ L ?  . - y s}},	9 , J 4  48 	, !%",,, )*T1, Tk	, , , , 
,^ 26 )u )Z$. )% )8&$ &$2:: &$R .8-F Jz* F(: (),<"= ( (  (, 	L #'Dd%P($ 9=$ $tRDK, .24 $$4B@ 34T%)td!#Q 8<#dBQUJ.**FC FC F3% 3Z 3D 3:* : :J :+< 0 48$)&'+/	He HuSz)D0H!H eH "D(	H 5:	H4 6:    d!2  e   */ 2Aj !&e A1HU 
T(9 U *t# hy.A e #
	A/ E"% % #%0 &(BD&*3l%!X  RE$2 d#HV 26 /Id :> 0Df 59 7v  e (; < rL   