diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-06-18 08:39:56 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-06-18 08:39:56 +0000 |
commit | 2caea08c65f6d881459de64f5f7c8c7886337806 (patch) | |
tree | 3bc54c5e3faebba536c30fc5ce10906d2936eaea /lib/Data/Packed/Internal | |
parent | 5db2ed78986bbc737b82e428392ee63999c8abfd (diff) |
saveMatrix
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 01d2ccf..68547bd 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -23,6 +23,7 @@ import Data.Packed.Internal.Vector | |||
23 | import Foreign hiding (xor) | 23 | import Foreign hiding (xor) |
24 | import Complex | 24 | import Complex |
25 | import Foreign.C.Types | 25 | import Foreign.C.Types |
26 | import Foreign.C.String | ||
26 | 27 | ||
27 | ----------------------------------------------------------------- | 28 | ----------------------------------------------------------------- |
28 | 29 | ||
@@ -350,6 +351,19 @@ fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double) | |||
350 | fromComplex z = (r,i) where | 351 | fromComplex z = (r,i) where |
351 | [r,i] = toColumns $ reshape 2 $ asReal z | 352 | [r,i] = toColumns $ reshape 2 $ asReal z |
352 | 353 | ||
353 | -- | loads a matrix from an ASCII file (the number of rows and columns must be known in advance). | 354 | -------------------------------------------------------------------------- |
354 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | 355 | |
355 | fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c) | 356 | -- | Saves a matrix as 2D ASCII table. |
357 | saveMatrix :: FilePath | ||
358 | -> String -- ^ format (%f, %g, %e) | ||
359 | -> Matrix Double | ||
360 | -> IO () | ||
361 | saveMatrix filename fmt m = do | ||
362 | charname <- newCString filename | ||
363 | charfmt <- newCString fmt | ||
364 | let o = if orderOf m == RowMajor then 1 else 0 | ||
365 | app1 (matrix_fprintf charname charfmt o) mat m "matrix_fprintf" | ||
366 | free charname | ||
367 | free charfmt | ||
368 | |||
369 | foreign import ccall "matrix_fprintf" matrix_fprintf :: Ptr CChar -> Ptr CChar -> CInt -> TM | ||