+
    ,i3P                        ^ RI t ^ RIt^ RIt^ RIt^RIHt ^ RIt^ RIt^ RIt^ RI	t	^RIH
t
HtHtHtHt . R#Ot] P                   R]R$,          3,          t] P                   ]]].]]]3,          3,          tR tR tR tR	 tR
 t]P                  ! ]]4       ]P                  ! ]P                  ]4       ]P                  ! ]]4       ]P                  ! ]]4       R t]P6                  R 4       t]P6                  R 4       tR tR%R R lltR&R lt R t!R t"R&RR/R llt#R t$R'R lt% ! R R4      t&R t'R t(R t)R t*RRR R/R! lt+RRR R/R" lt,R# )(    N)_uarray)BackendNotImplementedError	_Function_SkipBackendContext_SetBackendContext_BackendStateDispatchable.c                     ^ RI p VP                  V 4      pVP                  R4      pTpV F  p\        WV4      pK  	  Ve   \        P
                  ! WR4      pV#   \        \        3 d   p^ RIH	p YhRp?ii ; i)r   N.)UnpicklingError)
	importlibimport_modulesplitgetattrtypes
MethodTypeImportErrorAttributeErrorpickler   )	mod_nameqnameself_r   modulefuncqer   s	   &&&      =/usr/lib/python3/dist-packages/scipy/_lib/_uarray/_backend.pyunpickle_functionr   1   s|    %((2C A4#D  ##D0D( %*$%s   AA A8+A33A8c                     \        V R R4      p\        V RR4      p\        V RR4      p \        WV4      pW@Jd   \        P                  ! RV  RV 24      h\        WV33#   \        P                   d    Rp LDi ; i)
__module__N__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_functionr%   E   s    t\40HD.$/ED*d+E %8 ""D6!?vF
 	
 x666 !! s   A   A:9A:c                 V    \         P                  P                  V P                  4       3# N)r   r   	_unpickle_pickle)states   &r   pickle_stater+   W   s      **EMMO;;    c                 .    \         V P                  4       3# r'   )r   r)   ctxs   &r   pickle_set_backend_contextr0   [   s    s{{},,r,   c                 .    \         V P                  4       3# r'   )r   r)   r.   s   &r   pickle_skip_backend_contextr2   _   s    --r,   c                 ,    \         P                  ! 4       # )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   	get_state r,   r   r4   r4   i   s     r,   c               #     "   \        \        4       4      ;_uu_ 4        Rx  RRR4       R#   + '       g   i     R# ; i5i)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)	set_stater4   r5   r,   r   reset_stater8   w   s%      
9;		 
 			s   A-
A>		Ac              #     "   \        4       p\        P                  ! V 4        Rx  \        P                  ! VR4       R#   \        P                  ! TR4       i ; i5i)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)r4   r   r7   )r*   	old_states   & r   r7   r7      sD      Ie+)T*)T*s   !AA AAAc                    a a V V3R lpV# )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                 "   < \        V .SO5/ SB # r'   )generate_multimethod)aargskwargss   &r   wrapper#create_multimethod.<locals>.wrapper   s    #A7777r,   r5   )r?   r@   rA   s   jl r   create_multimethodrC      s    8 Nr,   c          	      j    V ^8  d   QhR\         R\        R\        R\        P                  R,          /# )   argument_extractorargument_replacerdomaindefaultN)ArgumentExtractorTypeArgumentReplacerTypestrtypingCallable)formats   "r   __annotate__rP      sE     KA KA-KA+KA KA __t#	KAr,   c                j    \        V 4      w  rEp\        V VVVVV4      p\        P                  ! Wp4      # )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)rF   rG   rH   rI   kw_defaultsarg_defaultsoptsua_funcs   &&&&    r   r=   r=      sD    B '33E&F#KtG ##G@@r,   Fc                    \         P                  ! 4       p V P                  VRW3,          #   \         d    / T n         M\         d     Mi ; i\        YT4      pY@P                  TRY3&   T# )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   set_backendrc      sy    $ 
!
!
#C##C$<== "!  Wd
3C58eV12Js   - AA
AAc                    \         P                  ! 4       p V P                  VR3,          #   \         d    / T n         M\         d     Mi ; i\        T 4      pY P                  TR3&   T# )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   r^   r   )r_   rb   r/   s   &  r   skip_backendrf     sq      
!
!
#C##CK00 "!  g
&C(+f%Js   , A A	AAc                    \         P                  ! V 4      p/ p. p\        4       pVP                  P	                  4        F  w  rVVP
                  \         P                  P                  Jd   VP
                  W%&   VP                  \         P                  P                  \         P                  P                  39   d   VP                  VP
                  4       VP                  V4       K  	  V\        V4      V3# r'   )inspect	signaturerZ   
parametersitemsrI   	ParameteremptykindPOSITIONAL_ONLYPOSITIONAL_OR_KEYWORDappendaddtuple)fsigrU   rV   rW   kvs   &      r   rR   rR   8  s    


A
CKL5D$$&99G--333YYKN66--33
 
 		* ' l+T11r,   try_lastc               4    \         P                  ! WW#4       R# )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   set_global_backend)r_   r`   ra   rx   s   &&&$r   rz   rz   J  s    @ w?r,   c                2    \         P                  ! V 4       R# )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   register_backend)r_   s   &r   r|   r|   m  s     W%r,   Tc                4    \         P                  ! WV4       R# )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   clear_backends)rH   
registeredglobalss   &&&r   r~   r~   }  s    8 6w7r,   c                   >   a  ] tR tRt o RtRR ltR tR t]tRt	V t
R# )	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                *    Wn         W n        W0n        R # r'   )valuetype	coercible)selfr   dispatch_typer   s   &&&&r   __init__Dispatchable.__init__  s    
!	"r,   c                @    V P                   V P                  3V,          # r'   )r   r   )r   indexs   &&r   __getitem__Dispatchable.__getitem__  s    		4::&u--r,   c                l    R \        V 4      P                   RV P                   : RV P                  : R2# )<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   r    r!   __firstlineno____doc__r   r   r   __repr____static_attributes____classdictcell__)__classdict__s   @r   r	   r	     s!     6#
.T Hr,   c                :    \         P                  ! \        V R7      # )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   )rS   partialr	   r   s   &r   mark_asr     s     \GGr,   c                   a  V 3R lpV# )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   <a  \         P                  ! S 4      VV 3R  l4       pV# )c                  x   < S! V / VB p\         ;QJ d    . V3R  lV 4       F  NK  	  5# ! V3R  lV 4       4      # )c              3   l   <"   T F)  p\        V\        4      '       g   \        VS4      MTx  K+  	  R # 5ir'   
isinstancer	   ).0argarg_types   & r   	<genexpr><all_of_type.<locals>.outer.<locals>.inner.<locals>.<genexpr>  s:       *C "#|44 S(+ *   14)rs   )r?   r@   extracted_argsr   r   s   *, r   inner)all_of_type.<locals>.outer.<locals>.inner  sH    !4262N5  *	5 5  *	  r,   rS   wraps)r   r   r   s   f r   outerall_of_type.<locals>.outer  s%    			 
	 r,   r5   )r   r   s   f r   all_of_typer     s     Lr,   c                F   a  \         P                  ! S 4      V 3R l4       pV# )
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                    < . pV  FX  pS! VP                   VP                  T;'       d    VP                  4      pV\        J d	   \        u # VP	                  V4       KZ  	  V# r'   r   r   r   NotImplementedrq   )dispatchablesr`   	converteddcconvert_singles   &&   r   __ua_convert__-wrap_single_convertor.<locals>.__ua_convert__  sX    	Aqww0F0F1;;GAN"%%Q  r,   r   r   r   s   f r   wrap_single_convertorr     (     __^$
 %
 r,   c                F   a  \         P                  ! S 4      V 3R l4       pV# )r   c                    < . pV FX  pS! YP                   VP                  T;'       d    VP                  4      pV\        J d	   \        u # VP	                  V4       KZ  	  V# r'   r   )r   r   r`   r   r   r   r   s   &&&   r   r   6wrap_single_convertor_instance.<locals>.__ua_convert__  sX    	AtWWafff6L6LMAN"%%Q  r,   r   r   s   f r   wrap_single_convertor_instancer   
  r   r,   ra   r`   c               d    \        WV4      3p\        P                  ! W%V4      p\        WdVR7      # )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

r`   ra   )r	   r   determine_backendrc   )r   r   rH   ra   r`   r   r_   s   &&$$$  r   r   r   #  s3    H "%?AM''vFGwD99r,   c                 a RV9   dE   VP                  R4      o\        ;QJ d    . V3R lV  4       F  NK  	  5M! V3R lV  4       4      p MP\        V 4      p \        ;QJ d    R V  4       F  '       d   K   RM	  RM! R V  4       4      '       g   \        R4      h\	        V4      ^ 8w  d   \        RV 24      h\
        P                  ! WV4      p\        WSVR7      # )	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   l   <"   T F)  p\        V\        4      '       d   TM\        VS4      x  K+  	  R # 5ir'   r   )r   r   	disp_types   & r   r   *determine_backend_multi.<locals>.<genexpr>  s0      
" A|,,A,q)2LL"r   c              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir'   r   )r   r   s   & r   r   r     s     F1:a..s   FTz6dispatchables must be instances of uarray.Dispatchablez'Received unexpected keyword arguments: r   )poprs   all	TypeErrorlenr   r   rc   )r   rH   ra   r`   r@   r_   r   s   &$$$, @r   determine_backend_multir   m  s    L & JJ/	 
"
 
"
 

 m,sFFsssFFFFTUU
6{aA&JKK''vFGwD99r,   )rc   rz   rf   r|   r   r   r~   rC   r=   r   r   r	   r   r   r   r   r7   r4   r8   r   r   r   )r	   .r'   )FF)TF)-rM   r   rh   rS    r   copyregr   
contextlibr[   r   r   r   r   r   __all__rN   rs   rJ   dictrK   r   r%   r+   r0   r2   r4   contextmanagerr8   r7   rC   r=   rc   rf   rR   rz   r|   r~   r	   r   r   r   r   r   r   r5   r,   r   <module>r      s            2 U3F-G(GH 
D%%t,, %(7$<-. y/ * w$$l 3 !#= > "$? @   + +"*KA\>:2$ @e  @F& 8>' 'T
H<22G:D G: G:TV:#'V:05V:r,   