#quantile #stats #statistics #r #nmath

r_mathlib

A port of R’s nmath stats module to Rust

3 unstable releases

0.2.0 Jul 27, 2023
0.1.1 Feb 27, 2023
0.1.0 Sep 18, 2020

#1895 in Math

GPL-2.0-or-later

585KB
10K SLoC

C 10K SLoC // 0.4% comments Rust 519 SLoC // 0.1% comments

Things I've done to make R's nmath library work

  1. Copied the nmath source
  2. Set MATHLIB_STANDALONE: telling nmath to build for use outside R
  3. Copied R's includes since they are still needed even with MATHLIB_STANDALONE.
  4. Copy Rconfig.h and config.h from the mingw dir (normally these files would be generated, but I think the math libs use very little of them).
  5. Copy Rmath.h from Rmath.h0.in and replace the build system placeholders (there are only 2).
  6. Manually whitelist the functions to include, otherwise we pull in a lot of stuff, including stuff outside the source tree (and also it doesn't compile for some reason).
  7. Rmath.h wierdly sets the normal functions as aliases - we have to use the raw function name here e.g. dnorm4.

I've done some work on rust versions of these functions in the riir branch. This branch should be used for testing those functions in future.

R is released as GPLv2 which I interpret as meaning this library must also be released as GPLv2. If all the functions were replaced with native rust ones, then the license could be changed to something more permissive.

No runtime deps

~0–2.2MB
~45K SLoC