summaryrefslogtreecommitdiff
path: root/lib/Data/Packed
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-09-28 12:25:56 +0000
committerAlberto Ruiz <aruiz@um.es>2007-09-28 12:25:56 +0000
commit3815bc25f62124063e02af83fe3c907336dc86f5 (patch)
tree50fddcf4e66780272fdddf5515540e0f5d200feb /lib/Data/Packed
parent74e7d42263b196c22d1f5da3d51beec69071600d (diff)
algorithms interface reorganized
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs12
-rw-r--r--lib/Data/Packed/Internal/aux.h2
-rw-r--r--lib/Data/Packed/Matrix.hs8
3 files changed, 21 insertions, 1 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
24import Control.Monad(when) 24import Control.Monad(when)
25import Data.List(transpose,intersperse) 25import Data.List(transpose,intersperse)
26import Data.Maybe(fromJust) 26import Data.Maybe(fromJust)
27import Foreign.C.String
28import Foreign.C.Types
27 29
28----------------------------------------------------------------- 30-----------------------------------------------------------------
29 31
@@ -371,6 +373,16 @@ fromComplex z = (r,i) where
371comp :: Vector Double -> Vector (Complex Double) 373comp :: Vector Double -> Vector (Complex Double)
372comp v = toComplex (v,constant 0 (dim v)) 374comp 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).
377fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double)
378fromFile 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
384foreign import ccall "aux.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM
385
374------------------------------------------------------------------------- 386-------------------------------------------------------------------------
375 387
376-- Generic definitions 388-- Generic definitions
diff --git a/lib/Data/Packed/Internal/aux.h b/lib/Data/Packed/Internal/aux.h
index 83111e5..73334e3 100644
--- a/lib/Data/Packed/Internal/aux.h
+++ b/lib/Data/Packed/Internal/aux.h
@@ -26,3 +26,5 @@ int diagR(KRVEC(d),RMAT(r));
26int diagC(KCVEC(d),CMAT(r)); 26int diagC(KCVEC(d),CMAT(r));
27 27
28const char * gsl_strerror (const int gsl_errno); 28const char * gsl_strerror (const int gsl_errno);
29
30int matrix_fscanf(char*filename, RMAT(a));
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 404fde7..2b93348 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -25,9 +25,10 @@ module Data.Packed.Matrix (
25 fromBlocks, 25 fromBlocks,
26 flipud, fliprl, 26 flipud, fliprl,
27 subMatrix, takeRows, dropRows, takeColumns, dropColumns, 27 subMatrix, takeRows, dropRows, takeColumns, dropColumns,
28 extractRows,
28 ident, diag, diagRect, takeDiag, 29 ident, diag, diagRect, takeDiag,
29 liftMatrix, liftMatrix2, 30 liftMatrix, liftMatrix2,
30 format, dispR, readMatrix, fromArray2D 31 format, dispR, readMatrix, fromFile, fromArray2D
31) where 32) where
32 33
33import Data.Packed.Internal 34import Data.Packed.Internal
@@ -209,3 +210,8 @@ dispC d m = disp m (shfc d)
209-- | creates a matrix from a table of numbers. 210-- | creates a matrix from a table of numbers.
210readMatrix :: String -> Matrix Double 211readMatrix :: String -> Matrix Double
211readMatrix = fromLists . map (map read). map words . filter (not.null) . lines 212readMatrix = fromLists . map (map read). map words . filter (not.null) . lines
213
214-- | rearranges the rows of a matrix according to the order given in a list of integers.
215extractRows :: Field t => [Int] -> Matrix t -> Matrix t
216extractRows l m = fromRows $ extract (toRows $ m) l
217 where extract l is = [l!!i |i<-is]