Daniel-Diaz / matrix

A Haskell native implementation of matrices and their operations.
BSD 3-Clause "New" or "Revised" License
35 stars 31 forks source link

Enhance performance by using Unboxed Vectors #54

Open OlivierSohn opened 6 years ago

OlivierSohn commented 6 years ago

I think the library would benefit from using Unboxed vectors (this and that ) instead the boxed versions.

Runtime performance would be enhanced because less memory will be required (one word less by matrix element) and many operations will be faster (because the CPU caches will be used more efficiently, as a continuous block of memory will contain more relevant information than before).

Daniel-Diaz commented 6 years ago

However, that would restrict what types can be used as elements of the matrix. We want to be able to use matrices for more than just numbers. We could have a separate module for an unboxed version, although that would require some work.

OlivierSohn commented 6 years ago

@Daniel-Diaz I didn't think of the aspect you mention, I was assuming every value is Unbox.

Now that I think about it, in my case the real need is to have a matrix of booleans. Even an Unboxed matrix would be far from an optimal representation, I may need to implement a matrix on top of ByteString, with bit-shifting to access elements if I want to really optimize for memory.

Edit : I'm leaving the issue opened in case someone has time to implement the unboxed version, but feel free to close it if it's not in your plans.