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.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Chris Lowis
  • 560
  • 4
  • 14

3 Answers3

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.

HMCFletch
  • 1,046
  • 1
  • 10
  • 19
  • Fantastic, thank you. I've taken a look at your library before, but it seems like you've made some considerable changes. Much appreciated! – Chris Lowis Sep 24 '11 at 13:23
  • @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. – Translunar Oct 13 '11 at 22:37
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.

Bill Dueber
  • 2,706
  • 17
  • 16
  • 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. – Chris Lowis Jul 27 '11 at 08:10
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. =)

Translunar
  • 3,739
  • 33
  • 55
  • 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! – Chris Lowis Oct 21 '11 at 11:58
  • 1
    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. – Translunar Apr 26 '12 at 18:54