The most efficient way to store large symmetric sparse matrices in python

I worked on compiling / testing a technique that I developed to solve differential equations for speed and efficiency.

This will require storage, manipulation, resizing and (at some point), probably, diagonalization of very large sparse matrices. I would like to have lines consisting of zeros and several (say, 5) units, and add them several times (in order of the number of processor used).

I thought it would be useful to have gpu accelleration - so any suggestions as to the best way to take advantage of this would also be appreciated (say pycuda, theano, etc.)

+5
source share
3 answers

You can use vocabulary and tuples to access data:

>>> size = (4,4)
>>> mat = {}
>>> mat[0,1] = 3
>>> mat[2,3] = 5
>>> for i in range(size[0]):
        for j in range(size[1]):
            print mat.get((i,j), 0) ,
        print

0 3 0 0
0 0 0 0
0 0 0 5
0 0 0 0

Of course, you should make a class for this and add the methods you need:

class Sparse(dict):
    pass

BTW, you can also use scipy.sparsefrom scipy lib

+4
source

, , ( , Intel MKL, ). AFAIK scipy.sparse , . Pysparse, . Pysparse, , , . , , Pysparse scipy ( , , , ), , , , scipy.

+7
+3

All Articles