summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-25 07:32:56 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-25 07:32:56 +0000
commit1871acb835b4fc164bcff3f6e7467884b87fbd0f (patch)
treeac1028d40778bbae532c3915276b5af21ba5f5cb /lib/Data/Packed/Matrix.hs
parent3d5d6f06598aac00906c93ac5358e68697c47fc7 (diff)
l.a. algorithms, etc.
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs35
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 0f9d998..36bf32e 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -13,11 +13,11 @@
13----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
14 14
15module Data.Packed.Matrix ( 15module Data.Packed.Matrix (
16 Matrix(rows,cols), Field, 16 Matrix(rows,cols),
17 fromLists, toLists, (><), (>|<), (@@>), 17 fromLists, toLists, (><), (>|<), (@@>),
18 trans, conjTrans, 18 trans, conjTrans,
19 reshape, flatten, 19 reshape, flatten, asRow, asColumn,
20 fromRows, toRows, fromColumns, toColumns, 20 fromRows, toRows, fromColumns, toColumns, fromBlocks,
21 joinVert, joinHoriz, 21 joinVert, joinHoriz,
22 flipud, fliprl, 22 flipud, fliprl,
23 liftMatrix, liftMatrix2, 23 liftMatrix, liftMatrix2,
@@ -43,6 +43,22 @@ joinVert ms = case common cols ms of
43joinHoriz :: Field t => [Matrix t] -> Matrix t 43joinHoriz :: Field t => [Matrix t] -> Matrix t
44joinHoriz ms = trans. joinVert . map trans $ ms 44joinHoriz ms = trans. joinVert . map trans $ ms
45 45
46{- | Creates a matrix from blocks given as a list of lists of matrices:
47
48@\> let a = 'diag' $ 'fromList' [5,7,2]
49\> let b = 'reshape' 4 $ 'constant' (-1) 12
50\> fromBlocks [[a,b],[b,a]]
51(6><7)
52 [ 5.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0
53 , 0.0, 7.0, 0.0, -1.0, -1.0, -1.0, -1.0
54 , 0.0, 0.0, 2.0, -1.0, -1.0, -1.0, -1.0
55 , -1.0, -1.0, -1.0, -1.0, 5.0, 0.0, 0.0
56 , -1.0, -1.0, -1.0, -1.0, 0.0, 7.0, 0.0
57 , -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 2.0 ]@
58-}
59fromBlocks :: Field t => [[Matrix t]] -> Matrix t
60fromBlocks = joinVert . map joinHoriz
61
46-- | Reverse rows 62-- | Reverse rows
47flipud :: Field t => Matrix t -> Matrix t 63flipud :: Field t => Matrix t -> Matrix t
48flipud m = fromRows . reverse . toRows $ m 64flipud m = fromRows . reverse . toRows $ m
@@ -98,6 +114,11 @@ dropColumns n mat = subMatrix (0,n) (rows mat, cols mat - n) mat
98 114
99---------------------------------------------------------------- 115----------------------------------------------------------------
100 116
117{- | Creates a vector by concatenation of rows
118
119@\> flatten ('ident' 3)
1209 # [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@
121-}
101flatten :: Matrix t -> Vector t 122flatten :: Matrix t -> Vector t
102flatten = cdat 123flatten = cdat
103 124
@@ -106,4 +127,10 @@ fromLists :: Field t => [[t]] -> Matrix t
106fromLists = fromRows . map fromList 127fromLists = fromRows . map fromList
107 128
108conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double) 129conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double)
109conjTrans = trans . liftMatrix conj \ No newline at end of file 130conjTrans = trans . liftMatrix conj
131
132asRow :: Field a => Vector a -> Matrix a
133asRow v = reshape (dim v) v
134
135asColumn :: Field a => Vector a -> Matrix a
136asColumn v = reshape 1 v