package eigen

  1. Overview
  2. Docs
Owl's OCaml interface to Eigen3 C++ library

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.3.tar.gz
md5=a3e9a83a291ec1d1f57a3913a4d30e10
sha512=bf978f27d28fdac370ce71380c40bfa3e70387452cc2284f56fb6728d1af0443d064063a92d6c23e6cfe11820f1f4efb6e52a07b572453ea928133548a82bec0

Description

Eigen is a thin OCaml interface to Eigen3 C++ template library used in Owl to provide basic numerical support for both sparse and dense matrix operations.

Published: 07 Mar 2019

README

Eigen - A Thin OCaml Interface to Eigen3 C++ Library

Simply put, Eigen is a very thin OCaml interface to Eigen3 C++ template library. This library is used by another OCaml numerical library -- Owl to provide basic support for both dense and sparse matrix operations.

Even though Eigen3 itself provides a rich set of matrix operations. This OCaml library only interfaces to the most necessary functions needed by Owl library. Therefore, you should only use Owl (which is much more powerful) to perform numerical operations.

To install the library from the source code, execute the following bash command.

make && make install

If you have questions or suggestions, please contact me via Email, LinkedIn, or Twitter.

Optional configuration

You can customise the optimization flags used to compile the C++ libeigen by setting EIGENCPP_OPTFLAGS, the default value is

EIGENCPP_OPTFLAGS = -Ofast -march=native -mfpmath=sse -funroll-loops -ffast-math

Similarly you can customise the optimization flags used to compile the eigen library by setting EIGEN_FLAGS, the default value is

EIGEN_FLAGS = -O3 -Ofast -march=native -mfpmath=sse -funroll-loops -ffast-math

These can be useful if the set of flags is not supported by your system or if you want to use more experimental features

Module Structure

This section is not meant for a tutorial but to help you understand how Eigen's OCaml modules are organised. In case you want to contribute in extending either Eigen or Owl, this would be helpful.

Eigen.Dense.S    (* module of float32 dense matrix *)
Eigen.Dense.D    (* module of float64 dense matrix *)
Eigen.Dense.C    (* module of complex32 dense matrix *)
Eigen.Dense.Z    (* module of complex64 dense matrix *)

The following code snippet creates a complex32 dense identity matrix then prints it out on the standard output.

let x = Eigen.Dense.C.eye 5 in Eigen.Dense.C.print x;;

Polymorphic Functions

The matrix created by each specific module has its own types. For example, Eigen.Sparse.C.create 3 3;; returns Eigen_types.SPMAT_C.c_spmat_c Ctypes.structure Ctypes_static.ptr. Hence a matrix needs to be passed to the functions in the corresponding module to process it.

However, if you want to implement polymorphic function atop of Eigen (e.g., in Owl), Eigen_types module provides some useful constructors to wrap these matrices into generic data types. Here are some examples.

Eigen_types.SPMAT_S (Eigen.Sparse.S.create 3 3);;
Eigen_types.SPMAT_D (Eigen.Sparse.D.create 3 3);;
Eigen_types.SPMAT_C (Eigen.Sparse.C.create 3 3);;
Eigen_types.SPMAT_Z (Eigen.Sparse.Z.create 3 3);;
...
Eigen_types.DSMAT_S (Eigen.Dense.S.create 3 3);;
Eigen_types.DSMAT_D (Eigen.Dense.D.create 3 3);;
Eigen_types.DSMAT_C (Eigen.Dense.C.create 3 3);;
Eigen_types.DSMAT_Z (Eigen.Dense.Z.create 3 3);;
...

Interfacing to C++

Interfacing between C and OCaml is relatively straightforward with Ctypes. However, Eigen3 is developed in C++ and heavily utilises template programming, I first expose the native C++ class methods as individual functions then use Ctypes to generate C stubs and interface to these functions.

The C++ functions are compiled into a static library libeigen.a which is linked using -lstdc++. The library is installed in ${libdir} (Oasis environment variable) which should be /usr/local/lib on both Mac and Linux platforms.

Other Information

Some functions in NeuralNetwork folder use the code from Google's Tensorflow hence they are subject to Apache License.

Dependencies (3)

  1. dune >= "1.1.0"
  2. ctypes >= "0.14.0" & < "0.21.0"
  3. ocaml >= "4.02"

Dev Dependencies

None

Used by (1)

  1. owl >= "0.5.0" & < "1.0.0"

Conflicts

None

OCaml

Innovation. Community. Security.