
    -i3P              
          S SK r S SKrS SKrS SKrSSKJr  S SKrS SKrS SKrS SK	r	SSKJ
r
JrJrJrJr  / SQr\ R                   S\S   4   r\ R                   \\\/\\\4   4   rS rS	 rS
 rS rS r\R                  " \\5        \R                  " \R                  \5        \R                  " \\5        \R                  " \\5        S r\R6                  S 5       r\R6                  S 5       rS r S(S\S\S\S\ R                   S-  4S jjr S)S jr!S r"S r#S)SS.S jjr$S r%S*S jr& " S S 5      r'S! r(S" r)S# r*S$ r+SSS%.S& jr,SSS%.S' jr-g)+    N   )_uarray)BackendNotImplementedError	_Function_SkipBackendContext_SetBackendContext_BackendState)set_backendset_global_backendskip_backendregister_backenddetermine_backenddetermine_backend_multiclear_backendscreate_multimethodgenerate_multimethodr   r   Dispatchablewrap_single_convertorwrap_single_convertor_instanceall_of_typemark_as	set_state	get_statereset_stater	   r   r   .)r   .c                     SS K n UR                  U 5      nUR                  S5      nUnU H  n[        XV5      nM     Ub  [        R
                  " XR5      nU$ ! [        [        4 a  nSSKJ	n  XeS nAff = f)Nr   .)UnpicklingError)
	importlibimport_modulesplitgetattrtypes
MethodTypeImportErrorAttributeErrorpickler   )	mod_nameqnameself_r   modulefuncqer   s	            N/var/www/html/venv/lib/python3.13/site-packages/scipy/_lib/_uarray/_backend.pyunpickle_functionr/   1   s|    %((2C A4#D  ##D0D( %*$%s   AA A6)A11A6c                     [        U SS 5      n[        U SS 5      n[        U SS 5      n [        XU5      nX@La  [        R                  " SU  SU 35      e[        XU44$ ! [        R                   a    S n NBf = f)N
__module____qualname____self__zCan't pickle z: it's not the same object as )r!   r/   r&   r   PicklingError)r+   r'   r(   r)   tests        r.   pickle_functionr6   E   s    t\40HD.$/ED*d+E %8 ""D6!?vF
 	
 x666 !! s   A A87A8c                 V    [         R                  R                  U R                  5       4$ N)r   r	   	_unpickle_pickle)states    r.   pickle_stater<   W   s      **EMMO;;    c                 .    [         U R                  5       4$ r8   )r   r:   ctxs    r.   pickle_set_backend_contextrA   [   s    s{{},,r=   c                 .    [         U R                  5       4$ r8   )r   r:   r?   s    r.   pickle_skip_backend_contextrC   _   s    --r=   c                  ,    [         R                  " 5       $ )z
Returns an opaque object containing the current state of all the backends.

Can be used for synchronization between threads/processes.

See Also
--------
set_state
    Sets the state returned by this function.
)r   r    r=   r.   r   r   i   s     r=   c               #   n   #    [        [        5       5         Sv   SSS5        g! , (       d  f       g= f7f)z
Returns a context manager that resets all state once exited.

See Also
--------
set_state
    Context manager that sets the backend state.
get_state
    Gets a state to be set by this context manager.
N)r   r   rE   r=   r.   r   r   w   s      
9;	 
 		s   5$	5
25c              #      #    [        5       n[        R                  " U 5         Sv   [        R                  " US5        g! [        R                  " US5        f = f7f)z
A context manager that sets the state of the backends to one returned by :obj:`get_state`.

See Also
--------
get_state
    Gets a state to be set by this context manager.
NT)r   r   r   )r;   	old_states     r.   r   r      sD      Ie+)T*)T*s   !AA  A AAc                     ^ ^ U U4S jnU$ )aM  
Creates a decorator for generating multimethods.

This function creates a decorator that can be used with an argument
extractor in order to generate a multimethod. Other than for the
argument extractor, all arguments are passed on to
:obj:`generate_multimethod`.

See Also
--------
generate_multimethod
    Generates a multimethod.
c                 "   > [        U /TQ70 TD6$ r8   )r   )aargskwargss    r.   wrapper#create_multimethod.<locals>.wrapper   s    #A7777r=   rE   )rL   rM   rN   s   `` r.   r   r      s    8 Nr=   argument_extractorargument_replacerdomaindefaultc                 j    [        U 5      u  pEn[        U UUUUU5      n[        R                  " Xp5      $ )a#  
Generates a multimethod.

Parameters
----------
argument_extractor : ArgumentExtractorType
    A callable which extracts the dispatchable arguments. Extracted arguments
    should be marked by the :obj:`Dispatchable` class. It has the same signature
    as the desired multimethod.
argument_replacer : ArgumentReplacerType
    A callable with the signature (args, kwargs, dispatchables), which should also
    return an (args, kwargs) pair with the dispatchables replaced inside the
    args/kwargs.
domain : str
    A string value indicating the domain of this multimethod.
default: Optional[Callable], optional
    The default implementation of this multimethod, where ``None`` (the default)
    specifies there is no default implementation.

Examples
--------
In this example, ``a`` is to be dispatched over, so we return it, while marking it
as an ``int``.
The trailing comma is needed because the args have to be returned as an iterable.

>>> def override_me(a, b):
...   return Dispatchable(a, int),

Next, we define the argument replacer that replaces the dispatchables inside
args/kwargs with the supplied ones.

>>> def override_replacer(args, kwargs, dispatchables):
...     return (dispatchables[0], args[1]), {}

Next, we define the multimethod.

>>> overridden_me = generate_multimethod(
...     override_me, override_replacer, "ua_examples"
... )

Notice that there's no default implementation, unless you supply one.

>>> overridden_me(1, "a")
Traceback (most recent call last):
    ...
uarray.BackendNotImplementedError: ...

>>> overridden_me2 = generate_multimethod(
...     override_me, override_replacer, "ua_examples", default=lambda x, y: (x, y)
... )
>>> overridden_me2(1, "a")
(1, 'a')

See Also
--------
uarray
    See the module documentation for how to override the method by creating
    backends.
)get_defaultsr   	functoolsupdate_wrapper)rP   rQ   rR   rS   kw_defaultsarg_defaultsoptsua_funcs           r.   r   r      sD    B '33E&F#KtG ##G@@r=   Fc                     [         R                  " 5       n U R                  USX4   $ ! [         a
    0 U l         O[         a     Of = f[        XU5      nX@R                  USX4'   U$ )a  
A context manager that sets the preferred backend.

Parameters
----------
backend
    The backend to set.
coerce
    Whether or not to coerce to a specific backend's types. Implies ``only``.
only
    Whether or not this should be the last backend to try.

See Also
--------
skip_backend: A context manager that allows skipping of backends.
set_global_backend: Set a single, global backend for a domain.
set)	threadingget_native_id__ua_cache__r%   KeyErrorr   )backendcoerceonlytidr@   s        r.   r
   r
      sy    $ 
!
!
#C##C$<== "!  Wd
3C58eV12Js   ) A	AAc                     [         R                  " 5       n U R                  US4   $ ! [         a
    0 U l         O[         a     Of = f[        U 5      nX R                  US4'   U$ )a  
A context manager that allows one to skip a given backend from processing
entirely. This allows one to use another backend's code in a library that
is also a consumer of the same backend.

Parameters
----------
backend
    The backend to skip.

See Also
--------
set_backend: A context manager that allows setting of backends.
set_global_backend: Set a single, global backend for a domain.
skip)r^   r_   r`   r%   ra   r   )rb   re   r@   s      r.   r   r     sq      
!
!
#C##CK00 "!  g
&C(+f%Js   ( A	AAc                    [         R                  " U 5      n0 n/ n[        5       nUR                  R	                  5        H  u  pVUR
                  [         R                  R                  La  UR
                  X%'   UR                  [         R                  R                  [         R                  R                  4;   a  UR                  UR
                  5        UR                  U5        M     U[        U5      U4$ r8   )inspect	signaturer]   
parametersitemsrS   	ParameteremptykindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDappendaddtuple)fsigrX   rY   rZ   kvs          r.   rU   rU   8  s    


A
CKL5D$$&99G--333YYKN66--33
 
 		* ' l+T11r=   )try_lastc                2    [         R                  " XX#5        g)a  
This utility method replaces the default backend for permanent use. It
will be tried in the list of backends automatically, unless the
``only`` flag is set on a backend. This will be the first tried
backend outside the :obj:`set_backend` context manager.

Note that this method is not thread-safe.

.. warning::
    We caution library authors against using this function in
    their code. We do *not* support this use-case. This function
    is meant to be used only by users themselves, or by a reference
    implementation, if one exists.

Parameters
----------
backend
    The backend to register.
coerce : bool
    Whether to coerce input types when trying this backend.
only : bool
    If ``True``, no more backends will be tried if this fails.
    Implied by ``coerce=True``.
try_last : bool
    If ``True``, the global backend is tried after registered backends.

See Also
--------
set_backend: A context manager that allows setting of backends.
skip_backend: A context manager that allows skipping of backends.
N)r   r   )rb   rc   rd   ry   s       r.   r   r   J  s    @ w?r=   c                 0    [         R                  " U 5        g)a  
This utility method sets registers backend for permanent use. It
will be tried in the list of backends automatically, unless the
``only`` flag is set on a backend.

Note that this method is not thread-safe.

Parameters
----------
backend
    The backend to register.
N)r   r   )rb   s    r.   r   r   m  s     W%r=   Tc                 2    [         R                  " XU5        g)a  
This utility method clears registered backends.

.. warning::
    We caution library authors against using this function in
    their code. We do *not* support this use-case. This function
    is meant to be used only by users themselves.

.. warning::
    Do NOT use this method inside a multimethod call, or the
    program is likely to crash.

Parameters
----------
domain : Optional[str]
    The domain for which to de-register backends. ``None`` means
    de-register for all domains.
registered : bool
    Whether or not to clear registered backends. See :obj:`register_backend`.
globals : bool
    Whether or not to clear global backends. See :obj:`set_global_backend`.

See Also
--------
register_backend : Register a backend globally.
set_global_backend : Set a global backend.
N)r   r   )rR   
registeredglobalss      r.   r   r   }  s    8 6w7r=   c                   2    \ rS rSrSrSS jrS rS r\rSr	g)	r   i  a  
A utility class which marks an argument with a specific dispatch type.


Attributes
----------
value
    The value of the Dispatchable.

type
    The type of the Dispatchable.

Examples
--------
>>> x = Dispatchable(1, str)
>>> x
<Dispatchable: type=<class 'str'>, value=1>

See Also
--------
all_of_type
    Marks all unmarked parameters of a function.

mark_as
    Allows one to create a utility function to mark as a given type.
c                 (    Xl         X l        X0l        g r8   )valuetype	coercible)selfr   dispatch_typer   s       r.   __init__Dispatchable.__init__  s    
!	"r=   c                 8    U R                   U R                  4U   $ r8   )r   r   )r   indexs     r.   __getitem__Dispatchable.__getitem__  s    		4::&u--r=   c                 l    S[        U 5      R                   SU R                   < SU R                  < S3$ )N<z: type=z, value=>)r   __name__r   )r   s    r.   __str__Dispatchable.__str__  s1    4:&&'wtyym8DJJ>QRSSr=   )r   r   r   N)T)
r   r1   r2   __firstlineno____doc__r   r   r   __repr____static_attributes__rE   r=   r.   r   r     s    6#
.T Hr=   r   c                 4    [         R                  " [        U S9$ )z
Creates a utility function to mark something as a specific type.

Examples
--------
>>> mark_int = mark_as(int)
>>> mark_int(1)
<Dispatchable: type=<class 'int'>, value=1>
r   )rV   partialr   r   s    r.   r   r     s     \GGr=   c                    ^  U 4S jnU$ )z
Marks all unmarked arguments as a given type.

Examples
--------
>>> @all_of_type(str)
... def f(a, b):
...     return a, Dispatchable(b, int)
>>> f('a', 1)
(<Dispatchable: type=<class 'str'>, value='a'>,
 <Dispatchable: type=<class 'int'>, value=1>)
c                 J   >^  [         R                  " T 5      UU 4S j5       nU$ )Nc                  >   > T" U 0 UD6n[        U4S jU 5       5      $ )Nc              3   j   >#    U  H(  n[        U[        5      (       d  [        UT5      OUv   M*     g 7fr8   
isinstancer   ).0argarg_types     r.   	<genexpr><all_of_type.<locals>.outer.<locals>.inner.<locals>.<genexpr>  s:       *C "#|44 S(+ *   03)rt   )rL   rM   extracted_argsr   r+   s      r.   inner)all_of_type.<locals>.outer.<locals>.inner  s.    !4262N  *	  r=   rV   wraps)r+   r   r   s   ` r.   outerall_of_type.<locals>.outer  s%    			 
	 r=   rE   )r   r   s   ` r.   r   r     s     Lr=   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )
Wraps a ``__ua_convert__`` defined for a single element to all elements.
If any of them return ``NotImplemented``, the operation is assumed to be
undefined.

Accepts a signature of (value, type, coerce).
c                    > / nU  HV  nT" UR                   UR                  U=(       a    UR                  5      nU[        L a  [        s  $ UR	                  U5        MX     U$ r8   r   r   r   NotImplementedrr   )dispatchablesrc   	converteddcconvert_singles        r.   __ua_convert__-wrap_single_convertor.<locals>.__ua_convert__  sU    	Aqww0F1;;GAN"%%Q  r=   r   r   r   s   ` r.   r   r     (     __^$
 %
 r=   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )r   c                    > / nU HV  nT" XR                   UR                  U=(       a    UR                  5      nU[        L a  [        s  $ UR	                  U5        MX     U$ r8   r   )r   r   rc   r   r   r   r   s         r.   r   6wrap_single_convertor_instance.<locals>.__ua_convert__  sU    	AtWWafff6LMAN"%%Q  r=   r   r   s   ` r.   r   r   
  r   r=   )rd   rc   c                ^    [        XU5      4n[        R                  " X%U5      n[        XdUS9$ )aJ  Set the backend to the first active backend that supports ``value``

This is useful for functions that call multimethods without any dispatchable
arguments. You can use :func:`determine_backend` to ensure the same backend
is used everywhere in a block of multimethod calls.

Parameters
----------
value
    The value being tested
dispatch_type
    The dispatch type associated with ``value``, aka
    ":ref:`marking <MarkingGlossary>`".
domain: string
    The domain to query for backends and set.
coerce: bool
    Whether or not to allow coercion to the backend's types. Implies ``only``.
only: bool
    Whether or not this should be the last backend to try.

See Also
--------
set_backend: For when you know which backend to set

Notes
-----

Support is determined by the ``__ua_convert__`` protocol. Backends not
supporting the type must return ``NotImplemented`` from their
``__ua_convert__`` if they don't support input of that type.

Examples
--------

Suppose we have two backends ``BackendA`` and ``BackendB`` each supporting
different types, ``TypeA`` and ``TypeB``. Neither supporting the other type:

>>> with ua.set_backend(ex.BackendA):
...     ex.call_multimethod(ex.TypeB(), ex.TypeB())
Traceback (most recent call last):
    ...
uarray.BackendNotImplementedError: ...

Now consider a multimethod that creates a new object of ``TypeA``, or
``TypeB`` depending on the active backend.

>>> with ua.set_backend(ex.BackendA), ua.set_backend(ex.BackendB):
...         res = ex.creation_multimethod()
...         ex.call_multimethod(res, ex.TypeA())
Traceback (most recent call last):
    ...
uarray.BackendNotImplementedError: ...

``res`` is an object of ``TypeB`` because ``BackendB`` is set in the
innermost with statement. So, ``call_multimethod`` fails since the types
don't match.

Instead, we need to first find a backend suitable for all of our objects.

>>> with ua.set_backend(ex.BackendA), ua.set_backend(ex.BackendB):
...     x = ex.TypeA()
...     with ua.determine_backend(x, "mark", domain="ua_examples"):
...         res = ex.creation_multimethod()
...         ex.call_multimethod(res, x)
TypeA

rc   rd   )r   r   r   r
   )r   r   rR   rd   rc   r   rb   s          r.   r   r   #  s3    H "%?AM''vFGwD99r=   c                4  ^ SU;   a'  UR                  S5      m[        U4S jU  5       5      n O-[        U 5      n [        S U  5       5      (       d  [        S5      e[	        U5      S:w  a  [        SU 35      e[
        R                  " XU5      n[        XSUS9$ )a	  Set a backend supporting all ``dispatchables``

This is useful for functions that call multimethods without any dispatchable
arguments. You can use :func:`determine_backend_multi` to ensure the same
backend is used everywhere in a block of multimethod calls involving
multiple arrays.

Parameters
----------
dispatchables: Sequence[Union[uarray.Dispatchable, Any]]
    The dispatchables that must be supported
domain: string
    The domain to query for backends and set.
coerce: bool
    Whether or not to allow coercion to the backend's types. Implies ``only``.
only: bool
    Whether or not this should be the last backend to try.
dispatch_type: Optional[Any]
    The default dispatch type associated with ``dispatchables``, aka
    ":ref:`marking <MarkingGlossary>`".

See Also
--------
determine_backend: For a single dispatch value
set_backend: For when you know which backend to set

Notes
-----

Support is determined by the ``__ua_convert__`` protocol. Backends not
supporting the type must return ``NotImplemented`` from their
``__ua_convert__`` if they don't support input of that type.

Examples
--------

:func:`determine_backend` allows the backend to be set from a single
object. :func:`determine_backend_multi` allows multiple objects to be
checked simultaneously for support in the backend. Suppose we have a
``BackendAB`` which supports ``TypeA`` and ``TypeB`` in the same call,
and a ``BackendBC`` that doesn't support ``TypeA``.

>>> with ua.set_backend(ex.BackendAB), ua.set_backend(ex.BackendBC):
...     a, b = ex.TypeA(), ex.TypeB()
...     with ua.determine_backend_multi(
...         [ua.Dispatchable(a, "mark"), ua.Dispatchable(b, "mark")],
...         domain="ua_examples"
...     ):
...         res = ex.creation_multimethod()
...         ex.call_multimethod(res, a, b)
TypeA

This won't call ``BackendBC`` because it doesn't support ``TypeA``.

We can also use leave out the ``ua.Dispatchable`` if we specify the
default ``dispatch_type`` for the ``dispatchables`` argument.

>>> with ua.set_backend(ex.BackendAB), ua.set_backend(ex.BackendBC):
...     a, b = ex.TypeA(), ex.TypeB()
...     with ua.determine_backend_multi(
...         [a, b], dispatch_type="mark", domain="ua_examples"
...     ):
...         res = ex.creation_multimethod()
...         ex.call_multimethod(res, a, b)
TypeA

r   c              3   j   >#    U  H(  n[        U[        5      (       a  UO[        UT5      v   M*     g 7fr8   r   )r   r   	disp_types     r.   r   *determine_backend_multi.<locals>.<genexpr>  s0      
" A|,,A,q)2LL"r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr8   r   )r   r   s     r.   r   r     s     F1:a..s   z6dispatchables must be instances of uarray.Dispatchabler   z'Received unexpected keyword arguments: r   )poprt   all	TypeErrorlenr   r   r
   )r   rR   rd   rc   rM   rb   r   s         @r.   r   r   m  s    L & JJ/	 
"
 

 m,FFFFTUU
6{aA&JKK''vFGwD99r=   r8   )FF)TF).typingr"   ri   rV    r   copyregr&   
contextlibr^   r   r   r   r   r	   __all__Callablert   ArgumentExtractorTypedictArgumentReplacerTyper/   r6   r<   rA   rC   r   contextmanagerr   r   r   strr   r
   r   rU   r   r   r   r   r   r   r   r   r   r   rE   r=   r.   <module>r      s            2 U3F-G(GH 
D%%t,, %(7$<-. y/ * w$$l 3 !#= > "$? @   + +"2 '+	KA-KA+KA KA __t#	KA\>:2$ @e  @F& 8>' 'T
H<22 =A G:V $(V:r=   