To illustrate the @cel comment, you can implement a simple counter class as follows:
class gmres_counter(object):
def __init__(self, disp=True):
self._disp = disp
self.niter = 0
def __call__(self, rk=None):
self.niter += 1
if self._disp:
print('iter %3i\trk = %s' % (self.niter, str(rk)))
You would use it as follows:
import numpy as np
from scipy.sparse.linalg import gmres
A = np.random.randn(10, 10)
b = np.random.randn(10)
counter = gmres_counter()
x, info = gmres(A, b, callback=counter)
print(counter.niter)
source
share