[Haskell-cafe] Fast conversion between Vector Double and Vector CDouble
Bas van Dijk
v.dijk.bas at gmail.com
Mon Apr 4 13:54:39 CEST 2011
Hello,
I just rewrote my levmar library[1] to use Vectors (from the vector
package[2]) instead of lists. I was expecting to see a significant
performance improvement. Unfortunately I only saw a 10% improvement.
However, I noticed I had a lot of conversions from Vector Double to
Vector CDouble and visa versa in my code:
import Data.Vector.Storable ( Vector )
mapRealToFrac ∷ (Storable α, Storable β, Real α, Fractional β)
⇒ Vector α → Vector β
mapRealToFrac = VS.map realToFrac
When I replace this with:
mapRealToFrac = unsafeCoerce
My application computes the same result but does it 28 times faster!
My question are:
1) Is this always safe? In other words: are the runtime
representations of Double and CDouble always equivalent or do they
vary between platforms?
2) Can the same improvement be accomplished using RULE pragma's?
3) Are there disadvantages of using CDouble instead of Double in the
levmar API? For some reason it feels wrong to use CDouble in the API
but I don't have a good argument against it yet.
Thanks,
Bas
[1] http://hackage.haskell.org/package/levmar
[2] http://hackage.haskell.org/package/vector
More information about the Haskell-Cafe
mailing list