diff options
Diffstat (limited to 'packages/base/src/Internal/Vector.hs')
-rw-r--r-- | packages/base/src/Internal/Vector.hs | 16 |
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 | ||
71 | vec :: (Storable t) => Vector t -> (((CInt -> Ptr t -> t1) -> t1) -> IO b) -> IO b | ||
72 | vec 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 #-} |
79 | avec :: Storable a => (CInt -> Ptr a -> b) -> Vector a -> b | 71 | avec :: Storable a => (CInt -> Ptr a -> b) -> Vector a -> b |
80 | avec f v = inlinePerformIO (unsafeWith v (return . f (fromIntegral (Vector.length v)))) | 72 | avec f v = inlinePerformIO (unsafeWith v (return . f (fromIntegral (Vector.length v)))) |
81 | infixl 1 `avec` | 73 | infixl 1 `avec` |
82 | 74 | ||
83 | {-# INLINE arrvec #-} | ||
84 | arrvec :: Storable a => (Ptr CInt -> Ptr a -> b) -> Vector a -> b | ||
85 | arrvec 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 |
90 | createVector :: Storable a => Int -> IO (Vector a) | 76 | createVector :: Storable a => Int -> IO (Vector a) |
91 | createVector n = do | 77 | createVector n = do |