TorchFuncRegistry¶
danling.tensors.TorchFuncRegistry
¶
Bases: Registry
TorchFuncRegistry
for extending PyTorch Tensor.
Source code in danling/tensors/utils.py
implement
¶
Implement an implementation for a torch function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function |
The torch function to implement. |
required |
Returns:
Name | Type | Description |
---|---|---|
function |
Callable
|
The registered function. |
Raises:
Type | Description |
---|---|
ValueError
|
If the function with the same name already registered and |
Examples:
Python Console Session
>>> import torch
>>> registry = TorchFuncRegistry("test")
>>> @registry.implement(torch.mean)
... def mean(input):
... raise input.mean()
>>> registry
TorchFuncRegistry(
(<built-in method mean of type object at ...>): <function mean at ...>
)