From 54bf6dda9ea940c16428eef401e331d3da6f355f Mon Sep 17 00:00:00 2001 From: Kamal Singh Rautela Date: Sun, 12 Apr 2026 12:08:56 +0530 Subject: [PATCH 1/5] feat: add C implementation for stats/base/dists/erlang/logpdf --- .../stats/base/dists/erlang/logpdf/README.md | 86 +++++++++ .../logpdf/benchmark/benchmark.native.js | 74 ++++++++ .../dists/erlang/logpdf/benchmark/c/Makefile | 146 +++++++++++++++ .../erlang/logpdf/benchmark/c/benchmark.c | 139 ++++++++++++++ .../base/dists/erlang/logpdf/binding.gyp | 170 ++++++++++++++++++ .../dists/erlang/logpdf/examples/c/Makefile | 146 +++++++++++++++ .../dists/erlang/logpdf/examples/c/example.c | 34 ++++ .../base/dists/erlang/logpdf/include.gypi | 53 ++++++ .../stdlib/stats/base/dists/erlang/logpdf.h | 35 ++++ .../base/dists/erlang/logpdf/lib/native.js | 48 +++++ .../base/dists/erlang/logpdf/manifest.json | 89 +++++++++ .../base/dists/erlang/logpdf/package.json | 3 + .../base/dists/erlang/logpdf/src/Makefile | 70 ++++++++ .../base/dists/erlang/logpdf/src/addon.c | 22 +++ .../stats/base/dists/erlang/logpdf/src/main.c | 51 ++++++ .../dists/erlang/logpdf/test/test.native.js | 156 ++++++++++++++++ 16 files changed, 1322 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include/stdlib/stats/base/dists/erlang/logpdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md index c18fe494d922..060af04a43ea 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md @@ -129,6 +129,92 @@ y = mylogpdf( 4.0 ); +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/erlang/logpdf.h" +``` + +#### stdlib_base_dists_erlang_logpdf( x, k, lambda ) + +Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for an [Erlang][erlang-distribution] distribution with shape parameter `k` and rate parameter `lambda`. + +```c +double y = stdlib_base_dists_erlang_logpdf( 1.0, 3.0, 1.5 ); +// returns ~-0.977 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **k**: `[in] double` shape parameter. +- **lambda**: `[in] double` rate parameter. + +```c +double stdlib_base_dists_erlang_logpdf( const double x, const double k, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/erlang/logpdf.h" +#include +#include + +int main( void ) { + const double x[] = { 0.0, 0.5, 1.0, 1.5, 2.0 }; + const double k[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; + const double lambda[] = { 0.5, 1.0, 1.5, 2.0, 2.5 }; + + double y; + int i; + for ( i = 0; i < 5; i++ ) { + y = stdlib_base_dists_erlang_logpdf( x[ i ], k[ i ], lambda[ i ] ); + printf( "x: %lf, k: %lf, lambda: %lf, ln(f(x; k, lambda)): %lf\n", x[ i ], k[ i ], lambda[ i ], y ); + } +} +``` + +
+ + + +
+ + +
## Examples diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..66f98d3ad5dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js @@ -0,0 +1,74 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var logpdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logpdf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var lambda; + var len; + var k; + var x; + var y; + var i; + + len = 100; + x = uniform( len, 0.1, 50.0, { + 'dtype': 'float64' + }); + k = discreteUniform( len, 1, 10, { + 'dtype': 'float64' + }); + lambda = uniform( len, 0.1, 20.0, { + 'dtype': 'float64' + }); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logpdf( x[ i % len ], k[ i % len ], lambda[ i % len ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..6daa14175a60 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/erlang/logpdf.h" +#include +#include +#include +#include +#include + +#define NAME "logpdf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %g\n", elapsed ); + printf( " rate: %g\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static double random_uniform( void ) { + int v = rand(); + return (double)v / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double lambda; + double x; + double k; + double y; + double t; + int i; + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + x = ( random_uniform() * 10.0 ) - 5.0; + k = floor( random_uniform() * 10.0 ); + lambda = floor( random_uniform() * 10.0 ) + 1.0; + y = stdlib_base_dists_erlang_logpdf( x, k, lambda ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Initialize the pseudorandom number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( ITERATIONS, elapsed ); + printf( "ok %d benchmark finished\n", i + 1 ); + } + print_summary( REPEATS, REPEATS ); + return 0; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c new file mode 100644 index 000000000000..6ddd42f02fe4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/erlang/logpdf.h" +#include +#include + +int main( void ) { + const double x[] = { 0.0, 0.5, 1.0, 1.5, 2.0 }; + const double k[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; + const double lambda[] = { 0.5, 1.0, 1.5, 2.0, 2.5 }; + + double y; + int i; + for ( i = 0; i < 5; i++ ) { + y = stdlib_base_dists_erlang_logpdf( x[ i ], k[ i ], lambda[ i ] ); + printf( "x: %lf, k: %lf, lambda: %lf, ln(f(x; k, lambda)): %lf\n", x[ i ], k[ i ], lambda[ i ], y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' Date: Wed, 3 Jun 2026 12:32:52 +0530 Subject: [PATCH 2/5] chore: initial clean up --- .../stats/base/dists/erlang/logpdf/README.md | 22 +++++--- .../erlang/logpdf/benchmark/benchmark.js | 39 ++++++-------- .../logpdf/benchmark/benchmark.native.js | 21 ++++---- .../erlang/logpdf/benchmark/c/benchmark.c | 30 ++++++----- .../dists/erlang/logpdf/examples/c/example.c | 20 ++++--- .../stdlib/stats/base/dists/erlang/logpdf.h | 2 +- .../base/dists/erlang/logpdf/manifest.json | 13 +---- .../stats/base/dists/erlang/logpdf/src/main.c | 21 ++------ .../dists/erlang/logpdf/test/test.factory.js | 20 ++----- .../dists/erlang/logpdf/test/test.logpdf.js | 53 ++++++++----------- .../dists/erlang/logpdf/test/test.native.js | 4 +- 11 files changed, 107 insertions(+), 138 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md index 060af04a43ea..26e0e03c3a67 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/README.md @@ -153,7 +153,7 @@ y = mylogpdf( 4.0 ); #### stdlib_base_dists_erlang_logpdf( x, k, lambda ) -Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for an [Erlang][erlang-distribution] distribution with shape parameter `k` and rate parameter `lambda`. +Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for an [Erlang][erlang-distribution] distribution with shape parameter `k` and rate parameter `lambda` at a value `x`. ```c double y = stdlib_base_dists_erlang_logpdf( 1.0, 3.0, 1.5 ); @@ -193,16 +193,24 @@ double stdlib_base_dists_erlang_logpdf( const double x, const double k, const do #include #include -int main( void ) { - const double x[] = { 0.0, 0.5, 1.0, 1.5, 2.0 }; - const double k[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; - const double lambda[] = { 0.5, 1.0, 1.5, 2.0, 2.5 }; +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 k; double y; int i; + for ( i = 0; i < 5; i++ ) { - y = stdlib_base_dists_erlang_logpdf( x[ i ], k[ i ], lambda[ i ] ); - printf( "x: %lf, k: %lf, lambda: %lf, ln(f(x; k, lambda)): %lf\n", x[ i ], k[ i ], lambda[ i ], y ); + x = random_uniform( 0.0, 10.0 ); + k = (double)rand() / ( (double)RAND_MAX + 1.0 ) * 10.0; + lambda = random_uniform( 0.0, 5.0 ); + y = stdlib_base_dists_erlang_logpdf( x, k, lambda ); + printf( "x: %lf, k: %lf, λ: %lf, ln(f(x;k,λ)): %lf\n", x, k, lambda, y ); } } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js index 451a91c5766b..0dee82568407 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js @@ -22,8 +22,8 @@ var bench = require( '@stdlib/bench' ); var Float64Array = require( '@stdlib/array/float64' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var format = require( '@stdlib/string/format' ); @@ -35,25 +35,22 @@ var logpdf = require( './../lib' ); bench( pkg, function benchmark( b ) { var lambda; - var len; + var opts; var k; var x; var y; var i; - len = 100; - x = new Float64Array( len ); - k = new Float64Array( len ); - lambda = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = discreteUniform( 0, 100 ); - k[ i ] = discreteUniform( 0, 100 ); - lambda[ i ] = uniform( EPS, 20.0 ); - } + opts = { + 'dtype': 'float64' + }; + x = discreteUniform( 100, 0, 100.0 ); + k = discreteUniform( 100, 0, 100.0 ); + lambda = uniform( 100, EPS, 20.0, opts ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = logpdf( x[ i % len ], k[ i % len ], lambda[ i % len ] ); + y = logpdf( x[ i % x.length ], k[ i % k.length ], lambda[ i % lambda.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -69,24 +66,20 @@ bench( pkg, function benchmark( b ) { bench( format( '%s:factory', pkg ), function benchmark( b ) { var mylogpdf; var lambda; - var len; + var opts; var k; var x; var y; var i; - k = 2.0; - lambda = 1.5; - mylogpdf = logpdf.factory( k, lambda ); - len = 100; - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = uniform( EPS, 50.0 ); - } + mylogpdf = logpdf.factory( 1.0, 1.5 ); + x = uniform( 100, EPS, 10.0, { + 'dtype': 'float64' + }); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = mylogpdf( x[ i % len ] ); + y = mylogpdf( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js index 66f98d3ad5dc..9272afaa4a35 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js @@ -25,6 +25,7 @@ var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -39,28 +40,24 @@ var opts = { // MAIN // -bench( pkg+'::native', opts, function benchmark( b ) { +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { var lambda; - var len; + var opts; var k; var x; var y; var i; - len = 100; - x = uniform( len, 0.1, 50.0, { + opts = { 'dtype': 'float64' - }); - k = discreteUniform( len, 1, 10, { - 'dtype': 'float64' - }); - lambda = uniform( len, 0.1, 20.0, { - 'dtype': 'float64' - }); + }; + x = discreteUniform( 100, 0, 100.0 ); + k = discreteUniform( 100, 0, 100.0 ); + lambda = uniform( 100, EPS, 20.0, opts ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = logpdf( x[ i % len ], k[ i % len ], lambda[ i % len ] ); + y = logpdf( x[ i % x.length ], k[ i % k.length ], lambda[ i % lambda.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c index 6daa14175a60..2fc36d8aaec4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/c/benchmark.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dists/erlang/logpdf.h" +#include "stdlib/constants/float64/eps.h" #include #include #include @@ -76,13 +77,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double random_uniform( void ) { - int v = rand(); - return (double)v / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); } /** @@ -91,20 +94,23 @@ static double random_uniform( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double lambda[ 100 ]; + double x[ 100 ]; + double k[ 100 ]; double elapsed; - double lambda; - double x; - double k; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( 0.0, 10.0 ); + k[ i ] = random_uniform( 0.0, 10.0 ); + lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( random_uniform() * 10.0 ) - 5.0; - k = floor( random_uniform() * 10.0 ); - lambda = floor( random_uniform() * 10.0 ) + 1.0; - y = stdlib_base_dists_erlang_logpdf( x, k, lambda ); + y = stdlib_base_dists_erlang_logpdf( x[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c index 6ddd42f02fe4..797dfb7e6d56 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/examples/c/example.c @@ -20,15 +20,23 @@ #include #include -int main( void ) { - const double x[] = { 0.0, 0.5, 1.0, 1.5, 2.0 }; - const double k[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; - const double lambda[] = { 0.5, 1.0, 1.5, 2.0, 2.5 }; +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 k; double y; int i; + for ( i = 0; i < 5; i++ ) { - y = stdlib_base_dists_erlang_logpdf( x[ i ], k[ i ], lambda[ i ] ); - printf( "x: %lf, k: %lf, lambda: %lf, ln(f(x; k, lambda)): %lf\n", x[ i ], k[ i ], lambda[ i ], y ); + x = random_uniform( 0.0, 10.0 ); + k = (double)rand() / ( (double)RAND_MAX + 1.0 ) * 10.0; + lambda = random_uniform( 0.0, 5.0 ); + y = stdlib_base_dists_erlang_logpdf( x, k, lambda ); + printf( "x: %lf, k: %lf, λ: %lf, ln(f(x;k,λ)): %lf\n", x, k, lambda, y ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include/stdlib/stats/base/dists/erlang/logpdf.h b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include/stdlib/stats/base/dists/erlang/logpdf.h index ad3576edf693..e32a03279aeb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include/stdlib/stats/base/dists/erlang/logpdf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/include/stdlib/stats/base/dists/erlang/logpdf.h @@ -24,7 +24,7 @@ extern "C" { #endif /** -* Evaluates the natural logarithm of the probability density function (PDF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda`. +* Evaluates the natural logarithm of the probability density function (PDF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda` at a value `x`. */ double stdlib_base_dists_erlang_logpdf( const double x, const double k, const double lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/manifest.json index f72c0d9b105d..37480d7abe54 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/manifest.json @@ -40,10 +40,7 @@ "dependencies": [ "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/assert/is-nan", - "@stdlib/stats/base/dists/gamma/logpdf", - "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pinf" + "@stdlib/stats/base/dists/gamma/logpdf" ] }, { @@ -59,10 +56,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/assert/is-nan", "@stdlib/stats/base/dists/gamma/logpdf", - "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/eps" ] }, @@ -79,10 +73,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/assert/is-nan", - "@stdlib/stats/base/dists/gamma/logpdf", - "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pinf" + "@stdlib/stats/base/dists/gamma/logpdf" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/main.c index 7015ac267d2d..652de532312e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/src/main.c @@ -19,33 +19,22 @@ #include "stdlib/stats/base/dists/erlang/logpdf.h" #include "stdlib/stats/base/dists/gamma/logpdf.h" #include "stdlib/math/base/assert/is_nonnegative_integer.h" -#include "stdlib/math/base/assert/is_nan.h" -#include "stdlib/constants/float64/ninf.h" -#include "stdlib/constants/float64/pinf.h" /** * Evaluates the natural logarithm of the probability density function (PDF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda` at a value `x`. * -* @param x input value -* @param k shape parameter (must be a nonnegative integer) -* @param lambda rate parameter (must be positive) -* @return evaluated logPDF +* @param x input value +* @param k shape parameter (must be a nonnegative integer) +* @param lambda rate parameter (must be positive) +* @return evaluated logPDF * * @example * double v = stdlib_base_dists_erlang_logpdf( 0.1, 1, 1.0 ); * // returns ~-0.1 */ double stdlib_base_dists_erlang_logpdf( const double x, const double k, const double lambda ) { - if ( - stdlib_base_is_nan( x ) || - !stdlib_base_is_nonnegative_integer( k ) || - stdlib_base_is_nan( lambda ) || - lambda <= 0.0 - ) { + if ( !stdlib_base_is_nonnegative_integer( k ) ) { return 0.0 / 0.0; // NaN } - if ( k == 0.0 ) { - return ( x == 0.0 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; - } return stdlib_base_dists_gamma_logpdf( x, k, lambda ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js index e3d6e7cd1a87..c3a74eada351 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js @@ -22,7 +22,7 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -169,8 +169,6 @@ tape( 'the created function evaluates the logpdf for `x` given large `k` and `la var expected; var lambda; var logpdf; - var delta; - var tol; var i; var k; var x; @@ -186,9 +184,7 @@ tape( 'the created function evaluates the logpdf for `x` given large `k` and `la if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[ i ] ); - tol = 450.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 700 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); @@ -198,8 +194,6 @@ tape( 'the created function evaluates the logpdf for `x` given a large shape par var expected; var lambda; var logpdf; - var delta; - var tol; var i; var k; var x; @@ -215,9 +209,7 @@ tape( 'the created function evaluates the logpdf for `x` given a large shape par if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[ i ] ); - tol = 350.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 300 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); @@ -227,8 +219,6 @@ tape( 'the created function evaluates the logpdf for `x` given a large rate para var expected; var lambda; var logpdf; - var delta; - var tol; var i; var k; var x; @@ -244,9 +234,7 @@ tape( 'the created function evaluates the logpdf for `x` given a large rate para if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[ i ] ); - tol = 450.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 600 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js index 99203a38ccf7..6f0c70451d3e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js @@ -23,6 +23,7 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -114,42 +115,36 @@ tape( 'if provided `lambda <= 0`, the function returns `NaN`', function test( t t.end(); }); -tape( 'the function evaluates the logpdf for `x` given large `k` and `lambda`', function test( t ) { +tape( 'the function evaluates the logpdf for `x` given a large rate', function test( t ) { var expected; var lambda; - var delta; - var tol; - var i; - var k; var x; + var k; var y; + var i; - expected = bothLarge.expected; - x = bothLarge.x; - k = bothLarge.k; - lambda = bothLarge.lambda; + expected = largeRate.expected; + x = largeRate.x; + k = largeRate.k; + lambda = largeRate.lambda; for ( i = 0; i < x.length; i++ ) { y = logpdf( x[i], k[i], lambda[i] ); if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[ i ] ); - tol = 450.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 600 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); }); -tape( 'the function evaluates the logpdf for `x` given large shape parameter `k`', function test( t ) { +tape( 'the function evaluates the logpdf for `x` given a large shape', function test( t ) { var expected; var lambda; - var delta; - var tol; - var i; - var k; var x; + var k; var y; + var i; expected = largeShape.expected; x = largeShape.x; @@ -160,36 +155,30 @@ tape( 'the function evaluates the logpdf for `x` given large shape parameter `k` if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[ i ] ); - tol = 350.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 300 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); }); -tape( 'the function evaluates the logpdf for `x` given large rate parameter `lambda`', function test( t ) { +tape( 'the function evaluates the logpdf for `x` given both large `k` and `lambda`', function test( t ) { var expected; var lambda; - var delta; - var tol; - var i; - var k; var x; + var k; var y; + var i; - expected = largeRate.expected; - x = largeRate.x; - k = largeRate.k; - lambda = largeRate.lambda; + expected = bothLarge.expected; + x = bothLarge.x; + k = bothLarge.k; + lambda = bothLarge.lambda; for ( i = 0; i < x.length; i++ ) { y = logpdf( x[i], k[i], lambda[i] ); if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - delta = abs( y - expected[ i ] ); - tol = 450.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 700 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.native.js index 12a5ce8967de..5ea6bbff8c90 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.native.js @@ -126,7 +126,7 @@ tape( 'the function evaluates the logpdf for `x` given a large shape', opts, fun if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[i], 1000 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 300 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); @@ -149,7 +149,7 @@ tape( 'the function evaluates the logpdf for `x` given both large `k` and `lambd if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', k: '+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[i], 1000 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 700 ), 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); From cda6e953582aa8d7f228cc80179d9fe05e22f232 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 3 Jun 2026 12:42:09 +0530 Subject: [PATCH 3/5] chore: update variables used --- .../stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js | 1 + .../@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js | 1 - .../@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js index 9272afaa4a35..72121c952026 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.native.js @@ -24,6 +24,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var uniform = require( '@stdlib/random/array/uniform' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var EPS = require( '@stdlib/constants/float64/eps' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var format = require( '@stdlib/string/format' ); var tryRequire = require( '@stdlib/utils/try-require' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js index c3a74eada351..c61bf878ec95 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.factory.js @@ -25,7 +25,6 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var factory = require( './../lib/factory.js' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js index 6f0c70451d3e..a2ff15b07392 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js @@ -26,7 +26,6 @@ var abs = require( '@stdlib/math/base/special/abs' ); var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var logpdf = require( './../lib' ); From f9d09858a0aee39fa5b2fbb795628d16dd5cec83 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 3 Jun 2026 12:51:56 +0530 Subject: [PATCH 4/5] chore: remove variables --- .../@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js index a2ff15b07392..5232368234a5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/test/test.logpdf.js @@ -22,7 +22,6 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); From d2d2cb398340896c913ac98cf99c5850d942eef4 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 3 Jun 2026 13:05:24 +0530 Subject: [PATCH 5/5] chore: update bench --- .../stats/base/dists/erlang/logpdf/benchmark/benchmark.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js index 0dee82568407..2ed25d9dda72 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/logpdf/benchmark/benchmark.js @@ -21,7 +21,6 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array/float64' ); var uniform = require( '@stdlib/random/array/uniform' ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -65,9 +64,6 @@ bench( pkg, function benchmark( b ) { bench( format( '%s:factory', pkg ), function benchmark( b ) { var mylogpdf; - var lambda; - var opts; - var k; var x; var y; var i;