[SciPy-User] How to assemble large sparse matrices effectively

Robert Cimrman cimrman3 at ntc.zcu.cz
Sat May 12 04:54:42 EDT 2012


Hello,

On 05/09/2012 07:44 PM, cp3028 wrote:
> Hello everyone,
>
> I am working on an FEM project using Scipy. Now my problem is, that
> the assembly of the sparse matrices is to slow. I compute the
> contribution of every element in dense small matrices (one for each
> element). For the assembly of the global matrices I loop over all
> small dense matrices and set the matrice entries the following way:
> ...
> [i,j] = someList[k][l]
> Mglobal[i,j] = Mglobal[i,j] + Mlocal[k,l]
> ...
>
> Mglobal is a lil_matrice of appropriate size, someList maps the
> indexing variables.

You can try to adapt [1], which is in Cython, and works with the CSR 
matrices.

Example usage:
assemble_matrix(m.data, m.indptr, m.indices, mtx_in_els,
                 element_indices, sign, row_connectivity,
                 column_connectivity)

- m is the global matrix in CSR format
- mtx_in_els is an array of element matrices of shape (n_elements, 1, 
n_rows, n_columns)
- element_indices are indices (of length n_elements) into the row and 
column element connectivity arrays.

r.

[1] 
https://github.com/sfepy/sfepy/blob/master/sfepy/fem/extmods/assemble.pyx




More information about the SciPy-User mailing list