summaryrefslogtreecommitdiff
path: root/README
blob: 3a260a4e2fe5c7c38103acfa3e89f896bbc5ad35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
-----------------------------------------
 A simple scientific library for Haskell
-----------------------------------------

REQUIREMENTS ----------------------------

1) GNU Scientific Library (http://www.gnu.org/software/gsl).
   In Ubuntu we need the package "libgsl0-dev".

2) BLAS/LAPACK (http://www.netlib.org/lapack).
   An optimized implementation is recommended. I have tested:

   - ATLAS (http://math-atlas.sourceforge.net).
     In Ubuntu the required packages are "refblas3-dev", "lapack3-dev",
     and "atlas3-base-dev" (or a version tuned for your machine).

   - Intel's MKL (http://www.intel.com/cd/software/products).
     There is a free noncommercial download of MKL for Linux.

For ghc-6.8.x you may also need:

- libgmp3-dev.

The following packages are used for simple graphics:

- gnuplot
- imagemagick

GNU-Octave can be used to check if the results
obtained by this library are correct.

INSTALLATION --------------------------------------

Automatic (using cabal-install and HackageDB):

    $ cabal install hmatrix

Manual:

    Install storable-complex from HackageDB and then

    $ runhaskell Setup.lhs configure --prefix=$HOME --user
    $ runhaskell Setup.lhs build
    $ runhaskell Setup.lhs haddock
    $ runhaskell Setup.lhs install

Using Intel's MKL:

    - add/modify environment variables (e.g. in your .bashrc):
          export LD_LIBRARY_PATH=/path/to/mkl/lib/arch
          export    LIBRARY_PATH=/path/to/mkl/lib/arch
      where arch = "32" or "em64t"

    - add the "-fmkl" flag in the cabal configuration command:
           $ runhaskell Setup.lhs configure --prefix=$HOME --user -fmkl
           $ runhaskell Setup.lhs build
           $ runhaskell Setup.lhs install

More information: http://www.hmatrix.googlepages.com/installation

See below for installation on Windows.

TESTS ---------------------------------------------

$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Prelude> Numeric.LinearAlgebra.Tests.runTests 20

Additional tests with big matrices (taking a few minutes):

$ runhaskell examples/experiments/bigtests

EXAMPLES ------------------------------------------------------

$ ghci
Prelude> :m + Numeric.GSL
Prelude Numeric.GSL> let quad = integrateQNG 1E-10
Prelude Numeric.GSL> quad (^2) 0 1
(0.3333333333333333,3.700743415417188e-15)

Prelude Numeric.GSL> :m + Numeric.LinearAlgebra
Prelude Numeric.LinearAlgebra> let m = (2><3)[1,2,3,4,5,6::Double]
Prelude Numeric.LinearAlgebra> let (u,d,v) = full svd m
Prelude Numeric.LinearAlgebra> d
(2><3)
 [ 9.508032000695724,                0.0, 0.0
 ,               0.0, 0.7728696356734838, 0.0 ]
Prelude Numeric.LinearAlgebra> u <> d <> trans v
(2><3)
 [ 1.0000000000000004,               2.0, 3.0
 , 3.9999999999999996, 5.000000000000001, 6.0 ]
Prelude Numeric.GSL> :q
Leaving GHCi.

A number of illustrative programs are included in the examples folder.

KNOWN PROBLEMS / BUGS -------------------------------

- Compilation with -O -fasm on 32-bit machines produces strange
  NaN's results on certain foreign calls. More info at
  http://www.hmatrix.googlepages.com/bugs

- On 64-bit machines the example "minimize.hs", when run from ghci,
  produces a segmentation fault. It happens in the call to
  gsl_multimin_fdfminimizer_alloc, inside the C wrapper.
  If the program is called by runhaskell, it just terminates
  prematurely, producing no results. Curiously, in compiled mode the
  program seems to work perfectly well.

- On Ubuntu 6.06 LTS (Dapper) atlas3-sse2-dev (3.6.0-20)
  produces segmentation faults when working with big matrices 
  on compiled programs. To expose the problem:

  $ cd examples
  $ ghc --make -O -fvia-C tests.hs
  $ ./tests --big

  If this crashes, just uninstall atlas3-sse2 and use atlas3-base-dev instead.
  Fortunately, atlas3-sse2-dev seems to work well on Ubuntu 7.10 Gutsy.
  A similar problem was reported at:
      http://article.gmane.org/gmane.linux.debian.devel.bugs.general/323065

- On distributions with old GSL versions you should comment out a couple of functions
  in the export lists of Ellint.hs and Debye.hs

CHANGES ---------------------------------------------------------

This is a new version of the library previously known as GSLHaskell.
It has been renamed to "hmatrix" because only a small part of GSL is actually
available, and most linear algebra is based on LAPACK.

The code has been extensively refactored. There is a new internal representation
which admits both C and Fortran matrices and avoids many transposes.

There are only minor API changes:

- The matrix product operator (<>) is now overloaded only for matrix-matrix,
  matrix-vector and vector-matrix, with the same base type. Dot product and scaling
  of vectors or matrices is now denoted by `dot` or (<.>) and `scale` or (.*).
  Conversions from real to complex objects must now be explicit.

- Most linear algebra functions admit both real and complex objects. Utilities such as
  ident or constant are now polymorphic.

- Runtime errors produced by GSL or LAPACK can be handled using Control.Exeception.catch.

Old GSLHaskell code will work with small modifications.

INSTALLATION ON WINDOWS ----------------------------------------

1) Download the developer files gsl-1.8-lib.zip from
   http://gnuwin32.sourceforge.net/packages/gsl.htm
   and copy the gsl headers folder (under include) to:
       C:\ghc\ghc.6.x.1\include
   These headers are also available from:
       http://perception.inf.um.es/~aruiz/darcs/hmatrix/gsl.zip

2) Copy libgsl.dll, libcblas.dll (from the binaries package gsl-1.8.bin.zip)
   and liblapack.dll (borrowed from the R system) to the ghc folder, e.g.:
       C:\ghc\ghc-6.x.x.
   Rename libcblas.dll to libblas.dll.
   They are needed to compile programs.
   These three dlls are available from:
       http://perception.inf.um.es/~aruiz/darcs/hmatrix/dll1.zip

2.5) Remove the following functions from the export list of
     lib/Numeric/GSL/Special/Ellint.hs:
     ellint_Pcomp_e, ellint_Pcomp, ellint_Dcomp_e, ellint_Dcomp

3) Install the package as usual:
       runhaskell Setup.lhs configure
       runhaskell Setup.lhs build
       runhaskell Setup.lhs install

3.5) If configure cannot find ld please see:
       http://article.gmane.org/gmane.comp.lang.haskell.cafe/32025

4) Copy the dlls available from:
       http://perception.inf.um.es/~aruiz/darcs/hmatrix/dll2.zip
   to the working directory or C:\windows\system
   They are required to run the programs and ghci.

5) run the tests

Unfortunately the lapack dll supplied by the R system does not include
zgels_, zgelss_, and zgees_, so the functions depending on them
(linearSolveLS, linearSolveSVD, and schur for complex data)
will produce a "non supported in this OS" runtime error.

If you find an alternative free and complete lapack.dll which works well
for this system please let me know.

The examples using graphics do not yet work in windows.

ACKNOWLEDGEMENTS -----------------------------------------------------

I thank Don Stewart, Henning Thielemann, Bulat Ziganshin and all the people
in the Haskell mailing lists for their help.

- Nico Mahlo discovered a bug in the eigendecomposition wrapper.

- Frederik Eaton discovered a bug in the design of the wrappers.

- Eric Kidd has created a wiki page explaining the installation on MacOS X:
  http://www.haskell.org/haskellwiki/GSLHaskell_on_MacOS_X

- Fawzi Mohamed discovered a portability bug in the lapack wrappers.

- Pedro E. López de Teruel fixed the interface to lapack.

- Antti Siira discovered a bug in the plotting functions.

- Paulo Tanimoto helped to fix the configuration of the required libraries.
  He also discovered the segfault of minimize.hs in ghci.

- Xiao-Yong Jin reported a bug on x86_64 caused by the assumptions in f2c.h,
  which are wrong for this architecture.

- Jason Schroeder reported an error in the documentation.

- Bulat Ziganshin gave invaluable help for the ST monad interface to
  in-place modifications.

- Don Stewart fixed the implementation of the internal data structures
  to achieve excellent, C-like performance in Haskell functions which
  explicitly work with the elements of vectors and matrices.

- Dylan Alex Simon improved the numeric instances to allow optimized
  implementations of signum and abs on Vectors.