How to get how many iterations reached a certain tolerance level in SciPy sparse linear system solvers ?
Solvers support the keyword argument callback, which is called after each iteration. So you can do something like this:
callback
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]
For Python 3, the following actions are performed:
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
Source: https://habr.com/ru/post/1614374/More articles:Programmatically PREVENT USB Hibernation Windows (C #) - c #Enabling local dependencies when deployed to lambda - node.jsHow can I create an N tuple of type T? - c ++How to download the response native JS package from the network in Android? - androidGetting the number of iterations of an iterative scipy gmres method - pythonClojure: lightning → html - clojureJSON API Standard v1 Normalization - jsonНевозможно использовать функциональность gamecenter - swift2Adding to an array in parallel - swiftShould the service layer accept objects or an identifier as input? Should responses be objects? - javaAll Articles