[SciPy-user] help about solver sparse matrix
David Warde-Farley
dwf@cs.toronto....
Sat Apr 19 18:49:45 CDT 2008
On 19-Apr-08, at 7:04 PM, Jose Lopez wrote:
> thanks
>
> but, how to get the number of iterations of the result?
There's no explicit support for this in the cgs method, but it does
let you pass in a function that gets called after iteration. You
could therefore use callbacks to keep track of how many iterations
your solution took. Take a look at the following example: I create an
object with a method "call" that updates it's internal 'cnt' variable
every time it gets called. (I commented out the print statement
because it'd be kind of long in this e-mail.
In [153]: from scipy import *
In [154]: class Counter:
.....: def __init__(self):
.....: self.cnt = 0
.....: def call(self, arg):
.....: self.cnt += 1
.....: # print "Iteration %3d: sqnorm=%5.4e" % (self.cnt,
sum(arg**2))
.....:
In [155]: c = Counter()
In [156]: A = abs(randn(50,50))
In [157]: A = sparse.csr_matrix(A + A.T)
In [158]: y = splinalg.cgs(A, randn(50), callback=c.call)
In [159]: c.cnt
Out[159]: 82
After that, stored inside the Counter object is the quantity you're
looking for.
Regards,
David
More information about the SciPy-user
mailing list