From 01832377377142696645a2ea800af2db3d0fac15 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Thu, 12 Jun 2014 14:15:05 +0200 Subject: improved loadMatrix --- packages/base/src/Data/Packed/IO.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'packages/base/src/Data/Packed/IO.hs') 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 @@ module Data.Packed.IO ( dispf, disps, dispcf, vecdisp, latexFormat, format, - readMatrix, fromArray2D, loadMatrix, saveMatrix + readMatrix, fromArray2D, loadMatrix, loadMatrix', saveMatrix ) where import Data.Packed @@ -155,5 +155,13 @@ loadMatrix :: FilePath -> IO (Matrix Double) loadMatrix f = do v <- vectorScan f c <- apparentCols f - return (reshape c v) + if (dim v `mod` c /= 0) + then + error $ printf "loadMatrix: %d elements and %d columns in file %s" + (dim v) c f + else + return (reshape c v) + + +loadMatrix' name = mbCatch (loadMatrix name) -- cgit v1.2.3