The state of sparse matrices and algorithms support in core.matrix

97 views
Skip to first unread message

Alexey Cherkaev

unread,
Oct 29, 2014, 2:34:28 AM10/29/14
to numerica...@googlegroups.com
Hi all,

What is the current state of support of sparse matrices and algorithms that work with them? (My main interest is something like BiCG or GMRES)

Are there implementations that support them?

Regards,
Alexey

Mike Anderson

unread,
Oct 29, 2014, 2:48:57 AM10/29/14
to numerica...@googlegroups.com
Hi Alexey,

The core.matrix API is designed to work equally well with sparse and dense matrix implementations.

Vectorz has reasonable sparse array support and I've got most of the current core.matrix functionality working with sparse matrices in vectorz-clj, but I haven't yet got round to optimising / benchmarking all the different code paths so it should probably be regarded as a bit experimental. If this is something you need, I'd be happy to advise and accept contributions to get the vectorz-clj sparse matrix support up to a good level.

I'm not aware of any other implementation that has much in the way of sparse matrix support right now.

Alexey Cherkaev

unread,
Oct 30, 2014, 5:39:34 AM10/30/14
to numerica...@googlegroups.com
Hi Mike,

Thanks for the reply. As I've ben using Vectorz already, it's good to know that there is sparse matrix support for them.

In my project, at the moment, I end up with 3-diagonal matrices. Since, their structure is very regular, I can represent them simply as 3 vectors. However, if I change some parts of the algorithm (for example, if I use a proper Newton's method in non-linear solver), I will end up with more complex but still sparse matrices. On the top of this, I would also like to have a more general solver, than one tailored specifically for 3-diagonal matrix (sweep method or also known as Thomas algorithm, afaik).

Is there the info on basic usage of sparse matrices in core.matrix? Just, how to make them, access the elements (if different from dense matrices) and multiply by a vector (also if different).

On the top of it, are there implementations of CG, BiCG or GMRES for core.matrix? If not, I can start looking into it (can be my holiday project for Dec-Jan).

Cheers,
Alexey

Mike Anderson

unread,
Oct 31, 2014, 1:09:39 AM10/31/14
to numerica...@googlegroups.com
On Thursday, 30 October 2014 17:39:34 UTC+8, Alexey Cherkaev wrote:
Hi Mike,

Thanks for the reply. As I've ben using Vectorz already, it's good to know that there is sparse matrix support for them.

In my project, at the moment, I end up with 3-diagonal matrices. Since, their structure is very regular, I can represent them simply as 3 vectors. However, if I change some parts of the algorithm (for example, if I use a proper Newton's method in non-linear solver), I will end up with more complex but still sparse matrices. On the top of this, I would also like to have a more general solver, than one tailored specifically for 3-diagonal matrix (sweep method or also known as Thomas algorithm, afaik).


Vectorz has a BandedMatrix class that might help you here (it is a sparse representation that stores bands as individual vectors, so can represent your 3-diagonal matrix very efficiently.
 
Is there the info on basic usage of sparse matrices in core.matrix? Just, how to make them, access the elements (if different from dense matrices) and multiply by a vector (also if different).

The API is effectively the same: element access, inner products, addition etc is identical. You can, for most purposes, use sparse matrices in exactly the same was as any other array.

There is a also "sparse" API function that attempts to convert a matrix into a sparse format, e.g.

(clojure.core.matrix/sparse my-dense-matrix)

The behaviour of this is implementation dependent however - not all implementations support sparse matrices, so it is sort of a "best efforts" conversion at present. I'd be interested in ideas on how to improve this in a generic way.

If the "sparse" function doesn't do what you need, then you may need to construct the actual sparse matrices directly with the implementation's own API (e.g. initialising a Vectorz matrix via Java interop)

 

On the top of it, are there implementations of CG, BiCG or GMRES for core.matrix? If not, I can start looking into it (can be my holiday project for Dec-Jan).

Not at the moment - sounds like a good project to take on! Would also be great to use a project like this to test out and improve the sparse matrix support more generally.

Mike Anderson

unread,
Dec 27, 2014, 10:56:40 PM12/27/14
to numerica...@googlegroups.com
Hi Alexey,

If you are still interested in this topic, the sparse matrix support in vectorz-clj recently got a big upgrade. 

I think it should now be pretty good for your use cases - but would appreciate some testing / feedback if you have a chance!
Reply all
Reply to author
Forward
0 new messages