diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 63ebddf..e76500b 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -24,6 +24,8 @@ import Complex | |||
24 | import Control.Monad(when) | 24 | import Control.Monad(when) |
25 | import Data.List(transpose,intersperse) | 25 | import Data.List(transpose,intersperse) |
26 | import Data.Maybe(fromJust) | 26 | import Data.Maybe(fromJust) |
27 | import Foreign.C.String | ||
28 | import Foreign.C.Types | ||
27 | 29 | ||
28 | ----------------------------------------------------------------- | 30 | ----------------------------------------------------------------- |
29 | 31 | ||
@@ -371,6 +373,16 @@ fromComplex z = (r,i) where | |||
371 | comp :: Vector Double -> Vector (Complex Double) | 373 | comp :: Vector Double -> Vector (Complex Double) |
372 | comp v = toComplex (v,constant 0 (dim v)) | 374 | comp v = toComplex (v,constant 0 (dim v)) |
373 | 375 | ||
376 | -- | loads a matrix efficiently from formatted ASCII text file (the number of rows and columns must be known in advance). | ||
377 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
378 | fromFile filename (r,c) = do | ||
379 | charname <- newCString filename | ||
380 | res <- createMatrix RowMajor r c | ||
381 | c_gslReadMatrix charname // mat dat res // check "gslReadMatrix" [] | ||
382 | --free charname -- TO DO: free the auxiliary CString | ||
383 | return res | ||
384 | foreign import ccall "aux.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM | ||
385 | |||
374 | ------------------------------------------------------------------------- | 386 | ------------------------------------------------------------------------- |
375 | 387 | ||
376 | -- Generic definitions | 388 | -- Generic definitions |