nlop.TorchOperator

Contents

nlop.TorchOperator#

class bartorch.nlop.TorchOperator#

Bases: NonlinearOperator

Nonlinear operator from a differentiable PyTorch function.

The derivative is torch.func.jvp and its adjoint torch.autograd.grad, both at the last evaluated point.

Parameters:
  • fn (callable) – Differentiable function of one tensor per input, returning one tensor per output.

  • ishape (tuple of int or sequence of tuple of int) – Domain and codomain, C order; a sequence of shapes gives that many inputs or outputs.

  • oshape (tuple of int or sequence of tuple of int) – Domain and codomain, C order; a sequence of shapes gives that many inputs or outputs.

Notes

BART’s operators are complex: a real argument arrives as w + 0j, and its gradient is complex, of which the real part is the gradient by w.

Examples

>>> F = TorchOperator(lambda p: p[0] * torch.exp(-t / p[1]), (2,), t.shape)
>>> nlop.IRGNM()(measured, F, x0=torch.tensor([1.0, 20.0]))

Also has the methods and properties of NonlinearOperator.