From 84141ae13de54ee0ceca8875107642d87434f789 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 02:36:48 -0800 Subject: [PATCH 01/13] feat: add the C src files --- .../stats/base/dists/hypergeometric/stdev.h | 43 ++++++++++++ .../dists/hypergeometric/stdev/src/Makefile | 70 +++++++++++++++++++ .../dists/hypergeometric/stdev/src/addon.c | 23 ++++++ .../dists/hypergeometric/stdev/src/main.c | 58 +++++++++++++++ 4 files changed, 194 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h new file mode 100644 index 000000000000..2280bc37e725 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.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_STDEV_H +#define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_STDEV_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 standard deviation 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 standard deviation of the distribution + */ +double stdlib_base_dists_hypergeometric_stdev( const double N, const double K, const double n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_STDEV_H diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/addon.c new file mode 100644 index 000000000000..b4724e6bc9db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_stdev ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c new file mode 100644 index 000000000000..b2da50296e4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c @@ -0,0 +1,58 @@ +/** +* @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" +#include "stdlib/math/base/special/sqrt.h" + +/** +* Returns the standard deviation of a hypergeometric distribution. +* +* @param N population size +* @param K subpopulation size +* @param n number of draws +* @return standard deviation of the distribution, or NaN if inputs are invalid +* +* @example +* double sd = stdlib_base_dists_hypergeometric_stdev( 16, 11, 4 ); +* // returns ~0.829 +* +* @example +* double sd = stdlib_base_dists_hypergeometric_stdev( 2, 1, 1 ); +* // returns 0.5 +* +* @example +* double sd = stdlib_base_dists_hypergeometric_stdev( 10, 5, 12 ); +* // returns NaN +*/ +double stdlib_base_dists_hypergeometric_stdev( 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 variance = n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)); + return stdlib_base_sqrt( variance ); +} From a752fafe2502250b2c6fbdd8f611016ec6fa943a Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 02:37:10 -0800 Subject: [PATCH 02/13] feat: add the C benchmark and example files --- .../hypergeometric/stdev/benchmark/c/Makefile | 146 ++++++++++++++++++ .../stdev/benchmark/c/benchmark.c | 143 +++++++++++++++++ .../hypergeometric/stdev/examples/c/Makefile | 146 ++++++++++++++++++ .../hypergeometric/stdev/examples/c/example.c | 46 ++++++ 4 files changed, 481 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c new file mode 100644 index 000000000000..ce89f16ad097 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c @@ -0,0 +1,143 @@ +/** +* @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/stdev.h" +#include "stdlib/math/base/special/round.h" +#include +#include +#include +#include +#include + +#define NAME "hypergeometric-stdev" +#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 number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double N[ 100 ]; + double K[ 100 ]; + double n[ 100 ]; + double sd; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + N[i] = stdlib_base_round(random_uniform(1.0, 100.0)); + K[i] = stdlib_base_round(random_uniform(0.0, N[i])); + n[i] = stdlib_base_round(random_uniform(0.0, N[i])); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + sd = stdlib_base_dists_hypergeometric_stdev( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + if ( sd != sd ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( sd != sd ) { + 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/stdev/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c new file mode 100644 index 000000000000..c07ff14b2d99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c @@ -0,0 +1,46 @@ +/** +* @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/stdev.h" +#include "stdlib/math/base/special/round.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double N; + double K; + double n; + double sd; + 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)); + sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); + + printf( "N: %lf, K: %lf, n: %lf, Standard Deviation: %lf\n", N, K, n, sd ); + } + + return 0; +} From 68f1402087811f29c2daa8242a3e9022fd66175e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 02:37:46 -0800 Subject: [PATCH 03/13] 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 --- --- .../stdev/benchmark/benchmark.native.js | 74 +++++++++ .../dists/hypergeometric/stdev/lib/native.js | 80 +++++++++ .../hypergeometric/stdev/test/test.native.js | 154 ++++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js new file mode 100644 index 000000000000..ed4896f6d7aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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 stdev = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( stdev 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 = stdev( 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/stdev/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js new file mode 100644 index 000000000000..e61824728812 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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 standard deviation 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} standard deviation +* +* @example +* var sd = stdev( 16, 11, 4 ); +* // returns ~0.829 +* +* @example +* var sd = stdev( 2, 1, 1 ); +* // returns 0.5 +* +* @example +* var sd = stdev( 10, 5, 12 ); +* // returns NaN +* +* @example +* var sd = stdev( 10.3, 10, 4 ); +* // returns NaN +* +* @example +* var sd = stdev( 10, 5.5, 4 ); +* // returns NaN +* +* @example +* var sd = stdev( 10, 5, 4.5 ); +* // returns NaN +* +* @example +* var sd = stdev( NaN, 10, 4 ); +* // returns NaN +* +* @example +* var sd = stdev( 20, NaN, 4 ); +* // returns NaN +* +* @example +* var sd = stdev( 20, 10, NaN ); +* // returns NaN +*/ +function stdev( N, K, n ) { + return addon( N, K, n ); +} + + +// EXPORTS // + +module.exports = stdev; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/test/test.native.js new file mode 100644 index 000000000000..69637bbad9b0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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 stdev = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( stdev 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 stdev, '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 = stdev( NaN, 10, 4 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = stdev( 20, NaN, 4 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = stdev( 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 = stdev( 10.5, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = stdev( -2, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = stdev( -1, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = stdev( 20.5, 10, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = stdev( 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 = stdev( 20, 3.5, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 20, -2, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 20, -1, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 20, 2.5, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 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 = stdev( 40, 20, 3.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 40, 20, -2 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 40, 20, -1 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 40, 20, 2.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = stdev( 40, 20, PINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the standard deviation 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 = stdev( 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 = 2.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 574808d1402bf0d791f9be9dcd0f5410f2e9200e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 02:38:35 -0800 Subject: [PATCH 04/13] build: added the json and gyp dependency files --- .../dists/hypergeometric/stdev/binding.gyp | 149 ++++++++++++++++++ .../dists/hypergeometric/stdev/include.gypi | 48 ++++++ .../dists/hypergeometric/stdev/manifest.json | 84 ++++++++++ .../dists/hypergeometric/stdev/package.json | 3 + 4 files changed, 284 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/binding.gyp new file mode 100644 index 000000000000..114dcb77c6aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include.gypi new file mode 100644 index 000000000000..235be47d6d3b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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 02:38:54 -0800 Subject: [PATCH 05/13] 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 --- --- .../base/dists/hypergeometric/stdev/README.md | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md index 9cf84e3e486d..ec6bc611010c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md @@ -147,6 +147,108 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/hypergeometric/stdev.h" +``` + +#### stdlib_base_dists_hypergeometric_stdev( N, K, n ) + +Returns the standard deviation of a hypergeometric distribution. + +```c +double out = stdlib_base_dists_hypergeometric_stdev( 16, 11, 4 ); +// returns ~0.829 +``` + +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_stdev( const double N, const double K, const double n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/hypergeometric/stdev.h" +#include "stdlib/math/base/special/round.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double N; + double K; + double n; + double sd; + 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)); + sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); + + printf( "N: %lf, K: %lf, n: %lf, Standard Deviation: %lf\n", N, K, n, sd ); + } + + return 0; +} +``` + +
+ + + +
+ + +
From 62b2f42b5f1f75e3368456840663ddb6fecef2b0 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 11 Jan 2025 00:15:13 -0800 Subject: [PATCH 06/13] refactor: apply suggestions from previous PRs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../base/dists/hypergeometric/stdev/README.md | 21 +- .../stdev/benchmark/c/benchmark.c | 18 +- .../dists/hypergeometric/stdev/binding.gyp | 267 ++++++++++-------- .../hypergeometric/stdev/examples/c/example.c | 35 ++- .../dists/hypergeometric/stdev/include.gypi | 53 ++-- .../stats/base/dists/hypergeometric/stdev.h | 50 ++-- .../dists/hypergeometric/stdev/lib/native.js | 18 +- .../dists/hypergeometric/stdev/src/main.c | 30 +- 8 files changed, 248 insertions(+), 244 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md index ec6bc611010c..f2af8aee6ba1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md @@ -175,7 +175,7 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_hypergeometric_stdev( N, K, n ) -Returns the standard deviation of a hypergeometric distribution. +Returns the [standard deviation][standard-deviation] 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_stdev( 16, 11, 4 ); @@ -211,33 +211,30 @@ double stdlib_base_dists_hypergeometric_stdev( const double N, const double K, c ### Examples ```c -#include "stdlib/stats/base/dists/hypergeometric/stdev.h" #include "stdlib/math/base/special/round.h" -#include +#include "stdlib/stats/base/dists/hypergeometric/stdev.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 sd; double N; double K; double n; - double sd; 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_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 ) ); sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); - - printf( "N: %lf, K: %lf, n: %lf, Standard Deviation: %lf\n", N, K, n, sd ); + printf( "N: %lf, K: %lf, n: %lf, SD(X;N,K,n): %lf\n", N, K, n, sd ); } - - return 0; } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c index ce89f16ad097..30263dc351ff 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c @@ -16,11 +16,11 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/stdev.h" #include "stdlib/math/base/special/round.h" -#include -#include +#include "stdlib/stats/base/dists/hypergeometric/stdev.h" #include +#include +#include #include #include @@ -72,7 +72,7 @@ static void print_results( double elapsed ) { static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec/1.0e6; + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; } /** @@ -84,7 +84,7 @@ static double tic( void ) { */ 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 ) ); } /** @@ -102,9 +102,9 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - N[i] = stdlib_base_round(random_uniform(1.0, 100.0)); - K[i] = stdlib_base_round(random_uniform(0.0, N[i])); - n[i] = stdlib_base_round(random_uniform(0.0, N[i])); + N[ i ] = stdlib_base_round( random_uniform( 1.0, 100.0 ) ); + K[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) ); + n[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) ); } t = tic(); @@ -137,7 +137,7 @@ int main( void ) { printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); - printf( "ok %d benchmark finished\n", i+1 ); + printf( "ok %d benchmark finished\n", i + 1 ); } print_summary( REPEATS, REPEATS ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/binding.gyp index 114dcb77c6aa..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c index c07ff14b2d99..4796dad76b11 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c @@ -16,31 +16,28 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/stdev.h" #include "stdlib/math/base/special/round.h" -#include +#include "stdlib/stats/base/dists/hypergeometric/stdev.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) ); + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); } int main( void ) { - double N; - double K; - double n; - double sd; - 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)); - sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); - - printf( "N: %lf, K: %lf, n: %lf, Standard Deviation: %lf\n", N, K, n, sd ); - } + double sd; + double N; + double K; + double n; + 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 ) ); + sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); + printf( "N: %lf, K: %lf, n: %lf, SD(X;N,K,n): %lf\n", N, K, n, sd ); + } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include.gypi index 235be47d6d3b..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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; + } - double variance = n * (K / N) * ((N - K) / N) * ((N - n) / (N - 1)); - return stdlib_base_sqrt( variance ); + double variance = n * ( K / N ) * ( ( N - K ) / N ) * ( ( N - n ) / ( N - 1 ) ); + return stdlib_base_sqrt( variance ); } From 1d5e74dba23bd83ae38c00ef59a981ac3637f303 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sat, 11 Jan 2025 08:18:30 +0000 Subject: [PATCH 07/13] chore: update copyright years --- .../include/stdlib/stats/base/dists/hypergeometric/stdev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h index 34f9581e379e..414ee5a024a7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 4eb00425b600834f65b266a560fe599ab30ae71f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 13 Jan 2025 20:33:05 -0800 Subject: [PATCH 08/13] 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/stdev/benchmark/benchmark.js | 3 ++- .../dists/hypergeometric/stdev/benchmark/benchmark.native.js | 3 ++- .../@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js index 536b57ba0ad8..0d2ff9c00440 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js @@ -23,6 +23,7 @@ var bench = require( '@stdlib/bench' ); var floor = require( '@stdlib/math/base/special/floor' ); var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var ceil = require( '@stdlib/math/base/special/ceil' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; @@ -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 = stdev( N, K, n ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js index ed4896f6d7aa..a5e8256030ba 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c index 5e491061be0d..54f3cb2c9610 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c @@ -19,6 +19,7 @@ #include "stdlib/constants/float64/pinf.h" #include "stdlib/math/base/assert/is_nonnegative_integer.h" #include "stdlib/math/base/special/sqrt.h" +#include "stdlib/stats/base/dists/hypergeometric/stdev.h" /** * Returns the standard deviation of a hypergeometric distribution. From 3bf90aeb76b68c93409e39f6360b40dea02c1b2f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 28 Jan 2025 22:52:10 -0800 Subject: [PATCH 09/13] fix: correct hypergeometric standard deviation 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: 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: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - 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 --- --- .../base/dists/hypergeometric/stdev/README.md | 27 ++++++------ .../stdev/benchmark/benchmark.js | 22 ++++++---- .../stdev/benchmark/benchmark.native.js | 10 ++--- .../stdev/benchmark/c/benchmark.c | 18 ++++---- .../hypergeometric/stdev/examples/c/example.c | 19 +++++---- .../stats/base/dists/hypergeometric/stdev.h | 11 ++--- .../dists/hypergeometric/stdev/lib/native.js | 10 ++--- .../dists/hypergeometric/stdev/manifest.json | 9 ++-- .../dists/hypergeometric/stdev/src/addon.c | 4 +- .../dists/hypergeometric/stdev/src/main.c | 16 ++++---- .../hypergeometric/stdev/test/test.native.js | 41 ------------------- 11 files changed, 73 insertions(+), 114 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md index f2af8aee6ba1..4c3186c0e150 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/README.md @@ -184,12 +184,12 @@ double out = stdlib_base_dists_hypergeometric_stdev( 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_stdev( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_stdev( const int32_t N, const int32_t K, const int32_t n ); ```
@@ -211,10 +211,11 @@ double stdlib_base_dists_hypergeometric_stdev( const double N, const double K, c ### Examples ```c -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/stdev.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 ); @@ -223,17 +224,17 @@ static double random_uniform( const double min, const double max ) { int main( void ) { double sd; - double N; - double K; - double n; + int32_t N; + int32_t K; + int32_t n; 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 ) ); sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, SD(X;N,K,n): %lf\n", N, K, n, sd ); + printf( "N: %d, K: %d, n: %d, SD(X;N,K,n): %lf\n", N, K, n, sd ); } } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js index 0d2ff9c00440..6083dc09683c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.js @@ -21,10 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var floor = require( '@stdlib/math/base/special/floor' ); -var randu = require( '@stdlib/random/base/randu' ); -var uniform = require( '@stdlib/random/base/uniform' ); -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 stdev = require( './../lib' ); @@ -33,18 +31,26 @@ var stdev = 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 = stdev( N, K, n ); + y = stdev( 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/stdev/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js index a5e8256030ba..ce85da0b6356 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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 ); + n[ i ] = discreteUniform( 0, N[ i ] ); + K[ i ] = discreteUniform( 0, N[ i ] ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c index 30263dc351ff..9b3f613d7795 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c @@ -16,11 +16,11 @@ * limitations under the License. */ -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/stdev.h" -#include -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include #include #include @@ -94,17 +94,17 @@ static double random_uniform( const double min, const double 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 sd; double t; int i; for ( i = 0; i < 100; i++ ) { - N[ i ] = stdlib_base_round( random_uniform( 1.0, 100.0 ) ); - K[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) ); - n[ i ] = stdlib_base_round( random_uniform( 0.0, 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/stdev/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c index 4796dad76b11..7bd17ac3f89d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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/stdev.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 ); @@ -28,16 +29,16 @@ static double random_uniform( const double min, const double max ) { int main( void ) { double sd; - double N; - double K; - double n; + int32_t N; + int32_t K; + int32_t n; 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 ) ); sd = stdlib_base_dists_hypergeometric_stdev( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, SD(X;N,K,n): %lf\n", N, K, n, sd ); + printf( "N: %d, K: %d, n: %d, SD(X;N,K,n): %lf\n", N, K, n, sd ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h index 414ee5a024a7..f31bd5778cfa 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/include/stdlib/stats/base/dists/hypergeometric/stdev.h @@ -19,6 +19,8 @@ #ifndef STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_STDEV_H #define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_STDEV_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 standard deviation 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 standard deviation of the distribution +* Returns the standard deviation of a hypergeometric distribution. */ -double stdlib_base_dists_hypergeometric_stdev( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_stdev( 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/stdev/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js index 2113d4137759..28e31ba0efc9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js @@ -26,13 +26,13 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Returns the standard deviation of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. +* Returns the standard deviation of a hypergeometric distribution. * * @private -* @param {number} N - population size -* @param {number} K - subpopulation size -* @param {number} n - number of draws -* @returns {number} standard deviation +* @param {NonNegativeInteger} N - population size +* @param {NonNegativeInteger} K - subpopulation size +* @param {NonNegativeInteger} n - number of draws +* @returns {NonNegativeNumber} standard deviation * * @example * var v = stdev( 16, 11, 4 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json index ff98a80b234d..a004cee4e823 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json @@ -39,7 +39,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/ternary", - "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/sqrt" ] @@ -56,10 +55,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/round" + "@stdlib/math/base/special/ceil" ] }, { @@ -74,10 +72,9 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/special/round", "@stdlib/constants/float64/pinf", - "@stdlib/math/base/special/sqrt" + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/ceil" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/addon.c index b4724e6bc9db..45a90cc2da28 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/addon.c @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/math/base/napi/ternary.h" #include "stdlib/stats/base/dists/hypergeometric/stdev.h" +#include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_stdev ) +STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_stdev ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c index 54f3cb2c9610..9d1737104ba4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c @@ -16,10 +16,10 @@ * limitations under the License. */ -#include "stdlib/constants/float64/pinf.h" -#include "stdlib/math/base/assert/is_nonnegative_integer.h" -#include "stdlib/math/base/special/sqrt.h" #include "stdlib/stats/base/dists/hypergeometric/stdev.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/constants/float64/pinf.h" +#include /** * Returns the standard deviation of a hypergeometric distribution. @@ -33,11 +33,11 @@ * double sd = stdlib_base_dists_hypergeometric_stdev( 16, 11, 4 ); * // returns ~0.829 */ -double stdlib_base_dists_hypergeometric_stdev( 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_stdev( 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 } - - double variance = n * ( K / N ) * ( ( N - K ) / N ) * ( ( N - n ) / ( N - 1 ) ); + double p = (double)K / (double)N; + double variance = n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) ); return stdlib_base_sqrt( variance ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/test/test.native.js index 69637bbad9b0..8d25286e7138 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/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 = stdev( NaN, 10, 4 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = stdev( 20, NaN, 4 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = stdev( 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 = stdev( 10.5, 4, 2 ); - t.equal( isnan( v ), true, 'returns NaN' ); - v = stdev( -2, 4, 2 ); t.equal( isnan( v ), true, 'returns NaN' ); v = stdev( -1, 4, 2 ); t.equal( isnan( v ), true, 'returns NaN' ); - v = stdev( 20.5, 10, 5 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = stdev( 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 = stdev( 20, 3.5, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = stdev( 20, -2, 10 ); t.equal( isnan( y ), true, 'returns NaN' ); y = stdev( 20, -1, 10 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = stdev( 20, 2.5, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = stdev( 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 = stdev( 40, 20, 3.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = stdev( 40, 20, -2 ); t.equal( isnan( y ), true, 'returns NaN' ); y = stdev( 40, 20, -1 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = stdev( 40, 20, 2.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = stdev( 40, 20, PINF ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); From 83bde37004d09a5242f7d7be80af0c180a3e11a7 Mon Sep 17 00:00:00 2001 From: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Date: Tue, 28 Jan 2025 23:13:52 -0800 Subject: [PATCH 10/13] chore: fix variable order Signed-off-by: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> --- .../base/dists/hypergeometric/stdev/benchmark/c/benchmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c index 9b3f613d7795..473d3bbc9f23 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c @@ -94,10 +94,10 @@ static double random_uniform( const double min, const double max ) { */ static double benchmark( void ) { double elapsed; + double sd; int32_t N[ 100 ]; int32_t K[ 100 ]; int32_t n[ 100 ]; - double sd; double t; int i; From a47ec2ab36a0e45747ba4d5d267cdef66f47a9e5 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 29 Jan 2025 00:03:54 -0800 Subject: [PATCH 11/13] 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: 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 --- --- .../stdev/benchmark/c/benchmark.c | 8 ++++---- .../dists/hypergeometric/stdev/lib/native.js | 18 +++--------------- .../base/dists/hypergeometric/stdev/src/main.c | 7 +++++-- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c index 473d3bbc9f23..7bf2ed405988 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c @@ -94,10 +94,10 @@ static double random_uniform( const double min, const double max ) { */ static double benchmark( void ) { double elapsed; - double sd; int32_t N[ 100 ]; int32_t K[ 100 ]; int32_t n[ 100 ]; + double y; double t; int i; @@ -109,14 +109,14 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - sd = stdlib_base_dists_hypergeometric_stdev( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); - if ( sd != sd ) { + y = stdlib_base_dists_hypergeometric_stdev( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + if ( y != y ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( sd != sd ) { + if ( y != y ) { printf( "should not return NaN\n" ); } return elapsed; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js index 28e31ba0efc9..3d91993f46e0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/lib/native.js @@ -47,27 +47,15 @@ var addon = require( './../src/addon.node' ); * // returns NaN * * @example -* var v = stdev( 10.3, 10, 4 ); +* var v = stdev( -2, 4, 2 ); * // returns NaN * * @example -* var v = stdev( 10, 5.5, 4 ); +* var v = stdev( 20, -2, 10 ); * // returns NaN * * @example -* var v = stdev( 10, 5, 4.5 ); -* // returns NaN -* -* @example -* var v = stdev( NaN, 10, 4 ); -* // returns NaN -* -* @example -* var v = stdev( 20, NaN, 4 ); -* // returns NaN -* -* @example -* var v = stdev( 20, 10, NaN ); +* var v = stdev( 40, 20, -2 ); * // returns NaN */ function stdev( N, K, n ) { diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c index 9d1737104ba4..6d2524e19650 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c @@ -34,10 +34,13 @@ * // returns ~0.829 */ double stdlib_base_dists_hypergeometric_stdev( const int32_t N, const int32_t K, const int32_t n ) { + double variance; + 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 variance = n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) ); + p = (double)K / (double)N; + variance = n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) ); return stdlib_base_sqrt( variance ); } From 1d9c995d7cbff76cdc834eab7e707528ed6fc8c8 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 28 Feb 2025 19:26:40 -0800 Subject: [PATCH 12/13] 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 --- --- .../base/dists/hypergeometric/stdev/benchmark/c/benchmark.c | 4 ++-- .../stats/base/dists/hypergeometric/stdev/manifest.json | 3 --- .../@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c index 7bf2ed405988..2fca54278b58 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/benchmark/c/benchmark.c @@ -93,10 +93,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 y; double t; int i; @@ -109,7 +109,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_dists_hypergeometric_stdev( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + y = stdlib_base_dists_hypergeometric_stdev( N[ i%100 ], K[ i%100 ], n[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json index a004cee4e823..4229e8aea358 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/manifest.json @@ -39,7 +39,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/ternary", - "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/sqrt" ] }, @@ -55,7 +54,6 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/ceil" ] @@ -72,7 +70,6 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/ceil" ] diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c index 6d2524e19650..5654180cb284 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c @@ -18,7 +18,6 @@ #include "stdlib/stats/base/dists/hypergeometric/stdev.h" #include "stdlib/math/base/special/sqrt.h" -#include "stdlib/constants/float64/pinf.h" #include /** @@ -37,7 +36,7 @@ double stdlib_base_dists_hypergeometric_stdev( const int32_t N, const int32_t K, double variance; 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 f862d4832235776a479f894ae64378ef017b0788 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 28 Feb 2025 19:39:00 -0800 Subject: [PATCH 13/13] 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/stdev/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c index 5654180cb284..41d0ce981fc2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/stdev/src/main.c @@ -40,6 +40,6 @@ double stdlib_base_dists_hypergeometric_stdev( const int32_t N, const int32_t K, return 0.0/0.0; // NaN } p = (double)K / (double)N; - variance = n * p * ( 1.0 - p ) * ( (double)(N-n) / (double)(N-1) ); + variance = n * p * ( 1.0-p ) * ( (double)(N-n)/(double)(N-1) ); return stdlib_base_sqrt( variance ); }