haripkannan haripkannan - 1 year ago 94
Python Question

Retrieving number of iterations that ran for sparse linear solver in SciPy

How to retrieve how many iterations ran to achieve specified tolerance level in SciPy sparse linear system solvers?

Answer Source

The solvers support a callback keyword argument that gets called after every iteration. So you could do something like this:

def solve_sparse(A, b):
  num_iters = 0

  def callback(xk):
    num_iters += 1

  # call the solver on your data
  return scipy.sparse.linalg.cg(A, b, callback=callback)[0]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download