Skip to content

possible issue with error message of sparse iterative solvers #12624

@gokhalen

Description

@gokhalen

My issue is about the error message reported with sparse iterative solver. I'm using scipy version 1.5.0 on Windows 10 under Anaconda.

Reproducing code example:

import numpy as np
from scipy.sparse.linalg import *  # gets solvers
from scipy import sparse,linalg

data=(1,1,1)
rows=(0,1,2)
cols=(0,1,2)

kk=sparse.coo_matrix((data,(rows,cols)),shape=(3,3))

data=(1,1,1)
rows=(0,1,2)
cols=(0,0,0)
rhs=sparse.coo_matrix((data,(rows,cols)),shape=(3,1))

The following

x,exitCode=bicg(kk,rhs)

yields the error message

Error message:

Traceback (most recent call last):

  File "G:\Work\Misc\sparserhsbugreport.py", line 23, in <module>
    x,exitCode=bicg(kk,rhs)

  File "<decorator-gen-1>", line 2, in bicg

  File "C:\Users\aa\anaconda3\envs\py383\lib\site-packages\scipy\_lib\_threadsafety.py", line 44, in caller
    return func(*a, **kw)

  File "C:\Users\aa\anaconda3\envs\py383\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 151, in bicg
    A,M,x,b,postprocess = make_system(A, M, x0, b)

  File "C:\Users\aa\anaconda3\envs\py383\lib\site-packages\scipy\sparse\linalg\isolve\utils.py", line 74, in make_system
    raise ValueError('A and b have incompatible dimensions')

ValueError: A and b have incompatible dimensions

However, the following works:

x,exitCode=bicg(kk,rhs.todense())

as noted here. This shows that the problem is not the dimensions of the rhs. The issue is that the rhs is a sparse vector. Maybe a better error message saying "Sparse right hand sides are not allowed" instead of the misleading "A and b have incompatible dimensions"

Scipy/Numpy/Python version information:

1.5.0 1.18.5 sys.version_info(major=3, minor=8, micro=3, releaselevel='final', serial=0)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions