diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-09-28 12:25:56 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-09-28 12:25:56 +0000 |
commit | 3815bc25f62124063e02af83fe3c907336dc86f5 (patch) | |
tree | 50fddcf4e66780272fdddf5515540e0f5d200feb /lib/GSL/Matrix.hs | |
parent | 74e7d42263b196c22d1f5da3d51beec69071600d (diff) |
algorithms interface reorganized
Diffstat (limited to 'lib/GSL/Matrix.hs')
-rw-r--r-- | lib/GSL/Matrix.hs | 35 |
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 | ||
25 | import Data.Packed.Internal | 24 | import Data.Packed.Internal |
26 | import Data.Packed.Matrix(fromLists,ident,takeDiag) | 25 | import Data.Packed.Matrix(fromLists,ident,takeDiag) |
27 | import GSL.Vector | 26 | import GSL.Vector |
28 | import Foreign | 27 | import Foreign |
29 | import Foreign.C.Types | ||
30 | import Complex | 28 | import Complex |
31 | import 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 | ||
258 | L \* U obtains a permuted version of the original matrix: | 255 | L \* 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 | ||
301 | extract l is = [l!!i |i<-is] | ||
302 | |||
303 | {- auxiliary function to get triangular matrices | 298 | {- auxiliary function to get triangular matrices |
304 | -} | 299 | -} |
305 | triang r c h v = reshape c $ fromList [el i j | i<-[0..r-1], j<-[0..c-1]] | 300 | triang 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 | -} | ||
317 | extractRows :: Field t => [Int] -> Matrix t -> Matrix t | ||
318 | extractRows 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). | ||
323 | fromFile :: FilePath -> (Int,Int) -> IO (Matrix Double) | ||
324 | fromFile 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 | ||
330 | foreign import ccall "gsl-aux.h matrix_fscanf" c_gslReadMatrix:: Ptr CChar -> TM | ||
331 | |||
332 | --------------------------------------------------------------------------- | ||