summaryrefslogtreecommitdiff
path: root/lib/Data/Packed
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs7
-rw-r--r--lib/Data/Packed/Matrix.hs4
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
3497 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ 3497 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@
350-} 350-}
351constant :: Field a => a -> Int -> Vector a 351constant :: Double -> Int -> Vector Double
352constant = constantD 352constant = constantD
353 353
354-------------------------------------------------------------------------- 354--------------------------------------------------------------------------
@@ -361,6 +361,11 @@ conj v = asComplex $ cdat $ reshape 2 (asReal v) `multiply` diag (fromList [1,-1
361toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) 361toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double)
362toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] 362toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i]
363 363
364-- | the inverse of 'toComplex'
365fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double)
366fromComplex 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)
365comp :: Vector Double -> Vector (Complex Double) 370comp :: Vector Double -> Vector (Complex Double)
366comp v = toComplex (v,constant 0 (dim v)) 371comp 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
80takeDiag :: (Field t) => Matrix t -> Vector t 80takeDiag :: (Field t) => Matrix t -> Vector t
81takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] 81takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]]
82 82
83ident :: (Num t, Field t) => Int -> Matrix t 83ident :: Int -> Matrix Double
84ident n = diag (constant 1 n) 84ident n = diag (constant 1 n)
85 85
86------------------------------------------------------------ 86------------------------------------------------------------