pylops.TorchOperator¶
- class pylops.TorchOperator(Op, batch=False, flatten=True, device='cpu', devicetorch='cpu')[source]¶
Wrap a PyLops operator into a Torch function.
This class can be used to wrap a pylops operator into a torch function. Doing so, users can mix native torch functions (e.g. basic linear algebra operations, neural networks, etc.) and pylops operators.
Since all operators in PyLops are linear operators, a Torch function is simply implemented by using the forward operator for its forward pass and the adjoint operator for its backward (gradient) pass.
- Parameters:
- Op
pylops.LinearOperator PyLops operator
- batch
bool, optional Input has single sample (
False) or batch of samples (True). Ifbatch=False, the input must be a 1-d Torch tensor of sizeOp.shape[1]forflatten=Trueor a tensor of sizeOp.dimsforflatten=False; ifbatch=True, the input must be a 2-d Torch tensor of size[nbatch, Op.shape[1]]forflatten=Trueor a tensor of size[nbatch, *Op.dims]forflatten=False, wherenbatchis the size of the batch. The output follows the same convention withOp.shape[0]andOp.dimsd. When usingadjoint, the roles ofOp.shape[1]/Op.dimsandOp.shape[0]/Op.dimsdare swapped.- flatten
bool, optional Input beyond the batch dimension is flattened (
True) or not (False). Seebatchfor more details.- device
str, optional Device to be used when applying operator (
cpuorgpu)- devicetorch
str, optional Device to be assigned the output of the operator to (any Torch-compatible device)
- Op
- Attributes:
- transpf
numpy.ndarray Deprecated, will be removed in v3.0.0. Indices to transpose batch to last dimension before applying
Op- transpb
numpy.ndarray Deprecated, will be removed in v3.0.0. Indices to transpose back batch to first dimension after applying
Op
- transpf
Methods
__init__(Op[, batch, flatten, device, ...])adjoint(x)Apply adjoint pass to input vector
apply(x)Apply forward pass to input vector
forward(x)Apply forward pass to input vector