From 4a2e3947ff1ee925239db6ef860a12b135de54e0 Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Sun, 15 Dec 2024 21:35:52 +0530
Subject: [PATCH 1/9] feat: add C implementation for binomial Variance
---
.../base/dists/binomial/variance/README.md | 93 ++++++++++
.../binomial/variance/benchmark/benchmark.js | 20 ++-
.../variance/benchmark/benchmark.native.js | 71 ++++++++
.../binomial/variance/benchmark/c/Makefile | 146 +++++++++++++++
.../binomial/variance/benchmark/c/benchmark.c | 140 +++++++++++++++
.../base/dists/binomial/variance/binding.gyp | 170 ++++++++++++++++++
.../binomial/variance/examples/c/Makefile | 146 +++++++++++++++
.../binomial/variance/examples/c/example.c | 42 +++++
.../base/dists/binomial/variance/include.gypi | 53 ++++++
.../stats/base/dists/binomial/variance.h | 38 ++++
.../dists/binomial/variance/lib/native.js | 74 ++++++++
.../dists/binomial/variance/manifest.json | 76 ++++++++
.../base/dists/binomial/variance/package.json | 3 +
.../base/dists/binomial/variance/src/Makefile | 70 ++++++++
.../base/dists/binomial/variance/src/addon.c | 23 +++
.../base/dists/binomial/variance/src/main.c | 44 +++++
.../binomial/variance/test/test.native.js | 109 +++++++++++
17 files changed, 1312 insertions(+), 6 deletions(-)
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include/stdlib/stats/base/dists/binomial/variance.h
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/lib/native.js
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/Makefile
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/addon.c
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
create mode 100644 lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
index 5aefba7068f3..6159c8f38ceb 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
@@ -141,6 +141,99 @@ for ( i = 0; i < 10; i++ ) {
+
+
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/stats/base/dists/binomial/variance.h"
+```
+
+#### stdlib_base_dists_binomial_variance( n, p )
+
+Returns the variance of a binomial distribution.
+
+```c
+double out = stdlib_base_dists_binomial_variance( 10, 0.5 );
+// returns 2.5
+```
+
+The function accepts the following arguments:
+
+- **n**: `[in] int` number of trials.
+- **p**: `[in] double` success probability.
+
+```c
+double stdlib_base_dists_binomial_variance( const int n, const double p );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/stats/base/dists/binomial/variance.h"
+#include
+#include
+
+static double random_uniform( const double min, const double max ) {
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
+ return min + ( v * ( max - min ) );
+}
+
+int main( void ) {
+ int n;
+ double p;
+ double y;
+ int i;
+
+ for ( i = 0; i < 25; i++ ) {
+ n = (int)random_uniform( 1, 100 );
+ p = random_uniform( 0, 1 );
+ y = stdlib_base_dists_binomial_variance( n, p );
+ printf( "n: %d, p: %lf, Var(X;n,p): %lf", n, p, y );
+ }
+}
+```
+
+
+
+
+
+
+
+
+
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
index b2a911db5609..10bc15e6bcf0 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
@@ -21,26 +21,34 @@
// MODULES //
var bench = require( '@stdlib/bench' );
-var ceil = require( '@stdlib/math/base/special/ceil' );
+var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
+var floor = require( '@stdlib/math/base/special/floor' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
-var pkg = require( './../package.json' ).name;
-var variance = require( './../lib' );
+var pkg = require( '@stdlib/stats/base/dists/binomial/median/package.json' ).name;
+var variance = require( '@stdlib/stats/base/dists/binomial/median/lib' );
// MAIN //
bench( pkg, function benchmark( b ) {
+ var len;
var n;
var p;
var y;
var i;
+ len = 100;
+ n = new Float64Array( len );
+ p = new Float64Array( len );
+ for ( i = 0; i < len; i++ ) {
+ n[ i ] = floor( ( randu() * 100.0 ) ) + 1;
+ p[ i ] = ( randu() * 0.8 ) + 0.1;
+ }
+
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
- n = ceil( randu()*100.0 );
- p = randu();
- y = variance( n, p );
+ y = variance( n[ i % len ], p[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
new file mode 100644
index 000000000000..31cee1575f7f
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
@@ -0,0 +1,71 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2024 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 tryRequire = require( '@stdlib/utils/try-require' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pkg = require( '@stdlib/stats/base/dists/binomial/median/package.json' ).name;
+
+
+// VARIABLES //
+
+var variance = tryRequire( resolve( __dirname, './../lib/native.js' ) );
+var opts = {
+ 'skip': ( variance instanceof Error )
+};
+
+
+// MAIN //
+
+bench( pkg+'::native', opts, function benchmark( b ) {
+ var len;
+ var n;
+ var p;
+ var y;
+ var i;
+
+ len = 100;
+ n = new Float64Array( len );
+ p = new Float64Array( len );
+ for ( i = 0; i < len; i++ ) {
+ n[ i ] = floor( ( randu() * 100.0 ) ) + 1;
+ p[ i ] = ( randu() * 0.8 ) + 0.1;
+ }
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = variance( n[ i % len ], p[ 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/binomial/variance/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile
new file mode 100644
index 000000000000..f69e9da2b4d3
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile
@@ -0,0 +1,146 @@
+#/
+# @license Apache-2.0
+#
+# Copyright (c) 2024 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/binomial/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
new file mode 100644
index 000000000000..48fc990b71c3
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
@@ -0,0 +1,140 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2024 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/binomial/variance.h"
+#include
+#include
+#include
+#include
+#include
+
+#define NAME "binomial-variance"
+#define ITERATIONS 1000000
+#define REPEATS 3
+
+/**
+* Prints the TAP version.
+*/
+static void print_version( void ) {
+ printf( "TAP version 13\n" );
+}
+
+/**
+* Prints the TAP summary.
+*
+* @param total total number of tests
+* @param passing total number of passing tests
+*/
+static void print_summary( int total, int passing ) {
+ printf( "#\n" );
+ printf( "1..%d\n", total ); // TAP plan
+ printf( "# total %d\n", total );
+ printf( "# pass %d\n", passing );
+ printf( "#\n" );
+ printf( "# ok\n" );
+}
+
+/**
+* Prints benchmarks results.
+*
+* @param elapsed elapsed time in seconds
+*/
+static void print_results( double elapsed ) {
+ double rate = (double)ITERATIONS / elapsed;
+ printf( " ---\n" );
+ printf( " iterations: %d\n", ITERATIONS );
+ printf( " elapsed: %0.9f\n", elapsed );
+ printf( " rate: %0.9f\n", rate );
+ printf( " ...\n" );
+}
+
+/**
+* Returns a clock time.
+*
+* @return clock time
+*/
+static double tic( void ) {
+ struct timeval now;
+ gettimeofday( &now, NULL );
+ return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
+}
+
+/**
+* Generates a random 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 p[ 100 ];
+ double y;
+ double t;
+ int i;
+
+ for ( i = 0; i < 100; i++ ) {
+ n[ i ] = random_uniform( 1, 100 );
+ p[ i ] = random_uniform( 0.1, 0.9 );
+ }
+
+ t = tic();
+ for ( i = 0; i < ITERATIONS; i++ ) {
+ y = stdlib_base_dists_binomial_variance( n[ i % 100 ], p[ i % 100 ] );
+ if ( y != y ) {
+ printf( "should not return NaN\n" );
+ break;
+ }
+ }
+ elapsed = tic() - t;
+ if ( y != y ) {
+ printf( "should not return NaN\n" );
+ }
+ return elapsed;
+}
+
+/**
+* Main execution sequence.
+*/
+int main( void ) {
+ double elapsed;
+ int i;
+
+ // 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/binomial/variance/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
new file mode 100644
index 000000000000..507cb00291e7
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
@@ -0,0 +1,170 @@
+# @license Apache-2.0
+#
+# Copyright (c) 2024 The Stdlib Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A `.gyp` file for building a Node.js native add-on.
+#
+# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
+# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
+{
+ # List of files to include in this file:
+ 'includes': [
+ './include.gypi',
+ ],
+
+ # Define variables to be used throughout the configuration for all targets:
+ 'variables': {
+ # Target name should match the add-on export name:
+ 'addon_target_name%': 'addon',
+
+ # Set variables based on the host OS:
+ 'conditions': [
+ [
+ 'OS=="win"',
+ {
+ # Define the object file suffix:
+ 'obj': 'obj',
+ },
+ {
+ # Define the object file suffix:
+ 'obj': 'o',
+ }
+ ], # end condition (OS=="win")
+ ], # end conditions
+ }, # end variables
+
+ # Define compile targets:
+ 'targets': [
+
+ # Target to generate an add-on:
+ {
+ # The target name should match the add-on export name:
+ 'target_name': '<(addon_target_name)',
+
+ # Define dependencies:
+ 'dependencies': [],
+
+ # Define directories which contain relevant include headers:
+ 'include_dirs': [
+ # Local include directory:
+ '<@(include_dirs)',
+ ],
+
+ # List of source files:
+ 'sources': [
+ '<@(src_files)',
+ ],
+
+ # Settings which should be applied when a target's object files are used as linker input:
+ 'link_settings': {
+ # Define libraries:
+ 'libraries': [
+ '<@(libraries)',
+ ],
+
+ # Define library directories:
+ 'library_dirs': [
+ '<@(library_dirs)',
+ ],
+ },
+
+ # C/C++ compiler flags:
+ 'cflags': [
+ # Enable commonly used warning options:
+ '-Wall',
+
+ # Aggressive optimization:
+ '-O3',
+ ],
+
+ # C specific compiler flags:
+ 'cflags_c': [
+ # Specify the C standard to which a program is expected to conform:
+ '-std=c99',
+ ],
+
+ # C++ specific compiler flags:
+ 'cflags_cpp': [
+ # Specify the C++ standard to which a program is expected to conform:
+ '-std=c++11',
+ ],
+
+ # Linker flags:
+ 'ldflags': [],
+
+ # Apply conditions based on the host OS:
+ 'conditions': [
+ [
+ 'OS=="mac"',
+ {
+ # Linker flags:
+ 'ldflags': [
+ '-undefined dynamic_lookup',
+ '-Wl,-no-pie',
+ '-Wl,-search_paths_first',
+ ],
+ },
+ ], # end condition (OS=="mac")
+ [
+ 'OS!="win"',
+ {
+ # C/C++ flags:
+ 'cflags': [
+ # Generate platform-independent code:
+ '-fPIC',
+ ],
+ },
+ ], # end condition (OS!="win")
+ ], # end conditions
+ }, # end target <(addon_target_name)
+
+ # Target to copy a generated add-on to a standard location:
+ {
+ 'target_name': 'copy_addon',
+
+ # Declare that the output of this target is not linked:
+ 'type': 'none',
+
+ # Define dependencies:
+ 'dependencies': [
+ # Require that the add-on be generated before building this target:
+ '<(addon_target_name)',
+ ],
+
+ # Define a list of actions:
+ 'actions': [
+ {
+ 'action_name': 'copy_addon',
+ 'message': 'Copying addon...',
+
+ # Explicitly list the inputs in the command-line invocation below:
+ 'inputs': [],
+
+ # Declare the expected outputs:
+ 'outputs': [
+ '<(addon_output_dir)/<(addon_target_name).node',
+ ],
+
+ # Define the command-line invocation:
+ 'action': [
+ 'cp',
+ '<(PRODUCT_DIR)/<(addon_target_name).node',
+ '<(addon_output_dir)/<(addon_target_name).node',
+ ],
+ },
+ ], # end actions
+ }, # end target copy_addon
+ ], # end targets
+}
\ No newline at end of file
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
new file mode 100644
index 000000000000..d53ef397c77d
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
@@ -0,0 +1,146 @@
+#/
+# @license Apache-2.0
+#
+# Copyright (c) 2024 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
\ No newline at end of file
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c
new file mode 100644
index 000000000000..ddb30cdb70a0
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c
@@ -0,0 +1,42 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2024 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/binomial/variance.h"
+#include
+#include
+
+static double random_uniform( const double min, const double max ) {
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
+ return min + ( v * (max - min) );
+}
+
+int main( void ) {
+ double n;
+ double p;
+ double y;
+ int i;
+
+ for ( i = 0; i < 25; i++ ) {
+ n = random_uniform( 1, 100 );
+ p = random_uniform( 0.1, 0.9 );
+ y = stdlib_base_dists_binomial_variance( n, p );
+ printf( "n: %lf, p: %lf, Var(X;n,p): %lf\n", n, p, y );
+ }
+
+ return 0;
+}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
new file mode 100644
index 000000000000..c6495fc1da3f
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
@@ -0,0 +1,53 @@
+# @license Apache-2.0
+#
+# Copyright (c) 2024 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': [
+ ' 1.0
+ ) {
+ return 0.0 / 0.0;
+ }
+ return n * p * (1.0 - p);
+}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
new file mode 100644
index 000000000000..63fbf2178931
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
@@ -0,0 +1,109 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2024 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 EPS = require( '@stdlib/constants/float64/eps' );
+
+
+// VARIABLES //
+
+var variance = tryRequire( resolve( __dirname, './../lib/native.js' ) );
+var opts = {
+ 'skip': ( variance instanceof Error )
+};
+
+
+// FIXTURES //
+
+var data = require( './fixtures/julia/data.json' );
+
+
+// TESTS //
+
+tape( 'main export is a function', opts, function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof variance, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
+ var v = variance( NaN, 0.5 );
+ t.equal( isnan( v ), true, 'returns NaN' );
+
+ v = variance( 10.0, NaN );
+ t.equal( isnan( v ), true, 'returns NaN' );
+
+ t.end();
+});
+
+tape( 'if provided `n < 0`, the function returns `NaN`', opts, function test( t ) {
+ var y;
+
+ y = variance( -1, 0.5 );
+ t.equal( isnan( y ), true, 'returns NaN' );
+
+ y = variance( NaN, 0.5 );
+ t.equal( isnan( y ), true, 'returns NaN' );
+
+ t.end();
+});
+
+tape( 'if provided `p < 0` or `p > 1`, the function returns `NaN`', opts, function test( t ) {
+ var y;
+
+ y = variance( 10, -0.1 );
+ t.equal( isnan( y ), true, 'returns NaN' );
+
+ y = variance( 10, 1.1 );
+ t.equal( isnan( y ), true, 'returns NaN' );
+
+ t.end();
+});
+
+tape( 'the function returns the variance of a binomial distribution', opts, function test( t ) {
+ var expected;
+ var delta;
+ var tol;
+ var n;
+ var p;
+ var i;
+ var y;
+
+ expected = data.expected;
+ n = data.n;
+ p = data.p;
+ for ( i = 0; i < expected.length; i++ ) {
+ y = variance( n[i], p[i] );
+ if ( y === expected[i] ) {
+ t.equal( y, expected[i], 'n: '+n[i]+', p: '+p[i]+', y: '+y+', expected: '+expected[i] );
+ } else {
+ delta = abs( y - expected[ i ] );
+ tol = 2.0 * EPS * abs( expected[ i ] );
+ t.ok( delta <= tol, 'within tolerance. n: '+n[i]+'. p: '+p[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
+ }
+ }
+ t.end();
+});
From b7b6fc933bbf23f13a39b2ce0e2435ddcd9199d7 Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Sun, 15 Dec 2024 21:57:28 +0530
Subject: [PATCH 2/9] fix: updated license copyright year
---
.../stats/base/dists/binomial/variance/benchmark/benchmark.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
index 10bc15e6bcf0..ba5ac1258117 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2018 The Stdlib Authors.
+* Copyright (c) 2024 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 909a758936074dc5093a4db4e55a4efdab277819 Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Thu, 19 Dec 2024 11:21:15 +0530
Subject: [PATCH 3/9] fix: added tab indentation in files
---
.../binomial/variance/benchmark/c/benchmark.c | 12 ++++-----
.../base/dists/binomial/variance/src/main.c | 26 +++++++++----------
2 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
index 48fc990b71c3..a32e095590c2 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
@@ -37,8 +37,8 @@ static void print_version( void ) {
/**
* Prints the TAP summary.
*
-* @param total total number of tests
-* @param passing total number of passing tests
+* @param total total number of tests
+* @param passing total number of passing tests
*/
static void print_summary( int total, int passing ) {
printf( "#\n" );
@@ -52,7 +52,7 @@ static void print_summary( int total, int passing ) {
/**
* Prints benchmarks results.
*
-* @param elapsed elapsed time in seconds
+* @param elapsed elapsed time in seconds
*/
static void print_results( double elapsed ) {
double rate = (double)ITERATIONS / elapsed;
@@ -77,9 +77,9 @@ static double tic( void ) {
/**
* Generates a random number on the interval [min,max).
*
-* @param min minimum value (inclusive)
-* @param max maximum value (exclusive)
-* @return random number
+* @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 );
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
index 68975b06511b..28191ef24fb8 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
@@ -22,23 +22,23 @@
/**
* Returns the variance of a binomial distribution.
*
-* @param n number of trials
-* @param p success probability
-* @return variance
+* @param n number of trials
+* @param p success probability
+* @return variance
*
* @example
* double y = stdlib_base_dists_binomial_variance( 10, 0.5 );
* // returns 2.5
*/
double stdlib_base_dists_binomial_variance( const double n, const double p ) {
- if (
- stdlib_base_is_nan( n ) ||
- stdlib_base_is_nan( p ) ||
- n < 0.0 ||
- p < 0.0 ||
- p > 1.0
- ) {
- return 0.0 / 0.0;
- }
- return n * p * (1.0 - p);
+ if (
+ stdlib_base_is_nan( n ) ||
+ stdlib_base_is_nan( p ) ||
+ n < 0.0 ||
+ p < 0.0 ||
+ p > 1.0
+ ) {
+ return 0.0 / 0.0;
+ }
+ return n * p * (1.0 - p);
}
From 7500facc94c63835aa5e09d1491c5452c0b639b8 Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Fri, 20 Dec 2024 11:25:54 +0530
Subject: [PATCH 4/9] fix: resolves issues as per given review
---
.../binomial/variance/benchmark/benchmark.js | 6 ++--
.../variance/benchmark/benchmark.native.js | 2 +-
.../base/dists/binomial/variance/binding.gyp | 2 +-
.../binomial/variance/examples/c/Makefile | 2 +-
.../base/dists/binomial/variance/include.gypi | 2 +-
.../dists/binomial/variance/lib/native.js | 28 ++++++-------------
.../dists/binomial/variance/manifest.json | 2 +-
.../base/dists/binomial/variance/src/Makefile | 2 +-
.../base/dists/binomial/variance/src/main.c | 6 ++--
9 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
index ba5ac1258117..729dbd9d2560 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 The Stdlib Authors.
+* 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.
@@ -25,8 +25,8 @@ var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
-var pkg = require( '@stdlib/stats/base/dists/binomial/median/package.json' ).name;
-var variance = require( '@stdlib/stats/base/dists/binomial/median/lib' );
+var pkg = require( './../package.json' ).name;
+var variance = require( './../lib' );
// MAIN //
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
index 31cee1575f7f..d2e1b23fcde2 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
@@ -27,7 +27,7 @@ var tryRequire = require( '@stdlib/utils/try-require' );
var floor = require( '@stdlib/math/base/special/floor' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
-var pkg = require( '@stdlib/stats/base/dists/binomial/median/package.json' ).name;
+var pkg = require( './../package.json' ).name;
// VARIABLES //
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
index 507cb00291e7..ec3992233442 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
@@ -167,4 +167,4 @@
], # end actions
}, # end target copy_addon
], # end targets
-}
\ No newline at end of file
+}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
index d53ef397c77d..6aed70daf167 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
@@ -143,4 +143,4 @@ run: $(c_targets)
clean:
$(QUIET) -rm -f *.o *.out
-.PHONY: clean
\ No newline at end of file
+.PHONY: clean
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
index c6495fc1da3f..575cb043c0bf 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
@@ -50,4 +50,4 @@
'
Date: Fri, 20 Dec 2024 11:48:31 +0530
Subject: [PATCH 5/9] chore: added extra tests and conditions
---
.../base/dists/binomial/variance/manifest.json | 9 ++++++---
.../base/dists/binomial/variance/src/main.c | 4 +++-
.../binomial/variance/test/test.native.js | 18 ++++++++++++------
3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
index db80b71a4aa4..7f1a3a58ea0a 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
@@ -39,7 +39,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/binary",
- "@stdlib/math/base/assert/is-nan"
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
@@ -54,7 +55,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nan"
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
@@ -69,7 +71,8 @@
"libraries": [],
"libpath": [],
"dependencies": [
- "@stdlib/math/base/assert/is-nan"
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-nonnegative-integer"
]
}
]
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
index b6165a30f842..392eb753a63f 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
@@ -18,6 +18,7 @@
#include "stdlib/stats/base/dists/binomial/variance.h"
#include "stdlib/math/base/assert/is_nan.h"
+#include "stdlib/math/base/assert/is_nonnegative_integer.h"
/**
* Returns the variance of a binomial distribution.
@@ -36,7 +37,8 @@ double stdlib_base_dists_binomial_variance( const double n, const double p ) {
stdlib_base_is_nan( p ) ||
n < 0.0 ||
p < 0.0 ||
- p > 1.0
+ p > 1.0 ||
+ !stdlib_base_is_nonnegative_integer( n )
) {
return 0.0 / 0.0;
}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
index 63fbf2178931..a9b37fd7c16c 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
@@ -59,14 +59,20 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
t.end();
});
-tape( 'if provided `n < 0`, the function returns `NaN`', opts, function test( t ) {
- var y;
+tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', function test( t ) {
+ var v;
- y = variance( -1, 0.5 );
- t.equal( isnan( y ), true, 'returns NaN' );
+ v = variance( 1.5, 0.5 );
+ t.equal( isnan( v ), true, 'returns NaN' );
- y = variance( NaN, 0.5 );
- t.equal( isnan( y ), true, 'returns NaN' );
+ v = variance( -2, 0.5 );
+ t.equal( isnan( v ), true, 'returns NaN' );
+
+ v = variance( -1, 0.5 );
+ t.equal( isnan( v ), true, 'returns NaN' );
+
+ v = variance( 2.5, 0.5 );
+ t.equal( isnan( v ), true, 'returns NaN' );
t.end();
});
From a5c199361b3ec0e064a4ea91f4ba557c6d6cd1ab Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Fri, 20 Dec 2024 11:55:30 +0530
Subject: [PATCH 6/9] docs: use spaces instead of tabs
---
.../dists/binomial/variance/benchmark/c/benchmark.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
index a32e095590c2..001c41325bec 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
@@ -37,8 +37,8 @@ static void print_version( void ) {
/**
* Prints the TAP summary.
*
-* @param total total number of tests
-* @param passing total number of passing tests
+* @param total total number of tests
+* @param passing total number of passing tests
*/
static void print_summary( int total, int passing ) {
printf( "#\n" );
@@ -52,7 +52,7 @@ static void print_summary( int total, int passing ) {
/**
* Prints benchmarks results.
*
-* @param elapsed elapsed time in seconds
+* @param elapsed elapsed time in seconds
*/
static void print_results( double elapsed ) {
double rate = (double)ITERATIONS / elapsed;
@@ -77,9 +77,9 @@ static double tic( void ) {
/**
* Generates a random number on the interval [min,max).
*
-* @param min minimum value (inclusive)
-* @param max maximum value (exclusive)
-* @return random number
+* @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 );
From ca035dd8c8d52030893110d4f6de4462c00edebe Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Mon, 6 Jan 2025 18:02:37 +0530
Subject: [PATCH 7/9] feat: added new implementation and other minor updates
---
.../base/dists/binomial/variance/README.md | 24 +++++++++++--------
.../binomial/variance/benchmark/benchmark.js | 11 +++++----
.../variance/benchmark/benchmark.native.js | 11 +++++----
.../binomial/variance/benchmark/c/Makefile | 2 +-
.../binomial/variance/benchmark/c/benchmark.c | 10 ++++----
.../base/dists/binomial/variance/binding.gyp | 2 +-
.../binomial/variance/examples/c/Makefile | 2 +-
.../binomial/variance/examples/c/example.c | 12 ++++++----
.../base/dists/binomial/variance/include.gypi | 2 +-
.../stats/base/dists/binomial/variance.h | 8 ++++---
.../dists/binomial/variance/lib/native.js | 7 ++----
.../dists/binomial/variance/manifest.json | 9 ++++---
.../base/dists/binomial/variance/src/Makefile | 2 +-
.../base/dists/binomial/variance/src/addon.c | 4 ++--
.../base/dists/binomial/variance/src/main.c | 14 +++++------
.../binomial/variance/test/test.native.js | 13 ++--------
16 files changed, 67 insertions(+), 66 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
index 6159c8f38ceb..71c8a67b20c2 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
@@ -167,20 +167,20 @@ for ( i = 0; i < 10; i++ ) {
#### stdlib_base_dists_binomial_variance( n, p )
-Returns the variance of a binomial distribution.
+Returns the [variance][variance] of a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`.
```c
-double out = stdlib_base_dists_binomial_variance( 10, 0.5 );
-// returns 2.5
+double out = stdlib_base_dists_binomial_variance( 100, 0.1 );
+// returns 0.9
```
The function accepts the following arguments:
-- **n**: `[in] int` number of trials.
+- **n**: `[in] int32_t` number of trials.
- **p**: `[in] double` success probability.
```c
-double stdlib_base_dists_binomial_variance( const int n, const double p );
+double stdlib_base_dists_binomial_variance( const int32_t n, const double p );
```
@@ -203,26 +203,30 @@ double stdlib_base_dists_binomial_variance( const int n, const double p );
```c
#include "stdlib/stats/base/dists/binomial/variance.h"
+#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 );
- return min + ( v * ( max - min ) );
+ return min + ( v * (max - min) );
}
int main( void ) {
- int n;
+ int32_t n;
double p;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
- n = (int)random_uniform( 1, 100 );
- p = random_uniform( 0, 1 );
+ n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
+ p = random_uniform( 0.0, 1.0 );
y = stdlib_base_dists_binomial_variance( n, p );
- printf( "n: %d, p: %lf, Var(X;n,p): %lf", n, p, y );
+ printf( "n: %d, p: %lf, Var(X;n,p): %lf\n", n, p, y );
}
+
+ return 0;
}
```
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
index 729dbd9d2560..a16c2394eb68 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.js
@@ -21,9 +21,10 @@
// MODULES //
var bench = require( '@stdlib/bench' );
+var ceil = require( '@stdlib/math/base/special/ceil' );
+var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var randu = require( '@stdlib/random/base/randu' );
-var floor = require( '@stdlib/math/base/special/floor' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var variance = require( './../lib' );
@@ -39,16 +40,16 @@ bench( pkg, function benchmark( b ) {
var i;
len = 100;
- n = new Float64Array( len );
+ n = new Int32Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
- n[ i ] = floor( ( randu() * 100.0 ) ) + 1;
- p[ i ] = ( randu() * 0.8 ) + 0.1;
+ n[ i ] = ceil( randu() * 100.0 );
+ p[ i ] = randu();
}
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
- y = variance( n[ i % len ], p[ i % len ] );
+ y = variance( n[ i%len ], p[ i%len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
index d2e1b23fcde2..4bff698fa4aa 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/benchmark.native.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -22,9 +22,10 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
+var Int32Array = require( '@stdlib/array/int32' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
-var floor = require( '@stdlib/math/base/special/floor' );
+var ceil = require( '@stdlib/math/base/special/ceil' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
@@ -48,11 +49,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
var i;
len = 100;
- n = new Float64Array( len );
+ n = new Int32Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
- n[ i ] = floor( ( randu() * 100.0 ) ) + 1;
- p[ i ] = ( randu() * 0.8 ) + 0.1;
+ n[ i ] = ceil( randu() * 100.0 );
+ p[ i ] = randu();
}
b.tic();
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile
index f69e9da2b4d3..a4bd7b38fd74 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/Makefile
@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
-# Copyright (c) 2024 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.
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
index 001c41325bec..130f87131f7d 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/benchmark/c/benchmark.c
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -17,7 +17,9 @@
*/
#include "stdlib/stats/base/dists/binomial/variance.h"
+#include "stdlib/math/base/special/ceil.h"
#include
+#include
#include
#include
#include
@@ -93,15 +95,15 @@ static double random_uniform( const double min, const double max ) {
*/
static double benchmark( void ) {
double elapsed;
- double n[ 100 ];
+ int32_t n[ 100 ];
double p[ 100 ];
double y;
double t;
int i;
for ( i = 0; i < 100; i++ ) {
- n[ i ] = random_uniform( 1, 100 );
- p[ i ] = random_uniform( 0.1, 0.9 );
+ n[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
+ p[ i ] = random_uniform( 0.0, 1.0 );
}
t = tic();
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
index ec3992233442..68a1ca11d160 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/binding.gyp
@@ -1,6 +1,6 @@
# @license Apache-2.0
#
-# Copyright (c) 2024 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.
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
index 6aed70daf167..25ced822f96a 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/Makefile
@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
-# Copyright (c) 2024 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.
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c
index ddb30cdb70a0..72b727c335b9 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/examples/c/example.c
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -17,7 +17,9 @@
*/
#include "stdlib/stats/base/dists/binomial/variance.h"
+#include "stdlib/math/base/special/ceil.h"
#include
+#include
#include
static double random_uniform( const double min, const double max ) {
@@ -26,16 +28,16 @@ static double random_uniform( const double min, const double max ) {
}
int main( void ) {
- double n;
+ int32_t n;
double p;
double y;
int i;
for ( i = 0; i < 25; i++ ) {
- n = random_uniform( 1, 100 );
- p = random_uniform( 0.1, 0.9 );
+ n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
+ p = random_uniform( 0.0, 1.0 );
y = stdlib_base_dists_binomial_variance( n, p );
- printf( "n: %lf, p: %lf, Var(X;n,p): %lf\n", n, p, y );
+ printf( "n: %d, p: %lf, Var(X;n,p): %lf\n", n, p, y );
}
return 0;
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
index 575cb043c0bf..ecfaf82a3279 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include.gypi
@@ -1,6 +1,6 @@
# @license Apache-2.0
#
-# Copyright (c) 2024 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.
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include/stdlib/stats/base/dists/binomial/variance.h b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include/stdlib/stats/base/dists/binomial/variance.h
index 1457c9d6590d..6a5072e0deec 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include/stdlib/stats/base/dists/binomial/variance.h
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/include/stdlib/stats/base/dists/binomial/variance.h
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -19,6 +19,8 @@
#ifndef STDLIB_STATS_BASE_DISTS_BINOMIAL_VARIANCE_H
#define STDLIB_STATS_BASE_DISTS_BINOMIAL_VARIANCE_H
+#include
+
/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
@@ -27,9 +29,9 @@ extern "C" {
#endif
/**
-* Returns the variance of a binomial distribution.
+* Returns the variance of a binomial distribution with number of trials `n` and success probability `p`.
*/
-double stdlib_base_dists_binomial_variance( const double n, const double p );
+double stdlib_base_dists_binomial_variance( const int32_t n, const double p );
#ifdef __cplusplus
}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/lib/native.js
index cfc6c2de973a..8e66bdfcf5bd 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/lib/native.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/lib/native.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -28,6 +28,7 @@ var addon = require( './../src/addon.node' );
/**
* Returns the variance of a binomial distribution.
*
+* @private
* @param {NonNegativeInteger} n - number of trials
* @param {Probability} p - success probability
* @returns {PositiveNumber} variance
@@ -41,10 +42,6 @@ var addon = require( './../src/addon.node' );
* // returns 5.0
*
* @example
-* var v = variance( 10.3, 0.5 );
-* // returns NaN
-*
-* @example
* var v = variance( 20, 1.1 );
* // returns NaN
*
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
index 7f1a3a58ea0a..356121a5ebdb 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
@@ -40,7 +40,8 @@
"dependencies": [
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
- "@stdlib/math/base/assert/is-nonnegative-integer"
+ "@stdlib/math/base/assert/is-nonnegative-integer",
+ "@stdlib/math/base/special/ceil"
]
},
{
@@ -56,7 +57,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
- "@stdlib/math/base/assert/is-nonnegative-integer"
+ "@stdlib/math/base/assert/is-nonnegative-integer",
+ "@stdlib/math/base/special/ceil"
]
},
{
@@ -72,7 +74,8 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
- "@stdlib/math/base/assert/is-nonnegative-integer"
+ "@stdlib/math/base/assert/is-nonnegative-integer",
+ "@stdlib/math/base/special/ceil"
]
}
]
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/Makefile
index bcf18aa46655..7733b6180cb4 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/Makefile
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/Makefile
@@ -1,7 +1,7 @@
#/
# @license Apache-2.0
#
-# Copyright (c) 2024 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.
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/addon.c
index cfa473caa46f..1bb3ef3f1e6e 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/addon.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/addon.c
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -20,4 +20,4 @@
#include "stdlib/math/base/napi/binary.h"
// cppcheck-suppress shadowFunction
-STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_binomial_variance );
+STDLIB_MATH_BASE_NAPI_MODULE_ID_D( stdlib_base_dists_binomial_variance );
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
index 392eb753a63f..ddb6ef73a17b 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
@@ -19,7 +19,7 @@
#include "stdlib/stats/base/dists/binomial/variance.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
-
+#include
/**
* Returns the variance of a binomial distribution.
*
@@ -28,17 +28,15 @@
* @return variance
*
* @example
-* double y = stdlib_base_dists_binomial_variance( 10, 0.5 );
-* // returns 2.5
+* double y = stdlib_base_dists_binomial_variance( 100, 0.1 );
+* // returns 0.9
*/
-double stdlib_base_dists_binomial_variance( const double n, const double p ) {
+double stdlib_base_dists_binomial_variance( const int32_t n, const double p ) {
if (
- stdlib_base_is_nan( n ) ||
stdlib_base_is_nan( p ) ||
- n < 0.0 ||
+ n < 0 ||
p < 0.0 ||
- p > 1.0 ||
- !stdlib_base_is_nonnegative_integer( n )
+ p > 1.0
) {
return 0.0 / 0.0;
}
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
index a9b37fd7c16c..39caeae91407 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
@@ -50,10 +50,7 @@ tape( 'main export is a function', opts, function test( t ) {
});
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
- var v = variance( NaN, 0.5 );
- t.equal( isnan( v ), true, 'returns NaN' );
-
- v = variance( 10.0, NaN );
+ var v = variance( 10, NaN );
t.equal( isnan( v ), true, 'returns NaN' );
t.end();
@@ -62,18 +59,12 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', function test( t ) {
var v;
- v = variance( 1.5, 0.5 );
- t.equal( isnan( v ), true, 'returns NaN' );
-
v = variance( -2, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
v = variance( -1, 0.5 );
t.equal( isnan( v ), true, 'returns NaN' );
- v = variance( 2.5, 0.5 );
- t.equal( isnan( v ), true, 'returns NaN' );
-
t.end();
});
From 6407b9cf8bd7cfb7c130bcbf699a41e99de1ae72 Mon Sep 17 00:00:00 2001
From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com>
Date: Mon, 6 Jan 2025 18:23:55 +0530
Subject: [PATCH 8/9] chore: updated copyright year
---
.../@stdlib/stats/base/dists/binomial/variance/src/main.c | 2 +-
.../stats/base/dists/binomial/variance/test/test.native.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
index ddb6ef73a17b..5011ac021705 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2024 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.
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
index 39caeae91407..8f65f6d5ed44 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/test/test.native.js
@@ -56,7 +56,7 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
t.end();
});
-tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', function test( t ) {
+tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) {
var v;
v = variance( -2, 0.5 );
From 5b3f5d530b0e6ca6a936766a2f294be5c51dd2db Mon Sep 17 00:00:00 2001
From: Philipp Burckhardt
Date: Tue, 7 Jan 2025 20:49:00 -0500
Subject: [PATCH 9/9] chore: apply suggestions from code review
Co-authored-by: Athan
Signed-off-by: Philipp Burckhardt
---
.../@stdlib/stats/base/dists/binomial/variance/README.md | 2 +-
.../@stdlib/stats/base/dists/binomial/variance/manifest.json | 3 +--
.../@stdlib/stats/base/dists/binomial/variance/src/main.c | 3 ++-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
index 71c8a67b20c2..2871357efc75 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/README.md
@@ -171,7 +171,7 @@ Returns the [variance][variance] of a [binomial][binomial-distribution] distribu
```c
double out = stdlib_base_dists_binomial_variance( 100, 0.1 );
-// returns 0.9
+// returns 9.0
```
The function accepts the following arguments:
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
index 356121a5ebdb..30c3a89fc163 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/manifest.json
@@ -40,8 +40,7 @@
"dependencies": [
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
- "@stdlib/math/base/assert/is-nonnegative-integer",
- "@stdlib/math/base/special/ceil"
+ "@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
index 5011ac021705..0889a36e8baf 100644
--- a/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
+++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/variance/src/main.c
@@ -20,6 +20,7 @@
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
#include
+
/**
* Returns the variance of a binomial distribution.
*
@@ -29,7 +30,7 @@
*
* @example
* double y = stdlib_base_dists_binomial_variance( 100, 0.1 );
-* // returns 0.9
+* // returns 9.0
*/
double stdlib_base_dists_binomial_variance( const int32_t n, const double p ) {
if (