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:
Oppylops.LinearOperator

PyLops operator

batchbool, optional

Input has single sample (False) or batch of samples (True). If batch=False, the input must be a 1-d Torch tensor of size Op.shape[1] for flatten=True or a tensor of size Op.dims for flatten=False; if batch=True, the input must be a 2-d Torch tensor of size [nbatch, Op.shape[1]] for flatten=True or a tensor of size [nbatch, *Op.dims] for flatten=False, where nbatch is the size of the batch. The output follows the same convention with Op.shape[0] and Op.dimsd. When using adjoint, the roles of Op.shape[1]/Op.dims and Op.shape[0]/Op.dimsd are swapped.

flattenbool, optional

Input beyond the batch dimension is flattened (True) or not (False). See batch for more details.

devicestr, optional

Device to be used when applying operator (cpu or gpu)

devicetorchstr, optional

Device to be assigned the output of the operator to (any Torch-compatible device)

Attributes:
transpfnumpy.ndarray

Deprecated, will be removed in v3.0.0. Indices to transpose batch to last dimension before applying Op

transpbnumpy.ndarray

Deprecated, will be removed in v3.0.0. Indices to transpose back batch to first dimension after applying Op

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

Examples using pylops.TorchOperator

20. Torch Operator

20. Torch Operator