From f5350c2bb1a4d61a89a54976dfd8d7ad277f60cd Mon Sep 17 00:00:00 2001 From: yuvi-mittal Date: Fri, 31 Jan 2025 23:03:35 +0530 Subject: [PATCH 1/4] feat: Add C implementation for @stdlib/stats/base/dists/planck/pmf --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/dists/planck/pmf/README.md | 99 ++++++++++ .../dists/planck/pmf/benchmark/benchmark.js | 16 +- .../planck/pmf/benchmark/benchmark.native.js | 71 ++++++++ .../dists/planck/pmf/benchmark/c/Makefile | 146 +++++++++++++++ .../dists/planck/pmf/benchmark/c/benchmark.c | 110 ++++++++++++ .../stats/base/dists/planck/pmf/binding.gyp | 170 ++++++++++++++++++ .../base/dists/planck/pmf/examples/c/Makefile | 146 +++++++++++++++ .../dists/planck/pmf/examples/c/example.c | 45 +++++ .../stats/base/dists/planck/pmf/include.gypi | 53 ++++++ .../stdlib/stats/base/dists/planck/pmf.h | 38 ++++ .../stats/base/dists/planck/pmf/lib/native.js | 67 +++++++ .../stats/base/dists/planck/pmf/manifest.json | 89 +++++++++ .../stats/base/dists/planck/pmf/package.json | 3 + .../stats/base/dists/planck/pmf/src/Makefile | 70 ++++++++ .../stats/base/dists/planck/pmf/src/addon.c | 23 +++ .../stats/base/dists/planck/pmf/src/main.c | 44 +++++ .../base/dists/planck/pmf/test/test.native.js | 154 ++++++++++++++++ 17 files changed, 1340 insertions(+), 4 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/include/stdlib/stats/base/dists/planck/pmf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/pmf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/pmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/planck/pmf/README.md index 3e232251e9fa..6b417b00c1e1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/pmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/pmf/README.md @@ -123,6 +123,105 @@ for ( i = 0; i < lambda.length; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/planck/pmf.h" +``` + +#### stdlib_base_dists_planck_pmf( x, lambda ) + +Returns a function for evaluating the probability mass function(pmf) of a Planck distribution with shape parameter `lambda`. + +```c +double out = stdlib_base_dists_planck_pmf( 4.0 , 3.0 ); +// returns ~0.0781 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_planck_pmf( const double x, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/planck/pmf.h" +#include +#include +static int random_discrete_uniform( const int min, const int max ) { + return min + rand() % ( max - min + 1 ); +} + +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 ) { + int x; + double lambda; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_discrete_uniform( 0, 5 ); + lambda = random_uniform( 0.1, 5.0 ); + y = stdlib_base_dists_planck_pmf( x, lambda ); + printf( "x: %d, \u03BB: %lf, P(X = x; \u03BB): %lf\n", x, lambda, y ); + } + return 0; +} +``` + +
+ + + +
+ + +