@@ -29,30 +29,32 @@ class Callbacks:
2929
3030 All methods take two input parameters: the solver itself, and the vector ``x``.
3131
32- Moreover, some callback may be used to implement custom stopping criteria for the solvers .
33- This can be done by adding a boolean attribute `stop` to the callback object, which will
34- be initially set to `False`. As soon as the callback sets this attribute to `True`, the
32+ Moreover, some callback may be used to implement custom stopping criteria for the solver .
33+ This can be done by adding a boolean attribute `` stop` ` to the callback object, which will
34+ be initially set to `` False`` . As soon as the callback sets this attribute to `` True` `, the
3535 ``run`` method of the solver will stop iterating and return the current model vector.
3636
3737 Examples
3838 --------
3939 >>> import numpy as np
4040 >>> from pylops.basicoperators import MatrixMult
41- >>> from pylops.optimization.solver import CG
41+ >>> from pylops.optimization.basic import CG
4242 >>> from pylops.optimization.callback import Callbacks
43+ >>>
4344 >>> class StoreIterCallback(Callbacks):
4445 ... def __init__(self):
4546 ... self.stored = []
4647 ... def on_step_end(self, solver, x):
4748 ... self.stored.append(solver.iiter)
48- >>> cb_sto = StoreIterCallback()
49+ >>>
4950 >>> Aop = MatrixMult(np.random.normal(0., 1., 36).reshape(6, 6))
5051 >>> Aop = Aop.H @ Aop
5152 >>> y = Aop @ np.ones(6)
53+ >>> cb_sto = StoreIterCallback()
5254 >>> cgsolve = CG(Aop, callbacks=[cb_sto, ])
5355 >>> xest = cgsolve.solve(y=y, x0=np.zeros(6), tol=0, niter=6, show=False)[0]
54- >>> xest
55- array([1., 1., 1., 1., 1., 1.])
56+ >>> xest, cb_sto.stored
57+ ( array([1., 1., 1., 1., 1., 1.]), [1, 2, 3, 4, 5, 6 ])
5658
5759 """
5860
0 commit comments