summaryrefslogtreecommitdiff
path: root/lib/Data
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-15 09:59:20 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-15 09:59:20 +0000
commitf901d49d1392327c79f1d4c63932fa350cfb506a (patch)
tree1955651cbd636686037ae279183c7f746ff5a1af /lib/Data
parentd14515a4a50d5b5335f9c1525432b68ab67fa7c8 (diff)
minor changes
Diffstat (limited to 'lib/Data')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs3
-rw-r--r--lib/Data/Packed/Matrix.hs15
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index 58b325c..8bca510 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -152,11 +152,12 @@ reshape c v = matrixFromVector RowMajor c v
152 152
153singleton x = reshape 1 (fromList [x]) 153singleton x = reshape 1 (fromList [x])
154 154
155-- | application of a vector function on the flattened matrix elements
155liftMatrix :: (Field a, Field b) => (Vector a -> Vector b) -> Matrix a -> Matrix b 156liftMatrix :: (Field a, Field b) => (Vector a -> Vector b) -> Matrix a -> Matrix b
156liftMatrix f MC { cols = c, cdat = d } = matrixFromVector RowMajor c (f d) 157liftMatrix f MC { cols = c, cdat = d } = matrixFromVector RowMajor c (f d)
157liftMatrix f MF { cols = c, fdat = d } = matrixFromVector ColumnMajor c (f d) 158liftMatrix f MF { cols = c, fdat = d } = matrixFromVector ColumnMajor c (f d)
158 159
159 160-- | application of a vector function on the flattened matrices elements
160liftMatrix2 :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t 161liftMatrix2 :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t
161liftMatrix2 f m1 m2 162liftMatrix2 f m1 m2
162 | not (compat m1 m2) = error "nonconformant matrices in liftMatrix2" 163 | not (compat m1 m2) = error "nonconformant matrices in liftMatrix2"
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