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/Internal/Matrix.hs | |
parent | 3d5d6f06598aac00906c93ac5358e68697c47fc7 (diff) |
l.a. algorithms, etc.
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 9309d1d..dd33943 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -93,6 +93,15 @@ createMatrix order r c = do | |||
93 | p <- createVector (r*c) | 93 | p <- createVector (r*c) |
94 | return (matrixFromVector order c p) | 94 | return (matrixFromVector order c p) |
95 | 95 | ||
96 | {- | Creates a matrix from a vector by grouping the elements in rows with the desired number of columns. | ||
97 | |||
98 | @\> reshape 4 ('fromList' [1..12]) | ||
99 | (3><4) | ||
100 | [ 1.0, 2.0, 3.0, 4.0 | ||
101 | , 5.0, 6.0, 7.0, 8.0 | ||
102 | , 9.0, 10.0, 11.0, 12.0 ]@ | ||
103 | |||
104 | -} | ||
96 | reshape :: (Field t) => Int -> Vector t -> Matrix t | 105 | reshape :: (Field t) => Int -> Vector t -> Matrix t |
97 | reshape c v = matrixFromVector RowMajor c v | 106 | reshape c v = matrixFromVector RowMajor c v |
98 | 107 | ||
@@ -140,7 +149,6 @@ liftMatrix f m = m { dat = f (dat m), tdat = f (tdat m) } -- check sizes | |||
140 | 149 | ||
141 | liftMatrix2 :: (Field t) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t | 150 | liftMatrix2 :: (Field t) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t |
142 | liftMatrix2 f m1 m2 = reshape (cols m1) (f (cdat m1) (cdat m2)) -- check sizes | 151 | liftMatrix2 f m1 m2 = reshape (cols m1) (f (cdat m1) (cdat m2)) -- check sizes |
143 | |||
144 | ------------------------------------------------------------------ | 152 | ------------------------------------------------------------------ |
145 | 153 | ||
146 | dotL a b = sum (zipWith (*) a b) | 154 | dotL a b = sum (zipWith (*) a b) |
@@ -200,6 +208,14 @@ multiplyD order a b | |||
200 | 208 | ||
201 | outer' u v = dat (outer u v) | 209 | outer' u v = dat (outer u v) |
202 | 210 | ||
211 | {- | Outer product of two vectors. | ||
212 | |||
213 | @\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3] | ||
214 | (3><3) | ||
215 | [ 5.0, 2.0, 3.0 | ||
216 | , 10.0, 4.0, 6.0 | ||
217 | , 15.0, 6.0, 9.0 ]@ | ||
218 | -} | ||
203 | outer :: (Num t, Field t) => Vector t -> Vector t -> Matrix t | 219 | outer :: (Num t, Field t) => Vector t -> Vector t -> Matrix t |
204 | outer u v = multiply RowMajor r c | 220 | outer u v = multiply RowMajor r c |
205 | where r = matrixFromVector RowMajor 1 u | 221 | where r = matrixFromVector RowMajor 1 u |