summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs17
-rw-r--r--lib/Data/Packed/Vector.hs2
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 078cb36..8f403f4 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -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, zipVectorWith, unzipVectorWith, 20 mapVector, mapVectorWithIndex, zipVectorWith, unzipVectorWith,
21 mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, 21 mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_,
22 foldVector, foldVectorG, foldLoop, foldVectorWithIndex, 22 foldVector, foldVectorG, foldLoop, foldVectorWithIndex,
23 createVector, vec, 23 createVector, vec,
@@ -497,6 +497,21 @@ mapVectorWithIndexM_ f v = do
497 mapVectorM' (k+1) t 497 mapVectorM' (k+1) t
498{-# INLINE mapVectorWithIndexM_ #-} 498{-# INLINE mapVectorWithIndexM_ #-}
499 499
500
501mapVectorWithIndex :: (Storable a, Storable b) => (Int -> a -> b) -> Vector a -> Vector b
502--mapVectorWithIndex g = head . mapVectorWithIndexM (\a b -> [g a b])
503mapVectorWithIndex f v = unsafePerformIO $ do
504 w <- createVector (dim v)
505 unsafeWith v $ \p ->
506 unsafeWith w $ \q -> do
507 let go (-1) = return ()
508 go !k = do x <- peekElemOff p k
509 pokeElemOff q k (f k x)
510 go (k-1)
511 go (dim v -1)
512 return w
513{-# INLINE mapVectorWithIndex #-}
514
500------------------------------------------------------------------- 515-------------------------------------------------------------------
501 516
502 517
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index f90f8e4..dad5d28 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -20,7 +20,7 @@ module Data.Packed.Vector (
20 fromList, (|>), toList, buildVector, 20 fromList, (|>), toList, buildVector,
21 dim, (@>), 21 dim, (@>),
22 subVector, takesV, join, 22 subVector, takesV, join,
23 mapVector, zipVector, zipVectorWith, unzipVector, unzipVectorWith, 23 mapVector, mapVectorWithIndex, zipVector, zipVectorWith, unzipVector, unzipVectorWith,
24 mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, 24 mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_,
25 foldLoop, foldVector, foldVectorG, foldVectorWithIndex 25 foldLoop, foldVector, foldVectorG, foldVectorWithIndex
26) where 26) where