U C^9@sdZddlZddlZddlZddlZddlmZmZmZddl m Z e e ej ddZeedeeded d Zd d Zd dZedZdddZdddZdS)z;Implementation of __array_function__ overrides from NEP-18.N) add_docstringimplement_array_function_get_implementing_args) getargspecZ!NUMPY_EXPERIMENTAL_ARRAY_FUNCTIONa Implement a function with checks for __array_function__ overrides. All arguments are required, and can only be passed by position. Arguments --------- 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 defaultscCstt|}tt|}|j|jksn|j|jksn|j|jksnt|jt|jksn|jdk rzt|jt|jkrztd||jdk r|jdt|jkrtddS)z:Verify that a dispatcher function has the right signature.NzGimplementation and dispatcher for %s have different function signaturesNzBdispatcher functions can only use None for default argument values) rrargsvarargskeywordsbooldefaultslen RuntimeError)implementation dispatcherZimplementation_specZdispatcher_specr7/tmp/pip-install-6_kvzl1k/numpy/numpy/core/overrides.pyverify_matching_signaturesHs.      rcsfdd}|S)zDecorator for overriding __module__ on a function or class. Example usage:: @set_module('numpy') def example(): pass assert example.__module__ == 'numpy' csdk r|_|Sr) __module__)funcmodulerr decoratoriszset_module..decoratorr)rrrrr set_module^s rz @functools.wraps(implementation) def {name}(*args, **kwargs): relevant_args = dispatcher(*args, **kwargs) return implement_array_function( implementation, {name}, relevant_args, args, kwargs) TFcs.tsfdd}|Sfdd}|S)aDecorator 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|jdk r|_|Sr)r__doc__r)r)rdocs_from_dispatcherrrrrs  z*array_function_dispatch..decoratorcstrt|rt|jtj|jd}t|ddd}|ttd}t ||||j}dk rj|_ ||_ |S)N)namez<__array_function__ internals>exec)filenamemode)rr functoolsr) rrr_wrapped_func_sourceformat__name__compiler!rrrZ_implementation)rsourceZ source_objectscopeZ public_apirrrverifyrrrs*    )ARRAY_FUNCTION_ENABLED)rrr)rrrr(rarray_function_dispatch|s !!r+csfdd}|S)zDLike array_function_dispatcher, but with function arguments flipped.cst|dS)N)r)r)r+)rrrrr)rrrsz1array_function_from_dispatcher..decoratorr)rrr)rrrr,rarray_function_from_dispatchersr-)NTF)NTT)r collectionsr!ostextwrapZnumpy.core._multiarray_umathrrrZnumpy.compat._inspectrr intenvirongetr* namedtuplerrrdedentr"r+r-rrrrs8 #   O