From d5a1d80634daa61a837ef752429cd0e282b79620 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 01:43:07 -0800 Subject: [PATCH 01/18] feat: add the C src files --- .../base/dists/hypergeometric/variance.h | 43 ++++++++++++ .../hypergeometric/variance/src/Makefile | 70 +++++++++++++++++++ .../dists/hypergeometric/variance/src/addon.c | 23 ++++++ .../dists/hypergeometric/variance/src/main.c | 56 +++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h new file mode 100644 index 000000000000..e326524c9e58 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h @@ -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. + */ + +#ifndef STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_VARIANCE_H +#define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_VARIANCE_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 + +/** + * Returns the variance of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. + * + * @param N population size + * @param K subpopulation size + * @param n number of draws + * @return variance of the distribution + */ +double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_VARIANCE_H diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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/hypergeometric/variance/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/addon.c new file mode 100644 index 000000000000..0088fc90e7e0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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/ternary.h" +#include "stdlib/stats/base/dists/hypergeometric/variance.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_variance ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c new file mode 100644 index 000000000000..a176d81bc6ea --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c @@ -0,0 +1,56 @@ +/** +* @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_nonnegative_integer.h" +#include "stdlib/constants/float64/pinf.h" + +/** +* Returns the variance of a hypergeometric distribution. +* +* @param N population size +* @param K subpopulation size +* @param n number of draws +* @return variance of the distribution, or NaN if inputs are invalid +* +* @example +* double v = stdlib_base_dists_hypergeometric_variance( 16, 11, 4 ); +* // returns ~0.688 +* +* @example +* double v = stdlib_base_dists_hypergeometric_variance( 2, 1, 1 ); +* // returns 0.25 +* +* @example +* double v = stdlib_base_dists_hypergeometric_variance( 10, 5, 12 ); +* // returns NaN +*/ +double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ) { + if ( + !stdlib_base_is_nonnegative_integer( N ) || + !stdlib_base_is_nonnegative_integer( K ) || + !stdlib_base_is_nonnegative_integer( n ) || + N == STDLIB_CONSTANT_FLOAT64_PINF || + K == STDLIB_CONSTANT_FLOAT64_PINF || + K > N || + n > N + ) { + return NAN; + } + + return n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)); +} From 164d28240d7c9f82ea4a4aa1a8053f13f9a72e30 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 01:43:28 -0800 Subject: [PATCH 02/18] feat: add the C benchmark and example files --- .../variance/benchmark/c/Makefile | 146 ++++++++++++++++++ .../variance/benchmark/c/benchmark.c | 141 +++++++++++++++++ .../variance/examples/c/Makefile | 146 ++++++++++++++++++ .../variance/examples/c/example.c | 48 ++++++ 4 files changed, 481 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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/hypergeometric/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c new file mode 100644 index 000000000000..ae4eeffae63a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c @@ -0,0 +1,141 @@ +/** + * @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/hypergeometric/variance.h" +#include +#include +#include +#include +#include + +#define NAME "hypergeometric-variance" +#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 + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + 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" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\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 integer on the interval [min,max]. + * + * @param min minimum value (inclusive) + * @param max maximum value (inclusive) + * @return random integer + */ +static int random_integer( const int min, const int max ) { + return min + rand() % ( max - min + 1 ); +} + +/** + * Runs a benchmark. + * + * @return elapsed time in seconds + */ +static double benchmark( void ) { + double elapsed; + double N[ 100 ]; + double K[ 100 ]; + double n[ 100 ]; + double v; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + N[ i ] = (double)random_integer( 10, 100 ); + K[ i ] = (double)random_integer( 1, (int)N[ i ] ); + n[ i ] = (double)random_integer( 1, (int)N[ i ] ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + v = stdlib_base_dists_hypergeometric_variance( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** + * Main execution sequence. + */ +int main( void ) { + double elapsed; + int i; + + // Use the current time to 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/hypergeometric/variance/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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/hypergeometric/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c new file mode 100644 index 000000000000..1413d0816c05 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c @@ -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. +*/ + +#include "stdlib/stats/base/dists/hypergeometric/variance.h" +#include +#include + +static int random_integer( const int min, const int max ) { + return min + rand() % ( max - min + 1 ); +} + +int main( void ) { + double N; + double K; + double n; + double v; + int i; + + printf( "Variance of the hypergeometric distribution:\n" ); + printf( "N\t\tK\t\tn\t\tVariance\n" ); + printf( "-------------------------------------------------" ); + + for ( i = 0; i < 10; i++ ) { + N = random_integer( 10, 100 ); + K = random_integer( 1, N ); + n = random_integer( 1, N ); + v = stdlib_base_dists_hypergeometric_variance( N, K, n ); + + printf( "N: %lf, K: %lf, n: %lf, Variance: %lf\n", N, K, n, v ); + } + + return 0; +} From 3a9000b845ce74d9ac3f9de711e0bdfa9de25bc3 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 01:46:06 -0800 Subject: [PATCH 03/18] feat: add the JS native files --- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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 --- --- .../variance/benchmark/benchmark.native.js | 74 +++++++++ .../hypergeometric/variance/lib/native.js | 80 +++++++++ .../variance/test/test.native.js | 154 ++++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js new file mode 100644 index 000000000000..7c73bd31d246 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js @@ -0,0 +1,74 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var variance = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( variance instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var len; + var N; + var K; + var n; + var y; + var i; + + len = 100; + N = new Float64Array( len ); + K = new Float64Array( len ); + n = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + N[ i ] = floor( ( randu() * 90.0 ) + 10.0 ); + K[ i ] = floor( randu() * N[ i ] ); + n[ i ] = floor( randu() * N[ i ] ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = variance( N[ i % len ], K[ i % len ], n[ 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/hypergeometric/variance/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js new file mode 100644 index 000000000000..b50026d18f6d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js @@ -0,0 +1,80 @@ +/** +* @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 // + +/** +* Returns the variance of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. +* +* @private +* @param {number} N - population size +* @param {number} K - subpopulation size +* @param {number} n - number of draws +* @returns {number} variance +* +* @example +* var v = variance( 16, 11, 4 ); +* // returns ~0.688 +* +* @example +* var v = variance( 2, 1, 1 ); +* // returns 0.25 +* +* @example +* var v = variance( 10, 5, 12 ); +* // returns NaN +* +* @example +* var v = variance( 10.3, 10, 4 ); +* // returns NaN +* +* @example +* var v = variance( 10, 5.5, 4 ); +* // returns NaN +* +* @example +* var v = variance( 10, 5, 4.5 ); +* // returns NaN +* +* @example +* var v = variance( NaN, 10, 4 ); +* // returns NaN +* +* @example +* var v = variance( 20, NaN, 4 ); +* // returns NaN +* +* @example +* var v = variance( 20, 10, NaN ); +* // returns NaN +*/ +function variance( N, K, n ) { + return addon( N, K, n ); +} + + +// EXPORTS // + +module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js new file mode 100644 index 000000000000..762cad3453d9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js @@ -0,0 +1,154 @@ +/** +* @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 tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); + + +// VARIABLES // + +var variance = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( variance instanceof Error ) +}; + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof variance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var v = variance( NaN, 10, 4 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( 20, NaN, 4 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( 20, 10, NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided an `N` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { + var v; + + v = variance( 10.5, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( -2, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( -1, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( 20.5, 10, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( PINF, 10, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided an `K` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { + var y; + + y = variance( 20, 3.5, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 20, -2, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 20, -1, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 20, 2.5, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 20, PINF, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { + var y; + + y = variance( 40, 20, 3.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 40, 20, -2 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 40, 20, -1 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 40, 20, 2.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = variance( 40, 20, PINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the variance of a hypergeometric distribution', opts, function test( t ) { + var expected; + var delta; + var tol; + var N; + var K; + var n; + var y; + var i; + + expected = data.expected; + N = data.N; + K = data.K; + n = data.n; + for ( i = 0; i < n.length; i++ ) { + y = variance( N[i], K[i], n[i] ); + if ( y === expected[i] ) { + t.equal( y, expected[i], 'N: '+N[i]+', K: '+K[i]+', n: '+n[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 18.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. N: '+N[i]+'. K: '+K[i]+'. n: '+n[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); From ecd708677325c083c5af40ec0e1b424f68c6aa25 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 01:47:03 -0800 Subject: [PATCH 04/18] build: added the json and gyp dependency files --- 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: 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: 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 --- --- .../base/dists/hypergeometric/package.json | 3 + .../dists/hypergeometric/variance/binding.gyp | 149 ++++++++++++++++++ .../hypergeometric/variance/include.gypi | 48 ++++++ .../hypergeometric/variance/manifest.json | 79 ++++++++++ 4 files changed, 279 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json index 6c26d1dfacc7..cd3f898aa581 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json @@ -14,10 +14,13 @@ } ], "main": "./lib", + "gypfile": true, "directories": { "doc": "./docs", "example": "./examples", + "include": "./include", "lib": "./lib", + "src": "./src", "test": "./test" }, "types": "./docs/types", diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/binding.gyp new file mode 100644 index 000000000000..114dcb77c6aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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/hypergeometric/variance/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include.gypi new file mode 100644 index 000000000000..235be47d6d3b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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 01:48:26 -0800 Subject: [PATCH 05/18] 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 --- --- .../dists/hypergeometric/variance/README.md | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md index 411b5410b3e4..4b4957de717b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md @@ -147,6 +147,106 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/hypergeometric/variance.h" +``` + +#### stdlib_base_dists_hypergeometric_variance( N, K, n ) + +Returns the variance of a hypergeometric distribution. + +```c +double out = stdlib_base_dists_hypergeometric_variance( 16, 11, 4 ); +// returns ~0.688 +``` + +The function accepts the following arguments: + +- **N**: `[in] double` population size. +- **K**: `[in] double` subpopulation size. +- **n**: `[in] double` number of draws. + +```c +double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/hypergeometric/variance.h" +#include +#include + +static int random_integer( const int min, const int max ) { + return min + rand() % ( max - min + 1 ); +} + +int main( void ) { + double N; + double K; + double n; + double v; + int i; + + for ( i = 0; i < 10; i++ ) { + N = random_integer( 10, 100 ); + K = random_integer( 1, N ); + n = random_integer( 1, N ); + v = stdlib_base_dists_hypergeometric_variance( N, K, n ); + + printf( "N: %lf, K: %lf, n: %lf, Variance: %lf\n", N, K, n, v ); + } + + return 0; +} +``` + +
+ + + +
+ + +
From 918c94aa00ce5353d22f69496a74c4924be785b1 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 02:01:33 -0800 Subject: [PATCH 06/18] refactor: update the example.c --- 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 --- --- .../hypergeometric/variance/examples/c/example.c | 12 +++++++----- .../base/dists/hypergeometric/variance/manifest.json | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c index 1413d0816c05..5e391892bc1f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c @@ -17,11 +17,13 @@ */ #include "stdlib/stats/base/dists/hypergeometric/variance.h" +#include "stdlib/math/base/special/round.h" #include #include -static int random_integer( const int min, const int max ) { - return min + rand() % ( max - min + 1 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); } int main( void ) { @@ -36,9 +38,9 @@ int main( void ) { printf( "-------------------------------------------------" ); for ( i = 0; i < 10; i++ ) { - N = random_integer( 10, 100 ); - K = random_integer( 1, N ); - n = random_integer( 1, N ); + N = stdlib_base_round(random_uniform(0.0, 20.0)); + K = stdlib_base_round(random_uniform(0.0, N)); + n = stdlib_base_round(random_uniform(0.0, K)); v = stdlib_base_dists_hypergeometric_variance( N, K, n ); printf( "N: %lf, K: %lf, n: %lf, Variance: %lf\n", N, K, n, v ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json index d12f001fd81d..608528a1ea49 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json @@ -72,6 +72,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nonnegative-integer", + "@stdlib/math/base/special/round", "@stdlib/constants/float64/pinf" ] } From 9791340b2828a7549264a2aabb71d044b9842e21 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 02:40:01 -0800 Subject: [PATCH 07/18] refactor: remove the print statements (initial ones) in example.c --- 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 --- --- .../base/dists/hypergeometric/variance/examples/c/example.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c index 5e391892bc1f..aa1128037b5a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c @@ -33,10 +33,6 @@ int main( void ) { double v; int i; - printf( "Variance of the hypergeometric distribution:\n" ); - printf( "N\t\tK\t\tn\t\tVariance\n" ); - printf( "-------------------------------------------------" ); - for ( i = 0; i < 10; i++ ) { N = stdlib_base_round(random_uniform(0.0, 20.0)); K = stdlib_base_round(random_uniform(0.0, N)); From 618141f67b063d330756f847161945e51f5ef1aa Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 10 Jan 2025 23:53:18 -0800 Subject: [PATCH 08/18] 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: 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 --- --- .../dists/hypergeometric/variance/README.md | 21 +- .../variance/benchmark/c/benchmark.c | 198 ++++++------- .../dists/hypergeometric/variance/binding.gyp | 267 ++++++++++-------- .../variance/examples/c/example.c | 33 +-- .../hypergeometric/variance/include.gypi | 53 ++-- .../base/dists/hypergeometric/variance.h | 32 +-- .../hypergeometric/variance/package.json | 3 + .../dists/hypergeometric/variance/src/main.c | 28 +- 8 files changed, 322 insertions(+), 313 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md index 4b4957de717b..e1a043a64227 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md @@ -175,7 +175,7 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_hypergeometric_variance( N, K, n ) -Returns the variance of a hypergeometric distribution. +Returns the [variance][variance] of a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws). ```c double out = stdlib_base_dists_hypergeometric_variance( 16, 11, 4 ); @@ -211,12 +211,14 @@ double stdlib_base_dists_hypergeometric_variance( const double N, const double K ### Examples ```c +#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/variance.h" -#include #include +#include -static int random_integer( const int min, const int max ) { - return min + rand() % ( max - min + 1 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); } int main( void ) { @@ -227,15 +229,12 @@ int main( void ) { int i; for ( i = 0; i < 10; i++ ) { - N = random_integer( 10, 100 ); - K = random_integer( 1, N ); - n = random_integer( 1, N ); + N = stdlib_base_round( random_uniform( 0.0, 20.0 ) ); + K = stdlib_base_round( random_uniform( 0.0, N ) ); + n = stdlib_base_round( random_uniform( 0.0, K ) ); v = stdlib_base_dists_hypergeometric_variance( N, K, n ); - - printf( "N: %lf, K: %lf, n: %lf, Variance: %lf\n", N, K, n, v ); + printf( "N: %lf, K: %lf, n: %lf, Var(X;N,K,n): %lf\n", N, K, n, v ); } - - return 0; } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c index ae4eeffae63a..3807dda0d853 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c @@ -1,25 +1,25 @@ /** - * @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. - */ +* @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/hypergeometric/variance.h" -#include -#include #include +#include +#include #include #include @@ -28,114 +28,114 @@ #define REPEATS 3 /** - * Prints the TAP version. - */ +* Prints the TAP version. +*/ static void print_version( void ) { - printf( "TAP version 13\n" ); + printf( "TAP version 13\n" ); } /** - * Prints the TAP summary. - * - * @param total total number of tests - * @param passing total number of passing tests - */ +* 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 - printf( "# total %d\n", total ); - printf( "# pass %d\n", passing ); - printf( "#\n" ); - printf( "# ok\n" ); + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); } /** - * Prints benchmarks results. - * - * @param elapsed elapsed time in seconds - */ +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ 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" ); + 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" ); } /** - * Returns a clock time. - * - * @return clock time - */ +* 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; + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; } /** - * Generates a random integer on the interval [min,max]. - * - * @param min minimum value (inclusive) - * @param max maximum value (inclusive) - * @return random integer - */ +* Generates a random integer on the interval [min,max]. +* +* @param min minimum value (inclusive) +* @param max maximum value (inclusive) +* @return random integer +*/ static int random_integer( const int min, const int max ) { - return min + rand() % ( max - min + 1 ); + return min + rand() % ( max - min + 1 ); } /** - * Runs a benchmark. - * - * @return elapsed time in seconds - */ +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ static double benchmark( void ) { - double elapsed; - double N[ 100 ]; - double K[ 100 ]; - double n[ 100 ]; - double v; - double t; - int i; + double elapsed; + double N[ 100 ]; + double K[ 100 ]; + double n[ 100 ]; + double v; + double t; + int i; - for ( i = 0; i < 100; i++ ) { - N[ i ] = (double)random_integer( 10, 100 ); - K[ i ] = (double)random_integer( 1, (int)N[ i ] ); - n[ i ] = (double)random_integer( 1, (int)N[ i ] ); - } + for ( i = 0; i < 100; i++ ) { + N[ i ] = (double)random_integer( 10, 100 ); + K[ i ] = (double)random_integer( 1, (int)N[ i ] ); + n[ i ] = (double)random_integer( 1, (int)N[ i ] ); + } - t = tic(); - for ( i = 0; i < ITERATIONS; i++ ) { - v = stdlib_base_dists_hypergeometric_variance( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + v = stdlib_base_dists_hypergeometric_variance( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; } /** - * Main execution sequence. - */ +* Main execution sequence. +*/ int main( void ) { - double elapsed; - int i; + double elapsed; + int i; - // Use the current time to seed the random number generator: - srand( time( NULL ) ); + // Use the current time to 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 ); + 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/hypergeometric/variance/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/binding.gyp index 114dcb77c6aa..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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/hypergeometric/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c index aa1128037b5a..bcac81042bd6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c @@ -16,31 +16,28 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/variance.h" #include "stdlib/math/base/special/round.h" -#include +#include "stdlib/stats/base/dists/hypergeometric/variance.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) ); + return min + ( v * ( max - min ) ); } int main( void ) { - double N; - double K; - double n; - double v; - int i; - - for ( i = 0; i < 10; i++ ) { - N = stdlib_base_round(random_uniform(0.0, 20.0)); - K = stdlib_base_round(random_uniform(0.0, N)); - n = stdlib_base_round(random_uniform(0.0, K)); - v = stdlib_base_dists_hypergeometric_variance( N, K, n ); - - printf( "N: %lf, K: %lf, n: %lf, Variance: %lf\n", N, K, n, v ); - } + double N; + double K; + double n; + double v; + int i; - return 0; + for ( i = 0; i < 10; i++ ) { + N = stdlib_base_round( random_uniform( 0.0, 20.0 ) ); + K = stdlib_base_round( random_uniform( 0.0, N ) ); + n = stdlib_base_round( random_uniform( 0.0, K ) ); + v = stdlib_base_dists_hypergeometric_variance( N, K, n ); + printf( "N: %lf, K: %lf, n: %lf, Var(X;N,K,n): %lf\n", N, K, n, v ); + } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include.gypi index 235be47d6d3b..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/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": [ - " N || - n > N - ) { - return NAN; - } + if ( !stdlib_base_is_nonnegative_integer( N ) || !stdlib_base_is_nonnegative_integer( K ) || !stdlib_base_is_nonnegative_integer( n ) || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) { + return NAN; + } - return n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)); + return n * ( K / N ) * ( ( N - K ) / N ) * ( ( N - n ) / ( N - 1 ) ); } From f69061fcd7498189686e8bc5a5c0f985fc23ca44 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 11 Jan 2025 00:06:32 -0800 Subject: [PATCH 09/18] fix: reverted accidental changes to package.json --- 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: 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: 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: 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/hypergeometric/package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json index cd3f898aa581..6c26d1dfacc7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/package.json @@ -14,13 +14,10 @@ } ], "main": "./lib", - "gypfile": true, "directories": { "doc": "./docs", "example": "./examples", - "include": "./include", "lib": "./lib", - "src": "./src", "test": "./test" }, "types": "./docs/types", From 927fd02484950f0c7556cbda13d28fbf8f74b1e6 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 11 Jan 2025 00:21:52 -0800 Subject: [PATCH 10/18] refactor: fix indentation of comments in header file --- 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: 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 --- --- .../stats/base/dists/hypergeometric/variance.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h index fd29cb16222a..eba53f129b88 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h @@ -20,20 +20,20 @@ #define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_VARIANCE_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. - */ +* 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 /** - * Returns the variance of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. - * - * @param N population size - * @param K subpopulation size - * @param n number of draws - * @return variance of the distribution - */ +* Returns the variance of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. +* +* @param N population size +* @param K subpopulation size +* @param n number of draws +* @return variance of the distribution +*/ double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ); #ifdef __cplusplus From b526436cf8e14cbd949361808bc0a53aa16688b6 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 13 Jan 2025 20:34:54 -0800 Subject: [PATCH 11/18] 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 --- --- .../base/dists/hypergeometric/variance/benchmark/benchmark.js | 3 ++- .../hypergeometric/variance/benchmark/benchmark.native.js | 3 ++- .../stats/base/dists/hypergeometric/variance/src/main.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js index 1f061715a87b..425b665245b1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var floor = require( '@stdlib/math/base/special/floor' ); +var uniform = require( '@stdlib/random/base/uniform' ); var randu = require( '@stdlib/random/base/randu' ); var ceil = require( '@stdlib/math/base/special/ceil' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -40,7 +41,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - N = ceil( randu()*100.0 ) + 1.0; + N = ceil( uniform( 1.0, 100.0 ) ); K = floor( randu()*N ); n = floor( randu()*N ); y = variance( N, K, n ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js index 7c73bd31d246..1d8ed7f5fbb7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js @@ -24,6 +24,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 floor = require( '@stdlib/math/base/special/floor' ); @@ -53,7 +54,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { K = new Float64Array( len ); n = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - N[ i ] = floor( ( randu() * 90.0 ) + 10.0 ); + N[ i ] = floor( uniform( 1.0, 100.0 ) ); K[ i ] = floor( randu() * N[ i ] ); n[ i ] = floor( randu() * N[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c index 151fc272964b..13b5d5856e8d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c @@ -18,6 +18,7 @@ #include "stdlib/constants/float64/pinf.h" #include "stdlib/math/base/assert/is_nonnegative_integer.h" +#include "stdlib/stats/base/dists/hypergeometric/variance.h" /** * Returns the variance of a hypergeometric distribution. From 82d5b0aff90ce8ab1262c77cc18e140825e317e6 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Thu, 23 Jan 2025 00:34:43 -0800 Subject: [PATCH 12/18] fix: update C files with correct implementation --- 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: 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 --- --- .../variance/benchmark/c/benchmark.c | 29 ++++++++++--------- .../variance/examples/c/example.c | 19 ++++++------ .../base/dists/hypergeometric/variance.h | 11 +++---- .../dists/hypergeometric/variance/src/addon.c | 4 +-- .../dists/hypergeometric/variance/src/main.c | 23 ++++++++------- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c index 3807dda0d853..549108a7a117 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c @@ -17,9 +17,11 @@ */ #include "stdlib/stats/base/dists/hypergeometric/variance.h" -#include -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include +#include #include #include @@ -75,14 +77,15 @@ static double tic( void ) { } /** -* Generates a random integer on the interval [min,max]. +* Generates a random number on the interval [min,max). * * @param min minimum value (inclusive) -* @param max maximum value (inclusive) -* @return random integer +* @param max maximum value (exclusive) +* @return random number */ -static int random_integer( const int min, const int max ) { - return min + rand() % ( max - min + 1 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); } /** @@ -92,17 +95,17 @@ static int random_integer( const int min, const int max ) { */ static double benchmark( void ) { double elapsed; - double N[ 100 ]; - double K[ 100 ]; - double n[ 100 ]; + int32_t N[ 100 ]; + int32_t K[ 100 ]; + int32_t n[ 100 ]; double v; double t; int i; for ( i = 0; i < 100; i++ ) { - N[ i ] = (double)random_integer( 10, 100 ); - K[ i ] = (double)random_integer( 1, (int)N[ i ] ); - n[ i ] = (double)random_integer( 1, (int)N[ i ] ); + N[ i ] = stdlib_base_ceil( random_uniform( 2.0, 100.0 ) ); + K[ i ] = stdlib_base_ceil( random_uniform( 0.0, N[ i ] ) ); + n[ i ] = stdlib_base_ceil( random_uniform( 0.0, N[ i ] ) ); } t = tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c index bcac81042bd6..7ea784389dbe 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/examples/c/example.c @@ -16,10 +16,11 @@ * limitations under the License. */ -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/variance.h" -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); @@ -27,17 +28,17 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double N; - double K; - double n; + int32_t N; + int32_t K; + int32_t n; double v; int i; for ( i = 0; i < 10; i++ ) { - N = stdlib_base_round( random_uniform( 0.0, 20.0 ) ); - K = stdlib_base_round( random_uniform( 0.0, N ) ); - n = stdlib_base_round( random_uniform( 0.0, K ) ); + N = stdlib_base_ceil( random_uniform( 2.0, 100.0 ) ); + K = stdlib_base_ceil( random_uniform( 0.0, N ) ); + n = stdlib_base_ceil( random_uniform( 0.0, N ) ); v = stdlib_base_dists_hypergeometric_variance( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, Var(X;N,K,n): %lf\n", N, K, n, v ); + printf( "N: %d, K: %d, n: %d, Var(X;N,K,n): %lf\n", N, K, n, v ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h index eba53f129b88..2025a9bfa8b3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/include/stdlib/stats/base/dists/hypergeometric/variance.h @@ -19,6 +19,8 @@ #ifndef STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_VARIANCE_H #define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_VARIANCE_H +#include + /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -27,14 +29,9 @@ extern "C" { #endif /** -* Returns the variance of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. -* -* @param N population size -* @param K subpopulation size -* @param n number of draws -* @return variance of the distribution +* Returns the variance of a hypergeometric distribution. */ -double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_variance( const int32_t N, const int32_t K, const int32_t n ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/addon.c index 0088fc90e7e0..37041cee8ee7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/addon.c @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/math/base/napi/ternary.h" #include "stdlib/stats/base/dists/hypergeometric/variance.h" +#include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_variance ) +STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_variance ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c index 13b5d5856e8d..6d5018a5d8fc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c @@ -16,26 +16,27 @@ * limitations under the License. */ -#include "stdlib/constants/float64/pinf.h" -#include "stdlib/math/base/assert/is_nonnegative_integer.h" #include "stdlib/stats/base/dists/hypergeometric/variance.h" +#include "stdlib/constants/float64/pinf.h" +#include /** * Returns the variance of a hypergeometric distribution. * -* @param N population size -* @param K subpopulation size -* @param n number of draws -* @return variance +* @param N population size +* @param K subpopulation size +* @param n number of draws +* @return variance * * @example * double v = stdlib_base_dists_hypergeometric_variance( 16, 11, 4 ); * // returns ~0.688 */ -double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ) { - if ( !stdlib_base_is_nonnegative_integer( N ) || !stdlib_base_is_nonnegative_integer( K ) || !stdlib_base_is_nonnegative_integer( n ) || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) { - return NAN; +double stdlib_base_dists_hypergeometric_variance( const int32_t N, const int32_t K, const int32_t n ) { + if ( N < 0 || K < 0 || n < 0 || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) { + return 0.0/0.0; // NaN } - - return n * ( K / N ) * ( ( N - K ) / N ) * ( ( N - n ) / ( N - 1 ) ); + double p = (double)K / (double)N; + double result = n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) ); + return result; } From 6ab2572e6b74b10e6e4987a01e59eb4d1a37e7f9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Thu, 23 Jan 2025 00:39:18 -0800 Subject: [PATCH 13/18] fix: update JS files with correct implementation --- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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 --- --- .../variance/benchmark/benchmark.js | 22 ++++++---- .../variance/benchmark/benchmark.native.js | 10 ++--- .../hypergeometric/variance/lib/native.js | 28 ++++--------- .../variance/test/test.native.js | 41 ------------------- 4 files changed, 26 insertions(+), 75 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js index 425b665245b1..05907dfb1147 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.js @@ -21,10 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var floor = require( '@stdlib/math/base/special/floor' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var randu = require( '@stdlib/random/base/randu' ); -var ceil = require( '@stdlib/math/base/special/ceil' ); +var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var variance = require( './../lib' ); @@ -33,18 +31,26 @@ var variance = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { + var len; var N; var K; var n; var y; var i; + len = 100; + N = new Float64Array( len ); + K = new Float64Array( len ); + n = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + N[ i ] = discreteUniform( 2, 100 ); + n[ i ] = discreteUniform( 0, N[ i ] ); + K[ i ] = discreteUniform( 0, N[ i ] ); + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - N = ceil( uniform( 1.0, 100.0 ) ); - K = floor( randu()*N ); - n = floor( randu()*N ); - y = variance( N, K, n ); + y = variance( N[ i % len ], K[ i % len ], n[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js index 1d8ed7f5fbb7..d1833aeafd71 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/benchmark.native.js @@ -23,11 +23,9 @@ 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); -var floor = require( '@stdlib/math/base/special/floor' ); var pkg = require( './../package.json' ).name; @@ -54,9 +52,9 @@ bench( pkg+'::native', opts, function benchmark( b ) { K = new Float64Array( len ); n = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - N[ i ] = floor( uniform( 1.0, 100.0 ) ); - K[ i ] = floor( randu() * N[ i ] ); - n[ i ] = floor( randu() * N[ i ] ); + N[ i ] = discreteUniform( 2, 100 ); + K[ i ] = discreteUniform( 0, N[ i ] ); + n[ i ] = discreteUniform( 0, N[ i ] ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js index b50026d18f6d..a1885f77614f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/lib/native.js @@ -26,13 +26,13 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Returns the variance of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. +* Returns the variance of a hypergeometric distribution. * * @private -* @param {number} N - population size -* @param {number} K - subpopulation size -* @param {number} n - number of draws -* @returns {number} variance +* @param {NonNegativeInteger} N - population size +* @param {NonNegativeInteger} K - subpopulation size +* @param {NonNegativeInteger} n - number of draws +* @returns {NonNegativeNumber} variance * * @example * var v = variance( 16, 11, 4 ); @@ -47,27 +47,15 @@ var addon = require( './../src/addon.node' ); * // returns NaN * * @example -* var v = variance( 10.3, 10, 4 ); +* var v = variance( -2, 4, 2 ); * // returns NaN * * @example -* var v = variance( 10, 5.5, 4 ); +* var v = variance( 20, -1, 10 ); * // returns NaN * * @example -* var v = variance( 10, 5, 4.5 ); -* // returns NaN -* -* @example -* var v = variance( NaN, 10, 4 ); -* // returns NaN -* -* @example -* var v = variance( 20, NaN, 4 ); -* // returns NaN -* -* @example -* var v = variance( 20, 10, NaN ); +* var v = variance( 40, 20, -2 ); * // returns NaN */ function variance( N, K, n ) { diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js index 762cad3453d9..e5f36690f509 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/test/test.native.js @@ -25,7 +25,6 @@ var tape = require( 'tape' ); var tryRequire = require( '@stdlib/utils/try-require' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); -var PINF = require( '@stdlib/constants/float64/pinf' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -50,79 +49,39 @@ tape( 'main export is a function', opts, function test( t ) { t.end(); }); -tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { - var v = variance( NaN, 10, 4 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = variance( 20, NaN, 4 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = variance( 20, 10, NaN ); - t.equal( isnan( v ), true, 'returns NaN' ); - - t.end(); -}); - tape( 'if provided an `N` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { var v; - v = variance( 10.5, 4, 2 ); - t.equal( isnan( v ), true, 'returns NaN' ); - v = variance( -2, 4, 2 ); t.equal( isnan( v ), true, 'returns NaN' ); v = variance( -1, 4, 2 ); t.equal( isnan( v ), true, 'returns NaN' ); - v = variance( 20.5, 10, 5 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = variance( PINF, 10, 5 ); - t.equal( isnan( v ), true, 'returns NaN' ); - t.end(); }); tape( 'if provided an `K` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { var y; - y = variance( 20, 3.5, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = variance( 20, -2, 10 ); t.equal( isnan( y ), true, 'returns NaN' ); y = variance( 20, -1, 10 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = variance( 20, 2.5, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = variance( 20, PINF, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { var y; - y = variance( 40, 20, 3.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = variance( 40, 20, -2 ); t.equal( isnan( y ), true, 'returns NaN' ); y = variance( 40, 20, -1 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = variance( 40, 20, 2.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = variance( 40, 20, PINF ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); From b621337147acf9a0997517bc966e659c46123d2d Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Thu, 23 Jan 2025 00:39:55 -0800 Subject: [PATCH 14/18] build: update manifest.json --- 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: 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 --- --- .../base/dists/hypergeometric/variance/manifest.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json index 608528a1ea49..48cbd2193f93 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json @@ -39,7 +39,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/ternary", - "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/constants/float64/pinf" ] }, @@ -55,8 +54,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/constants/float64/pinf" + "@stdlib/constants/float64/pinf", + "@stdlib/math/base/special/ceil" ] }, { @@ -71,9 +70,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/special/round", - "@stdlib/constants/float64/pinf" + "@stdlib/constants/float64/pinf", + "@stdlib/math/base/special/ceil" ] } ] From 855be936a66f05749e749bbeaea0ec156ba0adca Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Thu, 23 Jan 2025 00:40:41 -0800 Subject: [PATCH 15/18] docs: update README with correct documentation --- 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: 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: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../dists/hypergeometric/variance/README.md | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md index e1a043a64227..fda29eb4fb2b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md @@ -184,12 +184,12 @@ double out = stdlib_base_dists_hypergeometric_variance( 16, 11, 4 ); The function accepts the following arguments: -- **N**: `[in] double` population size. -- **K**: `[in] double` subpopulation size. -- **n**: `[in] double` number of draws. +- **N**: `[in] int32_t` population size. +- **K**: `[in] int32_t` subpopulation size. +- **n**: `[in] int32_t` number of draws. ```c -double stdlib_base_dists_hypergeometric_variance( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_variance( const int32_t N, const int32_t K, const int32_t n ); ```
@@ -211,10 +211,11 @@ double stdlib_base_dists_hypergeometric_variance( const double N, const double K ### Examples ```c -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/variance.h" -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); @@ -222,18 +223,18 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double N; - double K; - double n; + int32_t N; + int32_t K; + int32_t n; double v; int i; for ( i = 0; i < 10; i++ ) { - N = stdlib_base_round( random_uniform( 0.0, 20.0 ) ); - K = stdlib_base_round( random_uniform( 0.0, N ) ); - n = stdlib_base_round( random_uniform( 0.0, K ) ); + N = stdlib_base_ceil( random_uniform( 2.0, 100.0 ) ); + K = stdlib_base_ceil( random_uniform( 0.0, N ) ); + n = stdlib_base_ceil( random_uniform( 0.0, N ) ); v = stdlib_base_dists_hypergeometric_variance( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, Var(X;N,K,n): %lf\n", N, K, n, v ); + printf( "N: %d, K: %d, n: %d, Var(X;N,K,n): %lf\n", N, K, n, v ); } } ``` From f551661e556cba6cd58e62695ce35b71f9cee73d Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 29 Jan 2025 00:07:02 -0800 Subject: [PATCH 16/18] chore: follow code convention --- 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 --- --- .../stats/base/dists/hypergeometric/variance/src/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c index 6d5018a5d8fc..a27be613a5a4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c @@ -33,10 +33,11 @@ * // returns ~0.688 */ double stdlib_base_dists_hypergeometric_variance( const int32_t N, const int32_t K, const int32_t n ) { + double p; + if ( N < 0 || K < 0 || n < 0 || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) { return 0.0/0.0; // NaN } - double p = (double)K / (double)N; - double result = n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) ); - return result; + p = (double)K / (double)N; + return ( n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) )); } From c865184d1f8cf63c9b5161bd76d155bbde3ca43f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 28 Feb 2025 19:35:14 -0800 Subject: [PATCH 17/18] fix: remove infinity check in C implementation --- 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: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - 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: 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 --- --- .../dists/hypergeometric/variance/benchmark/c/benchmark.c | 4 ++-- .../stats/base/dists/hypergeometric/variance/manifest.json | 5 +---- .../stats/base/dists/hypergeometric/variance/src/main.c | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c index 549108a7a117..6945447966a9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/benchmark/c/benchmark.c @@ -94,10 +94,10 @@ static double random_uniform( const double min, const double max ) { * @return elapsed time in seconds */ static double benchmark( void ) { - double elapsed; int32_t N[ 100 ]; int32_t K[ 100 ]; int32_t n[ 100 ]; + double elapsed; double v; double t; int i; @@ -110,7 +110,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - v = stdlib_base_dists_hypergeometric_variance( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + v = stdlib_base_dists_hypergeometric_variance( N[ i%100 ], K[ i%100 ], n[ i%100 ] ); if ( v != v ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json index 48cbd2193f93..efbe8939dc98 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/manifest.json @@ -38,8 +38,7 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/napi/ternary", - "@stdlib/constants/float64/pinf" + "@stdlib/math/base/napi/ternary" ] }, { @@ -54,7 +53,6 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/ceil" ] }, @@ -70,7 +68,6 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/ceil" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c index a27be613a5a4..06f6c65853d9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c @@ -17,7 +17,6 @@ */ #include "stdlib/stats/base/dists/hypergeometric/variance.h" -#include "stdlib/constants/float64/pinf.h" #include /** @@ -35,7 +34,7 @@ double stdlib_base_dists_hypergeometric_variance( const int32_t N, const int32_t K, const int32_t n ) { double p; - if ( N < 0 || K < 0 || n < 0 || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) { + if ( N < 0 || K < 0 || n < 0 || K > N || n > N ) { return 0.0/0.0; // NaN } p = (double)K / (double)N; From 2011af575acd4686f473ee085708d7cab4fc6931 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 28 Feb 2025 19:38:00 -0800 Subject: [PATCH 18/18] chore: fix negative spacing --- 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: passed - 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 --- --- .../@stdlib/stats/base/dists/hypergeometric/variance/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c index 06f6c65853d9..79d8986fe728 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/src/main.c @@ -38,5 +38,5 @@ double stdlib_base_dists_hypergeometric_variance( const int32_t N, const int32_t return 0.0/0.0; // NaN } p = (double)K / (double)N; - return ( n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) )); + return ( n * p * ( 1.0-p ) * ( (double)(N-n)/(double)(N-1) ) ); }