From a901d4005dd1a76e6f0837dccfb2382739dd70e2 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 24 Dec 2024 19:46:32 +0530 Subject: [PATCH 1/8] feat: add C implementation for geometric logcdf --- .../base/dists/geometric/logcdf/README.md | 97 ++++++++++ .../geometric/logcdf/benchmark/benchmark.js | 14 +- .../logcdf/benchmark/benchmark.native.js | 71 ++++++++ .../geometric/logcdf/benchmark/c/Makefile | 146 +++++++++++++++ .../geometric/logcdf/benchmark/c/benchmark.c | 141 +++++++++++++++ .../base/dists/geometric/logcdf/binding.gyp | 170 ++++++++++++++++++ .../geometric/logcdf/examples/c/Makefile | 146 +++++++++++++++ .../geometric/logcdf/examples/c/example.c | 42 +++++ .../base/dists/geometric/logcdf/include.gypi | 53 ++++++ .../stats/base/dists/geometric/logcdf.h | 38 ++++ .../base/dists/geometric/logcdf/lib/native.js | 68 +++++++ .../base/dists/geometric/logcdf/manifest.json | 93 ++++++++++ .../base/dists/geometric/logcdf/package.json | 3 + .../base/dists/geometric/logcdf/src/Makefile | 70 ++++++++ .../base/dists/geometric/logcdf/src/addon.c | 23 +++ .../base/dists/geometric/logcdf/src/main.c | 76 ++++++++ .../geometric/logcdf/test/test.native.js | 148 +++++++++++++++ 17 files changed, 1396 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/include/stdlib/stats/base/dists/geometric/logcdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/README.md index 2120ab0cbe43..5a973c625156 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/logcdf/README.md @@ -139,6 +139,103 @@ for ( i = 0; i < 10; i++ ) { + + +
+ + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/geometric/logcdf.h" +``` + +#### stdlib_base_dists_geometric_logcdf( x, p ) + +Evaluates evaluating the logarithm of the [cumulative distribution function][cdf] of a [geometric][geometric-distribution] distribution with success probability `p` + +```c +double out = stdlib_base_dists_geometric_logcdf( 2.0, 0.5 ); +// returns ~-0.134 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **p**: `[in] double` probability of success. + +```c +double stdlib_base_dists_geometric_logcdf( const double x, const double p ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/geometric/logcdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#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 x; + double p; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + x = random_uniform( 0, 40 ); + p = random_uniform( 0.0, 1.0 ) + STDLIB_CONSTANT_FLOAT64_EPS; + y = stdlib_base_dists_geometric_logcdf( x, p ); + printf( "x: %lf, p: %lf, ln(F(x;p)): %lf\n", x, p, y ); + } +} +``` + +
+ + +