summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-06-18 08:39:56 +0000
committerAlberto Ruiz <aruiz@um.es>2009-06-18 08:39:56 +0000
commit2caea08c65f6d881459de64f5f7c8c7886337806 (patch)
tree3bc54c5e3faebba536c30fc5ce10906d2936eaea /lib/Data/Packed/Matrix.hs
parent5db2ed78986bbc737b82e428392ee63999c8abfd (diff)
saveMatrix
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 32eb991..ad0776e 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -30,7 +30,7 @@ module Data.Packed.Matrix (
30 ident, diag, diagRect, takeDiag, 30 ident, diag, diagRect, takeDiag,
31 liftMatrix, liftMatrix2, 31 liftMatrix, liftMatrix2,
32 format, 32 format,
33 loadMatrix, fromFile, fileDimensions, 33 loadMatrix, saveMatrix, fromFile, fileDimensions,
34 readMatrix, fromArray2D 34 readMatrix, fromArray2D
35) where 35) where
36 36
@@ -247,11 +247,15 @@ fileDimensions fname = do
247 then return (tot `div` c, c) 247 then return (tot `div` c, c)
248 else return (0,0) 248 else return (0,0)
249 249
250{- | loads a matrix from a formatted ASCII file. 250-- | Loads a matrix from an ASCII file formatted as a 2D table.
251-}
252loadMatrix :: FilePath -> IO (Matrix Double) 251loadMatrix :: FilePath -> IO (Matrix Double)
253loadMatrix file = fromFile file =<< fileDimensions file 252loadMatrix file = fromFile file =<< fileDimensions file
254 253
254-- | Loads a matrix from an ASCII file (the number of rows and columns must be known in advance).
255fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double)
256fromFile filename (r,c) = reshape c `fmap` fscanfVector filename (r*c)
257
258
255-- | rearranges the rows of a matrix according to the order given in a list of integers. 259-- | rearranges the rows of a matrix according to the order given in a list of integers.
256extractRows :: Element t => [Int] -> Matrix t -> Matrix t 260extractRows :: Element t => [Int] -> Matrix t -> Matrix t
257extractRows l m = fromRows $ extract (toRows $ m) l 261extractRows l m = fromRows $ extract (toRows $ m) l