diff options
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 20 | ||||
-rw-r--r-- | lib/Data/Packed/Vector.hs | 1 |
2 files changed, 21 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 | |||
146 | liftVector2 f u v = fromList $ zipWith f (toList u) (toList v) | 146 | liftVector2 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]) | ||
153 | 5 |> [1.0,2.0,3.0,11.0,5.0]@ | ||
154 | |||
155 | -} | ||
156 | updateVector :: Storable t => Int -- ^ position | ||
157 | -> (t->t) -- ^ modification function | ||
158 | -> Vector t -- ^ source | ||
159 | -> Vector t -- ^ result | ||
160 | updateVector 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 | ||
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 ( | |||
17 | fromList, (|>), toList, | 17 | fromList, (|>), toList, |
18 | dim, (@>), | 18 | dim, (@>), |
19 | subVector, join, | 19 | subVector, join, |
20 | updateVector, | ||
20 | constant, linspace, | 21 | constant, linspace, |
21 | vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex, | 22 | vectorMax, vectorMin, vectorMaxIndex, vectorMinIndex, |
22 | liftVector, liftVector2 | 23 | liftVector, liftVector2 |