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==Falsethe input must be a 1-d Torch tensor or a tensor of size equal toOp.dims; ifbatch==Truethe input must be a 2-d Torch tensor with batches along the first dimension or a tensor of size equal to[nbatch, *Op.dims]wherenbatchis the size of the batch- flatten
bool, optional Input is flattened along
Op.dims(True) or not (False)- 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 Indices to transpose batch to last dimension before applying
Op- transpb
numpy.ndarray Indices to transpose back batch to first dimension after applying
Op
- transpf
Methods
__init__(Op[, batch, flatten, device, ...])apply(x)Apply forward pass to input vector