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/Development.hs | 5 +++-- lib/Data/Packed/Internal/Vector.hs | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/Data/Packed/Development.hs b/lib/Data/Packed/Development.hs index 56e7b8f..a9e6ac2 100644 --- a/lib/Data/Packed/Development.hs +++ b/lib/Data/Packed/Development.hs @@ -9,8 +9,7 @@ -- Stability : provisional -- Portability : portable -- --- The implementation of the 'Vector' and 'Matrix' types is not exposed, --- but the library can be easily extended with additional foreign functions +-- The library can be easily extended with additional foreign functions -- using the tools in this module. Illustrative usage examples can be found -- in the @examples\/devel@ folder included in the package. -- @@ -22,6 +21,8 @@ module Data.Packed.Development ( vec, mat, app1, app2, app3, app4, MatrixOrder(..), orderOf, cmat, fmat, + unsafeFromForeignPtr, + unsafeToForeignPtr ) where import Data.Packed.Internal 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