nlop.TorchOperator#
- class bartorch.nlop.TorchOperator#
Bases:
NonlinearOperatorA nonlinear operator from a differentiable torch function.
The derivative is torch’s forward-mode Jacobian-vector product, and its adjoint the reverse-mode vector-Jacobian product, both at the last evaluated point.
- Parameters:
fn (callable) – A differentiable function on tensors. With several input shapes it takes that many arguments, and it may return several tensors.
ishape (tuple of int, or a sequence of them) – Domain and codomain, C order.
oshape (tuple of int, or a sequence of them) – Domain and codomain, C order.
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]))
Notes
A real argument is carried in the real part of a complex one: BART’s operators are complex throughout, so a weight arrives as
w + 0jand its gradient comes back complex. Take the real part of it.
Also has the methods and properties of NonlinearOperator.