diff options
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 7 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 89a162a..58b325c 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -348,7 +348,7 @@ foreign import ccall safe "aux.h constantC" | |||
348 | @> constant 2 7 | 348 | @> constant 2 7 |
349 | 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ | 349 | 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ |
350 | -} | 350 | -} |
351 | constant :: Field a => a -> Int -> Vector a | 351 | constant :: Double -> Int -> Vector Double |
352 | constant = constantD | 352 | constant = constantD |
353 | 353 | ||
354 | -------------------------------------------------------------------------- | 354 | -------------------------------------------------------------------------- |
@@ -361,6 +361,11 @@ conj v = asComplex $ cdat $ reshape 2 (asReal v) `multiply` diag (fromList [1,-1 | |||
361 | toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) | 361 | toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) |
362 | toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] | 362 | toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] |
363 | 363 | ||
364 | -- | the inverse of 'toComplex' | ||
365 | fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double) | ||
366 | fromComplex z = (r,i) where | ||
367 | [r,i] = toColumns $ reshape 2 $ asReal z | ||
368 | |||
364 | -- | converts a real vector into a complex representation (with zero imaginary parts) | 369 | -- | converts a real vector into a complex representation (with zero imaginary parts) |
365 | comp :: Vector Double -> Vector (Complex Double) | 370 | comp :: Vector Double -> Vector (Complex Double) |
366 | comp v = toComplex (v,constant 0 (dim v)) | 371 | comp v = toComplex (v,constant 0 (dim v)) |
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 01e8133..fc08ce4 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -75,12 +75,12 @@ diagRect s r c | |||
75 | | r == c = diag s | 75 | | r == c = diag s |
76 | | r < c = trans $ diagRect s c r | 76 | | r < c = trans $ diagRect s c r |
77 | | r > c = joinVert [diag s , zeros (r-c,c)] | 77 | | r > c = joinVert [diag s , zeros (r-c,c)] |
78 | where zeros (r,c) = reshape c $ constant 0 (r*c) | 78 | where zeros (r,c) = reshape c $ constantD 0 (r*c) |
79 | 79 | ||
80 | takeDiag :: (Field t) => Matrix t -> Vector t | 80 | takeDiag :: (Field t) => Matrix t -> Vector t |
81 | takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] | 81 | takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] |
82 | 82 | ||
83 | ident :: (Num t, Field t) => Int -> Matrix t | 83 | ident :: Int -> Matrix Double |
84 | ident n = diag (constant 1 n) | 84 | ident n = diag (constant 1 n) |
85 | 85 | ||
86 | ------------------------------------------------------------ | 86 | ------------------------------------------------------------ |