Embed from C
#include "minimage.h"
mi_cell box = mi_cell_ortho(10.0, 10.0, 10.0);
const double p[3] = {0.2, 0.0, 0.0};
const double q[3] = {9.4, 0.0, 0.0};
double d2 = 0.0;
if (mi_dist2(&box, p, q, &d2) != 0) {
fprintf(stderr, "%s\n", mi_last_error());
}
Link libminimage and add include/ to the include path. Meson
exposes minimage_dep. CMake exposes minimage::minimage.
Embed from C++
#include "minimage.hpp"
const minimage::Cell box = minimage::Cell::ortho(10.0, 10.0, 10.0);
const double d2 = box.dist2({0.2, 0.0, 0.0}, {9.4, 0.0, 0.0});
The header is a RAII wrap of minimage.h. Failures throw
minimage::Error.
Embed from Python
import minimage cell = minimage.Cell.ortho(10.0, 10.0, 10.0) print(cell.dist2([0.2, 0.0, 0.0], [9.4, 0.0, 0.0])) d2 = cell.dist2_pairs(ps, qs) # (n, 3) arrays in, numpy out f = cell.fixed_many(positions) # uint64 (n, 3) d2 = cell.dist2_pairs_fixed(f[i], f[j])
Array arguments go through DLPack: numpy, PyTorch, JAX, and CuPy host
arrays are read in place, and the result is a numpy array that owns
its buffer. A list in gives a list out. A device array raises; move it
to the host, or run the wrap on the device with minimage-burn.
Run on a GPU with Burn
burn/ is the minimage-burn crate, outside the workspace because
Burn needs Rust 1.95. Enable the backend features you need (wgpu,
vulkan, metal, cuda, rocm, cpu, flex, fusion).
use burn_tensor::{DType, Device, DeviceKind};
use minimage_burn::{to_vec, Lattice};
let device = Device::wgpu(DeviceKind::DefaultDevice);
let lat = Lattice::new(&cell, &device, DType::F32);
let sp = lat.fractions(&cell, &ps);
let sq = lat.fractions(&cell, &qs);
let d2 = to_vec(lat.dist2_pairs_fractional(sp, sq));
fractions folds on the CPU in double precision and uploads; the wrap
on the device is then exact in single or half precision.
dist2_pairs, dist2_many, and wrap take Cartesian rows instead.
pkg-config
pkg-config --cflags --libs minimage
Meson and CMake both write minimage.pc. Libs includes -L${libdir}
so a wrap consumer can find -lminimage.