From 5affd09aa6d4cf9137467dd57a82cbf25a92c532 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 23 Dec 2024 18:53:10 +0530 Subject: [PATCH 1/3] feat: add C implementation for exponential logcdf --- .../base/dists/exponential/logcdf/README.md | 96 ++++++++++ .../exponential/logcdf/benchmark/benchmark.js | 14 +- .../logcdf/benchmark/benchmark.native.js | 71 ++++++++ .../exponential/logcdf/benchmark/c/Makefile | 146 +++++++++++++++ .../logcdf/benchmark/c/benchmark.c | 141 +++++++++++++++ .../base/dists/exponential/logcdf/binding.gyp | 170 ++++++++++++++++++ .../exponential/logcdf/examples/c/Makefile | 146 +++++++++++++++ .../exponential/logcdf/examples/c/example.c | 41 +++++ .../dists/exponential/logcdf/include.gypi | 53 ++++++ .../stats/base/dists/exponential/logcdf.h | 38 ++++ .../dists/exponential/logcdf/lib/native.js | 68 +++++++ .../dists/exponential/logcdf/manifest.json | 90 ++++++++++ .../dists/exponential/logcdf/package.json | 3 + .../dists/exponential/logcdf/src/Makefile | 70 ++++++++ .../base/dists/exponential/logcdf/src/addon.c | 23 +++ .../base/dists/exponential/logcdf/src/main.c | 71 ++++++++ .../exponential/logcdf/test/test.native.js | 130 ++++++++++++++ 17 files changed, 1368 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/include/stdlib/stats/base/dists/exponential/logcdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/README.md index 30849581d276..2ddf3b182335 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/exponential/logcdf/README.md @@ -140,6 +140,102 @@ for ( i = 0; i < 10; i++ ) { + + +
+ + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/exponential/cdf.h" +``` + +#### stdlib_base_dists_exponential_cdf( x, lambda ) + +Evaluates the natural logarithm of the [cumulative distribution function (CDF)][cdf] for an exponential distribution with rate parameter `lambda`. + +```c +double out = stdlib_base_dists_exponential_logcdf( 2.0, 0.1 ); +// returns ~-1.708 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **lambda**: `[in] double` rate parameter. + +```c +double stdlib_base_dists_exponential_logcdf( const double x, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/exponential/logcdf.h" +#include "stdlib/constants/float64/eps.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 y; + int i; + + for ( i = 0; i < 25; i++ ) { + x = random_uniform( 0.0, 100.0 ); + lambda = random_uniform( 0.0, 100.0 ) + STDLIB_CONSTANT_FLOAT64_EPS; + y = stdlib_base_dists_exponential_logcdf( x, lambda ); + printf( "x: %lf, λ: %lf, ln(F(x;λ)): %lf\n", x, lambda, y ); + } +} +``` + +
+ + +