summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index ad0776e..6a6942d 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -19,7 +19,7 @@ module Data.Packed.Matrix (
19 (><), 19 (><),
20 trans, 20 trans,
21 reshape, flatten, 21 reshape, flatten,
22 fromLists, toLists, 22 fromLists, toLists, buildMatrix,
23 (@@>), 23 (@@>),
24 asRow, asColumn, 24 asRow, asColumn,
25 fromRows, toRows, fromColumns, toColumns, 25 fromRows, toRows, fromColumns, toColumns,
@@ -176,6 +176,21 @@ asRow v = reshape (dim v) v
176asColumn :: Element a => Vector a -> Matrix a 176asColumn :: Element a => Vector a -> Matrix a
177asColumn v = reshape 1 v 177asColumn v = reshape 1 v
178 178
179
180{- | creates a Matrix of the specified size using the supplied function to
181 to map the row/column position to the value at that row/column position.
182
183@> buildMatrix 3 4 (\ (r,c) -> fromIntegral r * fromIntegral c)
184(3><4)
185 [ 0.0, 0.0, 0.0, 0.0, 0.0
186 , 0.0, 1.0, 2.0, 3.0, 4.0
187 , 0.0, 2.0, 4.0, 6.0, 8.0]@
188-}
189buildMatrix :: Element a => Int -> Int -> ((Int, Int) -> a) -> Matrix a
190buildMatrix rc cc f =
191 fromLists $ map (\x -> map f x)
192 $ map (\ ri -> map (\ ci -> (ri, ci)) [0 .. (cc - 1)]) [0 .. (rc - 1)]
193
179----------------------------------------------------- 194-----------------------------------------------------
180 195
181fromArray2D :: (Element e) => Array (Int, Int) e -> Matrix e 196fromArray2D :: (Element e) => Array (Int, Int) e -> Matrix e