From ecd506eb1218251b5c86cd5c3ab6e40ae19168ad Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 11:32:58 -0800 Subject: [PATCH 01/17] feat: add the C src files --- .../stdlib/stats/base/dists/degenerate/mgf.h | 42 +++++++++++ .../base/dists/degenerate/mgf/src/Makefile | 70 +++++++++++++++++++ .../base/dists/degenerate/mgf/src/addon.c | 23 ++++++ .../base/dists/degenerate/mgf/src/main.c | 50 +++++++++++++ 4 files changed, 185 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h new file mode 100644 index 000000000000..81e99bab66d8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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. +*/ + +#ifndef STDLIB_STATS_BASE_DISTS_DEGENERATE_MGF_H +#define STDLIB_STATS_BASE_DISTS_DEGENERATE_MGF_H + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. +* +* @param t input value +* @param mu value at which to center the distribution +* @return evaluated MGF +*/ +double stdlib_base_dists_degenerate_mgf( const double t, const double mu ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_STATS_BASE_DISTS_DEGENERATE_MGF_H diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# 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. +# 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 + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c new file mode 100644 index 000000000000..404e429a2147 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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/math/base/napi/binary.h" +#include "stdlib/stats/base/dists/degenerate/mgf.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_degenerate_mgf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c new file mode 100644 index 000000000000..097c9bb8d526 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/exp.h" + +/** +* Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. +* +* @param t input value +* @param mu value at which to center the distribution +* @return evaluated MGF, or NaN if input is invalid +* +* @example +* double y = stdlib_base_dists_degenerate_mgf( 1.0, 1.0 ); +* // returns ~2.718 +* +* @example +* double y = stdlib_base_dists_degenerate_mgf( 2.0, 3.0 ); +* // returns ~403.429 +* +* @example +* double y = stdlib_base_dists_degenerate_mgf( NAN, 0.0 ); +* // returns NaN +* +* @example +* double y = stdlib_base_dists_degenerate_mgf( 0.0, NAN ); +* // returns NaN +*/ +double stdlib_base_dists_degenerate_mgf( const double t, const double mu ) { + if ( stdlib_base_is_nan( t ) || stdlib_base_is_nan( mu ) ) { + return 0.0/0.0; // NaN + } + return stdlib_base_exp( mu * t ); +} From dc4b644e52edea408f9981bb7ed1872915604fcd Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 11:33:14 -0800 Subject: [PATCH 02/17] feat: add the C benchmark and example files --- .../dists/degenerate/mgf/benchmark/c/Makefile | 146 ++++++++++++++++++ .../degenerate/mgf/benchmark/c/benchmark.c | 107 +++++++++++++ .../dists/degenerate/mgf/examples/c/Makefile | 146 ++++++++++++++++++ .../dists/degenerate/mgf/examples/c/example.c | 43 ++++++ 4 files changed, 442 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# 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. +# 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/degenerate/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..0369c36e549d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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/degenerate/mgf.h" +#include +#include +#include +#include +#include + +#define NAME "degenerate-mgf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +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 double benchmark( void ) { + double elapsed; + double t[ 100 ]; + double mu[ 100 ]; + double y; + double start; + int i; + + for ( i = 0; i < 100; i++ ) { + t[ i ] = random_uniform( -10.0, 10.0 ); + mu[ i ] = random_uniform( -20.0, 20.0 ); + } + + start = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_degenerate_mgf( t[ i%100 ], mu[ i%100 ] ); + if ( y != y ) { // Check for NaN + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - start; + + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +int main( void ) { + double elapsed; + int i; + + // Seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# 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. +# 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/degenerate/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c new file mode 100644 index 000000000000..ff010af26368 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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/degenerate/mgf.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 t; + double mu; + double result; + int i; + + for ( i = 0; i < 10; i++ ) { + t = random_uniform( -10.0, 10.0 ); + mu = random_uniform( -20.0, 20.0 ); + result = stdlib_base_dists_degenerate_mgf( t, mu ); + + printf( "t: %lf, mu: %lf, MGF: %lf\n", t, mu, result ); + } + + return 0; +} From 4f0d59f738194c7cc291c4e0a870f038de309b1d Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 11:33:28 -0800 Subject: [PATCH 03/17] feat: add the JS native files --- .../mgf/benchmark/benchmark.native.js | 70 ++++++++++++++++ .../base/dists/degenerate/mgf/lib/native.js | 63 +++++++++++++++ .../dists/degenerate/mgf/test/test.native.js | 81 +++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..afe515314dde --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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 Float64Array = require( '@stdlib/array/float64' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var mgf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mgf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var len; + var t; + var mu; + var y; + var i; + + len = 100; + t = new Float64Array( len ); + mu = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + t[ i ] = ( randu() * 20.0 ) - 10.0; + mu[ i ] = ( randu() * 40.0 ) - 20.0; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mgf( t[ i % len ], mu[ 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/degenerate/mgf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js new file mode 100644 index 000000000000..16cf2477f735 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. +* +* @private +* @param {number} t - input value +* @param {number} mu - constant value of the distribution +* @returns {number} evaluated MGF +* +* @example +* var y = mgf( 1.0, 2.0 ); +* // returns ~7.389 +* +* @example +* var y = mgf( 0.0, 2.0 ); +* // returns 1.0 +* +* @example +* var y = mgf( -1.0, 2.0 ); +* // returns ~0.135 +* +* @example +* var y = mgf( NaN, 2.0 ); +* // returns NaN +* +* @example +* var y = mgf( 1.0, NaN ); +* // returns NaN +*/ +function mgf( t, mu ) { + return addon( t, mu ); +} + + +// EXPORTS // + +module.exports = mgf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js new file mode 100644 index 000000000000..4d45c354586d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var exp = require( '@stdlib/math/base/special/exp' ); + + +// VARIABLES // + +var mgf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mgf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mgf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mgf( NaN, 0.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 0.0, NaN ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( NaN, NaN ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function evaluates the MGF of a degenerate distribution centered at `mu`', opts, function test( t ) { + var mu; + var x; + var y; + + mu = 0.0; + x = 2.0; + y = mgf( x, mu ); + t.equal( y, exp( x*mu ), 'returns expected value' ); + + mu = 2.0; + x = 1.0; + y = mgf( x, mu ); + t.equal( y, exp( x*mu ), 'returns expected value' ); + + x = 3.0; + y = mgf( x, mu ); + t.equal( y, exp( x*mu ), 'returns expected value' ); + + t.end(); +}); From 4b897d8e3e826b7e77d3432e9b6615250c6ab2d4 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 11:33:42 -0800 Subject: [PATCH 04/17] build: added the json and gyp dependency files --- .../base/dists/degenerate/mgf/binding.gyp | 149 ++++++++++++++++++ .../base/dists/degenerate/mgf/include.gypi | 48 ++++++ .../base/dists/degenerate/mgf/manifest.json | 79 ++++++++++ .../base/dists/degenerate/mgf/package.json | 3 + 4 files changed, 279 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/manifest.json diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp new file mode 100644 index 000000000000..114dcb77c6aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp @@ -0,0 +1,149 @@ +# @license Apache-2.0 +# +# 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. +# 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)", + "src/addon.c", + ], + # 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/degenerate/mgf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi new file mode 100644 index 000000000000..235be47d6d3b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi @@ -0,0 +1,48 @@ +# @license Apache-2.0 +# +# 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. +# 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: Sun, 5 Jan 2025 11:33:57 -0800 Subject: [PATCH 05/17] docs: update README with C API documentation --- 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/degenerate/mgf/README.md | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md index 4c413bc39279..56d1a32770b0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md @@ -132,6 +132,104 @@ for ( i = 0; i < 100; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/degenerate/mgf.h" +``` + +#### stdlib_base_dists_degenerate_mgf( mu ) + +Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. + +```c +double out = stdlib_base_dists_degenerate_mgf( 1.0, 1.0 ); +// returns ~2.718 +``` + +The function accepts the following arguments: + +- **t**: `[in] double` input value. +- **mu**: `[in] double` value at which to center the distribution. + +```c +double stdlib_base_dists_degenerate_mgf( const double t, const double mu ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/degenerate/mgf.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 t; + double mu; + double result; + int i; + + for ( i = 0; i < 10; i++ ) { + t = random_uniform( -10.0, 10.0 ); + mu = random_uniform( -20.0, 20.0 ); + result = stdlib_base_dists_degenerate_mgf( t, mu ); + + printf( "t: %lf, mu: %lf, MGF: %lf\n", t, mu, result ); + } + + return 0; +} +``` + +
+ + + +
+ + +
From 815e870b2f2f4c3dce5118e628f7ea8dafad52bb Mon Sep 17 00:00:00 2001 From: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:54:18 -0800 Subject: [PATCH 06/17] Update README.md Signed-off-by: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> --- .../@stdlib/stats/base/dists/degenerate/mgf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md index 56d1a32770b0..685db04abab0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md @@ -158,7 +158,7 @@ for ( i = 0; i < 100; i++ ) { #include "stdlib/stats/base/dists/degenerate/mgf.h" ``` -#### stdlib_base_dists_degenerate_mgf( mu ) +#### stdlib_base_dists_degenerate_mgf( t, mu ) Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. From 79edd0f3bd54cd9751c1fefb940707a956dccb92 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 7 Jan 2025 21:56:52 -0800 Subject: [PATCH 07/17] refactor: fixed the formatting issues --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../dists/degenerate/mgf/benchmark/c/benchmark.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c index 0369c36e549d..669161a30919 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c @@ -16,12 +16,12 @@ * limitations under the License. */ +#include #include "stdlib/stats/base/dists/degenerate/mgf.h" -#include -#include #include +#include +#include #include -#include #define NAME "degenerate-mgf" #define ITERATIONS 1000000 @@ -52,12 +52,12 @@ static void print_results( double elapsed ) { static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; } static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); - return min + ( v*(max-min) ); + return min + ( v * ( max - min ) ); } static double benchmark( void ) { @@ -75,7 +75,7 @@ static double benchmark( void ) { start = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_dists_degenerate_mgf( t[ i%100 ], mu[ i%100 ] ); + y = stdlib_base_dists_degenerate_mgf( t[ i % 100 ], mu[ i % 100 ] ); if ( y != y ) { // Check for NaN printf( "should not return NaN\n" ); break; @@ -93,7 +93,7 @@ int main( void ) { double elapsed; int i; - // Seed the random number generator: + // Seed the random number generator: srand( time( NULL ) ); print_version(); @@ -101,7 +101,7 @@ int main( void ) { printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); + printf( "ok %d benchmark finished\n", i + 1 ); } print_summary( REPEATS, REPEATS ); } From 0bf277e068130bf56a22dcb3c177767c081a3d1e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 7 Jan 2025 22:05:52 -0800 Subject: [PATCH 08/17] refactor: fixed the formatting issues --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - 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/degenerate/mgf/README.md | 11 +- .../degenerate/mgf/benchmark/c/benchmark.c | 2 +- .../base/dists/degenerate/mgf/binding.gyp | 267 ++++++++++-------- .../dists/degenerate/mgf/examples/c/example.c | 29 +- .../base/dists/degenerate/mgf/include.gypi | 53 ++-- .../base/dists/degenerate/mgf/manifest.json | 3 +- .../base/dists/degenerate/mgf/package.json | 4 +- .../base/dists/degenerate/mgf/src/main.c | 20 +- 8 files changed, 203 insertions(+), 186 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md index 685db04abab0..a0ebeadc49aa 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md @@ -195,6 +195,7 @@ double stdlib_base_dists_degenerate_mgf( const double t, const double mu ); ### Examples ```c +#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/degenerate/mgf.h" #include #include @@ -205,17 +206,17 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double t; - double mu; double result; + double mu; + double t; int i; for ( i = 0; i < 10; i++ ) { - t = random_uniform( -10.0, 10.0 ); - mu = random_uniform( -20.0, 20.0 ); + t = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); + mu = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); result = stdlib_base_dists_degenerate_mgf( t, mu ); - printf( "t: %lf, mu: %lf, MGF: %lf\n", t, mu, result ); + printf( "t: %lf, µ: %lf, M_X(t;µ): %lf\n", t, mu, result ); } return 0; diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c index 669161a30919..e018f928f251 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c @@ -93,7 +93,7 @@ int main( void ) { double elapsed; int i; - // Seed the random number generator: + // Seed the random number generator: srand( time( NULL ) ); print_version(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp index 114dcb77c6aa..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/binding.gyp @@ -19,131 +19,152 @@ # [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: + # 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"', { - # 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)", - "src/addon.c", - ], - # 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", + # 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', ], - # C++ specific compiler flags: - "cflags_cpp": [ - # Specify the C++ standard to which a program is expected to conform: - "-std=c++11", + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', ], - # 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: + }, + ], # 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': [ { - "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 + '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/degenerate/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c index ff010af26368..1d6f9890addc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c @@ -16,28 +16,29 @@ * limitations under the License. */ +#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/degenerate/mgf.h" -#include #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 ) ); + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); } int main( void ) { - double t; - double mu; - double result; - int i; + double result; + double mu; + double t; + int i; - for ( i = 0; i < 10; i++ ) { - t = random_uniform( -10.0, 10.0 ); - mu = random_uniform( -20.0, 20.0 ); - result = stdlib_base_dists_degenerate_mgf( t, mu ); + for ( i = 0; i < 10; i++ ) { + t = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); + mu = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); + result = stdlib_base_dists_degenerate_mgf( t, mu ); - printf( "t: %lf, mu: %lf, MGF: %lf\n", t, mu, result ); - } + printf( "t: %lf, µ: %lf, M_X(t;µ): %lf\n", t, mu, result ); + } - return 0; + return 0; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi index 235be47d6d3b..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include.gypi @@ -21,28 +21,33 @@ # [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, 8 Jan 2025 06:11:43 +0000 Subject: [PATCH 09/17] fix: resolve lint errors --- .../base/dists/degenerate/mgf/benchmark/benchmark.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js index afe515314dde..81a5ef6992ef 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js @@ -41,8 +41,8 @@ var opts = { bench( pkg+'::native', opts, function benchmark( b ) { var len; - var t; var mu; + var t; var y; var i; From b0d56dcc2d012adc7a46284c47efdd4163c2d6f9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 8 Jan 2025 19:08:44 -0800 Subject: [PATCH 10/17] refactor: fixed extra spaces and tabs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/dists/degenerate/mgf/README.md | 3 --- .../stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c | 2 +- .../stats/base/dists/degenerate/mgf/examples/c/example.c | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md index a0ebeadc49aa..a546db040533 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md @@ -215,11 +215,8 @@ int main( void ) { t = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); mu = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); result = stdlib_base_dists_degenerate_mgf( t, mu ); - printf( "t: %lf, µ: %lf, M_X(t;µ): %lf\n", t, mu, result ); } - - return 0; } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c index e018f928f251..2c33edc2d7fc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c @@ -93,7 +93,7 @@ int main( void ) { double elapsed; int i; - // Seed the random number generator: + // Seed the random number generator: srand( time( NULL ) ); print_version(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c index 1d6f9890addc..6a332e90814c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c @@ -36,9 +36,6 @@ int main( void ) { t = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); mu = stdlib_base_round( random_uniform( 0.0, 5.0 ) ); result = stdlib_base_dists_degenerate_mgf( t, mu ); - printf( "t: %lf, µ: %lf, M_X(t;µ): %lf\n", t, mu, result ); } - - return 0; } From 7536c25fa40bf98b33ea60d64877535cc91489b7 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 8 Jan 2025 19:10:06 -0800 Subject: [PATCH 11/17] refactor: update copyright year --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - 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: passed --- --- .../@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js index 4d45c354586d..3109ade9f4da 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 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. From 8b91b0298c00cc8915d0eb08278be77b50431999 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 10 Jan 2025 22:14:11 -0800 Subject: [PATCH 12/17] refactor: apply suggestions from previous PRs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - task: run_c_benchmarks status: passed - 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 --- --- .../@stdlib/stats/base/dists/degenerate/mgf/README.md | 2 +- .../stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c | 2 +- .../@stdlib/stats/base/dists/degenerate/mgf/src/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md index a546db040533..ddb56b0f889c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md @@ -160,7 +160,7 @@ for ( i = 0; i < 100; i++ ) { #### stdlib_base_dists_degenerate_mgf( t, mu ) -Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. +Evaluates the moment-generating function ([MGF][mgf]) of a [degenerate][degenerate] distribution with parameter `mu` (mean). ```c double out = stdlib_base_dists_degenerate_mgf( 1.0, 1.0 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c index 2c33edc2d7fc..77a1d21e063a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c @@ -16,12 +16,12 @@ * limitations under the License. */ -#include #include "stdlib/stats/base/dists/degenerate/mgf.h" #include #include #include #include +#include #define NAME "degenerate-mgf" #define ITERATIONS 1000000 diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c index ffbf3703b49b..be6117785603 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c @@ -24,7 +24,7 @@ * * @param t input value * @param mu value at which to center the distribution -* @return evaluated MGF, or NaN if input is invalid +* @return evaluated MGF * * @example * double y = stdlib_base_dists_degenerate_mgf( 1.0, 1.0 ); From 2a0d375d64af360519a4739cb521f52f6acc647e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 13 Jan 2025 20:10:06 -0800 Subject: [PATCH 13/17] refactor: added include in main.c and fixed the JS benchmark number generation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - 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/degenerate/mgf/benchmark/benchmark.js | 5 +++-- .../@stdlib/stats/base/dists/degenerate/mgf/src/main.c | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js index 592351adeb95..16d4f04f60e1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var mgf = require( './../lib' ); @@ -37,8 +38,8 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - t = ( randu()*100.0 ) - 100; - mu = ( randu()*100.0 ) - 50.0; + t = uniform( -100.0, 0.0 ); + mu = uniform( -50.0, 50.0 ); y = mgf( t, mu ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c index be6117785603..0d7302e25abc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c @@ -18,6 +18,7 @@ #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/special/exp.h" +#include "stdlib/stats/base/dists/degenerate/mgf.h" /** * Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. From 1e708ff59d6764a451a93bf152a62a4e33a5617c Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 13 Jan 2025 20:13:11 -0800 Subject: [PATCH 14/17] refactor: fixed the JS native benchmark number generation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../base/dists/degenerate/mgf/benchmark/benchmark.native.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js index 81a5ef6992ef..0a70044e869e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.native.js @@ -23,7 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var Float64Array = require( '@stdlib/array/float64' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -50,8 +50,8 @@ bench( pkg+'::native', opts, function benchmark( b ) { t = new Float64Array( len ); mu = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - t[ i ] = ( randu() * 20.0 ) - 10.0; - mu[ i ] = ( randu() * 40.0 ) - 20.0; + t[ i ] = uniform( -100.0, 0.0 ); + mu[ i ] = uniform( -50.0, 50.0 ); } b.tic(); From ab08e1e3da23704e0a988f827dfa955fc31653a6 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 15 Jan 2025 16:49:38 -0800 Subject: [PATCH 15/17] refactor: apply suggestions from PR review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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 --- --- .../mgf/include/stdlib/stats/base/dists/degenerate/mgf.h | 4 ---- .../@stdlib/stats/base/dists/degenerate/mgf/src/main.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h index 81e99bab66d8..28e5ea416ce8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/include/stdlib/stats/base/dists/degenerate/mgf.h @@ -28,10 +28,6 @@ extern "C" { /** * Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. -* -* @param t input value -* @param mu value at which to center the distribution -* @return evaluated MGF */ double stdlib_base_dists_degenerate_mgf( const double t, const double mu ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c index 0d7302e25abc..119588d66ba6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/main.c @@ -16,9 +16,9 @@ * limitations under the License. */ +#include "stdlib/stats/base/dists/degenerate/mgf.h" #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/special/exp.h" -#include "stdlib/stats/base/dists/degenerate/mgf.h" /** * Evaluates the moment-generating function (MGF) for a degenerate distribution centered at `mu`. From c155b431c3d1a67e69a13cb5626f9d070920dd0f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 15 Jan 2025 19:35:24 -0800 Subject: [PATCH 16/17] refactor: reapply suggestions from PR review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - 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/degenerate/mgf/README.md | 2 +- .../degenerate/mgf/benchmark/c/benchmark.c | 52 +++++++++++++++---- .../dists/degenerate/mgf/examples/c/example.c | 4 +- .../base/dists/degenerate/mgf/lib/native.js | 2 +- .../base/dists/degenerate/mgf/src/addon.c | 2 +- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md index ddb56b0f889c..0a9bcfb2239f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md @@ -195,8 +195,8 @@ double stdlib_base_dists_degenerate_mgf( const double t, const double mu ); ### Examples ```c -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/degenerate/mgf.h" +#include "stdlib/math/base/special/round.h" #include #include diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c index 77a1d21e063a..984d9f5bd660 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c @@ -17,9 +17,9 @@ */ #include "stdlib/stats/base/dists/degenerate/mgf.h" -#include -#include #include +#include +#include #include #include @@ -27,10 +27,19 @@ #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 ); // TAP plan @@ -40,6 +49,11 @@ static void print_summary( int total, int passing ) { printf( "# ok\n" ); } +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ static void print_results( double elapsed ) { double rate = (double)ITERATIONS / elapsed; printf( " ---\n" ); @@ -49,34 +63,51 @@ static void print_results( double elapsed ) { 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 [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); return min + ( v * ( max - min ) ); } +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ static double benchmark( void ) { - double elapsed; - double t[ 100 ]; double mu[ 100 ]; - double y; + double t[ 100 ]; + double elapsed; double start; + double y; int i; for ( i = 0; i < 100; i++ ) { - t[ i ] = random_uniform( -10.0, 10.0 ); - mu[ i ] = random_uniform( -20.0, 20.0 ); + t[ i ] = random_uniform( -10.0, 0.0 ); + mu[ i ] = random_uniform( -50.0, 50.0 ); } start = tic(); for ( i = 0; i < ITERATIONS; i++ ) { y = stdlib_base_dists_degenerate_mgf( t[ i % 100 ], mu[ i % 100 ] ); - if ( y != y ) { // Check for NaN + if ( y != y ) { printf( "should not return NaN\n" ); break; } @@ -89,11 +120,14 @@ static double benchmark( void ) { return elapsed; } +/** +* Main execution sequence. +*/ int main( void ) { double elapsed; int i; - // Seed the random number generator: + // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c index 6a332e90814c..0545da25f0f0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c @@ -16,10 +16,10 @@ * limitations under the License. */ -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/degenerate/mgf.h" -#include +#include "stdlib/math/base/special/round.h" #include +#include static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js index 16cf2477f735..8a4525c63757 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @private * @param {number} t - input value -* @param {number} mu - constant value of the distribution +* @param {number} mu - value at which to center the distribution * @returns {number} evaluated MGF * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c index 404e429a2147..c32cc76adca0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/math/base/napi/binary.h" #include "stdlib/stats/base/dists/degenerate/mgf.h" +#include "stdlib/math/base/napi/binary.h" // cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_degenerate_mgf ) From 631d46cd93265edf4cea828706aa4ee1b3683b1e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 17 Jan 2025 17:56:19 -0800 Subject: [PATCH 17/17] bench: move random number generation outside the benchmarking loops --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../degenerate/mgf/benchmark/benchmark.js | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js index 16d4f04f60e1..f8a7503ac17d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var Float64Array = require( '@stdlib/array/float64' ); var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; @@ -31,16 +31,23 @@ var mgf = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { + var len; var mu; var t; var y; var i; + len = 100; + t = new Float64Array( len ); + mu = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + t[ i ] = uniform( -100.0, 0.0 ); + mu[ i ] = uniform( -50.0, 50.0 ); + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - t = uniform( -100.0, 0.0 ); - mu = uniform( -50.0, 50.0 ); - y = mgf( t, mu ); + y = mgf( t[ i % len ], mu[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -55,6 +62,7 @@ bench( pkg, function benchmark( b ) { bench( pkg+':factory', function benchmark( b ) { var mymgf; + var len; var mu; var t; var y; @@ -62,11 +70,15 @@ bench( pkg+':factory', function benchmark( b ) { mu = 40.0; mymgf = mgf.factory( mu ); + len = 100; + t = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + t[ i ] = uniform( 0.0, 100.0 ); + } b.tic(); for ( i = 0; i < b.iterations; i++ ) { - t = randu() * 100.0; - y = mymgf( t ); + y = mymgf( t[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); }