From 9db1d50279e4114797b57cfaa9f2a8913772b7fc Mon Sep 17 00:00:00 2001 From: yuvi-mittal Date: Tue, 28 Jan 2025 16:13:38 +0530 Subject: [PATCH 1/4] Add C implementation for @stdlib/stats/base/dists/planck/logcdf --- 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/logcdf/README.md | 97 ++++++++++ .../planck/logcdf/benchmark/benchmark.js | 17 +- .../logcdf/benchmark/benchmark.native.js | 71 ++++++++ .../dists/planck/logcdf/benchmark/c/Makefile | 146 +++++++++++++++ .../planck/logcdf/benchmark/c/benchmark.c | 144 +++++++++++++++ .../base/dists/planck/logcdf/binding.gyp | 170 ++++++++++++++++++ .../dists/planck/logcdf/examples/c/Makefile | 146 +++++++++++++++ .../dists/planck/logcdf/examples/c/example.c | 44 +++++ .../base/dists/planck/logcdf/include.gypi | 53 ++++++ .../stdlib/stats/base/dists/planck/logcdf.h | 38 ++++ .../base/dists/planck/logcdf/lib/native.js | 63 +++++++ .../base/dists/planck/logcdf/manifest.json | 95 ++++++++++ .../base/dists/planck/logcdf/package.json | 3 + .../base/dists/planck/logcdf/src/Makefile | 70 ++++++++ .../base/dists/planck/logcdf/src/addon.c | 23 +++ .../stats/base/dists/planck/logcdf/src/main.c | 49 +++++ .../dists/planck/logcdf/test/test.native.js | 142 +++++++++++++++ 17 files changed, 1366 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md index d14304e5e82c..938d680b85fa 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md @@ -130,6 +130,103 @@ for ( i = 0; i < lambda.length; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/planck/logcdf.h" +``` + +#### stdlib_base_dists_planck_logcdf( x, lambda ) + +Evaluates the logarithm of cumulative distribution function (logcdf) for an planck distribution. + +```c +double out = stdlib_base_dists_planck_logcdf( 2, 0.5,); +// returns ~-0.2525 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_planck_logcdf +( const double x, const double lambda ); +``` +
+ + + + + +
+ +
+ + + + + +
+ +### Examples +```c +#include "stdlib/stats/base/dists/planck/logcdf.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) ); +} +static int discrete_uniform( const int min, const int max ) { + return min + (rand() % (max - min + 1)); +} + +int main( void ) { + double x; + double lambda; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + x = discrete_uniform( 0, 40.0 ); + lambda = random_uniform( 0.1, 5.0 ); + y = stdlib_base_dists_planck_logcdf( x, lambda ); + printf( "x: %lf, λ: %lf, ln(F(x;λ)): %lf\n", x, lambda, y ); + } +} +``` + +
+ + + +
+ + + + @@ -191,6 +192,7 @@ double stdlib_base_dists_planck_logcdf
### Examples + ```c #include "stdlib/stats/base/dists/planck/logcdf.h" #include @@ -204,17 +206,17 @@ static int discrete_uniform( const int min, const int max ) { } int main( void ) { - double x; - double lambda; - double y; - int i; - - for ( i = 0; i < 25; i++ ) { - x = discrete_uniform( 0, 40.0 ); - lambda = random_uniform( 0.1, 5.0 ); - y = stdlib_base_dists_planck_logcdf( x, lambda ); - printf( "x: %lf, λ: %lf, ln(F(x;λ)): %lf\n", x, lambda, y ); - } + double x; + double lambda; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + x = discrete_uniform( 0, 40.0 ); + lambda = random_uniform( 0.1, 5.0 ); + y = stdlib_base_dists_planck_logcdf( x, lambda ); + printf( "x: %lf, λ: %lf, ln(F(x;λ)): %lf\n", x, lambda, y ); + } } ``` From ec140d760518e8b69f013d0f08786edf4c51451a Mon Sep 17 00:00:00 2001 From: yuvi-mittal Date: Mon, 3 Feb 2025 13:17:44 +0530 Subject: [PATCH 3/4] Refactor random number generation in JS benchmarks --- 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/logcdf/README.md | 2 +- .../planck/logcdf/benchmark/benchmark.js | 7 +- .../logcdf/benchmark/benchmark.native.js | 2 +- .../stdlib/stats/base/dists/planck/logcdf.h | 2 +- .../base/dists/planck/logcdf/lib/native.js | 2 +- .../base/dists/planck/logcdf/manifest.json | 180 +++++++++--------- .../stats/base/dists/planck/logcdf/src/main.c | 2 +- 7 files changed, 99 insertions(+), 98 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md index 8c8e85a161ff..e4c7fda69a18 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/README.md @@ -158,7 +158,7 @@ for ( i = 0; i < lambda.length; i++ ) { #### stdlib_base_dists_planck_logcdf( x, lambda ) -Evaluates the logarithm of cumulative distribution function (logcdf) for an planck distribution. +Evaluates the logarithm of cumulative distribution function (logcdf) for an planck distribution with shape parameter `lambda`. ```c double out = stdlib_base_dists_planck_logcdf( 2, 0.5,); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.js index e92d5f100377..b15596282174 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.js @@ -63,12 +63,17 @@ bench( pkg, function benchmark( b ) { bench( pkg+':factory', function benchmark( b ) { var mylogcdf; + var len; var x; var y; var i; - x = discreteUniform( 100, 0, 40 ); + len = 100; mylogcdf = logcdf.factory( 0.3 ); + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[i] = discreteUniform( 0, 40 ); + } b.tic(); for ( i = 0; i < b.iterations; i++ ) { diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.native.js index 52989b6bb160..abca59025711 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/benchmark.native.js @@ -52,7 +52,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { x = new Float64Array( len ); for ( i = 0; i < len; i++ ) { x[i] = discreteUniform(0, 40); - lambda[i] = uniform(1.0, 11.0); + lambda[i] = uniform(1.0, 10.0); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h index da9c316f80a5..4c0d97eb58c2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -* Evaluates the logarithmic cumulative distribution function for an planck distribution with shape parameter 'lambda' at value 'x'. +*Evaluates the logarithm of cumulative distribution function (logcdf) for an planck distribution with shape parameter `lambda`. */ double stdlib_base_dists_planck_logcdf( const double x, const double lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/lib/native.js index d9fd593b7da7..fd4ad4bc3731 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Evaluates the logarithm of the cumulative distribution function (logCDF) for a Planck (discrete exponential) distribution with shape parameter `lambda` at a value `x`. +*Evaluates the logarithm of cumulative distribution function (logcdf) for an planck distribution with shape parameter `lambda`. * * @private * @param {number} x - input value diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/manifest.json index 17f0dec20354..3a8ca690ae76 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/manifest.json @@ -1,95 +1,91 @@ { - "options": { + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { "task": "build", - "wasm": false + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/expm1", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/pinf" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/expm1", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/pinf" + ] }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "wasm": false, - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/napi/binary", - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", - "@stdlib/math/base/special/expm1", - "@stdlib/math/base/special/ln", - "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pi", - "@stdlib/constants/float64/pinf" - - ] - }, - { - "task": "benchmark", - "wasm": false, - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", - "@stdlib/math/base/special/expm1", - "@stdlib/math/base/special/ln", - "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pi", - "@stdlib/constants/float64/pinf" - ] - }, - { - "task": "examples", - "wasm": false, - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", - "@stdlib/math/base/special/expm1", - "@stdlib/math/base/special/ln", - "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pi", - "@stdlib/constants/float64/pinf" - ] - } - ] - } + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/special/expm1", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/pinf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/main.c index eb0155cce12c..0a19683f860e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/main.c @@ -25,7 +25,7 @@ #include "stdlib/constants/float64/pinf.h" /** -* Evaluates the logarithm of the cumulative distribution function (logCDF) for a Planck distribution with shape parameter `lambda` at a value `x`. +* Evaluates the logarithm of the cumulative distribution function (logCDF) for a Planck distribution with shape parameter `lambda` . * * @param x input value * @param lambda shape parameter From 03670267a02147c3c9ee2d6f079c2d2e778ac631 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:51:26 +0000 Subject: [PATCH 4/4] chore: update copyright years --- .../@stdlib/stats/base/dists/planck/logcdf/benchmark/c/Makefile | 2 +- .../@stdlib/stats/base/dists/planck/logcdf/binding.gyp | 2 +- .../@stdlib/stats/base/dists/planck/logcdf/examples/c/Makefile | 2 +- .../@stdlib/stats/base/dists/planck/logcdf/include.gypi | 2 +- .../logcdf/include/stdlib/stats/base/dists/planck/logcdf.h | 2 +- .../@stdlib/stats/base/dists/planck/logcdf/src/Makefile | 2 +- .../@stdlib/stats/base/dists/planck/logcdf/src/addon.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/c/Makefile index f69e9da2b4d3..a4bd7b38fd74 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/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/logcdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/binding.gyp index ec3992233442..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/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/logcdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/examples/c/Makefile index 6aed70daf167..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/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/logcdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include.gypi index 575cb043c0bf..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/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/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h index 4c0d97eb58c2..6173b0610478 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/include/stdlib/stats/base/dists/planck/logcdf.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/logcdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/Makefile index bcf18aa46655..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/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/logcdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/addon.c index 644d6c7e866e..0bdb12e03e17 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/logcdf/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.