diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-10-24 09:42:36 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-10-24 09:42:36 +0000 |
commit | 2e441c3f4d08da050540256164456e18519d22ef (patch) | |
tree | faae9372692ac8b618337b3e97f8ff9d44df2d08 | |
parent | 9c65a03f4e2b3b09f6f2ac606c5b22f6df9cea14 (diff) |
documentation
-rw-r--r-- | README | 62 | ||||
-rw-r--r-- | examples/speed.hs | 20 | ||||
-rw-r--r-- | examples/speed.m | 7 | ||||
-rw-r--r-- | examples/tests.hs | 5 | ||||
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 12 | ||||
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 8 |
6 files changed, 77 insertions, 37 deletions
@@ -1,3 +1,6 @@ | |||
1 | A simple scientific library for Haskell | ||
2 | --------------------------------------- | ||
3 | |||
1 | REQUIREMENTS | 4 | REQUIREMENTS |
2 | 5 | ||
3 | 1) GNU Scientific Library (http://www.gnu.org/software/gsl) development packages | 6 | 1) GNU Scientific Library (http://www.gnu.org/software/gsl) development packages |
@@ -7,19 +10,20 @@ REQUIREMENTS | |||
7 | 10 | ||
8 | INSTALLATION | 11 | INSTALLATION |
9 | 12 | ||
10 | (More detailed information is included in the "tutorial", | ||
11 | available in the web page of the project.) | ||
12 | |||
13 | $ runhaskell Setup.lhs configure --prefix=$HOME | 13 | $ runhaskell Setup.lhs configure --prefix=$HOME |
14 | $ runhaskell Setup.lhs build | 14 | $ runhaskell Setup.lhs build |
15 | $ runhaskell Setup.lhs haddock | 15 | $ runhaskell Setup.lhs haddock |
16 | $ runhaskell Setup.lhs install --user | 16 | $ runhaskell Setup.lhs install --user |
17 | 17 | ||
18 | See below for installation on Windows. | ||
19 | |||
18 | USING ATLAS | 20 | USING ATLAS |
19 | 21 | ||
20 | $ ln -s /usr/lib/atlas/libblas.so.3.0 $HOME/lib/hssl-0.1/ghc-6.6.1/libcblas.so | 22 | $ ln -s /usr/lib/atlas/libblas.so.3.0 $HOME/lib/hssl-0.1/ghc-6.6.1/libcblas.so |
21 | $ ln -s /usr/lib/atlas/liblapack.so.3.0 $HOME/lib/hssl-0.1/ghc-6.6.1/liblapack.so | 23 | $ ln -s /usr/lib/atlas/liblapack.so.3.0 $HOME/lib/hssl-0.1/ghc-6.6.1/liblapack.so |
22 | 24 | ||
25 | (More info in the tutorial, available from the web page of the project.) | ||
26 | |||
23 | TESTS | 27 | TESTS |
24 | 28 | ||
25 | $ runhaskell examples/tests.hs | 29 | $ runhaskell examples/tests.hs |
@@ -46,10 +50,12 @@ Prelude Numeric.LinearAlgebra> u <> d <> trans v | |||
46 | Prelude Numeric.GSL> :q | 50 | Prelude Numeric.GSL> :q |
47 | Leaving GHCi. | 51 | Leaving GHCi. |
48 | 52 | ||
53 | A few illustrative programs are included in the examples folder. | ||
54 | |||
49 | CHANGES | 55 | CHANGES |
50 | 56 | ||
51 | This is a new version of GSLHaskell. The package is (provisionally) | 57 | This is a new version of GSLHaskell. The package is provisionally |
52 | called \C{hssl} (a simple scientific library for Haskell) because only | 58 | called "hssl" (a simple scientific library for Haskell) because only |
53 | a small part of GSL is available and linear algebra is based on LAPACK. | 59 | a small part of GSL is available and linear algebra is based on LAPACK. |
54 | 60 | ||
55 | The code has been extensively refactored. There is a new internal representation | 61 | The code has been extensively refactored. There is a new internal representation |
@@ -57,35 +63,18 @@ which admits both C and Fortran matrices and avoids many transposes. | |||
57 | 63 | ||
58 | There are only minor API changes: | 64 | There are only minor API changes: |
59 | 65 | ||
60 | - the matrix product operator \C{(<>)} is now overloaded only for matrix-matrix, | 66 | - The matrix product operator (<>) is now overloaded only for matrix-matrix, |
61 | matrix-vector and vector-matrix, with the same base type. The dot product and the scaling | 67 | matrix-vector and vector-matrix, with the same base type. Dot product and scaling |
62 | of vectors or matrices is now denoted by `dot` and `scale`. Conversions from real to | 68 | of vectors or matrices is now denoted by `dot` or (<.>) and `scale` or (.*). |
63 | complex objects must be explicit. | 69 | Conversions from real to complex objects must now be explicit. |
64 | 70 | ||
65 | - Most linear algebra functions admit both real and complex objects. Utilities such as | 71 | - Most linear algebra functions admit both real and complex objects. Utilities such as |
66 | ident or constant are now polymorphic. | 72 | ident or constant are now polymorphic. |
67 | 73 | ||
68 | - Runtime errors produced by GSL or LAPACK can be handled using \C{Control.Exeception.catch}. | 74 | - Runtime errors produced by GSL or LAPACK can be handled using Control.Exeception.catch. |
69 | 75 | ||
70 | Old GSLHaskell code will work with small modifications. | 76 | Old GSLHaskell code will work with small modifications. |
71 | 77 | ||
72 | ACKNOWLEDGEMENTS | ||
73 | |||
74 | I thank Henning Thielemann and all the people in the Haskell mailing lists for their help. | ||
75 | |||
76 | - Nico Mahlo discovered a bug in the eigendecomposition wrapper. | ||
77 | |||
78 | - Frederik Eaton discovered a bug in the design of the wrappers. | ||
79 | |||
80 | - Eric Kidd has created a wiki page explaining the installation on MacOS X: | ||
81 | http://www.haskell.org/haskellwiki/GSLHaskell_on_MacOS_X | ||
82 | |||
83 | - Fawzi Mohamed discovered a portability bug in the lapack wrappers. | ||
84 | |||
85 | - Pedro E. López de Teruel fixed the interface to lapack. | ||
86 | |||
87 | - Antti Siira discovered a bug in the plotting functions. | ||
88 | |||
89 | INSTALLATION ON WINDOWS | 78 | INSTALLATION ON WINDOWS |
90 | 79 | ||
91 | 1) Download the developer files gsl-1.8-lib.zip from | 80 | 1) Download the developer files gsl-1.8-lib.zip from |
@@ -109,3 +98,20 @@ INSTALLATION ON WINDOWS | |||
109 | Unfortunately the lapack dll supplied by the R system does not include zgels_ and zgelss_, | 98 | Unfortunately the lapack dll supplied by the R system does not include zgels_ and zgelss_, |
110 | so the functions depending on them (linearSolveLS and linearSolveSVD for complex data) | 99 | so the functions depending on them (linearSolveLS and linearSolveSVD for complex data) |
111 | will produce a "non supported" runtime error. | 100 | will produce a "non supported" runtime error. |
101 | |||
102 | ACKNOWLEDGEMENTS | ||
103 | |||
104 | I thank Henning Thielemann and all the people in the Haskell mailing lists for their help. | ||
105 | |||
106 | - Nico Mahlo discovered a bug in the eigendecomposition wrapper. | ||
107 | |||
108 | - Frederik Eaton discovered a bug in the design of the wrappers. | ||
109 | |||
110 | - Eric Kidd has created a wiki page explaining the installation on MacOS X: | ||
111 | http://www.haskell.org/haskellwiki/GSLHaskell_on_MacOS_X | ||
112 | |||
113 | - Fawzi Mohamed discovered a portability bug in the lapack wrappers. | ||
114 | |||
115 | - Pedro E. López de Teruel fixed the interface to lapack. | ||
116 | |||
117 | - Antti Siira discovered a bug in the plotting functions. | ||
diff --git a/examples/speed.hs b/examples/speed.hs index a937f31..865e3e1 100644 --- a/examples/speed.hs +++ b/examples/speed.hs | |||
@@ -1,3 +1,23 @@ | |||
1 | {- speed tests | ||
2 | |||
3 | $ ghc --make -O speed | ||
4 | In my machine: | ||
5 | $ ./speed 5 100000 1 | ||
6 | (3><3) | ||
7 | [ -1.7877285611885504e-2, 0.0, -0.9998401885597121 | ||
8 | , 0.0, 1.0, 0.0 | ||
9 | , 0.9998401885597168, 0.0, -1.7877285611891697e-2 ] | ||
10 | 0.29 CPU seconds | ||
11 | |||
12 | GNU-Octave: | ||
13 | ./speed.m | ||
14 | -0.017877255967426 0.000000000000000 -0.999840189089781 | ||
15 | 0.000000000000000 1.000000000000000 0.000000000000000 | ||
16 | 0.999840189089763 0.000000000000000 -0.017877255967417 | ||
17 | 9.69 seconds | ||
18 | |||
19 | -} | ||
20 | |||
1 | import Numeric.LinearAlgebra | 21 | import Numeric.LinearAlgebra |
2 | import System | 22 | import System |
3 | import Data.List(foldl1') | 23 | import Data.List(foldl1') |
diff --git a/examples/speed.m b/examples/speed.m index 10dbf78..2f41665 100644 --- a/examples/speed.m +++ b/examples/speed.m | |||
@@ -12,9 +12,10 @@ end | |||
12 | t0=time(); | 12 | t0=time(); |
13 | x = linspace(0,1,1E5); | 13 | x = linspace(0,1,1E5); |
14 | ac = eye(3); | 14 | ac = eye(3); |
15 | for a=x | 15 | for a = x |
16 | ac = rot(a)*ac; | 16 | ac = ac*rot(a); |
17 | end | 17 | end |
18 | 18 | ||
19 | format long | ||
19 | disp(ac); | 20 | disp(ac); |
20 | disp(time()-t0) | 21 | printf("%.2f seconds\n",time()-t0) |
diff --git a/examples/tests.hs b/examples/tests.hs index b44d140..9388671 100644 --- a/examples/tests.hs +++ b/examples/tests.hs | |||
@@ -12,6 +12,7 @@ import qualified Numeric.GSL.Matrix as GSL | |||
12 | import Test.QuickCheck hiding (test) | 12 | import Test.QuickCheck hiding (test) |
13 | import Test.HUnit hiding ((~:),test) | 13 | import Test.HUnit hiding ((~:),test) |
14 | import System.Random(randomRs,mkStdGen) | 14 | import System.Random(randomRs,mkStdGen) |
15 | import System.Info | ||
15 | 16 | ||
16 | type RM = Matrix Double | 17 | type RM = Matrix Double |
17 | type CM = Matrix (Complex Double) | 18 | type CM = Matrix (Complex Double) |
@@ -323,7 +324,9 @@ tests = do | |||
323 | quickCheck (invTest . sqm :: SqM (Complex Double) -> Bool) | 324 | quickCheck (invTest . sqm :: SqM (Complex Double) -> Bool) |
324 | putStrLn "--------- pinv ------" | 325 | putStrLn "--------- pinv ------" |
325 | quickCheck (pinvTest . sqm :: SqM Double -> Bool) | 326 | quickCheck (pinvTest . sqm :: SqM Double -> Bool) |
326 | quickCheck (pinvTest . sqm :: SqM (Complex Double) -> Bool) | 327 | if os == "mingw32" |
328 | then putStrLn "complex pinvTest skipped in this OS" | ||
329 | else quickCheck (pinvTest . sqm :: SqM (Complex Double) -> Bool) | ||
327 | putStrLn "--------- chol ------" | 330 | putStrLn "--------- chol ------" |
328 | runTestTT $ TestList | 331 | runTestTT $ TestList |
329 | [ test "cholR" cholRTest | 332 | [ test "cholR" cholRTest |
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 77906dc..605a6f3 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs | |||
@@ -48,12 +48,14 @@ import Data.List(transpose) | |||
48 | - we could carry both the matrix and its (lazily computed) transpose. | 48 | - we could carry both the matrix and its (lazily computed) transpose. |
49 | This may save some transpositions, but it is necessary to keep track of the | 49 | This may save some transpositions, but it is necessary to keep track of the |
50 | data which is actually computed to be used by functions like the matrix product | 50 | data which is actually computed to be used by functions like the matrix product |
51 | which admit both orders. Therefore, maybe it is better to have something like | 51 | which admit both orders. |
52 | viewC and viewF, which may actually perform a transpose if required. | ||
53 | 52 | ||
54 | - but if we need the transposed data and it is not in the structure, we must make | 53 | - but if we need the transposed data and it is not in the structure, we must make |
55 | sure that we touch the same foreignptr that is used in the computation. Access | 54 | sure that we touch the same foreignptr that is used in the computation. |
56 | to such pointer cannot be made by creating a new vector. | 55 | |
56 | - a reasonable solution is using two constructors for a matrix. Transposition just | ||
57 | "flips" the constructor. Actual data transposition is not done if followed by a | ||
58 | matrix product or another transpose. | ||
57 | 59 | ||
58 | -} | 60 | -} |
59 | 61 | ||
@@ -66,7 +68,7 @@ data Matrix t = MC { rows :: Int, cols :: Int, cdat :: Vector t, fdat :: Vector | |||
66 | -- MC: preferred by C, fdat may require a transposition | 68 | -- MC: preferred by C, fdat may require a transposition |
67 | -- MF: preferred by LAPACK, cdat may require a transposition | 69 | -- MF: preferred by LAPACK, cdat may require a transposition |
68 | 70 | ||
69 | -- | matrix transpose | 71 | -- | Matrix transpose. |
70 | trans :: Matrix t -> Matrix t | 72 | trans :: Matrix t -> Matrix t |
71 | trans MC {rows = r, cols = c, cdat = d, fdat = dt } = MF {rows = c, cols = r, fdat = d, cdat = dt } | 73 | trans MC {rows = r, cols = c, cdat = d, fdat = dt } = MF {rows = c, cols = r, fdat = d, cdat = dt } |
72 | trans MF {rows = r, cols = c, fdat = d, cdat = dt } = MC {rows = c, cols = r, cdat = d, fdat = dt } | 74 | trans MF {rows = r, cols = c, fdat = d, cdat = dt } = MC {rows = c, cols = r, cdat = d, fdat = dt } |
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index e94d038..a705975 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -193,6 +193,14 @@ dsp' sep as = unlines . map unwords' $ transpose mtp where | |||
193 | pad n str = replicate (n - length str) ' ' ++ str | 193 | pad n str = replicate (n - length str) ' ' ++ str |
194 | unwords' = concat . intersperse sep | 194 | unwords' = concat . intersperse sep |
195 | 195 | ||
196 | {- | Creates a string from a matrix given a separator and a function to show each entry. Using | ||
197 | this function the user can easily define any desired display function: | ||
198 | |||
199 | @import Text.Printf(printf)@ | ||
200 | |||
201 | @disp = putStrLn . format \" \" (printf \"%.2f\")@ | ||
202 | |||
203 | -} | ||
196 | format :: (Field t) => String -> (t -> String) -> Matrix t -> String | 204 | format :: (Field t) => String -> (t -> String) -> Matrix t -> String |
197 | format sep f m = dsp' sep . map (map f) . toLists $ m | 205 | format sep f m = dsp' sep . map (map f) . toLists $ m |
198 | 206 | ||