CallbackPrint

class odl.solvers.util.callback.CallbackPrint(func=None, fmt='{!r}', step=1, **kwargs)[source]

Bases: odl.solvers.util.callback.Callback

Callback for printing the current value.

Methods

reset(self)

Set iter to 0.

__init__(self, func=None, fmt='{!r}', step=1, \*\*kwargs)[source]

Initialize a new instance.

Parameters
funccallable, optional

Deprecated, use composition instead. See examples. Functional that should be called on the current iterate before printing. Default: print current iterate.

fmtstring, optional

Formating that should be applied. Will be used as

print(fmt.format(x))

where x is the input to the callback.

steppositive int, optional

Number of iterations between prints.

Other Parameters
kwargs :

Key word arguments passed to the print function.

Examples

Callback for simply printing the current iterate:

>>> callback = CallbackPrint()
>>> callback([1, 2])
[1, 2]

Apply function before printing via composition:

>>> callback = CallbackPrint() * np.sum
>>> callback([1, 2])
3

Format to two decimal points:

>>> callback = CallbackPrint(fmt='{0:.2f}') * np.sum
>>> callback([1, 2])
3.00