diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-06-25 07:32:56 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-06-25 07:32:56 +0000 |
commit | 1871acb835b4fc164bcff3f6e7467884b87fbd0f (patch) | |
tree | ac1028d40778bbae532c3915276b5af21ba5f5cb /lib/Data/Packed/Matrix.hs | |
parent | 3d5d6f06598aac00906c93ac5358e68697c47fc7 (diff) |
l.a. algorithms, etc.
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 35 |
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 | ||
15 | module Data.Packed.Matrix ( | 15 | module 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 | |||
43 | joinHoriz :: Field t => [Matrix t] -> Matrix t | 43 | joinHoriz :: Field t => [Matrix t] -> Matrix t |
44 | joinHoriz ms = trans. joinVert . map trans $ ms | 44 | joinHoriz 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 | -} | ||
59 | fromBlocks :: Field t => [[Matrix t]] -> Matrix t | ||
60 | fromBlocks = joinVert . map joinHoriz | ||
61 | |||
46 | -- | Reverse rows | 62 | -- | Reverse rows |
47 | flipud :: Field t => Matrix t -> Matrix t | 63 | flipud :: Field t => Matrix t -> Matrix t |
48 | flipud m = fromRows . reverse . toRows $ m | 64 | flipud 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) | ||
120 | 9 # [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ | ||
121 | -} | ||
101 | flatten :: Matrix t -> Vector t | 122 | flatten :: Matrix t -> Vector t |
102 | flatten = cdat | 123 | flatten = cdat |
103 | 124 | ||
@@ -106,4 +127,10 @@ fromLists :: Field t => [[t]] -> Matrix t | |||
106 | fromLists = fromRows . map fromList | 127 | fromLists = fromRows . map fromList |
107 | 128 | ||
108 | conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double) | 129 | conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double) |
109 | conjTrans = trans . liftMatrix conj \ No newline at end of file | 130 | conjTrans = trans . liftMatrix conj |
131 | |||
132 | asRow :: Field a => Vector a -> Matrix a | ||
133 | asRow v = reshape (dim v) v | ||
134 | |||
135 | asColumn :: Field a => Vector a -> Matrix a | ||
136 | asColumn v = reshape 1 v | ||