I am trying to use the scipy command gmres. My matrix is ββdense and large, so my plan was to use the command LinearOperatorto return only the vector matrix product. See my previous question here LinearOperator with two inputs . With the help of this question, I was able to build an object LinearOperatorthat successfully performs the calculation A*x, where Ais the matrix, and xis the vector.
The problem is what I'm calling gmres. I ran the command:
x, info = scipy.sparse.linalg.gmres(A, b)
and it returns an error that the operator Adoes not have dtype. This is true because it A.dtypereturns an error. My problem is that I have no idea what to specify for dtype. When I build my linear operator, dtypethere is an optional parameter for, but I do not know what to give it.
I tried to skip dtype='float64'and it froze my IDE, so I suspect I'm wrong there.
The attempt dtype = Nonesimply returns the default value, where dtype is not defined.
I also tried just determining Ato leave dtypeblank and then type A.dtype = None. This actually gives the attribute A.dtypeand gives a different error when called A.
This seems to be related to another problem, which is that gmres seems to want it to be given a precondition. I actually do not have the pre-conditioner that I want to give him, so he tries to build one, and he tries to use the same dtype type as A, but since A does not have the dtype attribute, it throws errors. Any suggestion would be greatly appreciated.
A = sparse.scipy.linalg.linearoperator(shape = (n,n), matvec = mv, dtype = 'float64')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/iterative.py", line 393, in gmres
A,M,x,b,postprocess = make_system(A,M,x0,b,xtype)
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/utils.py", line 119, in make_system
M = LinearOperator(A.shape, matvec=psolve, rmatvec=rpsolve, dtype=A.dtype)
AttributeError: LinearOperator instance has no attribute 'dtype'