Haskell Matrix Library...

David Roundy droundy at abridgegame.org
Sat Jun 25 07:09:47 EDT 2005

On Fri, Jun 24, 2005 at 07:49:47PM -0700, Frederik Eaton wrote:
> However, I was just planning to spend a few weeks writing a embedded
> domain specific language wrapper in Haskell for matlab/octave. Maybe
> that's harder than I'd imagined it would be - but the problem with
> writing a Haskell matrix library from scratch is that not only do you
> lose a lot of the functionality which has already been implemented in
> these programs, but you also lose all the work which has gone into
> tuning them for speed. They support a wide variety of optimized
> internal matrix representations which are transparent to the user,
> special fast linear algebra operations on those matrices, etc. And for
> the kind of applications that people use matlab and octave for, speed
> and scalability tend to be important. So an arrangement where you keep
> the optimized matlab kernel as a backend and just send it commands
> would seem to be preferable.

I'd expect that simply calling LAPACK you'd get as good performance as
octave for anything that octave does efficiently, and you'd get better
performance on operations such as for loops, which are extremely slow in
octave--at least, assuming you're not running interactively... but maybe
even then.  I may be wrong, but I think that LAPACK *is* the optimized
matlab kernel.  I guess there's a bit of smarts to decide whether octave
can get by with real arrays, but if you're using haskell you might prefer
to decide by hand whether matrices are real or complex.

> Plus, with an EDSL you could improve the type system, index matrices
> over arbitrary Enum-like types (which are translated to and from
> integers), graft rudimentary tensor support into Octave, etc.

I'd think that all these thing could be done more easily with a native
Haskell matrix library, since in that case you'd actually have control over
your data.  With an octave backend, I don't see how you could even
conveniently separate real and complex matrices... maybe that isn't one of
your goals, but it would seem to me like an improvement in the type

> Maybe there would also be uses for a native Haskell matrix library but
> my intuition is that something like what I described above would be
> more useful to more people. Am I wrong?

Either would be useful, but I'd guess that a simple Haskell matrix library
calling LAPACK would be more useful.  To seriously replace octave, you'd
need plotting functions, but I certainly wouldn't want to call octave,
which calls gnuplot--it'd be much more flexible to call gnuplot directly
(or use some other plotting plan).
David Roundy

More information about the Libraries mailing list