diff options
Diffstat (limited to 'packages/base')
-rw-r--r-- | packages/base/src/C/vector-aux.c | 5 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/IO.hs | 12 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Data.hs | 2 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Util.hs | 5 | ||||
-rw-r--r-- | packages/base/src/Numeric/Vectorized.hs | 2 |
5 files changed, 19 insertions, 7 deletions
diff --git a/packages/base/src/C/vector-aux.c b/packages/base/src/C/vector-aux.c index efb82af..2f47c8f 100644 --- a/packages/base/src/C/vector-aux.c +++ b/packages/base/src/C/vector-aux.c | |||
@@ -654,6 +654,9 @@ int zipQ(int code, KQVEC(a), KQVEC(b), QVEC(r)) { | |||
654 | int vectorScan(char * file, int* n, double**pp){ | 654 | int vectorScan(char * file, int* n, double**pp){ |
655 | FILE * fp; | 655 | FILE * fp; |
656 | fp = fopen (file, "r"); | 656 | fp = fopen (file, "r"); |
657 | if(!fp) { | ||
658 | ERROR(BAD_FILE); | ||
659 | } | ||
657 | int nbuf = 100*100; | 660 | int nbuf = 100*100; |
658 | double * p = (double*)malloc(nbuf*sizeof(double)); | 661 | double * p = (double*)malloc(nbuf*sizeof(double)); |
659 | int k=0; | 662 | int k=0; |
@@ -667,7 +670,7 @@ int vectorScan(char * file, int* n, double**pp){ | |||
667 | if (k==nbuf) { | 670 | if (k==nbuf) { |
668 | nbuf = nbuf * 2; | 671 | nbuf = nbuf * 2; |
669 | p = (double*)realloc(p,nbuf*sizeof(double)); | 672 | p = (double*)realloc(p,nbuf*sizeof(double)); |
670 | //printf("R\n"); | 673 | // printf("R\n"); |
671 | } | 674 | } |
672 | p[k++] = d; | 675 | p[k++] = d; |
673 | } | 676 | } |
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 | ||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index d5ce32f..b1a31fc 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs | |||
@@ -55,7 +55,7 @@ module Numeric.LinearAlgebra.Data( | |||
55 | 55 | ||
56 | -- * IO | 56 | -- * IO |
57 | disp, | 57 | disp, |
58 | loadMatrix, saveMatrix, | 58 | loadMatrix, loadMatrix', saveMatrix, |
59 | latexFormat, | 59 | latexFormat, |
60 | dispf, disps, dispcf, format, | 60 | dispf, disps, dispcf, format, |
61 | dispDots, dispBlanks, dispShort, | 61 | dispDots, dispBlanks, dispShort, |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Util.hs b/packages/base/src/Numeric/LinearAlgebra/Util.hs index b6f8966..6bb9d15 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Util.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Util.hs | |||
@@ -416,7 +416,7 @@ c ~!~ msg = when c (error msg) | |||
416 | 416 | ||
417 | formatSparse :: String -> String -> String -> Int -> Matrix Double -> String | 417 | formatSparse :: String -> String -> String -> Int -> Matrix Double -> String |
418 | 418 | ||
419 | formatSparse zeroI zeroF sep _ (approxInt -> Just m) = format sep f m | 419 | formatSparse zeroI _zeroF sep _ (approxInt -> Just m) = format sep f m |
420 | where | 420 | where |
421 | f 0 = zeroI | 421 | f 0 = zeroI |
422 | f x = printf "%.0f" x | 422 | f x = printf "%.0f" x |
@@ -424,7 +424,8 @@ formatSparse zeroI zeroF sep _ (approxInt -> Just m) = format sep f m | |||
424 | formatSparse zeroI zeroF sep n m = format sep f m | 424 | formatSparse zeroI zeroF sep n m = format sep f m |
425 | where | 425 | where |
426 | f x | abs (x::Double) < 2*peps = zeroI++zeroF | 426 | f x | abs (x::Double) < 2*peps = zeroI++zeroF |
427 | | abs (fromIntegral (round x) - x) / abs x < 2*peps = printf ("%.0f."++replicate n ' ') x | 427 | | abs (fromIntegral (round x::Int) - x) / abs x < 2*peps |
428 | = printf ("%.0f."++replicate n ' ') x | ||
428 | | otherwise = printf ("%."++show n++"f") x | 429 | | otherwise = printf ("%."++show n++"f") x |
429 | 430 | ||
430 | approxInt m | 431 | approxInt m |
diff --git a/packages/base/src/Numeric/Vectorized.hs b/packages/base/src/Numeric/Vectorized.hs index 936daba..6f0d240 100644 --- a/packages/base/src/Numeric/Vectorized.hs +++ b/packages/base/src/Numeric/Vectorized.hs | |||
@@ -294,7 +294,7 @@ vectorScan s = do | |||
294 | cs <- newCString s | 294 | cs <- newCString s |
295 | ok <- c_vectorScan cs pn pp | 295 | ok <- c_vectorScan cs pn pp |
296 | when (not (ok == 0)) $ | 296 | when (not (ok == 0)) $ |
297 | error ("vectorScan \"" ++ s ++"\"") | 297 | error ("vectorScan: file \"" ++ s ++"\" not found") |
298 | n <- fromIntegral <$> peek pn | 298 | n <- fromIntegral <$> peek pn |
299 | p <- peek pp | 299 | p <- peek pp |
300 | v <- createVector n | 300 | v <- createVector n |