zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
U
O±d}!ã@s¦dZddlZddlZddlZddlmZmZmZddlm    Z    e
e ej   dd¡ƒƒZdZdd    „Zeed
ƒeed ƒe d d ¡Zdd„Zdd„Zddd„Zddd„ZdS)z;Implementation of __array_function__ overrides from NEP-18.éN)Ú add_docstringÚimplement_array_functionÚ_get_implementing_args)Ú
getargspecZ!NUMPY_EXPERIMENTAL_ARRAY_FUNCTIONéarlike : array_like, optional
        Reference object to allow the creation of arrays which are not
        NumPy arrays. If an array-like passed in as ``like`` supports
        the ``__array_function__`` protocol, the result will be defined
        by it. In this case, it ensures the creation of an array object
        compatible with that passed in via this argument.cCs|jdk    r|j dt¡|_|S)Nz${ARRAY_FUNCTION_LIKE})Ú__doc__ÚreplaceÚarray_function_like_doc)Ú
public_api©r úKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/core/overrides.pyÚset_array_function_like_docs 
þr aû
    Implement a function with checks for __array_function__ overrides.
 
    All arguments are required, and can only be passed by position.
 
    Parameters
    ----------
    implementation : function
        Function that implements the operation on NumPy array without
        overrides when called like ``implementation(*args, **kwargs)``.
    public_api : function
        Function exposed by NumPy's public API originally called like
        ``public_api(*args, **kwargs)`` on which arguments are now being
        checked.
    relevant_args : iterable
        Iterable of arguments to check for __array_function__ methods.
    args : tuple
        Arbitrary positional arguments originally passed into ``public_api``.
    kwargs : dict
        Arbitrary keyword arguments originally passed into ``public_api``.
 
    Returns
    -------
    Result from calling ``implementation()`` or an ``__array_function__``
    method, as appropriate.
 
    Raises
    ------
    TypeError : if no implementation is found.
    ar
    Collect arguments on which to call __array_function__.
 
    Parameters
    ----------
    relevant_args : iterable of array-like
        Iterable of possibly array-like arguments to check for
        __array_function__ methods.
 
    Returns
    -------
    Sequence of arguments with __array_function__ methods, in the order in
    which they should be called.
    ÚArgSpeczargs varargs keywords defaultscCs¤tt|ƒŽ}tt|ƒŽ}|j|jksn|j|jksn|j|jksnt|jƒt|jƒksn|jdk    rzt|jƒt|jƒkrztd|ƒ‚|jdk    r |jdt|jƒkr tdƒ‚dS)z:Verify that a dispatcher function has the right signature.NzGimplementation and dispatcher for %s have different function signatures©NzBdispatcher functions can only use None for default argument values)    rrÚargsÚvarargsÚkeywordsÚboolÚdefaultsÚlenÚ RuntimeError)ÚimplementationÚ
dispatcherZimplementation_specZdispatcher_specr r r Úverify_matching_signaturesXs.   
ÿ
þÿýûÿúÿ
rcs‡fdd„}|S)zÉDecorator for overriding __module__ on a function or class.
 
    Example usage::
 
        @set_module('numpy')
        def example():
            pass
 
        assert example.__module__ == 'numpy'
    csˆdk    rˆ|_|Sr)Ú
__module__)Úfunc©Úmoduler r Ú    decoratoryszset_module.<locals>.decoratorr )rrr rr Ú
set_modulens rTFcs0ts‡‡‡fdd„}|S‡‡‡‡‡fdd„}|S)a•Decorator for adding dispatch with the __array_function__ protocol.
 
    See NEP-18 for example usage.
 
    Parameters
    ----------
    dispatcher : callable
        Function that when called like ``dispatcher(*args, **kwargs)`` with
        arguments from the NumPy function call returns an iterable of
        array-like arguments to check for ``__array_function__``.
    module : str, optional
        __module__ attribute to set on new function, e.g., ``module='numpy'``.
        By default, module is copied from the decorated function.
    verify : bool, optional
        If True, verify the that the signature of the dispatcher and decorated
        function signatures match exactly: all required and optional arguments
        should appear in order with the same names, but the default values for
        all optional arguments should be ``None``. Only disable verification
        if the dispatcher's signature needs to deviate for some particular
        reason, e.g., because the function has a signature like
        ``func(*args, **kwargs)``.
    docs_from_dispatcher : bool, optional
        If True, copy docs from the dispatcher function onto the dispatched
        function, rather than from the implementation. This is useful for
        functions defined in C, which otherwise don't have docstrings.
 
    Returns
    -------
    Function suitable for decorating the implementation of a NumPy function.
    cs"ˆrt|ˆjƒˆdk    rˆ|_|Sr)rrr©r)rÚdocs_from_dispatcherrr r r¢s
 z*array_function_dispatch.<locals>.decoratorcsfˆrtˆˆƒˆrtˆˆjƒt ˆ¡‡‡‡‡fdd„ƒ‰ˆjjˆjddˆ_ˆdk    r\ˆˆ_ˆˆ_    ˆS)Nc
s‚zˆ||Ž}Wn`tk
rn}zB|jd}ˆj}t|tƒrD| |¡sF‚| |ˆj¡}t|ƒd‚W5d}~XYnXtˆˆ|||ˆƒS)Nr)Ú    TypeErrorrÚ__name__Ú
isinstanceÚstrÚ
startswithrr)rÚkwargsZ relevant_argsÚexcÚmsgZ    disp_nameZnew_msg)rrr
Úuse_liker r r
±s"
 
þz>array_function_dispatch.<locals>.decorator.<locals>.public_apiz<__array_function__ internals>)Úco_nameÚ co_filename)
rrrÚ    functoolsÚwrapsÚ__code__rr#rZ_implementationr ©rr!rr*Úverify)rr
r rªs
 þ)ÚARRAY_FUNCTION_ENABLED)rrr1r!r*rr r0r Úarray_function_dispatch€s
!,r3cs‡‡‡‡fdd„}|S)zDLike array_function_dispatcher, but with function arguments flipped.cst|ˆˆˆdˆƒS)N)r1r!)r3)r©r!rrr1r r rÝsþþz1array_function_from_dispatcher.<locals>.decoratorr )rrr1r!rr r4r Úarray_function_from_dispatcherÙsr5)NTFF)NTT)rÚ collectionsr-ÚosZnumpy.core._multiarray_umathrrrZnumpy.compat._inspectrrÚintÚenvironÚgetr2r    r Ú
namedtuplerrrr3r5r r r r Ú<module>s< ÿÿ        þ#þ ÿ
Zÿ