summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hmatrix.cabal2
-rw-r--r--lib/Data/Packed/Internal/Vector.hs20
-rw-r--r--lib/Data/Packed/Vector.hs1
3 files changed, 22 insertions, 1 deletions
diff --git a/hmatrix.cabal b/hmatrix.cabal
index 6494d11..1268072 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.3.0.0 2Version: 0.3.1.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 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
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