summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--hmatrix.cabal2
-rw-r--r--lib/Data/Packed/Internal/Vector.hs17
-rw-r--r--lib/Data/Packed/Vector.hs2
4 files changed, 23 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index b2d63bf..21c58cb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
10.11.2.0
2========
3
4- mapVectorWithIndex
5
10.11.1.0 60.11.1.0
2======== 7========
3 8
diff --git a/hmatrix.cabal b/hmatrix.cabal
index a5563aa..e4e1f84 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.11.1.0 2Version: 0.11.2.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
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