Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scipy sparse dia_matrix solver

In a scipy program I'm creating a dia_matrix (sparse matrix type) with 5 diagonals. The centre diagonal the +1 & -1 diagonals and the +4 & -4 diagonals (usually >> 4, but the principle is the same), i.e. I have a typical PDE system matrix of the form:

[ a0  b0  0   0   0   d0  0   0   0  ... 0.0 ]
[ c1  a1  b1  0   0   0   d1  0   0  ... 0.0 ]
[ 0   c2  a2  b2  0   0   0   d2  0  ... 0.0 ]
[ 0   0   c3  a3  b3  0   0   0   d3 ... 0.0 ]
[ 0   0   0   c4  a4  b4  0   0   0  ... 0.0 ]
[ e5  0   0   0   c5  a5  b5  0   0  ... 0.0 ]
[ :   :   :   :   :   :   :   :   :   :  :   ]
[ 0   0   0   0   0   0   0   0   0  ... aN  ]

When I use scipy.linalg.dsolve.spsolve() to solve the matrix equation it works but I get the following reported back to me

>>> SparseEfficiencyWarning: spsolve requires CSC or CSR matrix format
    warn('spsolve requires CSC or CSR matrix format', SparseEfficiencyWarning)

If spsolve() is not efficient for solving the sparse matrix type dia_matrix's then what should I be using?

like image 416
dmon Avatar asked Oct 28 '25 05:10

dmon


1 Answers

The warning says it all, I think. Looks like it wants you to use a csr_matrix or a csc_matrix.

I'm assuming you're creating your matrix with scipy.sparse.diags. You should just be able to use format = 'csr' or format = 'csc' when you construct the matrix.

like image 162
John Vinyard Avatar answered Oct 29 '25 20:10

John Vinyard