diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-09 16:07:51 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-07-09 16:07:51 +0000 |
commit | c4531ceaa524b1f8a84dcdf3456d7a7b2831f902 (patch) | |
tree | 335a04f017ed8ff858336913939261d050672311 /lib/Data/Packed/Internal/Vector.hs | |
parent | 97e8a48be58fd53afccc7ae01ee6ec5805d5c1cd (diff) |
added unzipVectorWith
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index d97a86d..06db806 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -1,4 +1,4 @@ | |||
1 | {-# LANGUAGE MagicHash, CPP, UnboxedTuples, BangPatterns #-} | 1 | {-# LANGUAGE MagicHash, CPP, UnboxedTuples, BangPatterns, FlexibleContexts #-} |
2 | ----------------------------------------------------------------------------- | 2 | ----------------------------------------------------------------------------- |
3 | -- | | 3 | -- | |
4 | -- Module : Data.Packed.Internal.Vector | 4 | -- Module : Data.Packed.Internal.Vector |
@@ -17,7 +17,7 @@ module Data.Packed.Internal.Vector ( | |||
17 | Vector, dim, | 17 | Vector, dim, |
18 | fromList, toList, (|>), | 18 | fromList, toList, (|>), |
19 | join, (@>), safe, at, at', subVector, takesV, | 19 | join, (@>), safe, at, at', subVector, takesV, |
20 | mapVector, zipVector, | 20 | mapVector, zipVector, unzipVectorWith, |
21 | foldVector, foldVectorG, foldLoop, | 21 | foldVector, foldVectorG, foldLoop, |
22 | createVector, vec, | 22 | createVector, vec, |
23 | asComplex, asReal, | 23 | asComplex, asReal, |
@@ -318,6 +318,25 @@ zipVector f u v = unsafePerformIO $ do | |||
318 | return w | 318 | return w |
319 | {-# INLINE zipVector #-} | 319 | {-# INLINE zipVector #-} |
320 | 320 | ||
321 | -- | unzipWith for Vectors | ||
322 | unzipVectorWith :: (Storable (a,b), Storable c, Storable d) | ||
323 | => (a -> c) -> (b -> d) -> Vector (a,b) -> (Vector c,Vector d) | ||
324 | unzipVectorWith f g u = unsafePerformIO $ do | ||
325 | let n = dim u | ||
326 | v <- createVector n | ||
327 | w <- createVector n | ||
328 | unsafeWith u $ \pu -> | ||
329 | unsafeWith v $ \pv -> | ||
330 | unsafeWith w $ \pw -> do | ||
331 | let go (-1) = return () | ||
332 | go !k = do (x,y) <- peekElemOff pu k | ||
333 | pokeElemOff pv k (f x) | ||
334 | pokeElemOff pw k (g y) | ||
335 | go (k-1) | ||
336 | go (n-1) | ||
337 | return (v,w) | ||
338 | {-# INLINE unzipVectorWith #-} | ||
339 | |||
321 | foldVector f x v = unsafePerformIO $ | 340 | foldVector f x v = unsafePerformIO $ |
322 | unsafeWith (v::Vector Double) $ \p -> do | 341 | unsafeWith (v::Vector Double) $ \p -> do |
323 | let go (-1) s = return s | 342 | let go (-1) s = return s |