GSL-OCaml - GSL-Bindings for OCaml

This library was written by Olivier Andrieu. This version (gsl-ocaml) contains patches by Markus Mottl that may be merged into the original distribution in the future.

GSL-OCaml is an interface to the GSL (GNU scientific library) for the OCaml-language. The currently latest GSL-version known to be compatible is 2.0.

Requirements

The platform must not align doubles on double-word addresses, i.e. the C-macro ARCH_ALIGN_DOUBLE must be undefined in the OCaml C-configuration header in <caml/config.h>.

Installation

$ ./configure
$ make
$ make install

Configuring alternative BLAS-libraries

The underlying GSL-library depends on a C-implementation of the BLAS-library (Basic Linear Algebra Subroutines). It comes with its own implementation, gslcblas, which GSL will link with by default, e.g.:

$ gsl-config --libs
-L/opt/local/lib -lgsl -lgslcblas

This implementation is usually considerably slower than alternatives like OpenBLAS or ATLAS (Automatically Tuned Linear Algebra Software) or miscellaneous platform-specific vendor implementations.

If you want GSL-OCaml to link with another BLAS-implementation by default, you will need to set an environment variable before starting the build process. For example, if you are installing the package via OPAM, you may want to do the following:

$ export GSL_CBLAS_LIB=-lopenblas
$ gsl-config --libs
-L/opt/local/lib -lgsl -lopenblas
$ opam install gsl-ocaml

The above shows that after setting the environment variable GSL_CBLAS_LIB, gsl-config will return the correct linking flags to the build process of GSL-OCaml.

Note that on Mac OS X GSL-OCaml requires the Apple-specific, highly optimized vendor library vecLib, which is part of the Accelerate-framework, and will automatically link with it.

Documentation

Check the GSL manual to learn more about the GNU Scientific Library.

You can browse the OCaml module interfaces as ocamldoc-generated HTML files in directory API.docdir after building the documentation with make doc. It is also available online.

Usage Hints

Vectors and Matrices

There are several data types for handling vectors and matrices.

ERROR HANDLING

Errors in GSL functions are reported as exceptions:

Gsl.Error.Gsl_exn (errno, msg)

You have to call Gsl.Error.init () to initialize error reporting. Otherwise, the default GSL error handler is used and aborts the program, leaving a core dump (not so helpful with OCaml).

If a callback (for minimizers, solvers, etc.) raises an exception, gsl-ocaml either returns GSL_FAILURE or NaN to GSL depending on the type of callback. In either case the original OCaml exception is not propagated. The GSL function will either return normally (but probably with values containing NaNs somewhere) or raise a Gsl_exn exception.


Contact Information and Contributing

In the case of bugs, feature requests, contributions and similar, you can contact me here: markus.mottl@gmail.com

Up-to-date information should be available at: http://mmottl.github.io/gsl-ocaml

Enjoy!

Markus Mottl on September 21, 2016