summaryrefslogtreecommitdiff
path: root/packages/base/src/Data/Packed
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Data/Packed')
-rw-r--r--packages/base/src/Data/Packed/IO.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/base/src/Data/Packed/IO.hs b/packages/base/src/Data/Packed/IO.hs
index dbb2943..db03d5f 100644
--- a/packages/base/src/Data/Packed/IO.hs
+++ b/packages/base/src/Data/Packed/IO.hs
@@ -14,7 +14,7 @@
14 14
15module Data.Packed.IO ( 15module Data.Packed.IO (
16 dispf, disps, dispcf, vecdisp, latexFormat, format, 16 dispf, disps, dispcf, vecdisp, latexFormat, format,
17 readMatrix, fromArray2D 17 readMatrix, fromArray2D, loadMatrix, saveMatrix
18) where 18) where
19 19
20import Data.Packed 20import Data.Packed
@@ -22,6 +22,8 @@ import Data.Packed.Development
22import Text.Printf(printf) 22import Text.Printf(printf)
23import Data.List(intersperse) 23import Data.List(intersperse)
24import Data.Complex 24import Data.Complex
25import Numeric.Vectorized(vectorScan,saveMatrix)
26import Control.Applicative((<$>))
25 27
26{- | Creates a string from a matrix given a separator and a function to show each entry. Using 28{- | Creates a string from a matrix given a separator and a function to show each entry. Using
27this function the user can easily define any desired display function: 29this function the user can easily define any desired display function:
@@ -139,3 +141,17 @@ dispcf d m = sdims m ++ "\n" ++ format " " (showComplex d) m
139readMatrix :: String -> Matrix Double 141readMatrix :: String -> Matrix Double
140readMatrix = fromLists . map (map read). map words . filter (not.null) . lines 142readMatrix = fromLists . map (map read). map words . filter (not.null) . lines
141 143
144--------------------------------------------------------------------------------
145
146apparentCols :: FilePath -> IO Int
147apparentCols s = f . dropWhile null . map words . lines <$> readFile s
148 where
149 f [] = 0
150 f (x:_) = length x
151
152loadMatrix :: FilePath -> IO (Matrix Double)
153loadMatrix f = do
154 v <- vectorScan f
155 c <- apparentCols f
156 return (reshape c v)
157