diff options
Diffstat (limited to 'lib/Data')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 17 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 1 |
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 4383e79..0664e9b 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -179,6 +179,15 @@ joinVert ms = case common cols ms of | |||
179 | joinHoriz :: Field t => [Matrix t] -> Matrix t | 179 | joinHoriz :: Field t => [Matrix t] -> Matrix t |
180 | joinHoriz ms = trans. joinVert . map trans $ ms | 180 | joinHoriz ms = trans. joinVert . map trans $ ms |
181 | 181 | ||
182 | -- | creates a complex vector from vectors with real and imaginary parts | ||
183 | toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) | ||
184 | toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] | ||
185 | |||
186 | -- | obtains the complex conjugate of a complex vector | ||
187 | conj :: Vector (Complex Double) -> Vector (Complex Double) | ||
188 | conj v = asComplex $ cdat $ reshape 2 (asReal v) `mulC` diag (fromList [1,-1]) | ||
189 | where mulC = multiply RowMajor | ||
190 | |||
182 | ------------------------------------------------------------------------------ | 191 | ------------------------------------------------------------------------------ |
183 | 192 | ||
184 | -- | Reverse rows | 193 | -- | Reverse rows |
@@ -191,7 +200,7 @@ fliprl m = fromColumns . reverse . toColumns $ m | |||
191 | 200 | ||
192 | ----------------------------------------------------------------- | 201 | ----------------------------------------------------------------- |
193 | 202 | ||
194 | liftMatrix f m = m { dat = f dat, tdat = f tdat } -- check sizes | 203 | liftMatrix f m = m { dat = f (dat m), tdat = f (tdat m) } -- check sizes |
195 | 204 | ||
196 | ------------------------------------------------------------------ | 205 | ------------------------------------------------------------------ |
197 | 206 | ||
@@ -291,7 +300,7 @@ subMatrixG (r0,c0) (rt,ct) x = reshape ct $ fromList $ concat $ map (subList c0 | |||
291 | diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do | 300 | diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do |
292 | m <- createMatrix RowMajor n n | 301 | m <- createMatrix RowMajor n n |
293 | fun // vec v // mat dat m // check msg [dat m] | 302 | fun // vec v // mat dat m // check msg [dat m] |
294 | return m | 303 | return m {tdat = dat m} |
295 | 304 | ||
296 | -- | diagonal matrix from a real vector | 305 | -- | diagonal matrix from a real vector |
297 | diagR :: Vector Double -> Matrix Double | 306 | diagR :: Vector Double -> Matrix Double |
@@ -319,6 +328,6 @@ diagG v = reshape c $ fromList $ [ l!!(i-1) * delta k i | k <- [1..c], i <- [1.. | |||
319 | diagRect s r c | 328 | diagRect s r c |
320 | | dim s < min r c = error "diagRect" | 329 | | dim s < min r c = error "diagRect" |
321 | | r == c = diag s | 330 | | r == c = diag s |
322 | | r < c = joinHoriz [diag s , zeros (r,c-r)] | 331 | | r < c = trans $ diagRect s c r |
323 | | otherwise = joinVert [diag s , zeros (r-c,c)] | 332 | | r > c = joinVert [diag s , zeros (r-c,c)] |
324 | where zeros (r,c) = reshape c $ constant (r*c) 0 | 333 | where zeros (r,c) = reshape c $ constant (r*c) 0 |
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 36d5df7..8f4e6a4 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs | |||
@@ -145,6 +145,7 @@ asReal v = V { dim = 2*dim v, fptr = castForeignPtr (fptr v), ptr = castPtr (pt | |||
145 | asComplex :: Vector Double -> Vector (Complex Double) | 145 | asComplex :: Vector Double -> Vector (Complex Double) |
146 | asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) } | 146 | asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) } |
147 | 147 | ||
148 | |||
148 | constantG n x = fromList (replicate n x) | 149 | constantG n x = fromList (replicate n x) |
149 | 150 | ||
150 | constantR :: Int -> Double -> Vector Double | 151 | constantR :: Int -> Double -> Vector Double |