o
�J�hd� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlmZ ddlm Z m
Z
mZmZm
Z
mZmZmZ ddlZddlmZmZmZmZmZmZmZmZmZ g d�Z d>d e
d
edede
fd
d�Ze�d�edee
fdd���Z e�d�dee
fdd��Z!e�d�edee
e
f fdd���Z"de
fdd�Z# d?dee de
e gef de
e fdd�Z$de
dee de fdd�Z%eed�Z&eed �Z'eed!�Z(e�d�deee e
e
f ee
ef f fd"d#��Z)edee e
e
f fd$d%��Z*ed&d'� �Z+e�d�dee
fd(d)��Z,ed e
de-fd*d+��Z.d,d-� Z/G d.d/� d/�Z0d0d1� Z1d2d3� Z2d4d5� Z3d6d7� Z4ej5d8d9� �Z6G d:d;� d;e0�Z7ej5d<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��wraps)�Any�Callable�Dict�Iterable�List�Set�Tuple�Type) �_add_docstr�_get_function_stack_at�_has_torch_function�_has_torch_function_unary�_has_torch_function_variadic�_is_torch_function_mode_enabled�_len_torch_function_stack�_pop_torch_function_stack�_push_on_torch_function_stack)
�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 s t � �� ��fdd��}|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 sL t �� � t jdt��d� � | i |��W d � S 1 sw Y d S )N�ignore)�category�messager# )�warnings�catch_warnings�filterwarnings�UserWarning)�args�kwargs�r! r# r"