From aae45de54aca92c5f0f013e46c6d6f65508d76f5 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 24 Feb 2010 12:01:07 +0000 Subject: conversion from/to Data.Vector.Storable --- lib/Data/Packed/Internal/Vector.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/Data/Packed/Internal/Vector.hs') diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 66acd87..51c0d92 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs @@ -23,7 +23,9 @@ module Data.Packed.Internal.Vector ( createVector, withVector, vec, asComplex, asReal, fwriteVector, freadVector, fprintfVector, fscanfVector, - cloneVector + cloneVector, + unsafeToForeignPtr, + unsafeFromForeignPtr ) where import Data.Packed.Internal.Common @@ -51,6 +53,14 @@ data Vector t = , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block } +unsafeToForeignPtr :: Vector a -> (ForeignPtr a, Int, Int) +unsafeToForeignPtr v = (fptr v, 0, idim v) + +-- | Same convention as in Roman Leshchinskiy's vector package. +unsafeFromForeignPtr :: ForeignPtr a -> Int -> Int -> Vector a +unsafeFromForeignPtr fp i n | i == 0 = V {idim = n, fptr = fp} + | otherwise = error "unsafeFromForeignPtr with nonzero offset" + -- | Number of elements dim :: Vector t -> Int dim = idim -- cgit v1.2.3