diff options
Diffstat (limited to 'packages/base/src/Data/Packed')
-rw-r--r-- | packages/base/src/Data/Packed/IO.hs | 18 |
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 | ||
15 | module Data.Packed.IO ( | 15 | module 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 | ||
20 | import Data.Packed | 20 | import Data.Packed |
@@ -22,6 +22,8 @@ import Data.Packed.Development | |||
22 | import Text.Printf(printf) | 22 | import Text.Printf(printf) |
23 | import Data.List(intersperse) | 23 | import Data.List(intersperse) |
24 | import Data.Complex | 24 | import Data.Complex |
25 | import Numeric.Vectorized(vectorScan,saveMatrix) | ||
26 | import 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 |
27 | this function the user can easily define any desired display function: | 29 | this function the user can easily define any desired display function: |
@@ -139,3 +141,17 @@ dispcf d m = sdims m ++ "\n" ++ format " " (showComplex d) m | |||
139 | readMatrix :: String -> Matrix Double | 141 | readMatrix :: String -> Matrix Double |
140 | readMatrix = fromLists . map (map read). map words . filter (not.null) . lines | 142 | readMatrix = fromLists . map (map read). map words . filter (not.null) . lines |
141 | 143 | ||
144 | -------------------------------------------------------------------------------- | ||
145 | |||
146 | apparentCols :: FilePath -> IO Int | ||
147 | apparentCols s = f . dropWhile null . map words . lines <$> readFile s | ||
148 | where | ||
149 | f [] = 0 | ||
150 | f (x:_) = length x | ||
151 | |||
152 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
153 | loadMatrix f = do | ||
154 | v <- vectorScan f | ||
155 | c <- apparentCols f | ||
156 | return (reshape c v) | ||
157 | |||