summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Internal/Vector.hs')
-rw-r--r--packages/base/src/Internal/Vector.hs16
1 files changed, 1 insertions, 15 deletions
diff --git a/packages/base/src/Internal/Vector.hs b/packages/base/src/Internal/Vector.hs
index e5ac440..29b6797 100644
--- a/packages/base/src/Internal/Vector.hs
+++ b/packages/base/src/Internal/Vector.hs
@@ -14,7 +14,7 @@ module Internal.Vector(
14 I,Z,R,C, 14 I,Z,R,C,
15 fi,ti, 15 fi,ti,
16 Vector, fromList, unsafeToForeignPtr, unsafeFromForeignPtr, unsafeWith, 16 Vector, fromList, unsafeToForeignPtr, unsafeFromForeignPtr, unsafeWith,
17 createVector, vec, avec, arrvec, inlinePerformIO, 17 createVector, avec, inlinePerformIO,
18 toList, dim, (@>), at', (|>), 18 toList, dim, (@>), at', (|>),
19 vjoin, subVector, takesV, idxs, 19 vjoin, subVector, takesV, idxs,
20 buildVector, 20 buildVector,
@@ -67,25 +67,11 @@ dim = Vector.length
67 67
68 68
69-- C-Haskell vector adapter 69-- C-Haskell vector adapter
70-- vec :: Adapt (CInt -> Ptr t -> r) (Vector t) r
71vec :: (Storable t) => Vector t -> (((CInt -> Ptr t -> t1) -> t1) -> IO b) -> IO b
72vec x f = unsafeWith x $ \p -> do
73 let v g = do
74 g (fi $ dim x) p
75 f v
76{-# INLINE vec #-}
77
78{-# INLINE avec #-} 70{-# INLINE avec #-}
79avec :: Storable a => (CInt -> Ptr a -> b) -> Vector a -> b 71avec :: Storable a => (CInt -> Ptr a -> b) -> Vector a -> b
80avec f v = inlinePerformIO (unsafeWith v (return . f (fromIntegral (Vector.length v)))) 72avec f v = inlinePerformIO (unsafeWith v (return . f (fromIntegral (Vector.length v))))
81infixl 1 `avec` 73infixl 1 `avec`
82 74
83{-# INLINE arrvec #-}
84arrvec :: Storable a => (Ptr CInt -> Ptr a -> b) -> Vector a -> b
85arrvec f v = inlinePerformIO (unsafeWith (idxs [1,dim v]) (\p -> unsafeWith v (return . f p)))
86
87
88
89-- allocates memory for a new vector 75-- allocates memory for a new vector
90createVector :: Storable a => Int -> IO (Vector a) 76createVector :: Storable a => Int -> IO (Vector a)
91createVector n = do 77createVector n = do