diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-04-07 08:18:31 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-04-07 08:18:31 +0000 |
commit | c562a040612f89f9866f3173f91a954513befcb8 (patch) | |
tree | 363777aae045465bae2c73db71d9d74cd0ebe9a6 /lib/Data/Packed/Internal | |
parent | bc854c679c77cbdc97ee2e24383322550109118d (diff) |
toBlocks
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 04232a2..9ca8e58 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -16,7 +16,7 @@ | |||
16 | module Data.Packed.Internal.Vector ( | 16 | module Data.Packed.Internal.Vector ( |
17 | Vector, dim, | 17 | Vector, dim, |
18 | fromList, toList, (|>), | 18 | fromList, toList, (|>), |
19 | join, (@>), safe, at, at', subVector, | 19 | join, (@>), safe, at, at', subVector, takesV, |
20 | mapVector, zipVector, | 20 | mapVector, zipVector, |
21 | foldVector, foldVectorG, foldLoop, | 21 | foldVector, foldVectorG, foldLoop, |
22 | createVector, vec, | 22 | createVector, vec, |
@@ -222,6 +222,21 @@ join as = unsafePerformIO $ do | |||
222 | joiner cs 0 (advancePtr p n) | 222 | joiner cs 0 (advancePtr p n) |
223 | 223 | ||
224 | 224 | ||
225 | {- | Extract consecutive subvectors of the given sizes. | ||
226 | |||
227 | @> takesV [3,4] (linspace 10 (1,10)) | ||
228 | [3 |> [1.0,2.0,3.0],4 |> [4.0,5.0,6.0,7.0]]@ | ||
229 | |||
230 | -} | ||
231 | takesV :: Storable t => [Int] -> Vector t -> [Vector t] | ||
232 | takesV ms w | sum ms > dim w = error $ "takesV " ++ show ms ++ " on dim = " ++ (show $ dim w) | ||
233 | | otherwise = go ms w | ||
234 | where go [] _ = [] | ||
235 | go (n:ns) v = subVector 0 n v | ||
236 | : go ns (subVector n (dim v - n) v) | ||
237 | |||
238 | --------------------------------------------------------------- | ||
239 | |||
225 | -- | transforms a complex vector into a real vector with alternating real and imaginary parts | 240 | -- | transforms a complex vector into a real vector with alternating real and imaginary parts |
226 | asReal :: Vector (Complex Double) -> Vector Double | 241 | asReal :: Vector (Complex Double) -> Vector Double |
227 | asReal v = V { ioff = 2*ioff v, idim = 2*dim v, fptr = castForeignPtr (fptr v) } | 242 | asReal v = V { ioff = 2*ioff v, idim = 2*dim v, fptr = castForeignPtr (fptr v) } |