Solving sparse linear systems in CSR format with complex values #6901
Labels
defect
A clear bug or issue that prevents SciPy from being installed or used as expected
good first issue
Good topic for first contributor pull requests, with a relatively straightforward solution
scipy.sparse
Milestone
Hello, I'm working on using some of scipy's sparse solvers for both real and complex problems, and I seem to have found an issue when solving linear systems Ax=b where A is a real -valued matrix in csc format, and b is a complex numpy array. When I try to solve such a system, I get the following warning:
and the vector x that is returned only contains the real part of the solution. Now, if we explicitly cast A to be a complex data type by way of the dtype=np.cfloat flag in the constructor, then everything turns out fine. Now the rub is that I often use the same matrix A to solve linear systems with both real and complex right-hand-sides, and it would make sense for the output to be the same as the input, i.e. x should be real when A and b are real, and it should be complex when either A or b is complex. Casting A to a complex data type returns x as a complex array, which it may not be when b is real. Here's a minimal working example to show the warning being thrown:
The text was updated successfully, but these errors were encountered: