CallbackPrintIteration¶
-
class
odl.solvers.util.callback.
CallbackPrintIteration
(fmt='iter = {}', step=1, **kwargs)[source]¶ Bases:
odl.solvers.util.callback.Callback
Callback for printing the iteration count.
Methods
reset
(self)Set
iter
to 0.-
__init__
(self, fmt='iter = {}', step=1, \*\*kwargs)[source]¶ Initialize a new instance.
- Parameters
- fmtstring, optional
Format string for the text to be printed. The text is printed as:
print(fmt.format(cur_iter_num))
where
cur_iter_num
is the current iteration number.- steppositive int, optional
Number of iterations between output.
- Other Parameters
- kwargs :
Key word arguments passed to the print function.
Examples
Create simple callback that prints iteration count:
>>> callback = CallbackPrintIteration() >>> callback(None) iter = 0 >>> callback(None) iter = 1
Create callback that every 2nd iterate prints iteration count with a custom string:
>>> callback = CallbackPrintIteration(fmt='Current iter is {}.', ... step=2) >>> callback(None) Current iter is 0. >>> callback(None) # prints nothing >>> callback(None) Current iter is 2.
-