# [Scipy-tickets] [SciPy] #1225: Test errors in scipy.sparse when using MSVC/MKL build

SciPy Trac scipy-tickets@scipy....
Mon Apr 4 04:24:45 CDT 2011

```#1225: Test errors in scipy.sparse when using MSVC/MKL build
--------------------------+-------------------------------------------------
Reporter:  cjgohlke      |       Owner:  wnbell
Type:  defect        |      Status:  new
Priority:  normal        |   Milestone:  0.9.0
Component:  scipy.sparse  |     Version:  0.7.0
Keywords:                |
--------------------------+-------------------------------------------------
Changes (by ert):

Comment:

I just had a similar problem with the Enthought EPD 7.0 which includes
scipy 9.0rc2 with MKL and confirmed that it also exists with the latest
MKL of 9.0 on http://www.lfd.uci.edu/~gohlke/pythonlibs/

The code where splu fails and subsequently leads to a failure in spsolve
follows (Matrix from FEM solver for the heat equation):

{{{
from numpy import array
from scipy.linalg import solve, lu
from scipy.sparse import lil_matrix
from scipy.sparse.linalg import spsolve, splu

A = lil_matrix((8,8))
A[0, 0] = 2.58333333333
A[0, 4] = -1.5
A[0, 5] = -0.458333333333
A[1, 1] = 1.20833333333
A[1, 4] = 0.625
A[1, 5] = -1.45833333333
A[1, 6] = -0.75
A[2, 2] = 1.
A[3, 3] = 1.
A[4, 0] = -1.5
A[4, 1] = 0.625
A[4, 4] = 9.25
A[4, 5] = -3.
A[4, 6] = -3.25
A[5, 0] = -0.458333333333
A[5, 1] = -1.45833333333
A[5, 4] = -3.
A[5, 5] = 4.16666666667
A[6, 1] = -0.75
A[6, 4] = -3.25
A[6, 6] = 4.5
A[7, 7] = 1.

b = array((21.75, 1.75, 20., 20., 49., 1.5, 12., 20.))

A = A.tocsc()
print(spsolve(A, b))
print(splu(A))

}}}

The output is:

{{{
[  63.2213287   132.94040993   20.           20.           63.87622935
99.83437477   70.95623397   20.        ]
(array([[ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.],
[ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.],
[ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.],
[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.]]), array([[ 1.        ,
0.
,  0.        ,  0.        ,  0.        ,
0.        ,  0.        ,  0.        ],
[-0.17741935,  1.        ,  0.        ,  0.        ,  0.        ,
0.        ,  0.        ,  0.        ],
[ 0.        , -0.        ,  1.        ,  0.        ,  0.        ,
0.        ,  0.        ,  0.        ],
[ 0.        , -0.        ,  0.        ,  1.        ,  0.        ,
0.        ,  0.        ,  0.        ],
[-0.58064516, -0.42857143,  0.        ,  0.        ,  1.        ,
0.        ,  0.        ,  0.        ],
[ 0.        ,  0.51428571,  0.        ,  0.        , -0.22499175,
1.        ,  0.        ,  0.        ],
[ 0.        , -0.82857143,  0.        ,  0.        , -0.29820073,
-0.60394847,  1.        ,  0.        ],
[ 0.        , -0.        ,  0.        ,  0.        ,  0.        ,
-0.        ,  0.        ,  1.        ]]), array([[ 2.58333333,  0.
,  0.        ,  0.        , -1.5       ,
-0.45833333,  0.        ,  0.        ],
[ 0.        , -1.45833333,  0.        ,  0.        , -3.26612903,
4.08534946,  0.        ,  0.        ],
[ 0.        ,  0.        ,  1.        ,  0.        ,  0.        ,
0.        ,  0.        ,  0.        ],
[ 0.        ,  0.        ,  0.        ,  1.        ,  0.        ,
0.        ,  0.        ,  0.        ],
[ 0.        ,  0.        ,  0.        ,  0.        ,  6.97926267,
-1.51526498, -3.25      ,  0.        ],
[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
-2.44195898,  3.76877682,  0.        ],
[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
0.        ,  0.55699464,  0.        ],
[ 0.        ,  0.        ,  0.        ,  0.        ,  0.        ,
0.        ,  0.        ,  1.        ]]))
[ 21.75   1.75  20.    20.    49.     1.5   12.    20.  ]
Traceback (most recent call last):
File "sparsetest.py", line 37, in <module>
print(splu(A))
File "C:\Python27\lib\site-
packages\scipy\sparse\linalg\dsolve\linsolve.py", l
ine 173, in splu
ilu=False, options=_options)
RuntimeError: Factor is exactly singular
}}}

Note that spsolve silently failes and returns the vector b instead of the
solution and splu throws a singularity error. The matrix is not singular
as the dense LU shows.

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1225#comment:4>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```