From 1ed5a72d0e1f6502f2f5b5f6e3bf289e6f53b4a6 Mon Sep 17 00:00:00 2001 From: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Date: Thu, 16 Jan 2025 06:02:15 -0800 Subject: [PATCH] feat: add C implementation for `stats/base/dists/degenerate/quantile` PR-URL: https://github.com/stdlib-js/stdlib/pull/4587 Closes: https://github.com/stdlib-js/stdlib/issues/3546 Co-authored-by: Philipp Burckhardt Co-authored-by: stdlib-bot Reviewed-by: Philipp Burckhardt Signed-off-by: Philipp Burckhardt --- .../base/dists/degenerate/quantile/README.md | 95 ++++++++++ .../quantile/benchmark/benchmark.js | 3 +- .../quantile/benchmark/benchmark.native.js | 71 ++++++++ .../degenerate/quantile/benchmark/c/Makefile | 146 +++++++++++++++ .../quantile/benchmark/c/benchmark.c | 141 +++++++++++++++ .../dists/degenerate/quantile/binding.gyp | 170 ++++++++++++++++++ .../degenerate/quantile/examples/c/Makefile | 146 +++++++++++++++ .../degenerate/quantile/examples/c/example.c | 40 +++++ .../dists/degenerate/quantile/include.gypi | 53 ++++++ .../stats/base/dists/degenerate/quantile.h | 38 ++++ .../dists/degenerate/quantile/lib/native.js | 67 +++++++ .../dists/degenerate/quantile/manifest.json | 76 ++++++++ .../dists/degenerate/quantile/package.json | 3 + .../dists/degenerate/quantile/src/Makefile | 70 ++++++++ .../dists/degenerate/quantile/src/addon.c | 23 +++ .../base/dists/degenerate/quantile/src/main.c | 38 ++++ .../degenerate/quantile/test/test.native.js | 85 +++++++++ 17 files changed, 1264 insertions(+), 1 deletion(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/include/stdlib/stats/base/dists/degenerate/quantile.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/README.md index d88ee8a4a413..91b1573217d1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/quantile/README.md @@ -110,6 +110,101 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/degenerate/quantile.h" +``` + +#### stdlib_base_dists_degenerate_quantile( p, mu ) + +Evaluates the [quantile function][quantile-function] of a [degenerate distribution][degenerate-distribution] centered at `mu`. + +```c +double out = stdlib_base_dists_degenerate_quantile( 0.5, 2.0 ); +// returns 2.0 +``` + +The function accepts the following arguments: + +- **p**: `[in] double` input value (probability). +- **mu**: `[in] double` constant value of the distribution. + +```c +double stdlib_base_dists_degenerate_quantile( const double p, const double mu ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/degenerate/quantile.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); +} + +int main( void ) { + double result; + double mu; + double p; + int i; + + for ( i = 0; i < 10; i++ ) { + p = random_uniform( 0.0, 1.0 ); + mu = random_uniform( -20.0, 20.0 ); + result = stdlib_base_dists_degenerate_quantile( p, mu ); + printf( "p: %lf, µ: %lf, Q(p;µ): %lf \n", p, mu, result ); + } +} +``` + +
+ + + +
+ + +