views:

983

answers:

8

I'm looking for a good (well-tested, fully-featured, and ideally with a nice interface) matrix library for .NET/C#. My main requirements here are only that it should be free (I don't particularly care whether it's open-source in this case) and preferably support sparse matrix operations. The obligatory requirements are all the basic operations (e.g. multiplication, transposition, inversion) as well as finding eigenvalues & eigenvectors. Implementation of a numerical rather than/as well as analytical methods for discovery of eigenvalues, particularly the Lanczos algorithm for sparse matrices, would be highly preferable since the matrices I'm going to be dealing with are very large (lengths of 10,000 upwards) as well as square, and also reasonably sparse. Saying that, I could be asking for a bit much there, so any suggestions for a reasonably complete matrix library would be great.

Now I'm aware that Python has one or two useful libraries for such tasks (namely NumPy/SciPy), but .NET unfortunately seems to be lacking in the area.

A bit of searching turned up the following libraries for .NET, which I could potentially used:

However, since I have had no experience whatsoever using any of these libraries or others (and not exactly enough time to check each of them out properly in any case), I would very much appreciate if anyone here could discuss their recommendations regarding the various libraries, their pros/cons particularly with regards to suitability for my uses, and their general experiences with them.

Resorting to MatLab is always an option, but not a preferred one, as it would be much more convenient if I could integrate the matrix math directly with my program.

A: 

The now-defunct Managed DirectX library had some matrix support.

That has since been wrapped into Microsoft XNA, which is probably not a good fit for you, but the MDX Wikipedia article recommends something called SlimDX that might be okay.

Joel Coehoorn
Unfortunately, they're not really options for me given that they only support up to 4x4 matrices in size! I'm afraid I need something that can handle matrices with 1000s of rows/columns, and ideally handle sparse ones efficiently (when it comes to multiplication for example).
Noldorin
+2  A: 

I have us Mapack in the past and found it to be very good.

Although, I don't think it has Sparse matrices but it does support all the basic linear algegra functions.

JDunkerley
Yeah, there don't seem to be any with support for sparse matrices. Still, thanks for the recommendation.
Noldorin
+1  A: 

I used Mapack (the .Net port not the COM version) in a neural network project at university. I can't exactly remember the fine details of the library, but it did everything I needed it to and wasn't particularly onerous to use.

Ben Shepheard
Consensus seems to be (at least judging by two of the answers and the bit I've read elsewhere) that Mapack is the way to go as far as free libs, even though it isn't perfect. I'm also using matrix functionality for a university project, though it's physics-based one, so as long as I get the results out somehow it doesn't matter too much about the method. Anyway, thanks.
Noldorin
+2  A: 

Edit:

It wasn't quite there last time I evaluated it, but there has been quite a bit of activity, so you should also consider the (free and open source) dnAnalytics. (Hosted here on codeplex.)

In looking now, it seems they've finished their new version, and have added sparse matrix support, as well as other nice goodies.


If you want more robust support, you unfortunately really need to get into commercial packages for .NET atm.

There are two very feature-rich packages, both of which support matrices very well. Extreme Numerics works great, and has some very nice features. I've also heard very good things about the IMSL Visual Numerics math libraries.

Reed Copsey
Yeah, I've been starting to suspect you're right. Commercial packages aren't really an option I'm afraid, my being a university student. Still, thanks for the recommendations.
Noldorin
@Noldorin: I'd write to Jeremy at extreme numerics and ask if he could provide you a research license since you're a student, and it's not being used commercially. It's a small company, and the owner seems fairly friendly and responsive. (He's been great for support, pre-sales, etc.) It can't hurt. ;)
Reed Copsey
@Noldorin: I just remember dnAnalytics, and added it, too. It's probably the best non-commercial option.
Reed Copsey
@Reed: Great find there with dnAnalytics. :) I agree, it looks easily better than Mapack, especially given the support for sparse matrices. I'm very tempted to go with that now, and either implement the Lanczos algorithm on top or at worst export the matrix to Matlab and get it to do that for me. If none of that works out, I could definitely try getting in touch with Jeremy at Extreme Numerics.
Noldorin
@Reed: Thank you for the continued suggestions and comments. The answer is yours. :)
Noldorin
+2  A: 

Another alternative: IMSL for .NET. CenterSpace has the NMath libraries -- haven't used these.

tvanfosson
Those are both commercial, it seems. It's a shame, because they seem like rather good libraries...
Noldorin
@Noldorin: I did a pretty thorough search in the .NET space a while back. All of the good, robust matrix libs are pretty much commercial (at least as of early 2008).
Reed Copsey
@Reed: Yeah, that wouldn't surprise me at all... I'll take your word for it anyway. I'm wondering if using the Mapack library and implementing the Lanczos algorithm over it might do the job however.
Noldorin
@Noldorin: I actually think dnAnalytics is nicer then Mapack in the .NET world - see my edit for links.
Reed Copsey
+1  A: 

Meta.Numerics (hosted on codeplex) is a free package that will compute eigenvalues and eigenvectors of non-symmetric matrices, but it does not currently treat sparse matrices specially.

Thanks for the suggestion. I'll probably still go with dnAnalytics, as it can handle sparse matrices well, but that looks like a useful general-purpose library to keep in mind.
Noldorin
A: 

Regarding .NET and Python, you could use IronPython. However, you'll also need Ironclad to make SciPy and NumPy work with IronPython.

John D. Cook
A: 

have you considered math.net iridium ?

http://mathnet.opensourcedotnet.info/doc/Iridium.ashx