30

I'm looking for a Haskell linear algebra library that has the following features:

  • Matrix multiplication
  • Matrix addition
  • Matrix transposition
  • Rank calculation
  • Matrix inversion is a plus

and has the following properties:

  • arbitrary element (scalar) types (in particular element types that are not Storable instances). My elements are an instance of Num, additionally the multiplicative inverse can be calculated. The elements mathematically form a finite field (2256). That should be enough to implement the features mentioned above.
  • arbitrary matrix sizes (I'll probably need something like 100x100, but the matrix sizes will depend on the user's input so it should not be limited by anything else but the memory or the computational power available)
  • as fast as possible, but I'm aware that a library for arbitrary elements will probably not perform like a C/Fortran library that does the work (interfaced via FFI) because of the indirection of arbitrary (non Int, Double or similar) types. At least one pointer gets dereferenced when an element is touched
  • (written in Haskell, this is not a real requirement for me, but since my elements are no Storable instances the library has to be written in Haskell)

I already tried very hard and evaluated everything that looked promising (most of the libraries on Hackage directly state that they wont work for me). In particular I wrote test code using:

  • hmatrix, assumes Storable elements
  • Vec, but the documentation states:

    Low Dimension : Although the dimensionality is limited only by what GHC will handle, the library is meant for 2,3 and 4 dimensions. For general linear algebra, check out the excellent hmatrix library and blas bindings

I looked into the code and the documentation of many more libraries but nothing seems to suit my needs :-(.

Update

Since there seems to be nothing, I started a project on GitHub which aims to develop such a library. The current state is very minimalistic, not optimized for speed at all and only the most basic functions have tests and therefore should work. But should you be interested in using or helping out developing it: Contact me (you'll find my mail address on my web site) or send pull requests.

Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
  • `Storable` is elementary to the FFI, allowing values to be marshalled in to a form the interfaced code can read. Without that caveat, I imagine the work would need to be done entirely within Haskell. – Orbling Sep 05 '12 at 19:57
  • Yes, I know. And yes, I'm searching for a library entirely written in Haskell. Put that in the question. Thanks! – Johannes Weiss Sep 05 '12 at 19:59
  • Looking at the code for `Vec`, I think that the *Low Dimension* caveat is purely there because of the inefficiency of it running in Haskell only without using auxiliary compiled libraries. Hence the recommendation to use `hmatrix`. :-/ – Orbling Sep 05 '12 at 20:04
  • Hasn't `Vec` one type for each possible matrix size? It has e.g. `Matrix33` which is a *3x3* matrix. To support *100x100* matrices, GHC had to generate a lot of types. And: I think I need a library without static matrix size checking because I don't know the matrix sizes at compile time! – Johannes Weiss Sep 05 '12 at 20:07
  • Aye, sounds like you might have an opening for a new library. – Orbling Sep 05 '12 at 20:15
  • 1
    Hehe, I'll probably need to... I'm currently writing my diploma thesis (Master's thesis equivalent in Germany) in computer science/cryptography and I already had to write the finite field library. In fact, I interfaced a C++ library. Don't know if I have the time to additionally implement such an matrix library. I'll see... – Johannes Weiss Sep 05 '12 at 20:17
  • Hopefully somebody will come up with an existing library. I wonder if LAPACK could handle your data, if a suitable interface was devised to make your data Storable... I remember doing my master's thesis a decade ago, I'm sure you do not need this stress! lol – Orbling Sep 05 '12 at 20:24
  • LAPACK and even FFPACK/FFLAS do not even work with scalar elememts of the field I'm using (GF(2^256)). There are very few libraries for such large finite fields. With linear algebra algorithms it looks even worse. Therefore I'm looking for a generic lin alg library... – Johannes Weiss Sep 05 '12 at 20:51
  • I was looking for something like this a couple of months ago. If you end up developing something I would be interested in helping out (email in profile). – Chris Taylor Sep 06 '12 at 09:30
  • @ChrisTaylor , that's cool, thanks :-). I will let you know as soon as I really start implementing such a library. – Johannes Weiss Sep 06 '12 at 10:11

1 Answers1

-2

well, I'm note really sure how much relevant my answer is but Im having good experiences with GNU GSL library and there is a wrapper for haskel:

http://hackage.haskell.org/package/bindings-gsl

Check it out, maybe it will help you

xhudik
  • 2,414
  • 1
  • 21
  • 39