diff options
-rw-r--r-- | INSTALL | 58 | ||||
-rw-r--r-- | README | 128 | ||||
-rw-r--r-- | examples/benchmarks.hs | 13 |
3 files changed, 70 insertions, 129 deletions
@@ -0,0 +1,58 @@ | |||
1 | ----------------------------------------- | ||
2 | A simple scientific library for Haskell | ||
3 | ----------------------------------------- | ||
4 | |||
5 | INSTALLATION | ||
6 | |||
7 | Recommended method: | ||
8 | $ sudo apt-get install libgsl0-dev refblas3-dev lapack3-dev atlas3-[your arch]-dev | ||
9 | $ cabal install hmatrix | ||
10 | |||
11 | Detailed installation instructions: | ||
12 | http://www.hmatrix.googlepages.com/installation | ||
13 | |||
14 | INSTALLATION ON WINDOWS ---------------------------------------- | ||
15 | |||
16 | 1) Download the developer files gsl-1.8-lib.zip from | ||
17 | http://gnuwin32.sourceforge.net/packages/gsl.htm | ||
18 | and copy the gsl headers folder (under include) to: | ||
19 | C:\ghc\ghc.6.x.1\include | ||
20 | These headers are also available from: | ||
21 | http://perception.inf.um.es/~aruiz/darcs/hmatrix/gsl.zip | ||
22 | |||
23 | 2) Copy libgsl.dll, libcblas.dll (from the binaries package gsl-1.8.bin.zip) | ||
24 | and liblapack.dll (borrowed from the R system) to the ghc folder, e.g.: | ||
25 | C:\ghc\ghc-6.x.x. | ||
26 | Rename libcblas.dll to libblas.dll. | ||
27 | They are needed to compile programs. | ||
28 | These three dlls are available from: | ||
29 | http://perception.inf.um.es/~aruiz/darcs/hmatrix/dll1.zip | ||
30 | |||
31 | 2.5) Remove the following functions from the export list of | ||
32 | lib/Numeric/GSL/Special/Ellint.hs: | ||
33 | ellint_Pcomp_e, ellint_Pcomp, ellint_Dcomp_e, ellint_Dcomp | ||
34 | |||
35 | 3) Install the package as usual: | ||
36 | runhaskell Setup.lhs configure | ||
37 | runhaskell Setup.lhs build | ||
38 | runhaskell Setup.lhs install | ||
39 | |||
40 | 3.5) If configure cannot find ld please see: | ||
41 | http://article.gmane.org/gmane.comp.lang.haskell.cafe/32025 | ||
42 | |||
43 | 4) Copy the dlls available from: | ||
44 | http://perception.inf.um.es/~aruiz/darcs/hmatrix/dll2.zip | ||
45 | to the working directory or C:\windows\system | ||
46 | They are required to run the programs and ghci. | ||
47 | |||
48 | 5) run the tests | ||
49 | |||
50 | Unfortunately the lapack dll supplied by the R system does not include | ||
51 | zgels_, zgelss_, and zgees_, so the functions depending on them | ||
52 | (linearSolveLS, linearSolveSVD, and schur for complex data) | ||
53 | will produce a "non supported in this OS" runtime error. | ||
54 | |||
55 | If you find an alternative free and complete lapack.dll which works well | ||
56 | for this system please let me know. | ||
57 | |||
58 | The examples using graphics do not yet work in windows. | ||
@@ -2,63 +2,16 @@ | |||
2 | A simple scientific library for Haskell | 2 | A simple scientific library for Haskell |
3 | ----------------------------------------- | 3 | ----------------------------------------- |
4 | 4 | ||
5 | REQUIREMENTS ---------------------------- | 5 | INSTALLATION |
6 | |||
7 | 1) GNU Scientific Library (http://www.gnu.org/software/gsl). | ||
8 | In Ubuntu we need the package "libgsl0-dev". | ||
9 | |||
10 | 2) BLAS/LAPACK (http://www.netlib.org/lapack). | ||
11 | An optimized implementation is recommended. I have tested: | ||
12 | |||
13 | - ATLAS (http://math-atlas.sourceforge.net). | ||
14 | In Ubuntu the required packages are "refblas3-dev", "lapack3-dev", | ||
15 | and "atlas3-base-dev" (or a version tuned for your machine). | ||
16 | |||
17 | - Intel's MKL (http://www.intel.com/cd/software/products). | ||
18 | There is a free noncommercial download of MKL for Linux. | ||
19 | |||
20 | For ghc-6.8.x you may also need: | ||
21 | |||
22 | - libgmp3-dev. | ||
23 | |||
24 | The following packages are used for simple graphics: | ||
25 | |||
26 | - gnuplot | ||
27 | - imagemagick | ||
28 | |||
29 | GNU-Octave can be used to check if the results | ||
30 | obtained by this library are correct. | ||
31 | |||
32 | INSTALLATION -------------------------------------- | ||
33 | |||
34 | Automatic (using cabal-install and HackageDB): | ||
35 | 6 | ||
7 | Recommended method (ok in Ubuntu/Debian systems): | ||
8 | $ sudo apt-get install libgsl0-dev refblas3-dev lapack3-dev atlas3-[your_arch]-dev | ||
36 | $ cabal install hmatrix | 9 | $ cabal install hmatrix |
37 | 10 | ||
38 | Manual: | 11 | Detailed installation instructions: |
39 | 12 | http://www.hmatrix.googlepages.com/installation | |
40 | Install storable-complex from HackageDB and then | ||
41 | |||
42 | $ runhaskell Setup.lhs configure --prefix=$HOME --user | ||
43 | $ runhaskell Setup.lhs build | ||
44 | $ runhaskell Setup.lhs haddock | ||
45 | $ runhaskell Setup.lhs install | ||
46 | |||
47 | Using Intel's MKL: | ||
48 | 13 | ||
49 | - add/modify environment variables (e.g. in your .bashrc): | 14 | For installation in Windows see the companion INSTALL file. |
50 | export LD_LIBRARY_PATH=/path/to/mkl/lib/arch | ||
51 | export LIBRARY_PATH=/path/to/mkl/lib/arch | ||
52 | where arch = "32" or "em64t" | ||
53 | |||
54 | - add the "-fmkl" flag in the cabal configuration command: | ||
55 | $ runhaskell Setup.lhs configure --prefix=$HOME --user -fmkl | ||
56 | $ runhaskell Setup.lhs build | ||
57 | $ runhaskell Setup.lhs install | ||
58 | |||
59 | More information: http://www.hmatrix.googlepages.com/installation | ||
60 | |||
61 | See below for installation on Windows. | ||
62 | 15 | ||
63 | TESTS --------------------------------------------- | 16 | TESTS --------------------------------------------- |
64 | 17 | ||
@@ -110,75 +63,6 @@ KNOWN PROBLEMS / BUGS ------------------------------- | |||
110 | - On distributions with old GSL versions you should comment out a couple of functions | 63 | - On distributions with old GSL versions you should comment out a couple of functions |
111 | in the export lists of Ellint.hs and Debye.hs | 64 | in the export lists of Ellint.hs and Debye.hs |
112 | 65 | ||
113 | CHANGES --------------------------------------------------------- | ||
114 | |||
115 | This is a new version of the library previously known as GSLHaskell. | ||
116 | It has been renamed to "hmatrix" because only a small part of GSL is actually | ||
117 | available, and most linear algebra is based on LAPACK. | ||
118 | |||
119 | The code has been extensively refactored. There is a new internal representation | ||
120 | which admits both C and Fortran matrices and avoids many transposes. | ||
121 | |||
122 | There are only minor API changes: | ||
123 | |||
124 | - The matrix product operator (<>) is now overloaded only for matrix-matrix, | ||
125 | matrix-vector and vector-matrix, with the same base type. Dot product and scaling | ||
126 | of vectors or matrices is now denoted by `dot` or (<.>) and `scale` or (.*). | ||
127 | Conversions from real to complex objects must now be explicit. | ||
128 | |||
129 | - Most linear algebra functions admit both real and complex objects. Utilities such as | ||
130 | ident or constant are now polymorphic. | ||
131 | |||
132 | - Runtime errors produced by GSL or LAPACK can be handled using Control.Exeception.catch. | ||
133 | |||
134 | Old GSLHaskell code will work with small modifications. | ||
135 | |||
136 | INSTALLATION ON WINDOWS ---------------------------------------- | ||
137 | |||
138 | 1) Download the developer files gsl-1.8-lib.zip from | ||
139 | http://gnuwin32.sourceforge.net/packages/gsl.htm | ||
140 | and copy the gsl headers folder (under include) to: | ||
141 | C:\ghc\ghc.6.x.1\include | ||
142 | These headers are also available from: | ||
143 | http://perception.inf.um.es/~aruiz/darcs/hmatrix/gsl.zip | ||
144 | |||
145 | 2) Copy libgsl.dll, libcblas.dll (from the binaries package gsl-1.8.bin.zip) | ||
146 | and liblapack.dll (borrowed from the R system) to the ghc folder, e.g.: | ||
147 | C:\ghc\ghc-6.x.x. | ||
148 | Rename libcblas.dll to libblas.dll. | ||
149 | They are needed to compile programs. | ||
150 | These three dlls are available from: | ||
151 | http://perception.inf.um.es/~aruiz/darcs/hmatrix/dll1.zip | ||
152 | |||
153 | 2.5) Remove the following functions from the export list of | ||
154 | lib/Numeric/GSL/Special/Ellint.hs: | ||
155 | ellint_Pcomp_e, ellint_Pcomp, ellint_Dcomp_e, ellint_Dcomp | ||
156 | |||
157 | 3) Install the package as usual: | ||
158 | runhaskell Setup.lhs configure | ||
159 | runhaskell Setup.lhs build | ||
160 | runhaskell Setup.lhs install | ||
161 | |||
162 | 3.5) If configure cannot find ld please see: | ||
163 | http://article.gmane.org/gmane.comp.lang.haskell.cafe/32025 | ||
164 | |||
165 | 4) Copy the dlls available from: | ||
166 | http://perception.inf.um.es/~aruiz/darcs/hmatrix/dll2.zip | ||
167 | to the working directory or C:\windows\system | ||
168 | They are required to run the programs and ghci. | ||
169 | |||
170 | 5) run the tests | ||
171 | |||
172 | Unfortunately the lapack dll supplied by the R system does not include | ||
173 | zgels_, zgelss_, and zgees_, so the functions depending on them | ||
174 | (linearSolveLS, linearSolveSVD, and schur for complex data) | ||
175 | will produce a "non supported in this OS" runtime error. | ||
176 | |||
177 | If you find an alternative free and complete lapack.dll which works well | ||
178 | for this system please let me know. | ||
179 | |||
180 | The examples using graphics do not yet work in windows. | ||
181 | |||
182 | ACKNOWLEDGEMENTS ----------------------------------------------------- | 66 | ACKNOWLEDGEMENTS ----------------------------------------------------- |
183 | 67 | ||
184 | I thank Don Stewart, Henning Thielemann, Bulat Ziganshin and all the people | 68 | I thank Don Stewart, Henning Thielemann, Bulat Ziganshin and all the people |
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs index 517d402..78c1e5f 100644 --- a/examples/benchmarks.hs +++ b/examples/benchmarks.hs | |||
@@ -1,8 +1,7 @@ | |||
1 | {-# LANGUAGE BangPatterns #-} | 1 | {-# LANGUAGE BangPatterns #-} |
2 | 2 | ||
3 | -- compile as: | 3 | -- $ ghc --make -O2 benchmarks.hs |
4 | -- ghc --make -O2 -optc-O2 -fvia-C benchmarks.hs | 4 | |
5 | -- ghc --make -O benchmarks.hs | ||
6 | 5 | ||
7 | import Numeric.LinearAlgebra | 6 | import Numeric.LinearAlgebra |
8 | import System.Time | 7 | import System.Time |
@@ -22,11 +21,11 @@ time act = do | |||
22 | main = sequence_ [bench1,bench2,bench3,bench4] | 21 | main = sequence_ [bench1,bench2,bench3,bench4] |
23 | 22 | ||
24 | w :: Vector Double | 23 | w :: Vector Double |
25 | w = constant 1 30000000 | 24 | w = constant 1 5000000 |
26 | w2 = 1 * w | 25 | w2 = 1 * w |
27 | 26 | ||
28 | bench1 = do | 27 | bench1 = do |
29 | putStrLn "Sum of a vector with 30M doubles:" | 28 | putStrLn "Sum of a vector with 5M doubles:" |
30 | print$ vectorMax (w+w2) -- evaluate it | 29 | print$ vectorMax (w+w2) -- evaluate it |
31 | time $ printf " BLAS: %.2f: " $ sumVB w | 30 | time $ printf " BLAS: %.2f: " $ sumVB w |
32 | time $ printf " Haskell: %.2f: " $ sumVH w | 31 | time $ printf " Haskell: %.2f: " $ sumVH w |
@@ -91,7 +90,7 @@ bench3 = do | |||
91 | let v = flatten $ ident 500 :: Vector Double | 90 | let v = flatten $ ident 500 :: Vector Double |
92 | print $ vectorMax v -- evaluate it | 91 | print $ vectorMax v -- evaluate it |
93 | 92 | ||
94 | putStrLn "sum, dim=30M:" | 93 | putStrLn "sum, dim=5M:" |
95 | -- time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w) | 94 | -- time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w) |
96 | time $ print $ sumVector w | 95 | time $ print $ sumVector w |
97 | 96 | ||
@@ -114,7 +113,7 @@ foldVector f s v = foldLoop g s (dim v) | |||
114 | 113 | ||
115 | sumVector = foldVector (\k v s -> v k + s) 0.0 | 114 | sumVector = foldVector (\k v s -> v k + s) 0.0 |
116 | 115 | ||
117 | -- foldVector is slower if it is used in two places unles we use the above INLINE | 116 | -- foldVector is slower if used in two places unless we use the above INLINE |
118 | -- this does not happen with foldLoop | 117 | -- this does not happen with foldLoop |
119 | -------------------------------------------------------------------------------- | 118 | -------------------------------------------------------------------------------- |
120 | 119 | ||