Sparse Matrix Libraries for Ruby
Asked Answered
R

3

15

I'm looking for a Sparse Matrix library I can use from Ruby. I'm currently using the GNU Scientific Library bindings provided by the "gsl" gem, but my application would be better optimized if I used a dedicated sparse matrix library. I've investigated the linalg and NArray libraries. None of the these three libraries support sparse-matrix optimised storage or operations.

Is there anything out there I've missed - or an existing C library that may be possible to write bindings for? I'd prefer the former to that latter, as I haven't written C bindings in Ruby before, but I would be willing to attempt it.

Rising answered 18/7, 2011 at 7:57 Comment(0)
M
3

Like Bill mentioned above, the a pure ruby interpretation is going to be slower than you want, but might be good for prototyping. I have been working on just such a library over at https://github.com/hmcfletch/sparse-matrix

I haven't released it as a gem yet and there is more work to be done on it, but take a look at if you stil have a need.

Maurer answered 22/9, 2011 at 1:9 Comment(2)
Fantastic, thank you. I've taken a look at your library before, but it seems like you've made some considerable changes. Much appreciated!Rising
@HMCFletch, any interest in merging into SciRuby? We're working on an narray rewrite, and I was just about to start coding a sparse matrix.Likelihood
S
2

Pure ruby solutions are going to be ridiculously slow. I'd be tempted to pick up something like MTJ (http://code.google.com/p/matrix-toolkits-java/) and use it under JRuby.

There's a bunch of java code out there; much of it is pretty mature, although I don't know the space well enough to recommend a particular library. I can tell you that I've used java from jruby often and it's a joy to work with.

Shocking answered 26/7, 2011 at 0:25 Comment(1)
This looks like a good fit, thank you. I'd still be interested in something using FFI bindings so that it worked with different ruby versions, but this looks like a good approach. I'll have a look at the library and see if I can get it to work with JRuby.Rising
L
2

Have you seen SciRuby?

We don't have a sparse matrix implemented currently, but we're working on it. We're also in the process of rewriting NArray, with Masahiro Tanaka's blessing.

One goal is to have everything working in pure Ruby, in C (via GSL bindings, typically), and in Java for JRuby. (Pure Ruby would then be the fallback if GSL, etc., were unavailable.)

Side note: This is a terrible answer to this question. I post it here mainly so that anyone else who happens to be working on such things knows where to find us. =)

Likelihood answered 13/10, 2011 at 22:41 Comment(2)
Wow, no I hadn't - there was a scientific ruby project a long time ago, but I didn't realise it was still active. Thanks!Rising
Have you been keeping up to date on this at all? NMatrix's first alpha is out. gem install nmatrix. It's part of SciRuby and it has list-of-list and yale sparse support.Likelihood

© 2022 - 2024 — McMap. All rights reserved.