Crate r_mathlib

Source
Expand description

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.

Modules§

ffi
This module provides the output of bindgen, in case the raw functions are useful.

Functions§

beta_cdf
Evaluate the culmulative distribution function of the beta distribution with parameters a and b at x.
beta_pdf
Evaluate the probability density function of the beta distribution with parameters a and b at x.
beta_quantile
Evaluate the quantile function of the beta distribution with parameters a and b at probability p.
binomial_cdf
Evaluate the culmulative distribution function of the binomial distribution with n trials and probability of success p at x.
binomial_pdf
Evaluate the probability density function of the binomial distribution with n trials and probability of success p at x.
binomial_quantile
Evaluate the quantile function of the binomial distribution with n trials and probability of success pr at probability p.
cauchy_cdf
Evaluate the culmulative distribution function of the Cauchy distribution with parameters location and scale at x.
cauchy_pdf
Evaluate the probability density function of the Cauchy distribution with parameters location and scale at x.
cauchy_quantile
Evaluate the quantile function of the Cauchy distribution with parameters location and scale at probability p.
chi_squared_cdf
Evaluate the culmulative distribution function of the chi-squared distribution with df degrees of freedom at x.
chi_squared_pdf
Evaluate the probability density function of the chi-squared distribution with df degrees of freedom at x.
chi_squared_quantile
Evaluate the quantile function of the chi-squared distribution with df degrees of freedom at probability p.
exponential_cdf
Evaluate the culmulative distribution function of the exponential distribution with given scale at x.
exponential_pdf
Evaluate the probability density function of the exponential distribution with given scale at x.
exponential_quantile
Evaluate the quantile function of the exponential distribution with given scale at probability p.
f_cdf
Evaluate the culmulative distribution function of the f distribution with parameters df1 and df2 at x.
f_pdf
Evaluate the probability density function of the f distribution with parameters df1 and df2 at x. TODO I think df1 is the numerator degrees of freedom (when viewed as the ratio of two chi-squared dists. Check and doc this.
f_quantile
Evaluate the quantile function of the f distribution with parameters df1 and df2 at probability p.
gamma_cdf
Evaluate the culmulative density function of the gamma distribution with shape and scale at x.
gamma_pdf
Evaluate the probability density function of the gamma distribution with given shape and scale at x.
gamma_quantile
Evaluate the quantile function of the gamma distribution with shape and scale at probability p.
geometric_cdf
Evaluate the culmulative distribution function of the geometric distribution with trial probability p at x. P(X=x) = p(1-p)^x.
geometric_pdf
Evaluate the probability density function of the geometric distribution with trial probability p at x. P(X=x) = p(1-p)^x.
geometric_quantile
Evaluate the quantile function of the geometric distribution with trial probability prob at probability p. P(X=x) = p(1-p)^x.
hypergeometric_cdf
Evaluate the culmulative distribution function of the hypergeometric distribution. If samples samples were taken at random from a collection of succ successes and fail failures, then this function evaluates the chance of ≤x successes being in the sample.
hypergeometric_pdf
Evaluate the probability density function of the hypergeometric distribution. If samples samples were taken at random from a collection of succ successes and fail failures, then this function evaluates the chance of x successes being in the sample.
hypergeometric_quantile
Evaluate the quantile function of the hypergeometric distribution. If samples samples were taken at random from a collection of succ successes and fail failures, then this function evaluates the number of samples where there is p probability there are <= that many successes.
logistic_cdf
Evaluate the culmulative distribution function of the logistic distribution.
logistic_pdf
Evaluate the probability density function of the logistic distribution.
logistic_quantile
Evaluate the quantile function of the logistic distribution.
lognormal_cdf
Evaluate the culmulative distribution function of the log-normal distribution with parameters mean_log and sd_log at x.
lognormal_pdf
Evaluate the probability density function of the log-normal distribution with parameters mean_log and sd_log at x.
lognormal_quantile
Evaluate the quantile function of the log-normal distribution with parameters mean_log and sd_log at probability p.
neg_binomial_cdf
Evaluate the culmulative distribution function of the negative binomial distribution. If there is prob probability of successin a Bernoulli trial, and we perform trials until we see size successes, then this function returns the probability of seeing ≤x failures in those trials.
neg_binomial_pdf
Evaluate the probability density function of the negative binomial distribution. If there is prob probability of successin a Bernoulli trial, and we perform trials until we see size successes, then this function returns the probability of seeing x failures in those trials.
neg_binomial_quantile
Evaluate the quantile function of the negative binomial distribution. If there is prob probability of successin a Bernoulli trial, and we perform trials until we see size successes, then this function returns the number of failures we would expect to see with probability p.
non_central_beta_cdf
Evaluate the culmulative distribution function of the non-central beta distribution.
non_central_beta_pdf
Evaluate the probability density function of the non-central beta distribution.
non_central_beta_quantile
Evaluate the quantile function of the non-central beta distribution.
non_central_f_cdf
Evaluate the culmulative distribution function of the non-central f distribution.
non_central_f_pdf
Evaluate the probability density function of the non-central f distribution.
non_central_f_quantile
Evaluate the quantile function of the non-central f distribution.
non_central_t_cdf
Evaluate the culmulative distribution function of the non-central student’s t distribution.
non_central_t_pdf
Evaluate the probability density function of the non-central student’s t distribution.
non_central_t_quantile
Evaluate the quantile function of the non-central student’s t distribution.
noncentral_chi_squared_cdf
Evaluate the culmulative distribution function of the non-central chi-squared distribution with df degrees of freedom and non-centrality parameter ncp at x.
noncentral_chi_squared_pdf
Evaluate the probability density function of the non-central chi-squared distribution with df degrees of freedom and non-centrality parameter ncp at x.
noncentral_chi_squared_quantile
Evaluate the quantile function of the non-central chi-squared distribution with df degrees of freedom and non-centrality parameter ncp at probability p.
normal_cdf
Evaluate the culmulative density function of the normal distribution with mean mu and variance sigma squared at x.
normal_cdf_both
Evaluate the culmulative density function of the normal distribution with mean mu and variance sigma at x. Both integrals ((-∞, x) and (x, ∞)) are returned in that order.
normal_pdf
Evaluate the probability density function of the normal distribution with mean mu and variance sigma2 at x.
normal_quantile
Evaluate the quantile function of the normal distribution with mean mu and variance sigma squared at probability p.
poisson_cdf
Evaluate the culmulative distribution function of the poisson distribution.
poisson_pdf
Evaluate the probability density function of the poisson distribution.
poisson_quantile
Evaluate the quantile function of the poisson distribution.
signrank_cdf
Evaluate the culmulative distribution function of the signrankon signed rank distribution.
signrank_pdf
Evaluate the probability density function of the Wilcoxon signed rank distribution.
signrank_quantile
Evaluate the quantile function of the signrankon signed rank distribution.
students_t_cdf
Evaluate the culmulative distribution function of the student’s t distribution with degrees of freedom df at x.
students_t_pdf
Evaluate the probability density function of the student’s t distribution with degrees of freedom df at x.
students_t_quantile
Evaluate the quantile function of the student’s t distribution with degrees of freedom df at probability p.
tukey_pdf
Evaluate the culmulative distribution function of the studentized range distribution.
tukey_quantile
Evaluate the quantile function of the studentized range distribution.
weibull_cdf
Evaluate the culmulative distribution function of the Weibull distribution.
weibull_pdf
Evaluate the probability density function of the Weibull distribution.
weibull_quantile
Evaluate the quantile function of the Weibull distribution.
wilcox_cdf
Evaluate the culmulative distribution function of the Wilcoxon rank-sum distribution.
wilcox_pdf
Evaluate the probability density function of the Wilcoxon rank-sum distribution.
wilcox_quantile
Evaluate the quantile function of the Wilcoxon rank-sum distribution.