<commit_before># mlinterp
**mlinterp** is a fast C++ routine for linear interpolation in arbitrary dimensions (i.e., multilinear interpolation).

## Installing

First, ensure that you have [CMake](https://cmake.org/) installed on your system. Then, execute the following commands to install the mlinterp library:

```
git clone https://github.com/parsiad/mlinterp.git
cd mlinterp
cmake .
sudo make install
```

If you want to compile the examples, you can also execute:

```
make
```

## Examples

### 1d
Let's interpolate y = sin(x) using 15 evenly-spaced data points on the interval [-pi, pi].

```c++
#include <mlinterp>
using namespace mlinterp;

// Knots (xd) and values at the knots (yd)
constexpr int nd = 15;
double xd[nd];
double yd[nd];
for(int n = 0; n < nd; ++n) {
	xd[n] = -M_PI + (2. * M_PI) / (nd - 1) * n;
	yd[n] = std::sin(xd[n]);
}

// Points at which to interpolate
constexpr int ni = 100;
double xi[ni];
for(int n = 0; n < ni; ++n) {
	xi[n] = -M_PI + (2. * M_PI) / (ni - 1) * n;
}

// Perform interpolation
double yi[ni]; // Result is stored in this buffer
interp(&nd, ni, yd, yi, xd, xi);
```

![](https://raw.githubusercontent.com/parsiad/mlinterp/master/examples/1d.png)

### 2d

Let's interpolate z = sin(x)cos(y) using 15 evenly-spaced points along the x axis and 15 evenly-spaced points along the y axis.

```c++
#include <mlinterp>
using namespace mlinterp;

// Knots (xd times yd) and values at the knots (zd)
constexpr int nxd = 15, nyd = 15, nd[] = { nxd, nyd };
double xd[nxd];
for(int i = 0; i < nxd; ++i) {
	xd[i] = -M_PI + (2. * M_PI) / (nxd - 1) * i;
}
double yd[nyd];
for(int j = 0; j < nyd; ++j) {
	yd[j] = -M_PI + (2. * M_PI) / (nyd - 1) * j;
}
double zd[nxd * nyd];
for(int i = 0; i < nxd; ++i) {
	for(int j = 0; j < nyd; ++j) {
		const int n = j + i * nyd;
		zd[n] = sin(xd[i]) * cos(yd[j]);
	}
}

// Points at which to interpolate
constexpr int m = 100, ni = m * m;
double xi[ni];
double yi[ni];
for(int i = 0; i < m; ++i) {
	for(int j = 0; j < m; ++j) {
		const int n = j + i * m;
		xi[n] = -M_PI + (2. * M_PI) / (m - 1) * i;
		yi[n] = -M_PI + (2. * M_PI) / (m - 1) * j;
	}
}<commit_msg>Updated README.md.<commit_after># mlinterp
**mlinterp** is a fast C++ routine for linear interpolation in arbitrary dimensions (i.e., multilinear interpolation).

## Installing

### Quick and dirty

mlinterp is a header-only library, meaning that the fastest way to use it is to copy the file ```mlinterp/mlinterp.hpp``` into your own project directory and include it using ```#include <mlinterp.hpp>```.

### Clean install

If you are on a UNIX-like system with CMake installed, you can download mlinterp and run the following commands (from the mlinterp project directory) to install it to your system:

```
cmake .
sudo make install # Run this to install
make # Run this to compile examples
```

## Examples

### 1d
Let's interpolate y = sin(x) using 15 evenly-spaced data points on the interval [-pi, pi].

```c++
using namespace mlinterp;

// Knots (xd) and values at the knots (yd)
constexpr int nd = 15;
double xd[nd];
double yd[nd];
for(int n = 0; n < nd; ++n) {
	xd[n] = -M_PI + (2. * M_PI) / (nd - 1) * n;
	yd[n] = std::sin(xd[n]);
}

// Points at which to interpolate
constexpr int ni = 100;
double xi[ni];
for(int n = 0; n < ni; ++n) {
	xi[n] = -M_PI + (2. * M_PI) / (ni - 1) * n;
}

// Perform interpolation
double yi[ni]; // Result is stored in this buffer
interp(&nd, ni, yd, yi, xd, xi);
```

![](https://raw.githubusercontent.com/parsiad/mlinterp/master/examples/1d.png)

### 2d

Let's interpolate z = sin(x)cos(y) using 15 evenly-spaced points along the x axis and 15 evenly-spaced points along the y axis.

```c++
using namespace mlinterp;

// Knots (xd times yd) and values at the knots (zd)
constexpr int nxd = 15, nyd = 15, nd[] = { nxd, nyd };
double xd[nxd];
for(int i = 0; i < nxd; ++i) {
	xd[i] = -M_PI + (2. * M_PI) / (nxd - 1) * i;
}
double yd[nyd];
for(int j = 0; j < nyd; ++j) {
	yd[j] = -M_PI + (2. * M_PI) / (nyd - 1) * j;
}
double zd[nxd * nyd];
for(int i = 0; i < nxd; ++i) {
	for(int j = 0; j < nyd; ++j) {
		const int n = j + i * nyd;
		zd[n] = sin(xd[i]) * cos(yd[j]);
	}
}

// Points at which to interpolate
constexpr int m = 100, ni = m * m;
double xi[ni];
double yi[ni];
for(int i = 0; i < m; ++i) {
	for(int j = 0; j < m; ++j) {
		const int n = j + i * m;
		xi[n] = -M_PI + (2. * M_PI) / (m - 1) * i;
		yi[n] = -M_PI + (2. * M_PI) / (m - 1) * j;
	}
}
{'fraction_non_alphanumeric': 0.17918552036199095, 'fraction_numerical': 0.018552036199095023, 'mean_word_length': 3.1944971537001896, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 6, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2574989', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1813, 'n_words': 637}