�
J��gl� � �$ � d Z ddlZddlZddlZddlZddlZddlmZmZm Z m
Z
mZmZm
Z
mZ ddlmZ ddlZddlZddlmZmZmZmZmZmZmZmZmZ g d�Z d+d ed
ededefd
�Z ej d� � edee fd�� � � � Z ej d� � dee fd�� � Z! ej d� � edeeef fd�� � � � Z"defd�Z#d,dee
dee
ge
f de e
fd�Z$dedee
de
fd�Z% eed� � Z& eed� � Z' eed� � Z( ej d� � deee
e e f eeef f fd�� � Z)edee
e e f fd�� � Z*ed� � � Z+ ej d� � dee fd�� � Z,ed ede-fd�� � Z.d � Z/ G d!� d"� � Z0d#� Z1d$� Z2d%� Z3d&� Z4ej5 d'� � � Z6 G d(� d)e0� � Z7ej5 d*� � � Z8dS )-aE
Python implementation of ``__torch_function__``
While most of the torch API and handling for ``__torch_function__`` happens
at the C++ level, some of the torch API is written in Python so we need
python-level handling for ``__torch_function__`` overrides as well. The main
developer-facing functionality in this file are handle_torch_function and
has_torch_function. See torch/functional.py and test/test_overrides.py
for usage examples.
Note
----
heavily inspired by NumPy's ``__array_function__`` (see:
https://github.com/pytorch/pytorch/issues/24015 and
https://www.numpy.org/neps/nep-0018-array-function-protocol.html
)
If changing this file in a way that can affect ``__torch_function__`` overhead,
please report the benchmarks in ``benchmarks/overrides_benchmark``. See the
instructions in the ``README.md`` in that directory.
� N)�Dict�Set�List�Any�Callable�Iterable�Type�Tuple��wraps) �_has_torch_function�_has_torch_function_unary�_has_torch_function_variadic�_add_docstr�_push_on_torch_function_stack�_pop_torch_function_stack�_get_function_stack_at�_len_torch_function_stack�_is_torch_function_mode_enabled)
�get_ignored_functions�get_overridable_functions�get_testing_overrides�handle_torch_function�has_torch_function�resolve_name�is_tensor_like�is_tensor_method_or_property�wrap_torch_function�enable_reentrant_dispatch�.*is deprecated, please use.*�torch�func�regex�module�returnc �D � ��� t � � � � ��fd�� � }|S )a
Decorator that temporarily disables ``UserWarning``s for the given ``module`` if the warning message matches the
given ``regex`` pattern.
Arguments
---------
func : function
Function to disable the warnings for.
regex : str
A regex pattern compilable by ``re.compile``. This is used to match the ``UserWarning`` message.
module : str
The python module to which the filtering should be restricted.
Returns
-------
function
The wrapped function.
c � �� t j � � 5 t j dt ���� � �| i |��cd d d � � S # 1 swxY w Y d S )N�ignore)�category�messager$ )�warnings�catch_warnings�filterwarnings�UserWarning)�args�kwargsr"