WARNING: some of these instructions are now very out of date. However, there is a CI script which shows what does work; you are advised to look at that and emulate its installation steps.
This package requires GHC 7.8, cabal-install (available in the Haskell Platform), and the development packages for BLAS/LAPACK and GSL.
Ubuntu/Debian:
$ sudo apt-get install libgsl0-dev liblapack-dev libatlas-base-dev
$ cabal update
$ cabal install hmatrix-tests
Other distributions may require additional libraries. They can be given in a --configure-option.
Adrian Victor Crisciu has developed an installation method for systems which don't provide shared lapack libraries.
GSL must be installed via Homebrew or MacPorts.
Via Homebrew:
$ brew install gsl
$ cabal install hmatrix
Via MacPorts:
$ sudo port install gsl +universal
$ cabal install hmatrix
(Contributed by Heinrich Apfelmus, Torsten Kemps-Benedix and Ted Fujimoto).
-
Install the Haskell Tool Stack tool (
stack
). How to do that is explained here. -
Get, and link to the import library of, the OpenBLAS library. There are various ways to do that. Perhaps the easiest is to use MSYS2 to get it, which is explained in the steps under subheading 2(a) below.
-
stack
comes with a version of MSYS2. It is located in a subfolder of the folder returned by thestack path --programs
command. At the time of writing (9 September 2021), that subfolder ismsys2-20200903
. Change directory to that folder. In PowerShell:> stack path --programs | cd > cd msys2-20200903
-
Open a MSYS2 terminal window, with the
msys2_shell.cmd
command. In PowerShell:> .\msys2_shell.cmd
-
In principle, MSYS2 itself can be updated with the
pacman -Syu
command. At the time of writing, that may be complicated by keyring issues (see here and here to overcome such issues). In MSYS2:$ pacman -Syu
-
Use MSYS2 to install the OpenBLAS package (and its dependencies). In MSYS2:
$ pacman -S mingw-w64-x86_64-openblas
MSYS2 will put the import libraries in subfolder
\ming64\lib
. Thestack
enviroment will automatically add that folder to the list of library folders (see, back in PowerShell, the result of commandstack path --extra-library-dirs
). -
hmatrix
depends on OpenBLAS.hmatrix-gsl
depends on GSL (the GNU Scientific Library) andhmatrix-glpk
depends on GLPK (the GNU Linear Programming Kit). You can use MSYS2 to install GSL and GLPK packages too. In MSYS2:$ pacman -S mingw-w64-x86_64-gsl $ pacman -S mingw-w64-x86_64-glpk
Again, MSYS2 will put the import libraries in subfolder
\ming64\lib
. -
In
hmatrix.cabal
, ensure that theextra-libraries
specifiesopenblas
(only). (This was corrected inhmatrix-0.20.1
.) That is, the extract should read:if os(windows) if flag(openblas) extra-libraries: openblas else extra-libraries: blas lapack
-
Similarly, in
hmatrix-gsl.cabal
, ensure that theextra-libraries
specifiesgsl
(only). (This is incorrect inhmatrix-gsl-0.19.0.1
on Hackage, so a corrected local version of the package may be required.) That is, the extract should read:if os(windows) extra-libraries: gsl
-
To test, change directory to the repository folder
packages\tests
, and create astack.yaml
file there, with commandstack init
.Edit the
stack.yaml
file to refer to the location of a correcthmatrix-gsl.cabal
(if the version on Hackage is still incorrect).packages: - . - ../gsl
Then
stack ghci
can be invoked in that folder with an appropriateresolver
, and setting the flagopenblas
for packagehmatrix
, the flagonlygsl
for packagehmatrix-gsl
and the flaggsl
forhmatrix-tests
. At the time of writing,resolver lts-18.9
works with GHC 8.10.7. In PowerShell:> stack --resolver lts-18.9 ghci --flag hmatrix:openblas --flag hmatrix-gsl:onlygsl --flag hmatrix-tests:gsl
-
In GHCi, test the
Numeric.LinearAlbebra
module with the following (the almost successful output has many lines and so is shortened below):> Numeric.LinearAlgebra.Tests.runTests 20 ------ index +++ OK, passed 100 tests. +++ OK, passed 100 tests. ... +++ OK, passed 100 tests. ------ some unit tests ### Failure in: 9 C:\\\\<path>\\\\hmatrix\\\\packages\\\\tests\\\\src\\Numeric\\LinearAlgebra\\Tests.hs:75 randomGaussian Cases: 52 Tried: 52 Errors: 0 Failures: 1 *** Exception: ExitFailure 1
The failure of 'some unit tests' number 9 is discussed here.
WARNING: these alternative instructions may be out of date.
-
Download and unzip somewhere OpenBLAS http://www.openblas.net/
-
In MSYS2 console of Stack, i.e.: C:\Users{User}\AppData\Local\Programs\stack\x86_64-windows\msys2-{version}\msys2_shell.bat
$ cd /.../OpenBLAS $ pacman -Sy $ pacman -S make perl gcc-fortran $ make clean $ make $ make install
-
Then in normal Windows console for building hmatrix base lib (fill in user name, versions and check if paths are different on your machine):
> stack install --flag hmatrix:openblas --extra-include-dirs=C:\Users\{User}\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\opt\OpenBLAS\include --extra-lib-dirs=C:\Users\{User}\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\opt\OpenBLAS\bin --extra-lib-dirs=C:\Users\{User}\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\usr\lib\gcc\x86_64-pc-msys\6.3.0\
-
(Not tested). It should be possible to install the new package hmatrix >= 0.16 using the dlls contributed by Gilberto Camara available in gsl-lapack-windows.zip.
-
cabal update
-
Download and unzip gsl-lapack-windows.zip into a stable folder %GSL%
3.a) In a msys shell:
$ cabal install hmatrix-0.13.1.0 --extra-lib-dir=${GSL} --extra-include-dirs=${GSL}
3.b) In a normal windows cmd:
> cabal install --extra-lib-dir=%GSL% --extra-include-dirs=%GSL%
It may be necessary to put the dlls in the search path.
It is expected that a future version of the new hmatrix-gsl package can also be installed using this method.
> cabal update
-
Download and unzip somewhere OpenBLAS http://www.openblas.net/
-
In a normal Windows cmd:
cabal install --flags=openblas --extra-lib-dirs=C:...\OpenBLAS\lib --extra-include-dirs=C:...\OpenBLAS\include
After installation we can verify that the library works as expected:
$ cabal install hmatrix-tests
$ ghci
> Numeric.LinearAlgebra.Tests.runTests 20
+++ OK, passed 100 tests.
+++ OK, passed 100 tests.
... etc...
+++ OK, passed 100 tests.
------ some unit tests
Cases: 71 Tried: 71 Errors: 0 Failures: 0