summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Packed/Development.hs5
-rw-r--r--lib/Data/Packed/Internal/Vector.hs12
2 files changed, 14 insertions, 3 deletions
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 @@
9-- Stability : provisional 9-- Stability : provisional
10-- Portability : portable 10-- Portability : portable
11-- 11--
12-- The implementation of the 'Vector' and 'Matrix' types is not exposed, 12-- The library can be easily extended with additional foreign functions
13-- but the library can be easily extended with additional foreign functions
14-- using the tools in this module. Illustrative usage examples can be found 13-- using the tools in this module. Illustrative usage examples can be found
15-- in the @examples\/devel@ folder included in the package. 14-- in the @examples\/devel@ folder included in the package.
16-- 15--
@@ -22,6 +21,8 @@ module Data.Packed.Development (
22 vec, mat, 21 vec, mat,
23 app1, app2, app3, app4, 22 app1, app2, app3, app4,
24 MatrixOrder(..), orderOf, cmat, fmat, 23 MatrixOrder(..), orderOf, cmat, fmat,
24 unsafeFromForeignPtr,
25 unsafeToForeignPtr
25) where 26) where
26 27
27import Data.Packed.Internal 28import 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 (
23 createVector, withVector, vec, 23 createVector, withVector, vec,
24 asComplex, asReal, 24 asComplex, asReal,
25 fwriteVector, freadVector, fprintfVector, fscanfVector, 25 fwriteVector, freadVector, fprintfVector, fscanfVector,
26 cloneVector 26 cloneVector,
27 unsafeToForeignPtr,
28 unsafeFromForeignPtr
27) where 29) where
28 30
29import Data.Packed.Internal.Common 31import Data.Packed.Internal.Common
@@ -51,6 +53,14 @@ data Vector t =
51 , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block 53 , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block
52 } 54 }
53 55
56unsafeToForeignPtr :: Vector a -> (ForeignPtr a, Int, Int)
57unsafeToForeignPtr v = (fptr v, 0, idim v)
58
59-- | Same convention as in Roman Leshchinskiy's vector package.
60unsafeFromForeignPtr :: ForeignPtr a -> Int -> Int -> Vector a
61unsafeFromForeignPtr fp i n | i == 0 = V {idim = n, fptr = fp}
62 | otherwise = error "unsafeFromForeignPtr with nonzero offset"
63
54-- | Number of elements 64-- | Number of elements
55dim :: Vector t -> Int 65dim :: Vector t -> Int
56dim = idim 66dim = idim