diff options
-rw-r--r-- | hmatrix.cabal | 11 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 2 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 25 |
3 files changed, 33 insertions, 5 deletions
diff --git a/hmatrix.cabal b/hmatrix.cabal index 5265451..133b602 100644 --- a/hmatrix.cabal +++ b/hmatrix.cabal | |||
@@ -55,9 +55,9 @@ flag unsafe | |||
55 | 55 | ||
56 | library | 56 | library |
57 | if flag(splitBase) | 57 | if flag(splitBase) |
58 | build-depends: base >= 3, array, QuickCheck, HUnit, storable-complex | 58 | build-depends: base >= 3, array, QuickCheck, HUnit, storable-complex, process |
59 | else | 59 | else |
60 | build-depends: base < 3, QuickCheck, HUnit, storable-complex | 60 | build-depends: base < 3, QuickCheck, HUnit, storable-complex, process |
61 | 61 | ||
62 | Build-Depends: haskell98 | 62 | Build-Depends: haskell98 |
63 | Extensions: ForeignFunctionInterface, | 63 | Extensions: ForeignFunctionInterface, |
@@ -121,6 +121,13 @@ library | |||
121 | Numeric.LinearAlgebra.Tests.Properties | 121 | Numeric.LinearAlgebra.Tests.Properties |
122 | C-sources: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c, | 122 | C-sources: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c, |
123 | lib/Numeric/GSL/gsl-aux.c | 123 | lib/Numeric/GSL/gsl-aux.c |
124 | extra-source-files: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h, | ||
125 | lib/Numeric/LinearAlgebra/LAPACK/clapack.h, | ||
126 | lib/Numeric/GSL/gsl-aux.h | ||
127 | |||
128 | extra-source-files: lib/Numeric/GSL/Special/auto.hs, | ||
129 | lib/Numeric/GSL/Special/autoall.sh, | ||
130 | lib/Numeric/GSL/Special/replace.hs | ||
124 | 131 | ||
125 | ghc-prof-options: -auto-all | 132 | ghc-prof-options: -auto-all |
126 | 133 | ||
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 8a074a6..7678a12 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -351,7 +351,7 @@ fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double) | |||
351 | fromComplex z = (r,i) where | 351 | fromComplex z = (r,i) where |
352 | [r,i] = toColumns $ reshape 2 $ asReal z | 352 | [r,i] = toColumns $ reshape 2 $ asReal z |
353 | 353 | ||
354 | -- | loads a matrix efficiently from formatted ASCII text file (the number of rows and columns must be known in advance). | 354 | -- | loads a matrix from an ASCII file (the number of rows and columns must be known in advance). |
355 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | 355 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) |
356 | fromFile filename (r,c) = do | 356 | fromFile filename (r,c) = do |
357 | charname <- newCString filename | 357 | charname <- newCString filename |
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 0b50d8a..32eb991 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -29,7 +29,9 @@ module Data.Packed.Matrix ( | |||
29 | extractRows, | 29 | extractRows, |
30 | ident, diag, diagRect, takeDiag, | 30 | ident, diag, diagRect, takeDiag, |
31 | liftMatrix, liftMatrix2, | 31 | liftMatrix, liftMatrix2, |
32 | format, readMatrix, fromFile, fromArray2D | 32 | format, |
33 | loadMatrix, fromFile, fileDimensions, | ||
34 | readMatrix, fromArray2D | ||
33 | ) where | 35 | ) where |
34 | 36 | ||
35 | import Data.Packed.Internal | 37 | import Data.Packed.Internal |
@@ -37,6 +39,7 @@ import qualified Data.Packed.ST as ST | |||
37 | import Data.Packed.Vector | 39 | import Data.Packed.Vector |
38 | import Data.List(transpose,intersperse) | 40 | import Data.List(transpose,intersperse) |
39 | import Data.Array | 41 | import Data.Array |
42 | import System.Process(readProcess) | ||
40 | 43 | ||
41 | -- | creates a matrix from a vertical list of matrices | 44 | -- | creates a matrix from a vertical list of matrices |
42 | joinVert :: Element t => [Matrix t] -> Matrix t | 45 | joinVert :: Element t => [Matrix t] -> Matrix t |
@@ -227,10 +230,28 @@ dispC :: Int -> Matrix (Complex Double) -> IO () | |||
227 | dispC d m = disp m (shfc d) | 230 | dispC d m = disp m (shfc d) |
228 | -} | 231 | -} |
229 | 232 | ||
230 | -- | creates a matrix from a table of numbers. | 233 | -- | reads a matrix from a string containing a table of numbers. |
231 | readMatrix :: String -> Matrix Double | 234 | readMatrix :: String -> Matrix Double |
232 | readMatrix = fromLists . map (map read). map words . filter (not.null) . lines | 235 | readMatrix = fromLists . map (map read). map words . filter (not.null) . lines |
233 | 236 | ||
237 | {- | obtains the number of rows and columns in an ASCII data file | ||
238 | (provisionally using unix's wc). | ||
239 | -} | ||
240 | fileDimensions :: FilePath -> IO (Int,Int) | ||
241 | fileDimensions fname = do | ||
242 | wcres <- readProcess "wc" ["-w",fname] "" | ||
243 | contents <- readFile fname | ||
244 | let tot = read . head . words $ wcres | ||
245 | c = length . head . dropWhile null . map words . lines $ contents | ||
246 | if tot > 0 | ||
247 | then return (tot `div` c, c) | ||
248 | else return (0,0) | ||
249 | |||
250 | {- | loads a matrix from a formatted ASCII file. | ||
251 | -} | ||
252 | loadMatrix :: FilePath -> IO (Matrix Double) | ||
253 | loadMatrix file = fromFile file =<< fileDimensions file | ||
254 | |||
234 | -- | rearranges the rows of a matrix according to the order given in a list of integers. | 255 | -- | rearranges the rows of a matrix according to the order given in a list of integers. |
235 | extractRows :: Element t => [Int] -> Matrix t -> Matrix t | 256 | extractRows :: Element t => [Int] -> Matrix t -> Matrix t |
236 | extractRows l m = fromRows $ extract (toRows $ m) l | 257 | extractRows l m = fromRows $ extract (toRows $ m) l |