I am trying to use the scipy command gmres
. My matrix is ββdense and large, so my plan was to use the command LinearOperator
to 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 LinearOperator
that successfully performs the calculation A*x
, where A
is the matrix, and x
is 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 A
does not have dtype
. This is true because it A.dtype
returns an error. My problem is that I have no idea what to specify for dtype
. When I build my linear operator, dtype
there 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 = None
simply returns the default value, where dtype is not defined.
I also tried just determining A
to leave dtype
blank and then type A.dtype = None
. This actually gives the attribute A.dtype
and 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'