How to retrieve how many iterations ran to achieve specified tolerance level in SciPy sparse linear system solvers?
For Python 3, the following works:
def solve_sparse(A, b):
num_iters = 0
def callback(xk):
nonlocal num_iters
num_iters+=1
x,status=scipy.sparse.linalg.cg(A, b,tol=1e-15, callback=callback)
return x,status,num_iters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With