From f809f17b09ff5891ca55f598e9e96e10d463a8ac Mon Sep 17 00:00:00 2001 From: yuvi-mittal Date: Sat, 1 Feb 2025 02:08:18 +0530 Subject: [PATCH 1/3] feat: Add C implementation for @stdlib/stats/base/dists/planck/logpmf --- 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/logpmf/README.md | 100 ++++++++++- .../planck/logpmf/benchmark/benchmark.js | 16 +- .../logpmf/benchmark/benchmark.native.js | 71 ++++++++ .../dists/planck/logpmf/benchmark/c/Makefile | 146 +++++++++++++++ .../planck/logpmf/benchmark/c/benchmark.c | 146 +++++++++++++++ .../base/dists/planck/logpmf/binding.gyp | 170 ++++++++++++++++++ .../dists/planck/logpmf/examples/c/Makefile | 146 +++++++++++++++ .../dists/planck/logpmf/examples/c/example.c | 45 +++++ .../base/dists/planck/logpmf/include.gypi | 53 ++++++ .../stdlib/stats/base/dists/planck/logpmf.h | 38 ++++ .../base/dists/planck/logpmf/lib/native.js | 67 +++++++ .../base/dists/planck/logpmf/manifest.json | 92 ++++++++++ .../base/dists/planck/logpmf/package.json | 3 + .../base/dists/planck/logpmf/src/Makefile | 70 ++++++++ .../base/dists/planck/logpmf/src/addon.c | 23 +++ .../stats/base/dists/planck/logpmf/src/main.c | 49 +++++ .../dists/planck/logpmf/test/test.native.js | 149 +++++++++++++++ 17 files changed, 1379 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/README.md index bd177c1db4d7..fe1d5564e1ab 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/README.md @@ -101,7 +101,7 @@ y = mylogpmf( 1.0 ); ## Notes -- In virtually all cases, using the `logpmf` or `logcdf` functions is preferable to manually computing the logarithm of the `pmf` or `cdf`, respectively, since the latter is prone to overflow and underflow. +- In virtually all cases, using the `logpmf` or `loglogpmf` functions is preferable to manually computing the logarithm of the `pmf` or `logpmf`, respectively, since the latter is prone to overflow and underflow. @@ -133,6 +133,104 @@ for ( i = 0; i < lambda.length; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/planck/logpmf.h" +``` + +#### stdlib_base_dists_planck_logpmf( x, lambda ) + +Evaluates the logarithm of the [probability mass function][pmf] (PMF) of a Planck (discrete exponential) distribution with shape parameter `lambda`. + +```c +double out = stdlib_base_dists_planck_logpmf( 4.0 , 0.3 ); +// returns ~-2.5502 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_planck_logpmf( const double x, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/planck/logpmf.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 ) { + double lambda; + double y; + int x; + 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_logpmf( x, lambda ); + printf( "x: %d, lambda: %lf, F(x; lambda): %lf\n", x, lambda ,y ); + } +} +``` + +
+ + + +
+ + + @@ -161,7 +161,7 @@ for ( i = 0; i < lambda.length; i++ ) { #### stdlib_base_dists_planck_logpmf( x, lambda ) -Evaluates the logarithm of the [probability mass function][pmf] (PMF) of a Planck (discrete exponential) distribution with shape parameter `lambda`. +Evaluates the logarithm of the probability mass function (PMF) of a Planck distribution with shape parameter `lambda`. ```c double out = stdlib_base_dists_planck_logpmf( 4.0 , 0.3 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h index b8519ce17627..94b534a66684 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -* Evaluates the logpmf for an planck distribution. +* Evaluates the logarithm of the probability mass function (PMF) of a Planck distribution with shape parameter `lambda`. */ double stdlib_base_dists_planck_logpmf( const double x, const double lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/manifest.json index 9acc7ff41fbb..30aa2f4b82cb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/manifest.json @@ -42,10 +42,8 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/math/base/special/expm1", - "@stdlib/constants/float64/pi", "@stdlib/math/base/special/ln", "@stdlib/constants/float64/ninf" - ] }, { @@ -63,7 +61,6 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/math/base/special/expm1", - "@stdlib/constants/float64/pi", "@stdlib/math/base/special/ln", "@stdlib/constants/float64/ninf" ] @@ -83,7 +80,6 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/math/base/special/expm1", - "@stdlib/constants/float64/pi", "@stdlib/math/base/special/ln", "@stdlib/constants/float64/ninf" ] diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/main.c index e60ebbc7c04b..8f46c78ff621 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/main.c @@ -24,7 +24,7 @@ #include "stdlib/constants/float64/ninf.h" /** -* Evaluates the logarithm of the probability mass function (PMF) for a Planck distribution with shape parameter `lambda` at a value `x`. +* Evaluates the logarithm of the probability mass function (PMF) of a Planck distribution with shape parameter `lambda`. * * @param x input value * @param lambda shape parameter From 65564045c7646372968a02bfaf4953613ffec9d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:51:34 +0000 Subject: [PATCH 3/3] chore: update copyright years --- .../@stdlib/stats/base/dists/planck/logpmf/benchmark/c/Makefile | 2 +- .../@stdlib/stats/base/dists/planck/logpmf/binding.gyp | 2 +- .../@stdlib/stats/base/dists/planck/logpmf/examples/c/Makefile | 2 +- .../@stdlib/stats/base/dists/planck/logpmf/include.gypi | 2 +- .../logpmf/include/stdlib/stats/base/dists/planck/logpmf.h | 2 +- .../@stdlib/stats/base/dists/planck/logpmf/src/Makefile | 2 +- .../@stdlib/stats/base/dists/planck/logpmf/src/addon.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/c/Makefile index f69e9da2b4d3..a4bd7b38fd74 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/binding.gyp index ec3992233442..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/binding.gyp @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/examples/c/Makefile index 6aed70daf167..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/examples/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include.gypi index 575cb043c0bf..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h index 94b534a66684..6e3fe49c8a13 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/include/stdlib/stats/base/dists/planck/logpmf.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/Makefile index bcf18aa46655..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 The Stdlib Authors. +# Copyright (c) 2025 The Stdlib Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/addon.c index 5a6d1a9d82eb..97ba5aad758d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logpmf/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.