Matlab Install


  • A unix-like system (typically Linux or MacOs X) with a C++ compiler (gcc>=4.8, clang)
  • Cmake>=3.10
  • Matlab>=R2012
  • Optional: Cuda (>=9.0 is recommended)

From source using git

  1. Clone the KeOps repository at a location of your choice (denoted here by /path/to):
git clone /path/to/libkeops

Note that temporary files will be written into the ./libkeops/keopslab/build folder: this directory must have write permissions.

  1. Manually add the directory /path/to/libkeops to you matlab path: see Set the path
  2. Test your installation.

Set the path

There are two ways to tell Matlab that KeOpsLab is now available in /path/to/libkeops:

  • You can add this folder to your Matlab path once and for all: in the Matlab prompt, type
  • Otherwise, please add the following line to the beginning of your scripts:

Test that everything goes fine

Set the path and execute the following piece of code in a Matlab terminal:

x = reshape(1:9,3,[]); y = reshape(3:8,3,[]);

my_conv = Kernel('Sum_Reduction(SqNorm2(x-y),1)','x=Vi(0,3)','y=Vj(1,3)');

It should return:

ans =



For debugging purposes, you can force a “verbose” compilation mode by setting


in the file /path/to/keops/keopslab/default_options.m.

Old versions of Cuda

When using KeOps with Cuda version 8 or earlier, the compilation of complex formulas may take a very long time (several minutes). This typically happens when computing the derivative or second-order derivatives of a non-trivial function, as in the testShooting.m example script.

This delay is mainly due to the intensive use of modern C++11 templating features, for which the old (<=8) versions of the Cuda nvcc compiler were not optimized. Consequently, if you own a GPU with a compute capability >=3.0, we strongly recommend upgrading to Cuda>=9.

Cmake is not found

If an error involving cmake appears, it may be due to an incorrect linking of libstdc++. Try the following: exit Matlab, then type in a terminal

export LD_PRELOAD=$(ldd $( which cmake ) | grep libstdc++ | tr ' ' '\n' | grep /)

This will reload Matlab with, hopefully, a correct linking for cmake.