summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2008-06-01 11:39:07 +0000
committerAlberto Ruiz <aruiz@um.es>2008-06-01 11:39:07 +0000
commitb52e7d3c7e4ea85ab74166926e9f66697a074aae (patch)
treec1c3f2e7fb253fb21dcbdb01993ea6d1945ef28e /lib/Data/Packed/Internal
parentaa8d74a37a918855a727617d85868372abbbabaf (diff)
added updateVector
Diffstat (limited to 'lib/Data/Packed/Internal')
-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