From e9091f3e4d5d5ee455e861bf7206bb44f1c2995b Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 03:06:45 -0800 Subject: [PATCH 01/13] feat: add the C src files --- .../base/dists/hypergeometric/skewness.h | 44 ++++++++++++ .../hypergeometric/skewness/src/Makefile | 70 +++++++++++++++++++ .../dists/hypergeometric/skewness/src/addon.c | 23 ++++++ .../dists/hypergeometric/skewness/src/main.c | 60 ++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h new file mode 100644 index 000000000000..6876f92f89d6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h @@ -0,0 +1,44 @@ +/** +* @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_SKEWNESS_H +#define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_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 skewness 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 skewness of the distribution + */ +double stdlib_base_dists_hypergeometric_skewness( const double N, const double K, const double n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_H + diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/addon.c new file mode 100644 index 000000000000..a22173133126 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_skewness ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c new file mode 100644 index 000000000000..2d76720a72ae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c @@ -0,0 +1,60 @@ +/** +* @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 skewness of a hypergeometric distribution. +* +* @param N population size +* @param K subpopulation size +* @param n number of draws +* @return skewness of the distribution, or NaN if inputs are invalid +* +* @example +* double skew = stdlib_base_dists_hypergeometric_skewness( 16, 11, 4 ); +* // returns ~-0.258 +* +* @example +* double skew = stdlib_base_dists_hypergeometric_skewness( 4, 2, 2 ); +* // returns 0.0 +* +* @example +* double skew = stdlib_base_dists_hypergeometric_skewness( 10, 5, 12 ); +* // returns NaN +*/ +double stdlib_base_dists_hypergeometric_skewness( 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 p = (N - (2 * K)) * stdlib_base_sqrt(N - 1) * (N - (2 * n)); + double q = stdlib_base_sqrt(n * K * (N - K) * (N - n)) * (N - 2); + + return p / q; +} From 4af88082bd4db6f6788586c38f5ec0505ad486f5 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 03:07:11 -0800 Subject: [PATCH 02/13] feat: add the C benchmark and example files --- .../skewness/benchmark/c/Makefile | 146 ++++++++++++++++++ .../skewness/benchmark/c/benchmark.c | 143 +++++++++++++++++ .../skewness/examples/c/Makefile | 146 ++++++++++++++++++ .../skewness/examples/c/example.c | 46 ++++++ 4 files changed, 481 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c new file mode 100644 index 000000000000..eb48d7e38f43 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness.h" +#include "stdlib/math/base/special/round.h" +#include +#include +#include +#include +#include + +#define NAME "hypergeometric-skewness" +#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 skew; + 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++ ) { + skew = stdlib_base_dists_hypergeometric_skewness( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + if ( skew != skew ) { // Check for NaN + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( skew != skew ) { + 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/skewness/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c new file mode 100644 index 000000000000..91dd825e4611 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness.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 skew; + 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)); + skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); + + printf( "N: %lf, K: %lf, n: %lf, Skewness: %lf\n", N, K, n, skew ); + } + + return 0; +} From 781b55b1df0a1882752605dde525361c249253e0 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 03:07:41 -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 --- --- .../skewness/benchmark/benchmark.native.js | 74 +++++++++ .../hypergeometric/skewness/lib/native.js | 80 +++++++++ .../skewness/test/test.native.js | 154 ++++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js new file mode 100644 index 000000000000..42f7c8e4db42 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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 round = require( '@stdlib/math/base/special/round' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var skewness = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( skewness 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 ] = round( ( randu() * 90.0 ) + 10.0 ); + K[ i ] = round( randu() * N[ i ] ); + n[ i ] = round( randu() * N[ i ] ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = skewness( 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/skewness/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/lib/native.js new file mode 100644 index 000000000000..0d4457d8b1de --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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 skewness 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} skewness +* +* @example +* var skew = skewness( 16, 11, 4 ); +* // returns ~-0.258 +* +* @example +* var skew = skewness( 4, 2, 2 ); +* // returns 0.0 +* +* @example +* var skew = skewness( 10, 5, 12 ); +* // returns NaN +* +* @example +* var skew = skewness( 10.3, 10, 4 ); +* // returns NaN +* +* @example +* var skew = skewness( 10, 5.5, 4 ); +* // returns NaN +* +* @example +* var skew = skewness( 10, 5, 4.5 ); +* // returns NaN +* +* @example +* var skew = skewness( NaN, 10, 4 ); +* // returns NaN +* +* @example +* var skew = skewness( 20, NaN, 4 ); +* // returns NaN +* +* @example +* var skew = skewness( 20, 10, NaN ); +* // returns NaN +*/ +function skewness( N, K, n ) { + return addon( N, K, n ); +} + + +// EXPORTS // + +module.exports = skewness; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js new file mode 100644 index 000000000000..cdccf5f01479 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); + + +// VARIABLES // + +var skewness = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( skewness 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 skewness, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var v = skewness( NaN, 10, 4 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = skewness( 20, NaN, 4 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = skewness( 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 = skewness( 10.5, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = skewness( -2, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = skewness( -1, 4, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = skewness( 20.5, 10, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = skewness( 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 = skewness( 20, 3.5, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 20, -2, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 20, -1, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 20, 2.5, 10 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 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 = skewness( 40, 20, 3.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 40, 20, -2 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 40, 20, -1 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 40, 20, 2.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = skewness( 40, 20, PINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the skewness 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 = skewness( 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 = 1.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 966c857bffa42d3f3baf680f4f519eff01d74386 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sun, 5 Jan 2025 03:08:31 -0800 Subject: [PATCH 04/13] build: added the json and gyp dependency files --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../dists/hypergeometric/skewness/binding.gyp | 149 ++++++++++++++++++ .../hypergeometric/skewness/include.gypi | 48 ++++++ .../hypergeometric/skewness/manifest.json | 84 ++++++++++ .../hypergeometric/skewness/package.json | 3 + 4 files changed, 284 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/binding.gyp new file mode 100644 index 000000000000..114dcb77c6aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include.gypi new file mode 100644 index 000000000000..235be47d6d3b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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 03:09:12 -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 --- --- .../dists/hypergeometric/skewness/README.md | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md index a8e2156e839f..aac86701c34a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md @@ -147,6 +147,108 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/hypergeometric/skewness.h" +``` + +#### stdlib_base_dists_hypergeometric_skewness( N, K, n ) + +Returns the skewness of a hypergeometric distribution. + +```c +double out = stdlib_base_dists_hypergeometric_skewness( 16, 11, 4 ); +// returns ~-0.258 +``` + +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_skewnes ( const double N, const double K, const double n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/hypergeometric/skewness.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 skew; + 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)); + skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); + + printf( "N: %lf, K: %lf, n: %lf, Skewness: %lf\n", N, K, n, skew ); + } + + return 0; +} +``` + +
+ + + +
+ + +
From 54de59cbb40226f09020527f6bc5007ecd29cb3f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 7 Jan 2025 23:50:38 -0800 Subject: [PATCH 06/13] refactor: fixed the formatting issues --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../dists/hypergeometric/skewness/README.md | 16 +- .../skewness/benchmark/c/benchmark.c | 22 +- .../dists/hypergeometric/skewness/binding.gyp | 267 ++++++++++-------- .../skewness/examples/c/example.c | 34 +-- .../hypergeometric/skewness/include.gypi | 53 ++-- .../base/dists/hypergeometric/skewness.h | 1 - .../dists/hypergeometric/skewness/src/main.c | 30 +- 7 files changed, 216 insertions(+), 207 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md index aac86701c34a..d46da4ae06b8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md @@ -211,30 +211,30 @@ double stdlib_base_dists_hypergeometric_skewnes ( const double N, const double K ### Examples ```c -#include "stdlib/stats/base/dists/hypergeometric/skewness.h" #include "stdlib/math/base/special/round.h" -#include +#include "stdlib/stats/base/dists/hypergeometric/skewness.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 skew; double N; double K; double n; - double skew; 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 ) ); skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, Skewness: %lf\n", N, K, n, skew ); + printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew ); } return 0; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c index eb48d7e38f43..0e155bf64fe7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c @@ -16,13 +16,13 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/skewness.h" +#include #include "stdlib/math/base/special/round.h" -#include -#include +#include "stdlib/stats/base/dists/hypergeometric/skewness.h" #include +#include +#include #include -#include #define NAME "hypergeometric-skewness" #define ITERATIONS 1000000 @@ -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(); @@ -129,7 +129,7 @@ int main( void ) { double elapsed; int i; - // Use the current time to seed the random number generator: + // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); @@ -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/skewness/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/binding.gyp index 114dcb77c6aa..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c index 91dd825e4611..9de3cda10096 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c @@ -16,31 +16,31 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/skewness.h" #include "stdlib/math/base/special/round.h" -#include +#include "stdlib/stats/base/dists/hypergeometric/skewness.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 skew; - int i; + double skew; + double N; + double K; + double 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)); - skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); + 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 ) ); + skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, Skewness: %lf\n", N, K, n, skew ); - } + printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew ); + } - return 0; + return 0; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include.gypi index 235be47d6d3b..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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 p = (N - (2 * K)) * stdlib_base_sqrt(N - 1) * (N - (2 * n)); - double q = stdlib_base_sqrt(n * K * (N - K) * (N - n)) * (N - 2); + double p = ( N - ( 2 * K ) ) * stdlib_base_sqrt( N - 1 ) * ( N - ( 2 * n ) ); + double q = stdlib_base_sqrt( n * K * ( N - K ) * ( N - n ) ) * ( N - 2 ); - return p / q; + return p / q; } From c642b469bbbe044f551d50e8d1bb43d2c894ca35 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Wed, 8 Jan 2025 19:41:02 -0800 Subject: [PATCH 07/13] refactor: fixed extra spaces and tabs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/dists/hypergeometric/skewness/README.md | 5 +---- .../dists/hypergeometric/skewness/benchmark/c/benchmark.c | 2 +- .../base/dists/hypergeometric/skewness/examples/c/example.c | 3 --- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md index d46da4ae06b8..99d681f5465d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md @@ -189,7 +189,7 @@ The function accepts the following arguments: - **n**: `[in] double` number of draws. ```c -double stdlib_base_dists_hypergeometric_skewnes ( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_skewness ( const double N, const double K, const double n ); ```
@@ -233,11 +233,8 @@ int main( void ) { K = stdlib_base_round( random_uniform( 0.0, N ) ); n = stdlib_base_round( random_uniform( 0.0, K ) ); skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew ); } - - return 0; } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c index 0e155bf64fe7..82233f40e726 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c @@ -129,7 +129,7 @@ int main( void ) { double elapsed; int i; - // Use the current time to seed the random number generator: + // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c index 9de3cda10096..da3abb4076a6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c @@ -38,9 +38,6 @@ int main( void ) { K = stdlib_base_round( random_uniform( 0.0, N ) ); n = stdlib_base_round( random_uniform( 0.0, K ) ); skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew ); } - - return 0; } From 0049f535cecb737568c48de819779d831d5d3bfe Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Thu, 9 Jan 2025 03:43:42 +0000 Subject: [PATCH 08/13] chore: update copyright years --- .../base/dists/hypergeometric/skewness/test/test.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js index cdccf5f01479..49f881304bc6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 3986824329987658d1685c2a33580a5773dbb264 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 10 Jan 2025 22:24:28 -0800 Subject: [PATCH 09/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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/dists/hypergeometric/skewness/README.md | 2 +- .../base/dists/hypergeometric/skewness/benchmark/c/benchmark.c | 2 +- .../@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md index 99d681f5465d..32d1b1e5b159 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md @@ -175,7 +175,7 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_hypergeometric_skewness( N, K, n ) -Returns the skewness of a hypergeometric distribution. +Returns the [skewness][skewness] 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_skewness( 16, 11, 4 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c index 82233f40e726..3c4302c8a939 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c @@ -16,13 +16,13 @@ * limitations under the License. */ -#include #include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/skewness.h" #include #include #include #include +#include #define NAME "hypergeometric-skewness" #define ITERATIONS 1000000 diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c index cfefa374b9d0..8f90758e7086 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c @@ -26,7 +26,7 @@ * @param N population size * @param K subpopulation size * @param n number of draws -* @return skewness of the distribution, or NaN if inputs are invalid +* @return skewness * * @example * double skew = stdlib_base_dists_hypergeometric_skewness( 16, 11, 4 ); From aebf8f8df1d3cd51afd3d2ab596616583aba2cb2 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 11 Jan 2025 00:23:16 -0800 Subject: [PATCH 10/13] refactor: fix indentation of comments in header file --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/dists/hypergeometric/skewness.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h index 77ff692f9fd9..d396fbc41c6b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h @@ -20,20 +20,20 @@ #define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_H /* - * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. - */ +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ #ifdef __cplusplus extern "C" { #endif /** - * Returns the skewness 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 skewness of the distribution - */ +* Returns the skewness 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 skewness of the distribution +*/ double stdlib_base_dists_hypergeometric_skewness( const double N, const double K, const double n ); #ifdef __cplusplus From 06cc693c7b9ce637b0c67199fe6d90c364fbe0a8 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Mon, 13 Jan 2025 20:30:10 -0800 Subject: [PATCH 11/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/skewness/benchmark/benchmark.js | 3 ++- .../hypergeometric/skewness/benchmark/benchmark.native.js | 3 ++- .../stats/base/dists/hypergeometric/skewness/src/main.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js index d650f1f175ff..d9030c48adaa 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js @@ -21,6 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); var randu = require( '@stdlib/random/base/randu' ); var ceil = require( '@stdlib/math/base/special/ceil' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -39,7 +40,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - N = ceil( randu()*100.0 ) + 10; + N = ceil( uniform( 10.0, 100.0 ) ); K = ceil( randu()*(N-1) ); n = ceil( randu()*(N-1) ); y = skewness( N, K, n ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js index 42f7c8e4db42..30b55e67bfd1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js @@ -23,6 +23,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -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 ] = round( ( randu() * 90.0 ) + 10.0 ); + N[ i ] = round( uniform( 10.0, 100.0 ) ); K[ i ] = round( randu() * N[ i ] ); n[ i ] = round( randu() * N[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c index 8f90758e7086..c3d33975366a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness.h" /** * Returns the skewness of a hypergeometric distribution. From 119efaebcd5613c0360742dfd8b06440480e7e0b Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 28 Jan 2025 23:55:59 -0800 Subject: [PATCH 12/13] fix: correct implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../dists/hypergeometric/skewness/README.md | 31 +++++++------- .../skewness/benchmark/benchmark.js | 21 ++++++---- .../skewness/benchmark/benchmark.native.js | 10 ++--- .../skewness/benchmark/c/benchmark.c | 26 ++++++------ .../skewness/examples/c/example.c | 23 ++++++----- .../base/dists/hypergeometric/skewness.h | 11 ++--- .../hypergeometric/skewness/lib/native.js | 34 ++++----------- .../hypergeometric/skewness/manifest.json | 9 ++-- .../dists/hypergeometric/skewness/src/addon.c | 4 +- .../dists/hypergeometric/skewness/src/main.c | 26 +++++++----- .../skewness/test/test.native.js | 41 ------------------- 11 files changed, 93 insertions(+), 143 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md index 32d1b1e5b159..d597722ed4fc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md @@ -184,12 +184,12 @@ double out = stdlib_base_dists_hypergeometric_skewness( 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_skewness ( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_skewness ( const int32_t N, const int32_t K, const int32_t n ); ``` @@ -211,10 +211,11 @@ double stdlib_base_dists_hypergeometric_skewness ( const double N, const double ### Examples ```c -#include "stdlib/math/base/special/round.h" #include "stdlib/stats/base/dists/hypergeometric/skewness.h" -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); @@ -222,18 +223,18 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double skew; - double N; - double K; - double n; + int32_t N; + int32_t K; + int32_t n; + double y; 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 ) ); - skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew ); + N = stdlib_base_ceil( random_uniform( 10.0, 100.0 ) ); + K = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) ); + n = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) ); + y = stdlib_base_dists_hypergeometric_skewness( N, K, n ); + printf( "N: %d, K: %d, n: %d, skew(X;N,K,n): %lf\n", N, K, n, y ); } } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js index d9030c48adaa..c637da68d058 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js @@ -21,9 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var randu = require( '@stdlib/random/base/randu' ); -var ceil = require( '@stdlib/math/base/special/ceil' ); +var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var skewness = require( './../lib' ); @@ -32,18 +31,26 @@ var skewness = 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( 10, 100 ); + K[ i ] = discreteUniform( 1, N[ i ] - 1 ); + n[ i ] = discreteUniform( 1, N[ i ] - 1 ); + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - N = ceil( uniform( 10.0, 100.0 ) ); - K = ceil( randu()*(N-1) ); - n = ceil( randu()*(N-1) ); - y = skewness( N, K, n ); + y = skewness( 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/skewness/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js index 30b55e67bfd1..85dc6266f039 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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 uniform = require( '@stdlib/random/base/uniform' ); -var randu = require( '@stdlib/random/base/randu' ); +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 round = require( '@stdlib/math/base/special/round' ); 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 ] = round( uniform( 10.0, 100.0 ) ); - K[ i ] = round( randu() * N[ i ] ); - n[ i ] = round( randu() * N[ i ] ); + N[ i ] = discreteUniform( 10, 100 ); + K[ i ] = discreteUniform( 1, N[ i ] - 1 ); + n[ i ] = discreteUniform( 1, N[ i ] - 1 ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c index 3c4302c8a939..503e1d8d57aa 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness.h" -#include -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include #include #include @@ -94,29 +94,29 @@ 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 ]; - double skew; + int32_t N[ 100 ]; + int32_t K[ 100 ]; + int32_t n[ 100 ]; + double y; 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( 10.0, 100.0 ) ); + K[ i ] = stdlib_base_ceil( random_uniform( 0.0, N[ i ] - 1 ) ); + n[ i ] = stdlib_base_ceil( random_uniform( 0.0, N[ i ] - 1 ) ); } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - skew = stdlib_base_dists_hypergeometric_skewness( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); - if ( skew != skew ) { // Check for NaN + y = stdlib_base_dists_hypergeometric_skewness( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + if ( y != y ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( skew != skew ) { + if ( y != y ) { printf( "should not return NaN\n" ); } return elapsed; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c index da3abb4076a6..446b6f238362 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/skewness.h" -#include +#include "stdlib/math/base/special/ceil.h" #include +#include +#include static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); @@ -27,17 +28,17 @@ static double random_uniform( const double min, const double max ) { } int main( void ) { - double skew; - double N; - double K; - double n; + int32_t N; + int32_t K; + int32_t n; + double y; 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 ) ); - skew = stdlib_base_dists_hypergeometric_skewness( N, K, n ); - printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew ); + N = stdlib_base_ceil( random_uniform( 10.0, 100.0 ) ); + K = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) ); + n = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) ); + y = stdlib_base_dists_hypergeometric_skewness( N, K, n ); + printf( "N: %d, K: %d, n: %d, skew(X;N,K,n): %lf\n", N, K, n, y ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h index d396fbc41c6b..62902bd04eb2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h @@ -19,6 +19,8 @@ #ifndef STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_H #define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_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 skewness 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 skewness of the distribution +* Returns the skewness of a hypergeometric distribution. */ -double stdlib_base_dists_hypergeometric_skewness( const double N, const double K, const double n ); +double stdlib_base_dists_hypergeometric_skewness( 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/skewness/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/lib/native.js index 0d4457d8b1de..9e6d3aae8bd8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/lib/native.js @@ -26,48 +26,32 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Returns the skewness of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`. +* Returns the skewness of a hypergeometric distribution. * * @private -* @param {number} N - population size -* @param {number} K - subpopulation size -* @param {number} n - number of draws +* @param {NonNegativeInteger} N - population size +* @param {NonNegativeInteger} K - subpopulation size +* @param {NonNegativeInteger} n - number of draws * @returns {number} skewness * * @example -* var skew = skewness( 16, 11, 4 ); +* var v = skewness( 16, 11, 4 ); * // returns ~-0.258 * * @example -* var skew = skewness( 4, 2, 2 ); +* var v = skewness( 4, 2, 2 ); * // returns 0.0 * * @example -* var skew = skewness( 10, 5, 12 ); +* var v = skewness( 10, 5, 12 ); * // returns NaN * * @example -* var skew = skewness( 10.3, 10, 4 ); +* var v = skewness( 20, -2, 10 ); * // returns NaN * * @example -* var skew = skewness( 10, 5.5, 4 ); -* // returns NaN -* -* @example -* var skew = skewness( 10, 5, 4.5 ); -* // returns NaN -* -* @example -* var skew = skewness( NaN, 10, 4 ); -* // returns NaN -* -* @example -* var skew = skewness( 20, NaN, 4 ); -* // returns NaN -* -* @example -* var skew = skewness( 20, 10, NaN ); +* var v = skewness( -2, 4, 2 ); * // returns NaN */ function skewness( N, K, n ) { diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json index ff98a80b234d..a41550fa9a44 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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/math/base/special/sqrt", "@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/skewness/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/addon.c index a22173133126..b3ec787738e9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/addon.c @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/math/base/napi/ternary.h" #include "stdlib/stats/base/dists/hypergeometric/skewness.h" +#include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_skewness ) +STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_skewness ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c index c3d33975366a..d5094b062da4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c @@ -16,10 +16,9 @@ * 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/skewness.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/constants/float64/pinf.h" /** * Returns the skewness of a hypergeometric distribution. @@ -33,13 +32,20 @@ * double skew = stdlib_base_dists_hypergeometric_skewness( 16, 11, 4 ); * // returns ~-0.258 */ -double stdlib_base_dists_hypergeometric_skewness( 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 p = ( N - ( 2 * K ) ) * stdlib_base_sqrt( N - 1 ) * ( N - ( 2 * n ) ); - double q = stdlib_base_sqrt( n * K * ( N - K ) * ( N - n ) ) * ( N - 2 ); +double stdlib_base_dists_hypergeometric_skewness( const int32_t N, const int32_t K, const int32_t n ) { + double N_d; + double K_d; + double n_d; + double p; + double q; + 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 + } + N_d = (double)N; + K_d = (double)K; + n_d = (double)n; + p = ( N_d - ( 2.0 * K_d ) ) * stdlib_base_sqrt( N_d - 1.0 ) * ( N_d - ( 2.0 * n_d ) ); + q = stdlib_base_sqrt( n_d * K_d * ( N_d - K_d ) * ( N_d - n_d ) ) * ( N_d - 2.0 ); return p / q; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js index 49f881304bc6..a7e44cfd484d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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`', function test( t ) { - var v = skewness( NaN, 10, 4 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = skewness( 20, NaN, 4 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = skewness( 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 = skewness( 10.5, 4, 2 ); - t.equal( isnan( v ), true, 'returns NaN' ); - v = skewness( -2, 4, 2 ); t.equal( isnan( v ), true, 'returns NaN' ); v = skewness( -1, 4, 2 ); t.equal( isnan( v ), true, 'returns NaN' ); - v = skewness( 20.5, 10, 5 ); - t.equal( isnan( v ), true, 'returns NaN' ); - - v = skewness( 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 = skewness( 20, 3.5, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = skewness( 20, -2, 10 ); t.equal( isnan( y ), true, 'returns NaN' ); y = skewness( 20, -1, 10 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = skewness( 20, 2.5, 10 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = skewness( 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 = skewness( 40, 20, 3.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = skewness( 40, 20, -2 ); t.equal( isnan( y ), true, 'returns NaN' ); y = skewness( 40, 20, -1 ); t.equal( isnan( y ), true, 'returns NaN' ); - y = skewness( 40, 20, 2.5 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = skewness( 40, 20, PINF ); - t.equal( isnan( y ), true, 'returns NaN' ); - t.end(); }); From 3f04604e12297121e54c8c93019893bfaddb536e Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 28 Feb 2025 19:45:08 -0800 Subject: [PATCH 13/13] chore: apply suggestions from review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: 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: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/dists/hypergeometric/skewness/README.md | 2 +- .../dists/hypergeometric/skewness/benchmark/c/benchmark.c | 4 ++-- .../base/dists/hypergeometric/skewness/manifest.json | 3 --- .../stats/base/dists/hypergeometric/skewness/src/main.c | 8 ++++---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md index d597722ed4fc..948041b5040e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/README.md @@ -189,7 +189,7 @@ The function accepts the following arguments: - **n**: `[in] int32_t` number of draws. ```c -double stdlib_base_dists_hypergeometric_skewness ( const int32_t N, const int32_t K, const int32_t n ); +double stdlib_base_dists_hypergeometric_skewness( const int32_t N, const int32_t K, const int32_t n ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c index 503e1d8d57aa..52843844ef88 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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_skewness( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + y = stdlib_base_dists_hypergeometric_skewness( 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/skewness/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json index a41550fa9a44..4229e8aea358 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/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" ] @@ -73,7 +71,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/special/sqrt", - "@stdlib/constants/float64/pinf", "@stdlib/math/base/special/ceil" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c index d5094b062da4..88c3416a1406 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c @@ -18,7 +18,7 @@ #include "stdlib/stats/base/dists/hypergeometric/skewness.h" #include "stdlib/math/base/special/sqrt.h" -#include "stdlib/constants/float64/pinf.h" +#include /** * Returns the skewness of a hypergeometric distribution. @@ -39,13 +39,13 @@ double stdlib_base_dists_hypergeometric_skewness( const int32_t N, const int32_t double p; double q; - 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 } N_d = (double)N; K_d = (double)K; n_d = (double)n; - p = ( N_d - ( 2.0 * K_d ) ) * stdlib_base_sqrt( N_d - 1.0 ) * ( N_d - ( 2.0 * n_d ) ); - q = stdlib_base_sqrt( n_d * K_d * ( N_d - K_d ) * ( N_d - n_d ) ) * ( N_d - 2.0 ); + p = ( N_d - ( 2.0*K_d ) ) * stdlib_base_sqrt( N_d-1.0 ) * ( N_d - ( 2.0*n_d ) ); + q = stdlib_base_sqrt( n_d * K_d * ( N_d-K_d ) * ( N_d-n_d ) ) * ( N_d-2.0 ); return p / q; }