summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index fc08ce4..4f2ad90 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -24,7 +24,7 @@ module Data.Packed.Matrix (
24 fromBlocks, joinVert, joinHoriz, 24 fromBlocks, joinVert, joinHoriz,
25 flipud, fliprl, 25 flipud, fliprl,
26 subMatrix, takeRows, dropRows, takeColumns, dropColumns, 26 subMatrix, takeRows, dropRows, takeColumns, dropColumns,
27 diag, takeDiag, diagRect, ident, 27 ident, diag, diagRect, takeDiag,
28 liftMatrix, liftMatrix2, 28 liftMatrix, liftMatrix2,
29) where 29) where
30 30
@@ -69,6 +69,14 @@ fliprl m = fromColumns . reverse . toColumns $ m
69 69
70------------------------------------------------------------ 70------------------------------------------------------------
71 71
72{- | creates a rectangular diagonal matrix
73
74@> diagRect (constant 5 3) 3 4
75(3><4)
76 [ 5.0, 0.0, 0.0, 0.0
77 , 0.0, 5.0, 0.0, 0.0
78 , 0.0, 0.0, 5.0, 0.0 ]@
79-}
72diagRect :: (Field t, Num t) => Vector t -> Int -> Int -> Matrix t 80diagRect :: (Field t, Num t) => Vector t -> Int -> Int -> Matrix t
73diagRect s r c 81diagRect s r c
74 | dim s < min r c = error "diagRect" 82 | dim s < min r c = error "diagRect"
@@ -77,9 +85,11 @@ diagRect s r c
77 | r > c = joinVert [diag s , zeros (r-c,c)] 85 | r > c = joinVert [diag s , zeros (r-c,c)]
78 where zeros (r,c) = reshape c $ constantD 0 (r*c) 86 where zeros (r,c) = reshape c $ constantD 0 (r*c)
79 87
88-- | extracts the diagonal from a rectangular matrix
80takeDiag :: (Field t) => Matrix t -> Vector t 89takeDiag :: (Field t) => Matrix t -> Vector t
81takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] 90takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]]
82 91
92-- | creates the identity matrix of given dimension
83ident :: Int -> Matrix Double 93ident :: Int -> Matrix Double
84ident n = diag (constant 1 n) 94ident n = diag (constant 1 n)
85 95
@@ -138,12 +148,15 @@ flatten = cdat
138fromLists :: Field t => [[t]] -> Matrix t 148fromLists :: Field t => [[t]] -> Matrix t
139fromLists = fromRows . map fromList 149fromLists = fromRows . map fromList
140 150
151-- | conjugate transpose
141conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double) 152conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double)
142conjTrans = trans . liftMatrix conj 153conjTrans = trans . liftMatrix conj
143 154
155-- | creates a 1-row matrix from a vector
144asRow :: Field a => Vector a -> Matrix a 156asRow :: Field a => Vector a -> Matrix a
145asRow v = reshape (dim v) v 157asRow v = reshape (dim v) v
146 158
159-- | creates a 1-column matrix from a vector
147asColumn :: Field a => Vector a -> Matrix a 160asColumn :: Field a => Vector a -> Matrix a
148asColumn v = reshape 1 v 161asColumn v = reshape 1 v
149 162