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.hs15
1 files changed, 4 insertions, 11 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 66e5082..a8e998f 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -36,10 +36,10 @@ module Data.Packed.Matrix (
36import Data.Packed.Internal 36import Data.Packed.Internal
37import qualified Data.Packed.ST as ST 37import qualified Data.Packed.ST as ST
38import Data.Packed.Vector 38import Data.Packed.Vector
39import Data.List(transpose,intersperse)
40import Data.Array 39import Data.Array
41import System.Process(readProcess) 40import System.Process(readProcess)
42import Text.Printf(printf) 41import Text.Printf(printf)
42import Data.List(transpose)
43 43
44-- | creates a matrix from a vertical list of matrices 44-- | creates a matrix from a vertical list of matrices
45joinVert :: Element t => [Matrix t] -> Matrix t 45joinVert :: Element t => [Matrix t] -> Matrix t
@@ -85,7 +85,7 @@ adaptBlocks ms = ms' where
85 rs = map (compatdim . map rows) ms 85 rs = map (compatdim . map rows) ms
86 cs = map (compatdim . map cols) (transpose ms) 86 cs = map (compatdim . map cols) (transpose ms)
87 szs = sequence [rs,cs] 87 szs = sequence [rs,cs]
88 ms' = partit bc $ zipWith g szs (concat ms) 88 ms' = splitEvery bc $ zipWith g szs (concat ms)
89 89
90 g [Just nr,Just nc] m 90 g [Just nr,Just nc] m
91 | nr == r && nc == c = m 91 | nr == r && nc == c = m
@@ -249,13 +249,6 @@ shfc n z@ (a:+b)
249 249
250-} 250-}
251 251
252dsp' :: String -> [[String]] -> String
253dsp' sep as = unlines . map unwords' $ transpose mtp where
254 mt = transpose as
255 longs = map (maximum . map length) mt
256 mtp = zipWith (\a b -> map (pad a) b) longs mt
257 pad n str = replicate (n - length str) ' ' ++ str
258 unwords' = concat . intersperse sep
259 252
260{- | Creates a string from a matrix given a separator and a function to show each entry. Using 253{- | Creates a string from a matrix given a separator and a function to show each entry. Using
261this function the user can easily define any desired display function: 254this function the user can easily define any desired display function:
@@ -266,7 +259,7 @@ this function the user can easily define any desired display function:
266 259
267-} 260-}
268format :: (Element t) => String -> (t -> String) -> Matrix t -> String 261format :: (Element t) => String -> (t -> String) -> Matrix t -> String
269format sep f m = dsp' sep . map (map f) . toLists $ m 262format sep f m = table sep . map (map f) . toLists $ m
270 263
271{- 264{-
272disp m f = putStrLn $ "matrix ("++show (rows m) ++"x"++ show (cols m) ++")\n"++format " | " f m 265disp m f = putStrLn $ "matrix ("++show (rows m) ++"x"++ show (cols m) ++")\n"++format " | " f m
@@ -385,7 +378,7 @@ extractRows l m = fromRows $ extract (toRows $ m) l
385 378
386-} 379-}
387repmat :: (Element t) => Matrix t -> Int -> Int -> Matrix t 380repmat :: (Element t) => Matrix t -> Int -> Int -> Matrix t
388repmat m r c = fromBlocks $ partit c $ replicate (r*c) m 381repmat m r c = fromBlocks $ splitEvery c $ replicate (r*c) m
389 382
390-- | A version of 'liftMatrix2' which automatically adapt matrices with a single row or column to match the dimensions of the other matrix. 383-- | A version of 'liftMatrix2' which automatically adapt matrices with a single row or column to match the dimensions of the other matrix.
391liftMatrix2Auto :: (Element t, Element a, Element b) 384liftMatrix2Auto :: (Element t, Element a, Element b)