Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 451
Hari Avatar asked Nov 01 '25 12:11

Hari


1 Answers

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
like image 68
Abhilash Reddy M Avatar answered Nov 04 '25 03:11

Abhilash Reddy M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!