summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 1075e64..5a42f9d 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -146,3 +146,23 @@ liftVector2 :: (Storable a, Storable b, Storable c) => (a-> b -> c) -> Vector a
146liftVector2 f u v = fromList $ zipWith f (toList u) (toList v) 146liftVector2 f u v = fromList $ zipWith f (toList u) (toList v)
147 147
148----------------------------------------------------------------- 148-----------------------------------------------------------------
149
150{- | creates a new vector with a desired position updated with a modification function
151
152@> updateVector 3 (+7) (fromList [1..5])
1535 |> [1.0,2.0,3.0,11.0,5.0]@
154
155-}
156updateVector :: Storable t => Int -- ^ position
157 -> (t->t) -- ^ modification function
158 -> Vector t -- ^ source
159 -> Vector t -- ^ result
160updateVector k h (v@V {dim=n})
161 | k<0 || k >= n = error $ "updateVector out of range (dim="++show n++", pos="++show k++")"
162 | otherwise = unsafePerformIO $ do
163 r <- createVector n
164 let f _ s _ d = copyArray d s n
165 >> pokeElemOff d k (h (v`at'`k))
166 >> return 0
167 app2 f vec v vec r "updateVector"
168 return r