[Haskell-cafe] Repa array and Data.Vector.Storable.Mutable.

Ben Lippmeier benl at ouroborus.net
Wed May 1 13:34:07 UTC 2019



> On 26 Apr 2019, at 9:14 am, PICCA Frederic-Emmanuel <frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:
> 
> Hello
> 
> I would like a function which allows to freeze a Mutable Vector into a Repa array. of type Array F DIM2 a
> It seems to me that the the foreignPtr ownership should be transfer to the Repa Array, but I can not find a way to do this...
> 
> So what is the proper way to achieve this ?

If it’s a boxed Data.Vector then you have to copy it, because the ForeignPtr representation is unboxed. Freeze the mutable vector with Data.Vector.freeze or unsafeFreeze, then apply Data.Array.Repa.Repr.Vector.fromVector. This gives you a boxed Repa representation, then copy it into the unboxed ForeignPtr representation with copyP.

If you can build an unboxed Data.Vector.Storable instead, then apply unsafeToForeignPtr to get the guts of it, and give them to Data.Array.Repa.Repr.ForeignPtr.fromForeignPtr.


Ben.



More information about the Haskell-Cafe mailing list