欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Python torch.overrides.handle_torch_function实例讲解

最编程 2024-01-12 20:14:22
...

实现一个检查__torch_function__ 覆盖的函数。

请参阅 torch::autograd::handle_torch_function 以了解 C++ 实现中此函数的等效项。

:raises TypeError:if no implementation is found.:

示例

>>> def func(a):
...     if type(a) is not torch.Tensor: # This will make func dispatchable by __torch_function__
...         return handle_torch_function(func, (a,), a)
...     return a + 0