summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-12 19:09:47 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-12 19:09:47 +0000
commit0ff13d993b880739295de343bca62f06fac5ca0c (patch)
tree252a51b4314c19c04a9eda87973eeaae63167a41 /lib/Data/Packed/Matrix.hs
parentcd937c2be2900b8f13506d9ae7c731ad43d74e05 (diff)
documentation
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs62
1 files changed, 31 insertions, 31 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 45aaaba..01e8133 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -13,19 +13,19 @@
13----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
14 14
15module Data.Packed.Matrix ( 15module Data.Packed.Matrix (
16 Matrix(rows,cols), 16 Field,
17 fromLists, toLists, (><), (>|<), (@@>), 17 Matrix,rows,cols,
18 (><), reshape, flatten,
19 fromLists, toLists,
20 (@@>),
18 trans, conjTrans, 21 trans, conjTrans,
19 reshape, flatten, asRow, asColumn, 22 asRow, asColumn,
20 fromRows, toRows, fromColumns, toColumns, fromBlocks, 23 fromRows, toRows, fromColumns, toColumns,
21 joinVert, joinHoriz, 24 fromBlocks, joinVert, joinHoriz,
22 flipud, fliprl, 25 flipud, fliprl,
26 subMatrix, takeRows, dropRows, takeColumns, dropColumns,
27 diag, takeDiag, diagRect, ident,
23 liftMatrix, liftMatrix2, 28 liftMatrix, liftMatrix2,
24 multiply,
25 outer,
26 subMatrix,
27 takeRows, dropRows, takeColumns, dropColumns,
28 diag, takeDiag, diagRect, ident
29) where 29) where
30 30
31import Data.Packed.Internal 31import Data.Packed.Internal
@@ -83,6 +83,18 @@ takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols
83ident :: (Num t, Field t) => Int -> Matrix t 83ident :: (Num t, Field t) => Int -> Matrix t
84ident n = diag (constant 1 n) 84ident n = diag (constant 1 n)
85 85
86------------------------------------------------------------
87
88{- | An easy way to create a matrix:
89
90@\> (2><3)[1..6]
91(2><3)
92 [ 1.0, 2.0, 3.0
93 , 4.0, 5.0, 6.0 ]@
94
95This is the format produced by the instances of Show (Matrix a), which
96can also be used for input.
97-}
86(><) :: (Field a) => Int -> Int -> [a] -> Matrix a 98(><) :: (Field a) => Int -> Int -> [a] -> Matrix a
87r >< c = f where 99r >< c = f where
88 f l | dim v == r*c = matrixFromVector RowMajor c v 100 f l | dim v == r*c = matrixFromVector RowMajor c v
@@ -90,13 +102,6 @@ r >< c = f where
90 ++show (dim v) ++" in ("++show r++"><"++show c++")" 102 ++show (dim v) ++" in ("++show r++"><"++show c++")"
91 where v = fromList l 103 where v = fromList l
92 104
93(>|<) :: (Field a) => Int -> Int -> [a] -> Matrix a
94r >|< c = f where
95 f l | dim v == r*c = matrixFromVector ColumnMajor c v
96 | otherwise = error $ "inconsistent list size = "
97 ++show (dim v) ++" in ("++show r++"><"++show c++")"
98 where v = fromList l
99
100---------------------------------------------------------------- 105----------------------------------------------------------------
101 106
102-- | Creates a matrix with the first n rows of another matrix 107-- | Creates a matrix with the first n rows of another matrix
@@ -117,12 +122,19 @@ dropColumns n mat = subMatrix (0,n) (rows mat, cols mat - n) mat
117{- | Creates a vector by concatenation of rows 122{- | Creates a vector by concatenation of rows
118 123
119@\> flatten ('ident' 3) 124@\> flatten ('ident' 3)
1209 # [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@ 1259 |> [1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0]@
121-} 126-}
122flatten :: Field t => Matrix t -> Vector t 127flatten :: Field t => Matrix t -> Vector t
123flatten = cdat 128flatten = cdat
124 129
125-- | Creates a 'Matrix' from a list of lists (considered as rows). 130{- | Creates a 'Matrix' from a list of lists (considered as rows).
131
132@\> fromLists [[1,2],[3,4],[5,6]]
133(3><2)
134 [ 1.0, 2.0
135 , 3.0, 4.0
136 , 5.0, 6.0 ]@
137-}
126fromLists :: Field t => [[t]] -> Matrix t 138fromLists :: Field t => [[t]] -> Matrix t
127fromLists = fromRows . map fromList 139fromLists = fromRows . map fromList
128 140
@@ -137,15 +149,3 @@ asColumn v = reshape 1 v
137 149
138------------------------------------------------ 150------------------------------------------------
139 151
140{- | Outer product of two vectors.
141
142@\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3]
143(3><3)
144 [ 5.0, 2.0, 3.0
145 , 10.0, 4.0, 6.0
146 , 15.0, 6.0, 9.0 ]@
147-}
148outer :: (Num t, Field t) => Vector t -> Vector t -> Matrix t
149outer u v = multiply RowMajor r c
150 where r = matrixFromVector RowMajor 1 u
151 c = matrixFromVector RowMajor (dim v) v