summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Vector.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-05 11:29:18 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-05 11:29:18 +0000
commita4254a0b9bfbd720efbe42b86aa50107a74d56c7 (patch)
tree83370b1c0f4dea228b100194ac1fb0da78be2a61 /lib/Data/Packed/Internal/Vector.hs
parent1fb4ea70c517050d3cbad75357a4fffbf5a40e7b (diff)
subMatrix
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index 7dcefeb..6ed9339 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -119,23 +119,30 @@ subVector' k l (v@V {dim=n, ptr=p, fptr=fp})
119 | otherwise = v {dim=l, ptr=advancePtr p k} 119 | otherwise = v {dim=l, ptr=advancePtr p k}
120 120
121 121
122{- 122
123-- | creates a new Vector by joining a list of Vectors 123-- | creates a new Vector by joining a list of Vectors
124join :: Field t => [Vector t] -> Vector t 124join :: Field t => [Vector t] -> Vector t
125join [] = error "joining an empty list" 125join [] = error "joining zero vectors"
126join as = unsafePerformIO $ do 126join as = unsafePerformIO $ do
127 let tot = sum (map size as) 127 let tot = sum (map dim as)
128 p <- mallocForeignPtrArray tot 128 r@V {fptr = p, ptr = p'} <- createVector tot
129 withForeignPtr p $ \p -> 129 withForeignPtr p $ \_ ->
130 joiner as tot p 130 joiner as tot p'
131 return (V tot p) 131 return r
132 where joiner [] _ _ = return () 132 where joiner [] _ _ = return ()
133 joiner (V n b : cs) _ p = do 133 joiner (V {dim = n, fptr = b, ptr = q} : cs) _ p = do
134 withForeignPtr b $ \b' -> copyArray p b' n 134 withForeignPtr b $ \_ -> copyArray p q n
135 joiner cs 0 (advancePtr p n) 135 joiner cs 0 (advancePtr p n)
136-}
137 136
138 137
138-- | transforms a complex vector into a real vector with alternating real and imaginary parts
139asReal :: Vector (Complex Double) -> Vector Double
140asReal v = V { dim = 2*dim v, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) }
141
142-- | transforms a real vector into a complex vector with alternating real and imaginary parts
143asComplex :: Vector Double -> Vector (Complex Double)
144asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) }
145
139constantG n x = fromList (replicate n x) 146constantG n x = fromList (replicate n x)
140 147
141constantR :: Int -> Double -> Vector Double 148constantR :: Int -> Double -> Vector Double