From d5920af37731ea403b68993c32b492724e5363aa Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Sun, 29 Dec 2024 09:11:20 +0530 Subject: [PATCH] feat: add C implementation of `stats/base/dists/weibull/cdf` PR-URL: #4196 Closes: #3838 --------- Signed-off-by: Philipp Burckhardt Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../stats/base/dists/weibull/cdf/README.md | 98 ++++++++ .../dists/weibull/cdf/benchmark/benchmark.js | 17 +- .../weibull/cdf/benchmark/benchmark.native.js | 74 ++++++ .../dists/weibull/cdf/benchmark/c/Makefile | 146 ++++++++++++ .../dists/weibull/cdf/benchmark/c/benchmark.c | 143 ++++++++++++ .../stats/base/dists/weibull/cdf/binding.gyp | 170 ++++++++++++++ .../dists/weibull/cdf/examples/c/Makefile | 146 ++++++++++++ .../dists/weibull/cdf/examples/c/example.c | 42 ++++ .../base/dists/weibull/cdf/examples/index.js | 2 +- .../stats/base/dists/weibull/cdf/include.gypi | 53 +++++ .../stdlib/stats/base/dists/weibull/cdf.h | 38 ++++ .../base/dists/weibull/cdf/lib/native.js | 76 +++++++ .../base/dists/weibull/cdf/manifest.json | 83 +++++++ .../stats/base/dists/weibull/cdf/package.json | 3 + .../stats/base/dists/weibull/cdf/src/Makefile | 70 ++++++ .../stats/base/dists/weibull/cdf/src/addon.c | 23 ++ .../stats/base/dists/weibull/cdf/src/main.c | 50 +++++ .../dists/weibull/cdf/test/test.native.js | 211 ++++++++++++++++++ 18 files changed, 1440 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/include/stdlib/stats/base/dists/weibull/cdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/README.md index 87efe0d45b4d..3670b1d29c66 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/README.md @@ -151,6 +151,104 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/weibull/cdf.h" +``` + +#### stdlib_base_dists_weibull_cdf( x, k, lambda ) + +Evaluates the [cumulative distribution function][cdf] (CDF) for a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`. + +```c +double out = stdlib_base_dists_weibull_cdf( 2.0, 1.0, 1.0 ); +// returns ~0.865 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **k**: `[in] double` scale parameter. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_weibull_cdf( const double x, const double k, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/weibull/cdf.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 lambda; + double x; + double k; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + x = random_uniform( 0.0, 10.0 ); + lambda = random_uniform( 0.0, 10.0 ); + k = random_uniform( 0.0, 10.0 ); + y = stdlib_base_dists_weibull_cdf( x, k, lambda ); + printf( "x: %lf, k: %lf, λ: %lf, F(x;k,λ): %lf\n", x, k, lambda, y ); + } +} +``` + +
+ + + +
+ + +