From b52e7d3c7e4ea85ab74166926e9f66697a074aae Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sun, 1 Jun 2008 11:39:07 +0000 Subject: added updateVector --- lib/Data/Packed/Internal/Vector.hs | 20 ++++++++++++++++++++ lib/Data/Packed/Vector.hs | 1 + 2 files changed, 21 insertions(+) (limited to 'lib/Data') 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 liftVector2 f u v = fromList $ zipWith f (toList u) (toList v) ----------------------------------------------------------------- + +{- | creates a new vector with a desired position updated with a modification function + +@> updateVector 3 (+7) (fromList [1..5]) +5 |> [1.0,2.0,3.0,11.0,5.0]@ + +-} +updateVector :: Storable t => Int -- ^ position + -> (t->t) -- ^ modification function + -> Vector t -- ^ source + -> Vector t -- ^ result +updateVector k h (v@V {dim=n}) + | k<0 || k >= n = error $ "updateVector out of range (dim="++show n++", pos="++show k++")" + | otherwise = unsafePerformIO $ do + r <- createVector n + let f _ s _ d = copyArray d s n + >> pokeElemOff d k (h (v`at'`k)) + >> return 0 + app2 f vec v vec r "updateVector" + return r diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs index 6415c5c..9e3c206 100644 --- a/lib/Data/Packed/Vector.hs +++ b/lib/Data/Packed/Vector.hs @@ -17,6 +17,7 @@ module Data.Packed.Vector ( fromList, (|>), toList, dim, (@>), subVector, join, + updateVector, constant, linspace, vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex, liftVector, liftVector2 -- cgit v1.2.3