Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which haskell array implementation to use? AKA what are the pros and cons of each

What do I need? [an unordered list]

  • VERY easy parallelization
  • support for map, filter etc.
  • ability to perform array based computations efficiently, like A=B+C, sort of like matlab arrays.
  • Generation of SIMD code. I guess this is out of the question in the near future for anything, but hey, I can ask :)
  • support for matrices should be there at a minimum, higher dimensions are lower priority right now.
  • ability to get a pointer to it and create one from a C pointer.
  • Support from other libraries. IE, bindings to popular C math packages, i/o to disk or images if the arrays are 2D

What do I see?

  • Array package in haskell-platform. It's the blessed one and can do parallel
  • Data.Vector. Has loop fusion, but not in platform, so its maturity is unknown to me.
  • repa package, contributed by the DPH team, but doesn't work well with any stable ghc today.
  • Lots of variation in the level of support for array implementations. For instance, there doesn't seem to be an easy way to dump a 2D vector to a image file. IOW, the haskell community apparently hasn't settled on an array implementation.

So please, help me choose.

EDIT A=B+C refers to element wise addition, and not list concatenation

like image 884
rpg Avatar asked Mar 04 '11 16:03

rpg


2 Answers

Correct, the community hasn't settled on a good array implementation. I think it would be a good Haskell Prime submission to put forward the Vector API and remove Data.Array.

Vector is very mature! It has:

  • VERY easy parallelization
  • support for map, filter etc.
  • performs array based computations efficiently, like A=B+C (but I'm not in tune with how matlab does it)
  • vector creation from a pointer via Vector.Storable

It does not:

  • have enough support from other libraries. IE, bindings to popular C math packages
  • support matrices, but you can have vectors of vectors. If you build some vector-based matrix operations then perhaps you could upload to hackage as vector-matrix.
  • Generate SIMD code.

NOTE: You can turn bytestrings into vectors of whatever, so if you have an image as a bytestring then, via Vector.Storable, you might be able to do what you want with the image as a vector.

like image 149
Thomas M. DuBuisson Avatar answered Nov 02 '22 05:11

Thomas M. DuBuisson


(I am not allowed to comment)

rpg: Does hmatrix accept Data.Vector? It has a Data.Packed.Vector but are they the same?

Yes. The last version of hmatrix uses by default Data.Vector.Storable for 1D vectors (previously it was optional). The dependency on vector is not shown in Hackage, probably because it is in a configuration flag.

For LAPACK compatibility matrices are not Vector or Vector t, but they can be easily converted (e.g.: Data.Vector.fromList . toRows).

like image 30
Alberto Ruiz Avatar answered Nov 02 '22 06:11

Alberto Ruiz