From 093d161490cad7841b76a58d04a2aafe7e73397b Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:21:22 +0530 Subject: [PATCH 1/5] feat: add C implementation for exponential logpdf --- .../base/dists/exponential/logpdf/README.md | 96 ++++++++ .../exponential/logpdf/benchmark/benchmark.js | 14 +- .../logpdf/benchmark/benchmark.native.js | 71 ++++++ .../exponential/logpdf/benchmark/c/Makefile | 146 ++++++++++++ .../logpdf/benchmark/c/benchmark.c | 141 ++++++++++++ .../base/dists/exponential/logpdf/binding.gyp | 170 ++++++++++++++ .../exponential/logpdf/examples/c/Makefile | 146 ++++++++++++ .../exponential/logpdf/examples/c/example.c | 41 ++++ .../dists/exponential/logpdf/include.gypi | 53 +++++ .../stats/base/dists/exponential/logpdf.h | 38 ++++ .../dists/exponential/logpdf/lib/native.js | 68 ++++++ .../dists/exponential/logpdf/manifest.json | 87 ++++++++ .../dists/exponential/logpdf/package.json | 3 + .../dists/exponential/logpdf/src/Makefile | 70 ++++++ .../base/dists/exponential/logpdf/src/addon.c | 23 ++ .../base/dists/exponential/logpdf/src/main.c | 70 ++++++ .../exponential/logpdf/test/test.native.js | 208 ++++++++++++++++++ 17 files changed, 1442 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/include/stdlib/stats/base/dists/exponential/logpdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/README.md index 0c1bd0d6a8ab..cff18b524bbd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/exponential/logpdf/README.md @@ -137,6 +137,102 @@ for ( i = 0; i < 10; i++ ) { + + +
+ + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/exponential/logpdf.h" +``` + +#### stdlib_base_dists_exponential_logpdf( x, lambda ) + +Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for an [exponential][exponential-distribution] distribution with rate parameter `lambda`. + +```c +double out = stdlib_base_dists_exponential_logpdf( 2.0, 0.7 ); +// returns ~0.173 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **lambda**: `[in] double` rate parameter. + +```c +double stdlib_base_dists_exponential_logpdf( const double x, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/exponential/logpdf.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_logpdf( x, lambda ); + printf( "x: %lf, λ: %lf, ln(f(x;λ)): %lf\n", x, lambda, y ); + } +} +``` + +
+ + +