I am attempting to use Scipy's gmres
command. My matrix is dense and large, so my plan was to use the LinearOperator
command to return only the matrix vector product. Please see my previous question here LinearOperator with Two Inputs. With help from that question, I was able to build a LinearOperator
object which successfully does the computation A*x
where A
is the matrix and x
is the vector.
The problem is when I call gmres
. I run the command:
x, info = scipy.sparse.linalg.gmres(A, b)
and it returns the error that the operator A
has no dtype
. This is true, as A.dtype
returns an error. My problem is that I have no idea what to specify for dtype
. When I construct my linear operator, there is an optional parameter to pass for dtype
, but I do not know what to give it.
I tried passing dtype='float64'
and that froze my IDE, so I suspect I'm wrong there.
Trying dtype = None
just yields the default, where dtype is not defined.
I also tried simply defining A
leaving dtype
blank, and then typing A.dtype = None
. This actually gives the attribute A.dtype
and yields another error when calling A
.
This seems to be linked to another problem, which is that the gmres seems to want a preconditioner given to it. I don't actually have a pre-conditioner I want to give it, so it tries to construct one and it tries to use the same dtype as A but, since A has no dtype attribute it errors out. 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'