hmatrix installation
September 9, 2021 ยท View on GitHub
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.
Linux
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.
Mac OS/X
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).
Windows 10
Stack-based build (preferred)
-
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.
2(a) Get OpenBLAS library with stack's MSYS2
-
stackcomes with a version of MSYS2. It is located in a subfolder of the folder returned by thestack path --programscommand. 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.cmdcommand. In PowerShell:> .\msys2_shell.cmd -
In principle, MSYS2 itself can be updated with the
pacman -Syucommand. 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-openblasMSYS2 will put the import libraries in subfolder
\ming64\lib. Thestackenviroment will automatically add that folder to the list of library folders (see, back in PowerShell, the result of commandstack path --extra-library-dirs). -
hmatrixdepends on OpenBLAS.hmatrix-gsldepends on GSL (the GNU Scientific Library) andhmatrix-glpkdepends 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-glpkAgain, MSYS2 will put the import libraries in subfolder
\ming64\lib. -
In
hmatrix.cabal, ensure that theextra-librariesspecifiesopenblas(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-librariesspecifiesgsl(only). (This is incorrect inhmatrix-gsl-0.19.0.1on 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.yamlfile there, with commandstack init.Edit the
stack.yamlfile to refer to the location of a correcthmatrix-gsl.cabal(if the version on Hackage is still incorrect).packages: - . - ../gslThen
stack ghcican be invoked in that folder with an appropriateresolver, and setting the flagopenblasfor packagehmatrix, the flagonlygslfor packagehmatrix-gsland the flaggslforhmatrix-tests. At the time of writing,resolver lts-18.9works 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.LinearAlbebramodule 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 1The failure of 'some unit tests' number 9 is discussed here.
2(b) Build OpenBLAS library from source
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\
-
Cabal-based build
(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.
Alternative Windows build
> 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
Tests
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