summaryrefslogtreecommitdiff
path: root/lib/GSL/Matrix.hs
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/GSL/Matrix.hs
parent74e7d42263b196c22d1f5da3d51beec69071600d (diff)
algorithms interface reorganized
Diffstat (limited to 'lib/GSL/Matrix.hs')
-rw-r--r--lib/GSL/Matrix.hs35
1 files changed, 2 insertions, 33 deletions
diff --git a/lib/GSL/Matrix.hs b/lib/GSL/Matrix.hs
index c1bce37..3a54226 100644
--- a/lib/GSL/Matrix.hs
+++ b/lib/GSL/Matrix.hs
@@ -18,17 +18,14 @@ module GSL.Matrix(
18 qr, 18 qr,
19 cholR, -- cholC, 19 cholR, -- cholC,
20 luSolveR, luSolveC, 20 luSolveR, luSolveC,
21 luR, luC, 21 luR, luC
22 fromFile, extractRows
23) where 22) where
24 23
25import Data.Packed.Internal 24import Data.Packed.Internal
26import Data.Packed.Matrix(fromLists,ident,takeDiag) 25import Data.Packed.Matrix(fromLists,ident,takeDiag)
27import GSL.Vector 26import GSL.Vector
28import Foreign 27import Foreign
29import Foreign.C.Types
30import Complex 28import Complex
31import Foreign.C.String
32 29
33{- | eigendecomposition of a real symmetric matrix using /gsl_eigen_symmv/. 30{- | eigendecomposition of a real symmetric matrix using /gsl_eigen_symmv/.
34 31
@@ -257,7 +254,7 @@ p is a permutation:
257 254
258L \* U obtains a permuted version of the original matrix: 255L \* U obtains a permuted version of the original matrix:
259 256
260@\> 'extractRows' p m 257@\> extractRows p m
261 2.+3.i -7. 0. 258 2.+3.i -7. 0.
262 1. 2. -3. 259 1. 2. -3.
263 1. -1.i 2.i 260 1. -1.i 2.i
@@ -298,35 +295,7 @@ luC m = (l,u,p, fromIntegral s') where
298 add = liftMatrix2 $ vectorZipC Add 295 add = liftMatrix2 $ vectorZipC Add
299 mul = liftMatrix2 $ vectorZipC Mul 296 mul = liftMatrix2 $ vectorZipC Mul
300 297
301extract l is = [l!!i |i<-is]
302
303{- auxiliary function to get triangular matrices 298{- auxiliary function to get triangular matrices
304-} 299-}
305triang r c h v = reshape c $ fromList [el i j | i<-[0..r-1], j<-[0..c-1]] 300triang r c h v = reshape c $ fromList [el i j | i<-[0..r-1], j<-[0..c-1]]
306 where el i j = if j-i>=h then v else 1 - v 301 where el i j = if j-i>=h then v else 1 - v
307
308{- | rearranges the rows of a matrix according to the order given in a list of integers.
309
310> > extractRows [3,3,0,1] (ident 4)
311> 0. 0. 0. 1.
312> 0. 0. 0. 1.
313> 1. 0. 0. 0.
314> 0. 1. 0. 0.
315
316-}
317extractRows :: Field t => [Int] -> Matrix t -> Matrix t
318extractRows l m = fromRows $ extract (toRows $ m) l
319
320--------------------------------------------------------------
321
322-- | loads a matrix efficiently from formatted ASCII text file (the number of rows and columns must be known in advance).
323fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double)
324fromFile filename (r,c) = do
325 charname <- newCString filename
326 res <- createMatrix RowMajor r c
327 c_gslReadMatrix charname // mat dat res // check "gslReadMatrix" []
328 --free charname -- TO DO: free the auxiliary CString
329 return res
330foreign import ccall "gsl-aux.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM
331
332---------------------------------------------------------------------------