本文簡要介紹python語言中 torch.overrides.wrap_torch_function
的用法。
用法:
torch.overrides.wrap_torch_function(dispatcher)
dispatcher(可調用) -返回傳遞給函數的 Tensor-likes 的可迭代對象的可調用對象。
使用與
__torch_function__
相關的函數包裝給定函數。注意
此裝飾器可能會降低代碼的性能。通常,將您的代碼表達為一係列本身支持 __torch_function__ 的函數就足夠了。如果您發現自己處於罕見的情況並非如此,例如如果您正在包裝一個低級庫並且您還需要它為Tensor-likes 工作,那麽這個函數是可用的。
例子
>>> def dispatcher(a): # Must have the same signature as func ... return (a,) >>> @torch.overrides.wrap_torch_function(dispatcher) >>> def func(a): # This will make func dispatchable by __torch_function__ ... return a + 0
參數:
相關用法
- Python PyTorch wrap用法及代碼示例
- Python PyTorch wav2vec2_model用法及代碼示例
- Python PyTorch weight_norm用法及代碼示例
- Python PyTorch where用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
- Python PyTorch cholesky用法及代碼示例
- Python PyTorch vdot用法及代碼示例
- Python PyTorch ELU用法及代碼示例
- Python PyTorch ScaledDotProduct.__init__用法及代碼示例
- Python PyTorch gumbel_softmax用法及代碼示例
- Python PyTorch get_tokenizer用法及代碼示例
- Python PyTorch saved_tensors_hooks用法及代碼示例
- Python PyTorch positive用法及代碼示例
- Python PyTorch renorm用法及代碼示例
- Python PyTorch AvgPool2d用法及代碼示例
- Python PyTorch MaxUnpool3d用法及代碼示例
- Python PyTorch Bernoulli用法及代碼示例
- Python PyTorch Tensor.unflatten用法及代碼示例
- Python PyTorch Sigmoid用法及代碼示例
- Python PyTorch Tensor.register_hook用法及代碼示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代碼示例
- Python PyTorch sqrt用法及代碼示例
- Python PyTorch PackageImporter.id用法及代碼示例
- Python PyTorch column_stack用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.overrides.wrap_torch_function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。