diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-06-12 14:15:05 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-06-12 14:15:05 +0200 |
commit | 01832377377142696645a2ea800af2db3d0fac15 (patch) | |
tree | 4988111123ac1e8ad4cc377bb713f8fff6ee3274 /packages/base/src/Data | |
parent | 302a220b636d510ccf654e3671e8a93391c13523 (diff) |
improved loadMatrix
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r-- | packages/base/src/Data/Packed/IO.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/packages/base/src/Data/Packed/IO.hs b/packages/base/src/Data/Packed/IO.hs index f7afa80..85f1b37 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, loadMatrix, saveMatrix | 17 | readMatrix, fromArray2D, loadMatrix, loadMatrix', saveMatrix |
18 | ) where | 18 | ) where |
19 | 19 | ||
20 | import Data.Packed | 20 | import Data.Packed |
@@ -155,5 +155,13 @@ loadMatrix :: FilePath -> IO (Matrix Double) | |||
155 | loadMatrix f = do | 155 | loadMatrix f = do |
156 | v <- vectorScan f | 156 | v <- vectorScan f |
157 | c <- apparentCols f | 157 | c <- apparentCols f |
158 | return (reshape c v) | 158 | if (dim v `mod` c /= 0) |
159 | then | ||
160 | error $ printf "loadMatrix: %d elements and %d columns in file %s" | ||
161 | (dim v) c f | ||
162 | else | ||
163 | return (reshape c v) | ||
164 | |||
165 | |||
166 | loadMatrix' name = mbCatch (loadMatrix name) | ||
159 | 167 | ||