From 71a080a463c0de1534ed2687cf0952450b7166c9 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 27 Dec 2024 23:04:06 +0530 Subject: [PATCH 01/26] feat: add-erlang-mgf --- .../stats/base/dists/erlang/mgf/README.md | 107 ++++++++++ .../erlang/mgf/benchmark/benchmark.native.js | 66 ++++++ .../dists/erlang/mgf/benchmark/c/Makefile | 146 +++++++++++++ .../dists/erlang/mgf/benchmark/c/benchmark.c | 138 ++++++++++++ .../stats/base/dists/erlang/mgf/binding.gyp | 170 +++++++++++++++ .../base/dists/erlang/mgf/examples/c/Makefile | 146 +++++++++++++ .../dists/erlang/mgf/examples/c/example.c | 38 ++++ .../stats/base/dists/erlang/mgf/include.gypi | 53 +++++ .../stdlib/stats/base/dists/erlang/mgf.h | 38 ++++ .../stats/base/dists/erlang/mgf/lib/native.js | 83 ++++++++ .../stats/base/dists/erlang/mgf/manifest.json | 85 ++++++++ .../stats/base/dists/erlang/mgf/package.json | 3 + .../stats/base/dists/erlang/mgf/src/Makefile | 70 ++++++ .../stats/base/dists/erlang/mgf/src/addon.c | 23 ++ .../stats/base/dists/erlang/mgf/src/main.c | 66 ++++++ .../base/dists/erlang/mgf/test/test.native.js | 201 ++++++++++++++++++ 16 files changed, 1433 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index f89e0dca8782..395eb346a790 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -163,6 +163,113 @@ for ( i = 0; i < 10; i++ ) { + + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/erlang/mgf.h" +``` + +#### stdlib_base_dists_erlang_mgf( t, k, lambda ) + +Evaluates the moment-generating function (MGF) for a erlang distribution. + +```c +double y = stdlib_base_dists_erlan _mgf( 0.3, 1, 1.0 ); +// returns ~1.429 + +y = stdlib_base_dists_erlan _mgf( 2.0, 2, 3.0 ); +// returns ~9.0 + +y = stdlib_base_dists_erlan _mgf( -1.0, 2, 2.0 ); +// returns ~0.444 + +y = stdlib_base_dists_erlan _mgf( NaN, 1, 1.0 ); +// returns NaN + +y = stdlib_base_dists_erlan _mgf( 0.0, NaN, 1.0 ); +// returns NaN + +y = stdlib_base_dists_erlan _mgf( 0.0, 1, NaN ); +// returns NaN +``` + +The function accepts the following arguments: + +- **t**: `[in] double` input value. +- **k**: `[in] double` shape parameter +- **lambda**: `[in] double` rate parameter + +```c +double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/erlang/mgf.h" +#include "stdlib/math/base/special/round.h" +#include +#include + +int main( void ) { + double lambda; + double k; + double t; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + k = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 ); + lambda = ( (double)rand() / (double)RAND_MAX ) *10.0 ; + t = ( (double)rand() / (double)RAND_MAX ); + y = stdlib_base_dists_erlang_mgf( t, k, lambda ); + printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); + } +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..27dd3ffa2b34 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js @@ -0,0 +1,66 @@ +/** +* @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 ceil = require( '@stdlib/math/base/special/ceil' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var mgf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mgf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var lambda; + var k; + var t; + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + k = ceil( randu()*100.0 ); + lambda = ( randu()*20.0 ) + EPS; + t = randu()*lambda; + y = mgf( t, k, lambda ); + 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/erlang/mgf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/Makefile new file mode 100644 index 000000000000..f69e9da2b4d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..c80e0df775c8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -0,0 +1,138 @@ +/** +* @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/erlang/mgf.h" +#include "stdlib/math/base/special/ceil.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "erlang-mgf" +#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 [0,1). +* +* @return random number +*/ +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double lambda; + double k; + double t; + double x; + int i; + + x = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + k = stdlib_base_ceil( ( (double)rand() / (double)RAND_MAX )* 100.0 ); + lambda = ( ( (double)rand() / (double)RAND_MAX )*20.0 ) + STDLIB_CONSTANT_FLOAT64_EPS; + t = ( (double)rand() / (double)RAND_MAX )* lambda; + y = stdlib_base_dists_erlang_mgf( t, k, lambda ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - x; + 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/erlang/mgf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/binding.gyp new file mode 100644 index 000000000000..ec3992233442 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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 +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/Makefile new file mode 100644 index 000000000000..6aed70daf167 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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 diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c new file mode 100644 index 000000000000..cc19948f5b59 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c @@ -0,0 +1,38 @@ +/** +* @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/erlang/mgf.h" +#include "stdlib/math/base/special/round.h" +#include +#include + +int main( void ) { + double lambda; + double k; + double t; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + k = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 ); + lambda = ( (double)rand() / (double)RAND_MAX ) *10.0 ; + t = ( (double)rand() / (double)RAND_MAX ); + y = stdlib_base_dists_erlang_mgf( t, k, lambda ); + printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include.gypi new file mode 100644 index 000000000000..575cb043c0bf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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': [ + '= lambda + ) { + return 0.0 / 0.0; + } + return stdlib_base_pow( 1.0 - (t/lambda), -k ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js new file mode 100644 index 000000000000..b972ba6a8c07 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js @@ -0,0 +1,201 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); + + +// FIXTURES // + +var largeShape = require( './fixtures/julia/large_shape.json' ); +var largeRate = require( './fixtures/julia/large_rate.json' ); +var bothLarge = require( './fixtures/julia/both_large.json' ); + + +// VARIABLES // + +var mgf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mgf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mgf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y = mgf( NaN, 0.0, 1.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + y = mgf( 0.0, NaN, 1.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + y = mgf( 0.0, 1.0, NaN ); + t.equal( isnan( y ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'if provided a negative `k`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mgf( 2.0, -1.0, 2.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 0.0, -1.0, 2.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, NINF, 1.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, NINF, PINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, NINF, NINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, NINF, NaN ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mgf( 2.0, 2.0, -1.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 0.0, 2.0, -1/0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, 1.0, NINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, PINF, NINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, NINF, NINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + y = mgf( 2.0, NaN, NINF ); + t.equal( isnan( y ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided `t >= lambda`, the function returns `NaN`', opts, function test( t ) { + var y = mgf( 1.5, 1, 1.0 ); + t.equal( isnan( y ), true, 'returns NaN' ); + y = mgf( 0.8, 1, 0.5 ); + t.equal( isnan( y ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function evaluates the mgf for `x` given large `k` and `lambda`', opts, function test( t ) { + var expected; + var lambda; + var delta; + var tol; + var i; + var k; + var x; + var y; + + expected = bothLarge.expected; + x = bothLarge.x; + k = bothLarge.k; + lambda = bothLarge.lambda; + for ( i = 0; i < x.length; i++ ) { + y = mgf( x[i], k[i], lambda[i] ); + if ( y === expected[i] ) { + t.equal( y, expected[i], 'x: '+x[i]+', k:'+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 2500.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the mgf for `x` given large shape parameter `k`', opts, function test( t ) { + var expected; + var lambda; + var delta; + var tol; + var i; + var k; + var x; + var y; + + expected = largeShape.expected; + x = largeShape.x; + k = largeShape.k; + lambda = largeShape.lambda; + for ( i = 0; i < x.length; i++ ) { + y = mgf( x[i], k[i], lambda[i] ); + if ( y === expected[i] ) { + t.equal( y, expected[i], 'x: '+x[i]+', k:'+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 2000.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the mgf for `x` given large rate parameter `lambda`', opts, function test( t ) { + var expected; + var lambda; + var delta; + var tol; + var i; + var k; + var x; + var y; + + expected = largeRate.expected; + x = largeRate.x; + k = largeRate.k; + lambda = largeRate.lambda; + for ( i = 0; i < x.length; i++ ) { + y = mgf( x[i], k[i], lambda[i] ); + if ( y === expected[i] ) { + t.equal( y, expected[i], 'x: '+x[i]+', k:'+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 1250.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); From c9a8a64b20730195a8eacb72c3ed65bd64194b21 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 27 Dec 2024 23:13:07 +0530 Subject: [PATCH 02/26] fix: CI errors --- .../@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c | 1 + .../@stdlib/stats/base/dists/erlang/mgf/manifest.json | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index c80e0df775c8..16fbc2b79a05 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -97,6 +97,7 @@ static double benchmark( void ) { double k; double t; double x; + double y; int i; x = tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json index d8b7157f4128..13db02b2cfd7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json @@ -59,6 +59,7 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/pow", "@stdlib/math/base/special/ceil", + "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/constants/float64/eps" ] }, @@ -78,6 +79,7 @@ "@stdlib/math/base/special/pow", "@stdlib/math/base/special/ceil", "@stdlib/constants/float64/eps", + "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/math/base/special/round" ] } From 40c958263f066d0662a8280c4787d289f4c980a3 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 18 Jan 2025 01:19:20 +0530 Subject: [PATCH 03/26] chore: clean up --- .../stats/base/dists/erlang/mgf/README.md | 30 ++++++----------- .../dists/erlang/mgf/benchmark/benchmark.js | 32 +++++++++++++++---- .../erlang/mgf/benchmark/benchmark.native.js | 23 ++++++++++--- .../dists/erlang/mgf/benchmark/c/benchmark.c | 31 +++++++++++------- .../dists/erlang/mgf/examples/c/example.c | 13 +++++--- .../stdlib/stats/base/dists/erlang/mgf.h | 2 +- .../stats/base/dists/erlang/mgf/src/main.c | 2 +- 7 files changed, 84 insertions(+), 49 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index 395eb346a790..d762e7948838 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -189,26 +189,11 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_erlang_mgf( t, k, lambda ) -Evaluates the moment-generating function (MGF) for a erlang distribution. +Evaluates the moment-generating function (MGF) for a erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. ```c -double y = stdlib_base_dists_erlan _mgf( 0.3, 1, 1.0 ); +double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); // returns ~1.429 - -y = stdlib_base_dists_erlan _mgf( 2.0, 2, 3.0 ); -// returns ~9.0 - -y = stdlib_base_dists_erlan _mgf( -1.0, 2, 2.0 ); -// returns ~0.444 - -y = stdlib_base_dists_erlan _mgf( NaN, 1, 1.0 ); -// returns NaN - -y = stdlib_base_dists_erlan _mgf( 0.0, NaN, 1.0 ); -// returns NaN - -y = stdlib_base_dists_erlan _mgf( 0.0, 1, NaN ); -// returns NaN ``` The function accepts the following arguments: @@ -245,6 +230,11 @@ double stdlib_base_dists_erlang_mgf( const double t, const double k, const doubl #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 lambda; double k; @@ -253,9 +243,9 @@ int main( void ) { int i; for ( i = 0; i < 10; i++ ) { - k = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 ); - lambda = ( (double)rand() / (double)RAND_MAX ) *10.0 ; - t = ( (double)rand() / (double)RAND_MAX ); + k = stdlib_base_round( random_uniform( 0.0, 10.0 ) ); + lambda = random_uniform( 0.0, 10.0 ) ; + t = random_uniform( 0.0, 1.0 ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js index 251b0e9a0823..5d605121df1e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js @@ -22,7 +22,8 @@ var bench = require( '@stdlib/bench' ); var ceil = require( '@stdlib/math/base/special/ceil' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -33,17 +34,29 @@ var mgf = require( './../lib' ); bench( pkg, function benchmark( b ) { var lambda; + var len; var k; var t; var y; var i; + len = 100; + k = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + k[ i ] = ceil( uniform( 0.0, 100.0 ) ); + } + lambda = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + lambda[ i ] = uniform( EPS, 20.0 ); + } + t = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + t[ i ] = uniform( 0.0, lambda ); + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - k = ceil( randu()*100.0 ); - lambda = ( randu()*20.0 ) + EPS; - t = randu()*lambda; - y = mgf( t, k, lambda ); + y = mgf( t[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -59,6 +72,7 @@ bench( pkg, function benchmark( b ) { bench( pkg+':factory', function benchmark( b ) { var lambda; var mymgf; + var len; var k; var t; var y; @@ -68,10 +82,14 @@ bench( pkg+':factory', function benchmark( b ) { lambda = 1.5; mymgf = mgf.factory( k, lambda ); + len = 100; + t = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + t[ i ] = uniform( 0.0, lambda ); + } b.tic(); for ( i = 0; i < b.iterations; i++ ) { - t = randu()*lambda; - y = mymgf( t ); + y = mymgf( t[ i%100 ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js index 27dd3ffa2b34..5a7365bd382a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js @@ -23,7 +23,8 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var ceil = require( '@stdlib/math/base/special/ceil' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -42,17 +43,29 @@ var opts = { bench( pkg+'::native', opts, function benchmark( b ) { var lambda; + var len; var k; var t; var y; var i; + len = 100; + k = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + k[ i ] = ceil( uniform( 0.0, 100.0 ) ); + } + lambda = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + lambda[ i ] = uniform( EPS, 20.0 ); + } + t = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + t[ i ] = uniform( 0.0, lambda ); + } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - k = ceil( randu()*100.0 ); - lambda = ( randu()*20.0 ) + EPS; - t = randu()*lambda; - y = mgf( t, k, lambda ); + y = mgf( t[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index 16fbc2b79a05..ace8983ec38c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -77,13 +77,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static double rand_double( void ) { - int r = rand(); - return (double)r / ( (double)RAND_MAX + 1.0 ); +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); } /** @@ -93,18 +95,25 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double lambda; - double k; - double t; + double lambda[ 100 ]; + double k[ 100 ]; + double t[ 100 ]; double x; double y; int i; + for ( i = 0; i < 100; i++ ) { + k[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); + } + for ( i = 0; i < 100; i++ ) { + lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + for ( i = 0; i < 100; i++ ) { + t[ i ] = random_uniform( 0.0, lambda ); + } + x = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - k = stdlib_base_ceil( ( (double)rand() / (double)RAND_MAX )* 100.0 ); - lambda = ( ( (double)rand() / (double)RAND_MAX )*20.0 ) + STDLIB_CONSTANT_FLOAT64_EPS; - t = ( (double)rand() / (double)RAND_MAX )* lambda; y = stdlib_base_dists_erlang_mgf( t, k, lambda ); if ( y != y ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c index cc19948f5b59..31172812d247 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c @@ -21,17 +21,22 @@ #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 lambda; double k; - double t; + double t; double y; int i; for ( i = 0; i < 10; i++ ) { - k = stdlib_base_round( ( (double)rand() / (double)RAND_MAX ) * 10.0 ); - lambda = ( (double)rand() / (double)RAND_MAX ) *10.0 ; - t = ( (double)rand() / (double)RAND_MAX ); + k = stdlib_base_round( random_uniform( 0.0, 10.0 ) ); + lambda = random_uniform( 0.0, 10.0 ) ; + t = random_uniform( 0.0, 1.0 ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h index 81660201734c..374c944e5050 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -Evaluates the moment-generating function (MGF) for a erlang distribution with shape parameter `k` and rate parameter `lambda` at a value `t`. +Evaluates the moment-generating function (MGF) for a erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. */ double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 4c37a3f9257b..723879cc6238 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -22,7 +22,7 @@ #include "stdlib/math/base/special/pow.h" /** -* Evaluates the moment-generating function (MGF) for a Bernoulli distribution with success probability `p` at a value `t`. +* Evaluates the moment-generating function (MGF) for a erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. * * @param t input value * @param p success probability From 8034e8d98c25d5b4c07a7cca078dfb7cb9ba8c7b Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 18 Jan 2025 01:21:48 +0530 Subject: [PATCH 04/26] fix: lint errors --- .../@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index ace8983ec38c..221f3ad3f30a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -98,7 +98,7 @@ static double benchmark( void ) { double lambda[ 100 ]; double k[ 100 ]; double t[ 100 ]; - double x; + double x; double y; int i; From d0638937e6f0bf41dabbd7ea051958ca6df4f0c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Fri, 17 Jan 2025 19:52:45 +0000 Subject: [PATCH 05/26] chore: update copyright years --- .../stats/base/dists/erlang/mgf/benchmark/benchmark.native.js | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/benchmark/c/Makefile | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/binding.gyp | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/examples/c/Makefile | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/include.gypi | 2 +- .../erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/lib/native.js | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/src/Makefile | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/src/addon.c | 2 +- lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/test/test.native.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js index 5a7365bd382a..bcd790e73d77 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/Makefile index f69e9da2b4d3..a4bd7b38fd74 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index 221f3ad3f30a..000f28af44fd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/binding.gyp index ec3992233442..68a1ca11d160 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/Makefile index 6aed70daf167..25ced822f96a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c index 31172812d247..d52760eda0a0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include.gypi index 575cb043c0bf..ecfaf82a3279 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h index 374c944e5050..2b27a70b5914 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js index 3041db1d1964..addf17775054 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/Makefile index bcf18aa46655..7733b6180cb4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/Makefile +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c index b4f84f9ce4db..99147bee52a9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 723879cc6238..9a9622a9beb5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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/erlang/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js index b972ba6a8c07..482ab1e26738 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/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. From 3d4ef6a78a90b363da6193ab468fd7f3e957a258 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 18 Jan 2025 01:35:46 +0530 Subject: [PATCH 06/26] chore: update bench --- .../stats/base/dists/erlang/mgf/benchmark/benchmark.js | 2 +- .../stats/base/dists/erlang/mgf/benchmark/benchmark.native.js | 2 +- .../stats/base/dists/erlang/mgf/benchmark/c/benchmark.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js index 5d605121df1e..35e08f0bd69b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js @@ -51,7 +51,7 @@ bench( pkg, function benchmark( b ) { } t = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - t[ i ] = uniform( 0.0, lambda ); + t[ i ] = uniform( 0.0, lambda[ i ] ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js index 5a7365bd382a..1fefacbd68dc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js @@ -60,7 +60,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { } t = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - t[ i ] = uniform( 0.0, lambda ); + t[ i ] = uniform( 0.0, lambda[ i ] ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index 221f3ad3f30a..d68879778107 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -109,12 +109,12 @@ static double benchmark( void ) { lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); } for ( i = 0; i < 100; i++ ) { - t[ i ] = random_uniform( 0.0, lambda ); + t[ i ] = random_uniform( 0.0, lambda[ i ] ); } x = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_dists_erlang_mgf( t, k, lambda ); + y = stdlib_base_dists_erlang_mgf( t[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; From 3762f890125c43362fa0f08e29a9ecd907529099 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 31 Jan 2025 23:22:28 +0530 Subject: [PATCH 07/26] chore: minor updates --- .../@stdlib/stats/base/dists/erlang/mgf/README.md | 4 ++-- .../stats/base/dists/erlang/mgf/benchmark/benchmark.js | 8 ++++---- .../base/dists/erlang/mgf/benchmark/benchmark.native.js | 6 +++--- .../stats/base/dists/erlang/mgf/examples/c/example.c | 2 +- .../mgf/include/stdlib/stats/base/dists/erlang/mgf.h | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/manifest.json | 2 -- .../@stdlib/stats/base/dists/erlang/mgf/src/main.c | 2 +- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index d762e7948838..fd0862640eba 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -189,7 +189,7 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_erlang_mgf( t, k, lambda ) -Evaluates the moment-generating function (MGF) for a erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. +Evaluates the moment-generating function (mgf) for a Erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. ```c double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); @@ -245,7 +245,7 @@ int main( void ) { for ( i = 0; i < 10; i++ ) { k = stdlib_base_round( random_uniform( 0.0, 10.0 ) ); lambda = random_uniform( 0.0, 10.0 ) ; - t = random_uniform( 0.0, 1.0 ); + t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js index 35e08f0bd69b..360602d4e8e2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var ceil = require( '@stdlib/math/base/special/ceil' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -43,7 +43,7 @@ bench( pkg, function benchmark( b ) { len = 100; k = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - k[ i ] = ceil( uniform( 0.0, 100.0 ) ); + k[ i ] = discreteUniform( 0.0, 100.0 ); } lambda = new Float64Array( len ); for ( i = 0; i < len; i++ ) { @@ -56,7 +56,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = mgf( t[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); + y = mgf( t[ i % len ], k[ i % len ], lambda[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -89,7 +89,7 @@ bench( pkg+':factory', function benchmark( b ) { } b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = mymgf( t[ i%100 ] ); + y = mymgf( t[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js index 0b3e9de3ccc2..01ce76951b23 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var ceil = require( '@stdlib/math/base/special/ceil' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); @@ -52,7 +52,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { len = 100; k = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - k[ i ] = ceil( uniform( 0.0, 100.0 ) ); + k[ i ] = discreteUniform( 0.0, 100.0 ); } lambda = new Float64Array( len ); for ( i = 0; i < len; i++ ) { @@ -65,7 +65,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = mgf( t[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); + y = mgf( t[ i % len ], k[ i % len ], lambda[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c index d52760eda0a0..4815a12f0830 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c @@ -36,7 +36,7 @@ int main( void ) { for ( i = 0; i < 10; i++ ) { k = stdlib_base_round( random_uniform( 0.0, 10.0 ) ); lambda = random_uniform( 0.0, 10.0 ) ; - t = random_uniform( 0.0, 1.0 ); + t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h index 2b27a70b5914..5e4ec9a72c83 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h @@ -27,7 +27,7 @@ extern "C" { #endif /** -Evaluates the moment-generating function (MGF) for a erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. +* Evaluates the moment-generating function (mgf) for a Erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. */ double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json index 13db02b2cfd7..fc9c76b08575 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/manifest.json @@ -77,8 +77,6 @@ "dependencies": [ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/pow", - "@stdlib/math/base/special/ceil", - "@stdlib/constants/float64/eps", "@stdlib/math/base/assert/is-nonnegative-integer", "@stdlib/math/base/special/round" ] diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 9a9622a9beb5..29e398e1e5a7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -22,7 +22,7 @@ #include "stdlib/math/base/special/pow.h" /** -* Evaluates the moment-generating function (MGF) for a erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. +* Evaluates the moment-generating function (mgf) for a Erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. * * @param t input value * @param p success probability From 025599f42c51d81c7e2e505adb60a37214344a72 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Wed, 5 Feb 2025 21:57:29 +0530 Subject: [PATCH 08/26] chore: changes from code review --- .../stats/base/dists/erlang/mgf/README.md | 6 ++--- .../dists/erlang/mgf/benchmark/c/benchmark.c | 2 +- .../stats/base/dists/erlang/mgf/lib/native.js | 1 + .../stats/base/dists/erlang/mgf/src/main.c | 22 +------------------ 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index fd0862640eba..4842777c1d80 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -198,9 +198,9 @@ double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); The function accepts the following arguments: -- **t**: `[in] double` input value. -- **k**: `[in] double` shape parameter -- **lambda**: `[in] double` rate parameter +- **t**: `[in] double` input value. +- **k**: `[in] double` shape parameter. +- **lambda**: `[in] double` rate parameter. ```c double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index 1c58d1c822af..d75bacf0a29e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -114,7 +114,7 @@ static double benchmark( void ) { x = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_dists_erlang_mgf( t[ i%100 ], k[ i%100 ], lambda[ i%100 ] ); + y = stdlib_base_dists_erlang_mgf( t[ i % 100 ], k[ i % 100 ], lambda[ i % 100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js index addf17775054..e5dbfc08e06f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js @@ -28,6 +28,7 @@ var addon = require( './../src/addon.node' ); /** * Evaluates the moment-generating function (MGF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda` at a value `t`. * +* @private * @param {number} t - input value * @param {NonNegativeInteger} k - shape parameter * @param {PositiveNumber} lambda - rate parameter diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 29e398e1e5a7..7e1bc23224d4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -26,31 +26,11 @@ * * @param t input value * @param p success probability -* @returns evaluated MGF +* @returns moment-generating function * * @example * double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); * // returns ~1.429 -* -* @example -* double y = stdlib_base_dists_erlang_mgf( 2.0, 2, 3.0 ); -* // returns ~9.0 -* -* @example -* double y = stdlib_base_dists_erlang_mgf( -1.0, 2, 2.0 ); -* // returns ~0.444 -* -* @example -* double y = stdlib_base_dists_erlang_mgf( NaN, 1, 1.0 ); -* // returns NaN -* -* @example -* double y = stdlib_base_dists_erlang_mgf( 0.0, NaN, 1.0 ); -* // returns NaN -* -* @example -* double y = stdlib_base_dists_erlang_mgf( 0.0, 1, NaN ); -* // returns NaN */ double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ) { if ( From 77fde89d057309fabe9c5263d518028fa51ffe66 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Wed, 5 Feb 2025 22:50:15 +0530 Subject: [PATCH 09/26] chore: update C doxygen --- .../@stdlib/stats/base/dists/erlang/mgf/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 7e1bc23224d4..0981e2832b16 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -26,7 +26,7 @@ * * @param t input value * @param p success probability -* @returns moment-generating function +* @returns evaluated mgf * * @example * double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); @@ -42,5 +42,5 @@ double stdlib_base_dists_erlang_mgf( const double t, const double k, const doubl ) { return 0.0 / 0.0; } - return stdlib_base_pow( 1.0 - (t/lambda), -k ); + return stdlib_base_pow( 1.0 - (t / lambda ), -k ); } From 3e5f04bf0e0c5159fe31d017df70e0e22a450a48 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Thu, 6 Feb 2025 10:52:18 +0530 Subject: [PATCH 10/26] chore: stuff from code review --- .../@stdlib/stats/base/dists/erlang/mgf/README.md | 2 +- .../stats/base/dists/erlang/mgf/benchmark/benchmark.js | 8 ++------ .../base/dists/erlang/mgf/benchmark/benchmark.native.js | 8 ++------ .../stats/base/dists/erlang/mgf/benchmark/c/benchmark.c | 4 ---- .../stats/base/dists/erlang/mgf/examples/c/example.c | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/src/main.c | 2 +- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index 4842777c1d80..0accf7a03475 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -247,7 +247,7 @@ int main( void ) { lambda = random_uniform( 0.0, 10.0 ) ; t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); - printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); + printf( "t: %1f. k: %1f. λ: %1f. M_X(t;k,λ): %lf\n", t, k , lambda , y ); } } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js index 360602d4e8e2..342750274e19 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js @@ -42,15 +42,11 @@ bench( pkg, function benchmark( b ) { len = 100; k = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - k[ i ] = discreteUniform( 0.0, 100.0 ); - } lambda = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - lambda[ i ] = uniform( EPS, 20.0 ); - } t = new Float64Array( len ); for ( i = 0; i < len; i++ ) { + k[ i ] = discreteUniform( 0.0, 100.0 ); + lambda[ i ] = uniform( EPS, 20.0 ); t[ i ] = uniform( 0.0, lambda[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js index 01ce76951b23..9e17e345d721 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js @@ -51,15 +51,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { len = 100; k = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - k[ i ] = discreteUniform( 0.0, 100.0 ); - } lambda = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - lambda[ i ] = uniform( EPS, 20.0 ); - } t = new Float64Array( len ); for ( i = 0; i < len; i++ ) { + k[ i ] = discreteUniform( 0.0, 100.0 ); + lambda[ i ] = uniform( EPS, 20.0 ); t[ i ] = uniform( 0.0, lambda[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index d75bacf0a29e..1903ea5fb256 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -104,11 +104,7 @@ static double benchmark( void ) { for ( i = 0; i < 100; i++ ) { k[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); - } - for ( i = 0; i < 100; i++ ) { lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); - } - for ( i = 0; i < 100; i++ ) { t[ i ] = random_uniform( 0.0, lambda[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c index 4815a12f0830..0d1132b24271 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c @@ -38,6 +38,6 @@ int main( void ) { lambda = random_uniform( 0.0, 10.0 ) ; t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); - printf( "t: %1f, k: %1f, λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); + printf( "t: %1f. k: %1f. λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 0981e2832b16..6620ac8f1c41 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -26,7 +26,7 @@ * * @param t input value * @param p success probability -* @returns evaluated mgf +* @return evaluated mgf * * @example * double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); From 6e82f8200f4067c68758bf1969445927b67e7b63 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 7 Feb 2025 11:02:53 +0530 Subject: [PATCH 11/26] chore: minor clean up --- .../@stdlib/stats/base/dists/erlang/mgf/README.md | 2 +- .../stats/base/dists/erlang/mgf/benchmark/benchmark.js | 1 + .../stats/base/dists/erlang/mgf/examples/c/example.c | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/src/main.c | 7 ++++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index 0accf7a03475..ce7c22eca96f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -247,7 +247,7 @@ int main( void ) { lambda = random_uniform( 0.0, 10.0 ) ; t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); - printf( "t: %1f. k: %1f. λ: %1f. M_X(t;k,λ): %lf\n", t, k , lambda , y ); + printf( "t: %lf, k: %lf, λ: %lf, M_X(t;k,λ): %lf\n", t, k, lambda, y ); } } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js index 342750274e19..518f68070015 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js @@ -83,6 +83,7 @@ bench( pkg+':factory', function benchmark( b ) { for ( i = 0; i < len; i++ ) { t[ i ] = uniform( 0.0, lambda ); } + b.tic(); for ( i = 0; i < b.iterations; i++ ) { y = mymgf( t[ i % len ] ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c index 0d1132b24271..1edd737230d6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c @@ -38,6 +38,6 @@ int main( void ) { lambda = random_uniform( 0.0, 10.0 ) ; t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); - printf( "t: %1f. k: %1f. λ: %1f, M_X(t;k,λ): %lf\n", t, k , lambda , y ); + printf( "t: %lf, k: %lf, λ: %1f, M_X(t;k,λ): %lf\n", t, k, lambda, y ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index 6620ac8f1c41..d445a5b86087 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -24,9 +24,10 @@ /** * Evaluates the moment-generating function (mgf) for a Erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. * -* @param t input value -* @param p success probability -* @return evaluated mgf +* @param t input value +* @param k shape parameter +* @param lambda rate parameter +* @return evaluated mgf * * @example * double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); From ef4f313a28f204b7f405cf0cf56e141f27ccd6d3 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 7 Feb 2025 20:21:00 +0530 Subject: [PATCH 12/26] chore: update markdown description --- lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index ce7c22eca96f..e472c2f889e9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -189,7 +189,7 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_erlang_mgf( t, k, lambda ) -Evaluates the moment-generating function (mgf) for a Erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. +Evaluates the [moment-generating function][mgf] (mgf) for an [Erlang][erlang-distribution] distribution with parameters `k` (shape parameter) and `lambda` (rate parameter). ```c double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); From 0ca86bdabc3f4357631b1f8ace88df0483ac90cf Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 05:59:56 +0530 Subject: [PATCH 13/26] feat: add `stats/strided/svariancepn` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/svariancepn/README.md | 392 ++++++++++++++++++ .../svariancepn/benchmark/benchmark.js | 96 +++++ .../svariancepn/benchmark/benchmark.native.js | 101 +++++ .../benchmark/benchmark.ndarray.js | 96 +++++ .../benchmark/benchmark.ndarray.native.js | 101 +++++ .../strided/svariancepn/benchmark/c/Makefile | 146 +++++++ .../benchmark/c/benchmark.length.c | 197 +++++++++ .../stats/strided/svariancepn/binding.gyp | 170 ++++++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 ++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/svariancepn/docs/repl.txt | 114 +++++ .../strided/svariancepn/docs/types/index.d.ts | 95 +++++ .../strided/svariancepn/docs/types/test.ts | 187 +++++++++ .../strided/svariancepn/examples/c/Makefile | 146 +++++++ .../strided/svariancepn/examples/c/example.c | 37 ++ .../strided/svariancepn/examples/index.js | 36 ++ .../stats/strided/svariancepn/include.gypi | 53 +++ .../stdlib/stats/strided/svariancepn.h | 45 ++ .../stats/strided/svariancepn/lib/index.js | 68 +++ .../stats/strided/svariancepn/lib/main.js | 35 ++ .../stats/strided/svariancepn/lib/native.js | 35 ++ .../stats/strided/svariancepn/lib/ndarray.js | 91 ++++ .../strided/svariancepn/lib/ndarray.native.js | 53 +++ .../strided/svariancepn/lib/svariancepn.js | 62 +++ .../svariancepn/lib/svariancepn.native.js | 52 +++ .../stats/strided/svariancepn/manifest.json | 104 +++++ .../stats/strided/svariancepn/package.json | 81 ++++ .../stats/strided/svariancepn/src/Makefile | 70 ++++ .../stats/strided/svariancepn/src/addon.c | 64 +++ .../stats/strided/svariancepn/src/main.c | 90 ++++ .../stats/strided/svariancepn/test/test.js | 82 ++++ .../strided/svariancepn/test/test.ndarray.js | 196 +++++++++ .../svariancepn/test/test.ndarray.native.js | 205 +++++++++ .../svariancepn/test/test.svariancepn.js | 200 +++++++++ .../test/test.svariancepn.native.js | 209 ++++++++++ 37 files changed, 3909 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/include/stdlib/stats/strided/svariancepn.h create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/svariancepn.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/lib/svariancepn.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.native.js diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md b/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md new file mode 100644 index 000000000000..343e1d95143b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/README.md @@ -0,0 +1,392 @@ + + +# svariancepn + +> Calculate the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var svariancepn = require( '@stdlib/stats/strided/svariancepn' ); +``` + +#### svariancepn( N, correction, x, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array `x` using a two-pass algorithm. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + +var v = svariancepn( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); + +var v = svariancepn( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = svariancepn( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### svariancepn.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + +var v = svariancepn.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); + +var v = svariancepn.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var svariancepn = require( '@stdlib/stats/strided/svariancepn' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +console.log( x ); + +var v = svariancepn( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/strided/svariancepn.h" +``` + +#### stdlib_strided_svariancepn( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svariancepn( 3, 1.0f, x, 1 ); +// returns ~4.3333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +float stdlib_strided_svariancepn( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_svariancepn_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svariancepn_ndarray( 3, 1.0f, x, 1, 0 ); +// returns ~4.3333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +float stdlib_strided_svariancepn_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/strided/svariancepn.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svariancepn( N, 1.0f, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} +``` + +
+ + + +
+ + + +* * * + +
+ +## References + +- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a]. +- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.js new file mode 100644 index 000000000000..7c7a1f505ec6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var svariancepn = require( './../lib/svariancepn.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancepn( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.native.js new file mode 100644 index 000000000000..40ed11862ad8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.native.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var svariancepn = tryRequire( resolve( __dirname, './../lib/svariancepn.native.js' ) ); +var opts = { + 'skip': ( svariancepn instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancepn( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6ac8e147cd6d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var svariancepn = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancepn( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..8d8b769a0d5e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var svariancepn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( svariancepn instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancepn( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/Makefile new file mode 100644 index 000000000000..7280962b4c4d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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.length.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/strided/svariancepn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..efbc1370a277 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/benchmark/c/benchmark.length.c @@ -0,0 +1,197 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svariancepn.h" +#include +#include +#include +#include +#include + +#define NAME "svariancepn" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* 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 iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, 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 [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_svariancepn( len, 1.0f, x, 1 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_svariancepn_ndarray( len, 1.0f, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/binding.gyp b/lib/node_modules/@stdlib/stats/strided/svariancepn/binding.gyp new file mode 100644 index 000000000000..7d0005b2e390 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2020 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 +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/repl.txt new file mode 100644 index 000000000000..c41646ed7569 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/repl.txt @@ -0,0 +1,114 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a single-precision floating-point strided array + using a two-pass algorithm. + + The `N` and stride parameters determine which elements in `x` are accessed + at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float32Array + Input array. + + strideX: integer + Stride Length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a single-precision floating-point strided array + using a two-pass algorithm and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float32Array + Input array. + + strideX: integer + Stride Length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/index.d.ts new file mode 100644 index 000000000000..f8e1149f7003 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/index.d.ts @@ -0,0 +1,95 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `svariancepn`. +*/ +interface Routine { + /** + * Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + * + * var v = svariancepn( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: Float32Array, strideX: number ): number; + + /** + * Computes the variance of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + * + * var v = svariancepn.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +* +* var v = svariancepn( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +* +* var v = svariancepn.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var svariancepn: Routine; + + +// EXPORTS // + +export = svariancepn; diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/test.ts new file mode 100644 index 000000000000..de555a0e092a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/docs/types/test.ts @@ -0,0 +1,187 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +import svariancepn = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float32Array( 10 ); + + svariancepn( x.length, 1, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn( '10', 1, x, 1 ); // $ExpectError + svariancepn( true, 1, x, 1 ); // $ExpectError + svariancepn( false, 1, x, 1 ); // $ExpectError + svariancepn( null, 1, x, 1 ); // $ExpectError + svariancepn( undefined, 1, x, 1 ); // $ExpectError + svariancepn( [], 1, x, 1 ); // $ExpectError + svariancepn( {}, 1, x, 1 ); // $ExpectError + svariancepn( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn( x.length, '10', x, 1 ); // $ExpectError + svariancepn( x.length, true, x, 1 ); // $ExpectError + svariancepn( x.length, false, x, 1 ); // $ExpectError + svariancepn( x.length, null, x, 1 ); // $ExpectError + svariancepn( x.length, undefined, x, 1 ); // $ExpectError + svariancepn( x.length, [], x, 1 ); // $ExpectError + svariancepn( x.length, {}, x, 1 ); // $ExpectError + svariancepn( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + svariancepn( x.length, 1, 10, 1 ); // $ExpectError + svariancepn( x.length, 1, '10', 1 ); // $ExpectError + svariancepn( x.length, 1, true, 1 ); // $ExpectError + svariancepn( x.length, 1, false, 1 ); // $ExpectError + svariancepn( x.length, 1, null, 1 ); // $ExpectError + svariancepn( x.length, 1, undefined, 1 ); // $ExpectError + svariancepn( x.length, 1, [], 1 ); // $ExpectError + svariancepn( x.length, 1, {}, 1 ); // $ExpectError + svariancepn( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn( x.length, 1, x, '10' ); // $ExpectError + svariancepn( x.length, 1, x, true ); // $ExpectError + svariancepn( x.length, 1, x, false ); // $ExpectError + svariancepn( x.length, 1, x, null ); // $ExpectError + svariancepn( x.length, 1, x, undefined ); // $ExpectError + svariancepn( x.length, 1, x, [] ); // $ExpectError + svariancepn( x.length, 1, x, {} ); // $ExpectError + svariancepn( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + + svariancepn(); // $ExpectError + svariancepn( x.length ); // $ExpectError + svariancepn( x.length, 1 ); // $ExpectError + svariancepn( x.length, 1, x ); // $ExpectError + svariancepn( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( true, 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( false, 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( null, 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( [], 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, true ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, false ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, null ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + + svariancepn.ndarray(); // $ExpectError + svariancepn.ndarray( x.length ); // $ExpectError + svariancepn.ndarray( x.length, 1 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1 ); // $ExpectError + svariancepn.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/Makefile b/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/Makefile new file mode 100644 index 000000000000..ff5293d3059f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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/strided/svariancepn/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/example.c new file mode 100644 index 000000000000..efa709b943f1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/c/example.c @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svariancepn.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svariancepn( N, 1.0f, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/index.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/index.js new file mode 100644 index 000000000000..9944adbd1f65 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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'; + +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svariancepn = require( './../lib' ); + +var x; +var i; + +x = new Float32Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( (randu()*100.0) - 50.0 ); +} +console.log( x ); + +var v = svariancepn( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/include.gypi b/lib/node_modules/@stdlib/stats/strided/svariancepn/include.gypi new file mode 100644 index 000000000000..26476a8c2655 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2020 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': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "variance", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "strided", + "strided array", + "typed", + "array", + "float32", + "float", + "single", + "float32array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/src/Makefile b/lib/node_modules/@stdlib/stats/strided/svariancepn/src/Makefile new file mode 100644 index 000000000000..dd720a3de8f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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/strided/svariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/strided/svariancepn/src/addon.c new file mode 100644 index 000000000000..034d1c99b7c4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/src/addon.c @@ -0,0 +1,64 @@ +/** +* @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/strided/svariancepn.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" +#include "stdlib/napi/argv_float.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancepn)( N, correction, X, strideX ), v ); + return v; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancepn_ndarray)( N, correction, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/src/main.c b/lib/node_modules/@stdlib/stats/strided/svariancepn/src/main.c new file mode 100644 index 000000000000..bf303e4549f5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/src/main.c @@ -0,0 +1,90 @@ +/** +* @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/strided/svariancepn.h" +#include "stdlib/blas/ext/base/ssumpw.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svariancepn)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_svariancepn_ndarray)( N, correction, X, strideX, ox ); +} + +/** +* Computes the variance of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svariancepn_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; + double dN; + double n; + float mu; + float M2; + float M; + float d; + + dN = (double)N; + n = dN - (double)correction; + if ( N <= 0 || n <= 0.0f ) { + return 0.0f / 0.0f; // NaN + } + if ( N == 1 || strideX == 0 ) { + return 0.0f; + } + // Compute an estimate for the mean: + mu = (double)API_SUFFIX(stdlib_strided_ssumpw_ndarray)( N, X, strideX, offsetX ) / dN; + + ix = offsetX; + + // Compute the variance... + M2 = 0.0f; + M = 0.0f; + for ( i = 0; i < N; i++ ) { + d = X[ ix ] - mu; + M2 += d * d; + M += d; + ix += strideX; + } + return (float)((double)M2/n) - ( (float)((double)M/dN) * (float)((double)M/n) ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.js new file mode 100644 index 000000000000..770452394cee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var svariancepn = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof svariancepn.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var svariancepn = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( svariancepn, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var svariancepn; + var main; + + main = require( './../lib/svariancepn.js' ); + + svariancepn = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( svariancepn, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.js new file mode 100644 index 000000000000..761d1a72f833 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svariancepn = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( svariancepn.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancepn( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancepn( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = svariancepn( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.native.js new file mode 100644 index 000000000000..071119c39781 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.ndarray.native.js @@ -0,0 +1,205 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var svariancepn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( svariancepn instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( svariancepn.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancepn( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancepn( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = svariancepn( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.js new file mode 100644 index 000000000000..5440fa2661e4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svariancepn = require( './../lib/svariancepn.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( svariancepn.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 0, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 1, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancepn( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancepn( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = svariancepn( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.native.js b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.native.js new file mode 100644 index 000000000000..078308abd5a3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancepn/test/test.svariancepn.native.js @@ -0,0 +1,209 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var svariancepn = tryRequire( resolve( __dirname, './../lib/svariancepn.native.js' ) ); +var opts = { + 'skip': ( svariancepn instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', opts, function test( t ) { + t.strictEqual( svariancepn.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 0, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancepn( x.length, 1, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancepn( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancepn( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancepn( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancepn( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancepn( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancepn( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = svariancepn( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From b693ff6bd72f531092f713f47b295197ee1bb3ae Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 06:01:22 +0530 Subject: [PATCH 14/26] remove: remove `stats/base/svariancepn` from namespace This commit removes the `svariancepn` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `stats/base/svariancepn` To migrate, users should access the same symbol via the `@stdlib/stats/strided/svariancepn` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 28 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------ 2 files changed, 37 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index ccc90d682153..87558fdcea3f 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -127,7 +127,6 @@ import stdevtk = require( '@stdlib/stats/base/stdevtk' ); import stdevwd = require( '@stdlib/stats/base/stdevwd' ); import stdevyc = require( '@stdlib/stats/base/stdevyc' ); import svariance = require( '@stdlib/stats/base/svariance' ); -import svariancepn = require( '@stdlib/stats/base/svariancepn' ); import svariancetk = require( '@stdlib/stats/base/svariancetk' ); import svariancewd = require( '@stdlib/stats/base/svariancewd' ); import svarianceyc = require( '@stdlib/stats/base/svarianceyc' ); @@ -2981,33 +2980,6 @@ interface Namespace { */ svariance: typeof svariance; - /** - * Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = ns.svariancepn( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = ns.svariancepn.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - svariancepn: typeof svariancepn; - /** * Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index 3705ba13d849..b077534762df 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -999,15 +999,6 @@ setReadOnly( ns, 'stdevyc', require( '@stdlib/stats/base/stdevyc' ) ); */ setReadOnly( ns, 'svariance', require( '@stdlib/stats/base/svariance' ) ); -/** -* @name svariancepn -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/svariancepn} -*/ -setReadOnly( ns, 'svariancepn', require( '@stdlib/stats/base/svariancepn' ) ); - /** * @name svariancetk * @memberof ns From fbce42c8ae4ce2a5517960942d70ce4eaef15c3e Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:11:28 +0530 Subject: [PATCH 15/26] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 4 ++-- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 8 ++++---- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- .../@stdlib/stats/base/snanvariancepn/README.md | 4 ++-- .../@stdlib/stats/base/svariance/lib/ndarray.js | 2 +- .../@stdlib/stats/base/svariance/lib/svariance.js | 2 +- .../@stdlib/stats/base/svariance/manifest.json | 8 ++++---- .../@stdlib/stats/base/svariance/src/svariance.c | 2 +- lib/node_modules/@stdlib/stats/base/variancepn/README.md | 4 ++-- .../@stdlib/stats/strided/dsvariancepn/README.md | 4 ++-- .../@stdlib/stats/strided/dvariancepn/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/sstdevpn/README.md | 4 ++-- .../@stdlib/stats/strided/sstdevpn/lib/ndarray.js | 2 +- .../@stdlib/stats/strided/sstdevpn/manifest.json | 8 ++++---- .../@stdlib/stats/strided/sstdevpn/src/main.c | 2 +- 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index f64420e02dbb..4e15c8e400ba 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2168,7 +2168,7 @@ ns.push({ '@stdlib/stats/strided/dsvariance', '@stdlib/stats/base/variancepn', '@stdlib/stats/base/sdsvariance', - '@stdlib/stats/base/svariancepn' + '@stdlib/stats/strided/svariancepn' ] }); @@ -2280,7 +2280,7 @@ ns.push({ '@stdlib/stats/strided/dnanvariancepn', '@stdlib/stats/strided/dstdevpn', '@stdlib/stats/strided/dvariance', - '@stdlib/stats/base/svariancepn', + '@stdlib/stats/strided/svariancepn', '@stdlib/stats/base/variancepn' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index a124da06d75a..e94d99b3c955 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1406,7 +1406,7 @@ ns.push({ '@stdlib/stats/base/nanvariancepn', '@stdlib/stats/base/snanstdevpn', '@stdlib/stats/base/snanvariance', - '@stdlib/stats/base/svariancepn' + '@stdlib/stats/strided/svariancepn' ] }); @@ -1652,7 +1652,7 @@ ns.push({ '@stdlib/stats/base/sstdev', '@stdlib/stats/base/sstdevmpn', '@stdlib/stats/base/stdevpn', - '@stdlib/stats/base/svariancepn' + '@stdlib/stats/strided/svariancepn' ] }); @@ -1920,8 +1920,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.svariancepn', - 'path': '@stdlib/stats/base/svariancepn', - 'value': require( '@stdlib/stats/base/svariancepn' ), + 'path': '@stdlib/stats/strided/svariancepn', + 'value': require( '@stdlib/stats/strided/svariancepn' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariancepn', diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index 659c3487efab..a87d68ddc2ff 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -239,7 +239,7 @@ The namespace contains the following statistical functions: - [`stdevyc( N, correction, x, stride )`][@stdlib/stats/base/stdevyc]: calculate the standard deviation of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`svariance( N, correction, x, stride )`][@stdlib/stats/base/svariance]: calculate the variance of a single-precision floating-point strided array. - [`svariancech( N, correction, x, strideX )`][@stdlib/stats/strided/svariancech]: calculate the variance of a single-precision floating-point strided array using a one-pass trial mean algorithm. -- [`svariancepn( N, correction, x, strideX )`][@stdlib/stats/base/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. +- [`svariancepn( N, correction, x, strideX )`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. - [`svariancetk( N, correction, x, strideX )`][@stdlib/stats/base/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. - [`svariancewd( N, correction, x, stride )`][@stdlib/stats/base/svariancewd]: calculate the variance of a single-precision floating-point strided array using Welford's algorithm. - [`svarianceyc( N, correction, x, strideX )`][@stdlib/stats/base/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -663,7 +663,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/strided/svariancech]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancech -[@stdlib/stats/base/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancepn +[@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn [@stdlib/stats/base/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancetk diff --git a/lib/node_modules/@stdlib/stats/base/snanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/snanvariancepn/README.md index 6ad69d007365..eb6a46aed57a 100644 --- a/lib/node_modules/@stdlib/stats/base/snanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/snanvariancepn/README.md @@ -247,7 +247,7 @@ console.log( v ); - [`@stdlib/stats/base/nanvariancepn`][@stdlib/stats/base/nanvariancepn]: calculate the variance of a strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/base/snanstdevpn`][@stdlib/stats/base/snanstdevpn]: calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/base/snanvariance`][@stdlib/stats/base/snanvariance]: calculate the variance of a single-precision floating-point strided array ignoring NaN values. -- [`@stdlib/stats/base/svariancepn`][@stdlib/stats/base/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/svariancepn`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm.
@@ -277,7 +277,7 @@ console.log( v ); [@stdlib/stats/base/snanvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariance -[@stdlib/stats/base/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancepn +[@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn diff --git a/lib/node_modules/@stdlib/stats/base/svariance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/svariance/lib/ndarray.js index 70c500b9c611..db272a3ada9a 100644 --- a/lib/node_modules/@stdlib/stats/base/svariance/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariance/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var svariancepn = require( '@stdlib/stats/base/svariancepn' ).ndarray; +var svariancepn = require( '@stdlib/stats/strided/svariancepn' ).ndarray; // MAIN // diff --git a/lib/node_modules/@stdlib/stats/base/svariance/lib/svariance.js b/lib/node_modules/@stdlib/stats/base/svariance/lib/svariance.js index a9ef2dcedb1e..c47f5aaef586 100644 --- a/lib/node_modules/@stdlib/stats/base/svariance/lib/svariance.js +++ b/lib/node_modules/@stdlib/stats/base/svariance/lib/svariance.js @@ -20,7 +20,7 @@ // MODULES // -var svariancepn = require( '@stdlib/stats/base/svariancepn' ); +var svariancepn = require( '@stdlib/stats/strided/svariancepn' ); // MAIN // diff --git a/lib/node_modules/@stdlib/stats/base/svariance/manifest.json b/lib/node_modules/@stdlib/stats/base/svariance/manifest.json index c98e5bd1cd8a..676981f220cc 100644 --- a/lib/node_modules/@stdlib/stats/base/svariance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/svariance/manifest.json @@ -26,7 +26,7 @@ ], "confs": [ { - "task": "build", + "task": "build", "src": [ "./src/svariance.c" ], @@ -38,7 +38,7 @@ ], "libpath": [], "dependencies": [ - "@stdlib/stats/base/svariancepn", + "@stdlib/stats/strided/svariancepn", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -60,7 +60,7 @@ ], "libpath": [], "dependencies": [ - "@stdlib/stats/base/svariancepn" + "@stdlib/stats/strided/svariancepn" ] }, { @@ -76,7 +76,7 @@ ], "libpath": [], "dependencies": [ - "@stdlib/stats/base/svariancepn" + "@stdlib/stats/strided/svariancepn" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/svariance/src/svariance.c b/lib/node_modules/@stdlib/stats/base/svariance/src/svariance.c index e30a39299066..1920eca150e9 100644 --- a/lib/node_modules/@stdlib/stats/base/svariance/src/svariance.c +++ b/lib/node_modules/@stdlib/stats/base/svariance/src/svariance.c @@ -17,7 +17,7 @@ */ #include "stdlib/stats/base/svariance.h" -#include "stdlib/stats/base/svariancepn.h" +#include "stdlib/stats/strided/svariancepn.h" #include /** diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/README.md b/lib/node_modules/@stdlib/stats/base/variancepn/README.md index 0ec558db1f6b..3338288f2554 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/variancepn/README.md @@ -184,7 +184,7 @@ var v = variancepn.ndarray( N, 1, x, 2, 1 ); - If `N <= 0`, both functions return `NaN`. - If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Depending on the environment, the typed versions ([`dvariancepn`][@stdlib/stats/strided/dvariancepn], [`svariancepn`][@stdlib/stats/base/svariancepn], etc.) are likely to be significantly more performant. +- Depending on the environment, the typed versions ([`dvariancepn`][@stdlib/stats/strided/dvariancepn], [`svariancepn`][@stdlib/stats/strided/svariancepn], etc.) are likely to be significantly more performant. @@ -259,7 +259,7 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray -[@stdlib/stats/base/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancepn +[@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn [@neely:1966a]: https://doi.org/10.1145/365719.365958 diff --git a/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md b/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md index fccad672bde6..531a7ddea356 100644 --- a/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dsvariancepn/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/strided/dvariancepn`][@stdlib/stats/strided/dvariancepn]: calculate the variance of a double-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/strided/dsvariance`][@stdlib/stats/strided/dsvariance]: calculate the variance of a single-precision floating-point strided array using extended accumulation and returning an extended precision result. - [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. -- [`@stdlib/stats/base/svariancepn`][@stdlib/stats/base/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/svariancepn`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. @@ -381,7 +381,7 @@ int main( void ) { [@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn -[@stdlib/stats/base/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancepn +[@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn diff --git a/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md b/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md index 571e0e9ca157..fe0650b2339c 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariancepn/README.md @@ -352,7 +352,7 @@ int main( void ) { - [`@stdlib/stats/strided/dnanvariancepn`][@stdlib/stats/strided/dnanvariancepn]: calculate the variance of a double-precision floating-point strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/strided/dstdevpn`][@stdlib/stats/strided/dstdevpn]: calculate the standard deviation of a double-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. -- [`@stdlib/stats/base/svariancepn`][@stdlib/stats/base/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/svariancepn`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. - [`@stdlib/stats/base/variancepn`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. @@ -381,7 +381,7 @@ int main( void ) { [@stdlib/stats/strided/dvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dvariance -[@stdlib/stats/base/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancepn +[@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn [@stdlib/stats/base/variancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancepn diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevpn/README.md b/lib/node_modules/@stdlib/stats/strided/sstdevpn/README.md index 8ee7c691611b..e897dbe21914 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevpn/README.md +++ b/lib/node_modules/@stdlib/stats/strided/sstdevpn/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/base/snanstdevpn`][@stdlib/stats/base/snanstdevpn]: calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a two-pass algorithm. - [`@stdlib/stats/base/sstdev`][@stdlib/stats/base/sstdev]: calculate the standard deviation of a single-precision floating-point strided array. - [`@stdlib/stats/base/stdevpn`][@stdlib/stats/base/stdevpn]: calculate the standard deviation of a strided array using a two-pass algorithm. -- [`@stdlib/stats/base/svariancepn`][@stdlib/stats/base/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. +- [`@stdlib/stats/strided/svariancepn`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. @@ -383,7 +383,7 @@ int main( void ) { [@stdlib/stats/base/stdevpn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevpn -[@stdlib/stats/base/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancepn +[@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevpn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/sstdevpn/lib/ndarray.js index 6a1f8158955a..c34824a59ad4 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevpn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/sstdevpn/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var svariancepn = require( '@stdlib/stats/base/svariancepn' ).ndarray; +var svariancepn = require( '@stdlib/stats/strided/svariancepn' ).ndarray; var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevpn/manifest.json b/lib/node_modules/@stdlib/stats/strided/sstdevpn/manifest.json index 970ba1c06193..3d93fac5a44a 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevpn/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/sstdevpn/manifest.json @@ -41,7 +41,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancepn", + "@stdlib/stats/strided/svariancepn", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -65,7 +65,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancepn" + "@stdlib/stats/strided/svariancepn" ] }, { @@ -83,7 +83,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancepn" + "@stdlib/stats/strided/svariancepn" ] }, { @@ -101,7 +101,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancepn" + "@stdlib/stats/strided/svariancepn" ] } ] diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevpn/src/main.c b/lib/node_modules/@stdlib/stats/strided/sstdevpn/src/main.c index ba471d050a43..4f67481615e1 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevpn/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/sstdevpn/src/main.c @@ -17,7 +17,7 @@ */ #include "stdlib/stats/strided/sstdevpn.h" -#include "stdlib/stats/base/svariancepn.h" +#include "stdlib/stats/strided/svariancepn.h" #include "stdlib/blas/base/shared.h" #include "stdlib/math/base/special/sqrtf.h" #include "stdlib/strided/base/stride2offset.h" From af9229782d9a2af41886d32845ae26ec78ee1b23 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:12:15 +0530 Subject: [PATCH 16/26] remove: remove `stats/base/svariancepn` This commit removes `@stdlib/stats/base/svariancepn` in favor of `@stdlib/stats/strided/svariancepn`. BREAKING CHANGE: remove `stats/base/svariancepn` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/svariancepn`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- 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 --- --- .../@stdlib/stats/base/svariancepn/README.md | 392 ------------------ .../base/svariancepn/benchmark/benchmark.js | 96 ----- .../svariancepn/benchmark/benchmark.native.js | 101 ----- .../benchmark/benchmark.ndarray.js | 96 ----- .../benchmark/benchmark.ndarray.native.js | 101 ----- .../base/svariancepn/benchmark/c/Makefile | 146 ------- .../benchmark/c/benchmark.length.c | 197 --------- .../stats/base/svariancepn/binding.gyp | 170 -------- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 -- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/svariancepn/docs/repl.txt | 114 ----- .../base/svariancepn/docs/types/index.d.ts | 95 ----- .../stats/base/svariancepn/docs/types/test.ts | 187 --------- .../base/svariancepn/examples/c/Makefile | 146 ------- .../base/svariancepn/examples/c/example.c | 37 -- .../stats/base/svariancepn/examples/index.js | 36 -- .../stats/base/svariancepn/include.gypi | 53 --- .../include/stdlib/stats/base/svariancepn.h | 45 -- .../stats/base/svariancepn/lib/index.js | 68 --- .../stats/base/svariancepn/lib/main.js | 35 -- .../stats/base/svariancepn/lib/native.js | 35 -- .../stats/base/svariancepn/lib/ndarray.js | 91 ---- .../base/svariancepn/lib/ndarray.native.js | 53 --- .../stats/base/svariancepn/lib/svariancepn.js | 62 --- .../svariancepn/lib/svariancepn.native.js | 52 --- .../stats/base/svariancepn/manifest.json | 104 ----- .../stats/base/svariancepn/package.json | 81 ---- .../stats/base/svariancepn/src/Makefile | 70 ---- .../stats/base/svariancepn/src/addon.c | 64 --- .../@stdlib/stats/base/svariancepn/src/main.c | 90 ---- .../stats/base/svariancepn/test/test.js | 82 ---- .../base/svariancepn/test/test.ndarray.js | 196 --------- .../svariancepn/test/test.ndarray.native.js | 205 --------- .../base/svariancepn/test/test.svariancepn.js | 200 --------- .../test/test.svariancepn.native.js | 209 ---------- 37 files changed, 3909 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/benchmark.length.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/binding.gyp delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/example.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/include.gypi delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/include/stdlib/stats/base/svariancepn.h delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/svariancepn.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/lib/svariancepn.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/manifest.json delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/src/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/src/main.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.native.js diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/README.md b/lib/node_modules/@stdlib/stats/base/svariancepn/README.md deleted file mode 100644 index 8c8c11bae988..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/README.md +++ /dev/null @@ -1,392 +0,0 @@ - - -# svariancepn - -> Calculate the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var svariancepn = require( '@stdlib/stats/base/svariancepn' ); -``` - -#### svariancepn( N, correction, x, strideX ) - -Computes the [variance][variance] of a single-precision floating-point strided array `x` using a two-pass algorithm. - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - -var v = svariancepn( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); - -var v = svariancepn( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = svariancepn( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### svariancepn.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - -var v = svariancepn.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); - -var v = svariancepn.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var svariancepn = require( '@stdlib/stats/base/svariancepn' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float32' -}); -console.log( x ); - -var v = svariancepn( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/stats/base/svariancepn.h" -``` - -#### stdlib_strided_svariancepn( N, correction, \*X, strideX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm. - -```c -const float x[] = { 1.0f, -2.0f, 2.0f }; - -float v = stdlib_strided_svariancepn( 3, 1.0f, x, 1 ); -// returns ~4.3333f -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. - -```c -float stdlib_strided_svariancepn( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); -``` - -#### stdlib_strided_svariancepn_ndarray( N, correction, \*X, strideX, offsetX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. - -```c -const float x[] = { 1.0f, -2.0f, 2.0f }; - -float v = stdlib_strided_svariancepn_ndarray( 3, 1.0f, x, 1, 0 ); -// returns ~4.3333f -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **offsetX**: `[in] CBLAS_INT` starting index for `X`. - -```c -float stdlib_strided_svariancepn_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); -``` - -
- - - - - -
- -
- - - - - -
- -### Examples - -```c -#include "stdlib/stats/base/svariancepn.h" -#include - -int main( void ) { - // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; - - // Specify the number of elements: - const int N = 4; - - // Specify the stride length: - const int strideX = 2; - - // Compute the variance: - float v = stdlib_strided_svariancepn( N, 1.0f, x, strideX ); - - // Print the result: - printf( "sample variance: %f\n", v ); -} -``` - -
- - - -
- - - -* * * - -
- -## References - -- Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a]. -- Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.js deleted file mode 100644 index 7c7a1f505ec6..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var svariancepn = require( './../lib/svariancepn.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancepn( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.native.js deleted file mode 100644 index 40ed11862ad8..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.native.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var pkg = require( './../package.json' ).name; - - -// VARIABLES // - -var svariancepn = tryRequire( resolve( __dirname, './../lib/svariancepn.native.js' ) ); -var opts = { - 'skip': ( svariancepn instanceof Error ) -}; -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancepn( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+'::native:len='+len, opts, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.js deleted file mode 100644 index 6ac8e147cd6d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var svariancepn = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancepn( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.native.js deleted file mode 100644 index 8d8b769a0d5e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/benchmark.ndarray.native.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var pkg = require( './../package.json' ).name; - - -// VARIABLES // - -var svariancepn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( svariancepn instanceof Error ) -}; -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancepn( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+'::native:ndarray:len='+len, opts, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/Makefile deleted file mode 100644 index 7280962b4c4d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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.length.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/svariancepn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/benchmark.length.c deleted file mode 100644 index 22117461d90c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/benchmark/c/benchmark.length.c +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svariancepn.h" -#include -#include -#include -#include -#include - -#define NAME "svariancepn" -#define ITERATIONS 1000000 -#define REPEATS 3 -#define MIN 1 -#define MAX 6 - -/** -* 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 iterations number of iterations -* @param elapsed elapsed time in seconds -*/ -static void print_results( int iterations, 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 [0,1). -* -* @return random number -*/ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark1( int iterations, int len ) { - double elapsed; - float x[ len ]; - float v; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; - } - v = 0.0f; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - // cppcheck-suppress uninitvar - v = stdlib_strided_svariancepn( len, 1.0f, x, 1 ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark2( int iterations, int len ) { - double elapsed; - float x[ len ]; - float v; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; - } - v = 0.0f; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - // cppcheck-suppress uninitvar - v = stdlib_strided_svariancepn_ndarray( len, 1.0f, x, 1, 0 ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int iter; - int len; - int i; - int j; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - count = 0; - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark1( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:ndarray:len=%d\n", NAME, len ); - elapsed = benchmark2( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - print_summary( count, count ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/binding.gyp b/lib/node_modules/@stdlib/stats/base/svariancepn/binding.gyp deleted file mode 100644 index 7d0005b2e390..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/binding.gyp +++ /dev/null @@ -1,170 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2020 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 -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/repl.txt deleted file mode 100644 index c41646ed7569..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/repl.txt +++ /dev/null @@ -1,114 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a single-precision floating-point strided array - using a two-pass algorithm. - - The `N` and stride parameters determine which elements in `x` are accessed - at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Float32Array - Input array. - - strideX: integer - Stride Length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a single-precision floating-point strided array - using a two-pass algorithm and alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Float32Array - Input array. - - strideX: integer - Stride Length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/index.d.ts deleted file mode 100644 index f8e1149f7003..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/index.d.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface describing `svariancepn`. -*/ -interface Routine { - /** - * Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = svariancepn( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: Float32Array, strideX: number ): number; - - /** - * Computes the variance of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = svariancepn.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* -* var v = svariancepn( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* -* var v = svariancepn.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var svariancepn: Routine; - - -// EXPORTS // - -export = svariancepn; diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/test.ts deleted file mode 100644 index de555a0e092a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/docs/types/test.ts +++ /dev/null @@ -1,187 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -import svariancepn = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float32Array( 10 ); - - svariancepn( x.length, 1, x, 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn( '10', 1, x, 1 ); // $ExpectError - svariancepn( true, 1, x, 1 ); // $ExpectError - svariancepn( false, 1, x, 1 ); // $ExpectError - svariancepn( null, 1, x, 1 ); // $ExpectError - svariancepn( undefined, 1, x, 1 ); // $ExpectError - svariancepn( [], 1, x, 1 ); // $ExpectError - svariancepn( {}, 1, x, 1 ); // $ExpectError - svariancepn( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn( x.length, '10', x, 1 ); // $ExpectError - svariancepn( x.length, true, x, 1 ); // $ExpectError - svariancepn( x.length, false, x, 1 ); // $ExpectError - svariancepn( x.length, null, x, 1 ); // $ExpectError - svariancepn( x.length, undefined, x, 1 ); // $ExpectError - svariancepn( x.length, [], x, 1 ); // $ExpectError - svariancepn( x.length, {}, x, 1 ); // $ExpectError - svariancepn( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a Float32Array... -{ - const x = new Float32Array( 10 ); - - svariancepn( x.length, 1, 10, 1 ); // $ExpectError - svariancepn( x.length, 1, '10', 1 ); // $ExpectError - svariancepn( x.length, 1, true, 1 ); // $ExpectError - svariancepn( x.length, 1, false, 1 ); // $ExpectError - svariancepn( x.length, 1, null, 1 ); // $ExpectError - svariancepn( x.length, 1, undefined, 1 ); // $ExpectError - svariancepn( x.length, 1, [], 1 ); // $ExpectError - svariancepn( x.length, 1, {}, 1 ); // $ExpectError - svariancepn( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn( x.length, 1, x, '10' ); // $ExpectError - svariancepn( x.length, 1, x, true ); // $ExpectError - svariancepn( x.length, 1, x, false ); // $ExpectError - svariancepn( x.length, 1, x, null ); // $ExpectError - svariancepn( x.length, 1, x, undefined ); // $ExpectError - svariancepn( x.length, 1, x, [] ); // $ExpectError - svariancepn( x.length, 1, x, {} ); // $ExpectError - svariancepn( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float32Array( 10 ); - - svariancepn(); // $ExpectError - svariancepn( x.length ); // $ExpectError - svariancepn( x.length, 1 ); // $ExpectError - svariancepn( x.length, 1, x ); // $ExpectError - svariancepn( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( true, 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( false, 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( null, 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( [], 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, true ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, false ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, null ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float32Array( 10 ); - - svariancepn.ndarray(); // $ExpectError - svariancepn.ndarray( x.length ); // $ExpectError - svariancepn.ndarray( x.length, 1 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1 ); // $ExpectError - svariancepn.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/Makefile deleted file mode 100644 index ff5293d3059f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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/svariancepn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/example.c deleted file mode 100644 index 914cd990de0a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/examples/c/example.c +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svariancepn.h" -#include - -int main( void ) { - // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; - - // Specify the number of elements: - const int N = 4; - - // Specify the stride length: - const int strideX = 2; - - // Compute the variance: - float v = stdlib_strided_svariancepn( N, 1.0f, x, strideX ); - - // Print the result: - printf( "sample variance: %f\n", v ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/svariancepn/examples/index.js deleted file mode 100644 index 9944adbd1f65..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/examples/index.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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'; - -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svariancepn = require( './../lib' ); - -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} -console.log( x ); - -var v = svariancepn( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/include.gypi b/lib/node_modules/@stdlib/stats/base/svariancepn/include.gypi deleted file mode 100644 index 26476a8c2655..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/include.gypi +++ /dev/null @@ -1,53 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2020 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': [ - '=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdmath", - "statistics", - "stats", - "mathematics", - "math", - "variance", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "strided", - "strided array", - "typed", - "array", - "float32", - "float", - "single", - "float32array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/src/Makefile b/lib/node_modules/@stdlib/stats/base/svariancepn/src/Makefile deleted file mode 100644 index dd720a3de8f2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/src/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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/svariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/svariancepn/src/addon.c deleted file mode 100644 index 052b650eb331..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/src/addon.c +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @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/svariancepn.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/napi/export.h" -#include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_strided_float32array.h" -#include "stdlib/napi/create_double.h" -#include "stdlib/napi/argv_float.h" -#include - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) - STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancepn)( N, correction, X, strideX ), v ); - return v; -} - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon_method( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); - STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancepn_ndarray)( N, correction, X, strideX, offsetX ), v ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/svariancepn/src/main.c deleted file mode 100644 index 758e48bcf37e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/src/main.c +++ /dev/null @@ -1,90 +0,0 @@ -/** -* @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/svariancepn.h" -#include "stdlib/blas/ext/base/ssumpw.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/strided/base/stride2offset.h" - -/** -* Computes the variance of a single-precision floating-point strided array using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @return output value -*/ -float API_SUFFIX(stdlib_strided_svariancepn)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { - const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - return API_SUFFIX(stdlib_strided_svariancepn_ndarray)( N, correction, X, strideX, ox ); -} - -/** -* Computes the variance of a single-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @param offsetX starting index for X -* @return output value -*/ -float API_SUFFIX(stdlib_strided_svariancepn_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - CBLAS_INT ix; - CBLAS_INT i; - double dN; - double n; - float mu; - float M2; - float M; - float d; - - dN = (double)N; - n = dN - (double)correction; - if ( N <= 0 || n <= 0.0f ) { - return 0.0f / 0.0f; // NaN - } - if ( N == 1 || strideX == 0 ) { - return 0.0f; - } - // Compute an estimate for the mean: - mu = (double)API_SUFFIX(stdlib_strided_ssumpw_ndarray)( N, X, strideX, offsetX ) / dN; - - ix = offsetX; - - // Compute the variance... - M2 = 0.0f; - M = 0.0f; - for ( i = 0; i < N; i++ ) { - d = X[ ix ] - mu; - M2 += d * d; - M += d; - ix += strideX; - } - return (float)((double)M2/n) - ( (float)((double)M/dN) * (float)((double)M/n) ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.js b/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.js deleted file mode 100644 index 770452394cee..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var svariancepn = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof svariancepn.ndarray, 'function', 'method is a function' ); - t.end(); -}); - -tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { - var svariancepn = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( svariancepn, mock, 'returns expected value' ); - t.end(); - - function tryRequire() { - return mock; - } - - function mock() { - // Mock... - } -}); - -tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { - var svariancepn; - var main; - - main = require( './../lib/svariancepn.js' ); - - svariancepn = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( svariancepn, main, 'returns expected value' ); - t.end(); - - function tryRequire() { - return new Error( 'Cannot find module' ); - } -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.js deleted file mode 100644 index 761d1a72f833..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.js +++ /dev/null @@ -1,196 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svariancepn = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( svariancepn.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancepn( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancepn( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = svariancepn( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.native.js deleted file mode 100644 index 071119c39781..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.ndarray.native.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var svariancepn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( svariancepn instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( svariancepn.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancepn( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancepn( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = svariancepn( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.js b/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.js deleted file mode 100644 index 5440fa2661e4..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.js +++ /dev/null @@ -1,200 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svariancepn = require( './../lib/svariancepn.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( svariancepn.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 0, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 1, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancepn( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancepn( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = svariancepn( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.native.js b/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.native.js deleted file mode 100644 index 078308abd5a3..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancepn/test/test.svariancepn.native.js +++ /dev/null @@ -1,209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var svariancepn = tryRequire( resolve( __dirname, './../lib/svariancepn.native.js' ) ); -var opts = { - 'skip': ( svariancepn instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancepn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( svariancepn.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 0, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancepn( x.length, 1, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancepn( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancepn( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancepn( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancepn( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancepn( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancepn( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', opts, function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = svariancepn( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From 5d860053727c6a6569c931d62e499bb37e878fda Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:14:47 +0530 Subject: [PATCH 17/26] feat: add `stats/strided/svariancetk` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/svariancetk/README.md | 420 ++++++++++++++++++ .../svariancetk/benchmark/benchmark.js | 96 ++++ .../svariancetk/benchmark/benchmark.native.js | 101 +++++ .../benchmark/benchmark.ndarray.js | 96 ++++ .../benchmark/benchmark.ndarray.native.js | 101 +++++ .../strided/svariancetk/benchmark/c/Makefile | 146 ++++++ .../benchmark/c/benchmark.length.c | 197 ++++++++ .../stats/strided/svariancetk/binding.gyp | 170 +++++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../equation_population_variance_textbook.svg | 81 ++++ .../docs/img/equation_sample_mean.svg | 43 ++ .../img/equation_unbiased_sample_variance.svg | 61 +++ ...tion_unbiased_sample_variance_textbook.svg | 85 ++++ .../stats/strided/svariancetk/docs/repl.txt | 114 +++++ .../strided/svariancetk/docs/types/index.d.ts | 95 ++++ .../strided/svariancetk/docs/types/test.ts | 187 ++++++++ .../strided/svariancetk/examples/c/Makefile | 146 ++++++ .../strided/svariancetk/examples/c/example.c | 37 ++ .../strided/svariancetk/examples/index.js | 30 ++ .../stats/strided/svariancetk/include.gypi | 53 +++ .../stdlib/stats/strided/svariancetk.h | 45 ++ .../stats/strided/svariancetk/lib/index.js | 68 +++ .../stats/strided/svariancetk/lib/main.js | 35 ++ .../stats/strided/svariancetk/lib/native.js | 35 ++ .../stats/strided/svariancetk/lib/ndarray.js | 76 ++++ .../strided/svariancetk/lib/ndarray.native.js | 53 +++ .../strided/svariancetk/lib/svariancetk.js | 53 +++ .../svariancetk/lib/svariancetk.native.js | 52 +++ .../stats/strided/svariancetk/manifest.json | 100 +++++ .../stats/strided/svariancetk/package.json | 81 ++++ .../stats/strided/svariancetk/src/Makefile | 70 +++ .../stats/strided/svariancetk/src/addon.c | 64 +++ .../stats/strided/svariancetk/src/main.c | 74 +++ .../stats/strided/svariancetk/test/test.js | 82 ++++ .../strided/svariancetk/test/test.ndarray.js | 196 ++++++++ .../svariancetk/test/test.ndarray.native.js | 205 +++++++++ .../svariancetk/test/test.svariancetk.js | 200 +++++++++ .../test/test.svariancetk.native.js | 209 +++++++++ 39 files changed, 4053 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance_textbook.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/include/stdlib/stats/strided/svariancetk.h create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/svariancetk.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/lib/svariancetk.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.native.js diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md b/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md new file mode 100644 index 000000000000..efc3376a125c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/README.md @@ -0,0 +1,420 @@ + + +# svariancetk + +> Calculate the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +After rearranging terms, the population [variance][variance] can be equivalently expressed as + + + +```math +\sigma^2 = \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i^2 - \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i \ \biggr)^2\ \biggr) +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +Similar to the population [variance][variance], after rearranging terms, the **unbiased sample variance** can be equivalently expressed as + + + +```math +s^2 = \frac{1}{n-1}\biggl(\ \sum_{i=0}^{n-1} x_i^2 - \frac{1}{n}\biggl(\ \sum_{i=0}^{n-1} x_i \ \biggr)^2\ \biggr) +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var svariancetk = require( '@stdlib/stats/strided/svariancetk' ); +``` + +#### svariancetk( N, correction, x, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array `x` using a one-pass textbook algorithm. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + +var v = svariancetk( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); + +var v = svariancetk( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = svariancetk( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### svariancetk.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + +var v = svariancetk.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); + +var v = svariancetk.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. +- Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of returning a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the variance exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var svariancetk = require( '@stdlib/stats/strided/svariancetk' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +console.log( x ); + +var v = svariancetk( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/strided/svariancetk.h" +``` + +#### stdlib_strided_svariancetk( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svariancetk( 3, 1.0f, x, 1 ); +// returns ~4.3333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +float stdlib_strided_svariancetk( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_svariancetk_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svariancetk_ndarray( 3, 1.0f, x, 1, 0 ); +// returns ~4.3333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +float stdlib_strided_svariancetk_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/strided/svariancetk.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svariancetk( N, 1.0f, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} +``` + +
+ + + +
+ + + +* * * + +
+ +## References + +- Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.js new file mode 100644 index 000000000000..68820a10499a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var svariancetk = require( './../lib/svariancetk.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancetk( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f2950786c9a4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.native.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var svariancetk = tryRequire( resolve( __dirname, './../lib/svariancetk.native.js' ) ); +var opts = { + 'skip': ( svariancetk instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancetk( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..5fd2d978c543 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var svariancetk = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancetk( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..4653bf3c9957 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var svariancetk = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( svariancetk instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svariancetk( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/Makefile new file mode 100644 index 000000000000..7280962b4c4d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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.length.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/strided/svariancetk/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..f635d6f3aee5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/benchmark/c/benchmark.length.c @@ -0,0 +1,197 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svariancetk.h" +#include +#include +#include +#include +#include + +#define NAME "svariancetk" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* 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 iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, 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 [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_svariancetk( len, 1.0f, x, 1 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_svariancetk_ndarray( len, 1.0f, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/binding.gyp b/lib/node_modules/@stdlib/stats/strided/svariancetk/binding.gyp new file mode 100644 index 000000000000..7d0005b2e390 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2020 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 +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance_textbook.svg b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance_textbook.svg new file mode 100644 index 000000000000..923bd7a21462 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance_textbook.svg @@ -0,0 +1,81 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i Superscript 2 Baseline minus StartFraction 1 Over upper N EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i Baseline right-parenthesis squared right-parenthesis + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg new file mode 100644 index 000000000000..ccf58f263bb0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg @@ -0,0 +1,85 @@ + +s squared equals StartFraction 1 Over n minus 1 EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i Superscript 2 Baseline minus StartFraction 1 Over n EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i Baseline right-parenthesis squared right-parenthesis + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/repl.txt new file mode 100644 index 000000000000..807fbf2a6c32 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/repl.txt @@ -0,0 +1,114 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a single-precision floating-point strided array + using a one-pass textbook algorithm. + + The `N` and stride parameters determine which elements in `x` are accessed + at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float32Array + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a single-precision floating-point strided array + using a one-pass textbook algorithm and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float32Array + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/index.d.ts new file mode 100644 index 000000000000..4e1d7827a817 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/index.d.ts @@ -0,0 +1,95 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `svariancetk`. +*/ +interface Routine { + /** + * Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + * + * var v = svariancetk( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: Float32Array, strideX: number ): number; + + /** + * Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + * + * var v = svariancetk.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +* +* var v = svariancetk( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +* +* var v = svariancetk.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var svariancetk: Routine; + + +// EXPORTS // + +export = svariancetk; diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/test.ts new file mode 100644 index 000000000000..058418af092c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/types/test.ts @@ -0,0 +1,187 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +import svariancetk = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float32Array( 10 ); + + svariancetk( x.length, 1, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk( '10', 1, x, 1 ); // $ExpectError + svariancetk( true, 1, x, 1 ); // $ExpectError + svariancetk( false, 1, x, 1 ); // $ExpectError + svariancetk( null, 1, x, 1 ); // $ExpectError + svariancetk( undefined, 1, x, 1 ); // $ExpectError + svariancetk( [], 1, x, 1 ); // $ExpectError + svariancetk( {}, 1, x, 1 ); // $ExpectError + svariancetk( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk( x.length, '10', x, 1 ); // $ExpectError + svariancetk( x.length, true, x, 1 ); // $ExpectError + svariancetk( x.length, false, x, 1 ); // $ExpectError + svariancetk( x.length, null, x, 1 ); // $ExpectError + svariancetk( x.length, undefined, x, 1 ); // $ExpectError + svariancetk( x.length, [], x, 1 ); // $ExpectError + svariancetk( x.length, {}, x, 1 ); // $ExpectError + svariancetk( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + svariancetk( x.length, 1, 10, 1 ); // $ExpectError + svariancetk( x.length, 1, '10', 1 ); // $ExpectError + svariancetk( x.length, 1, true, 1 ); // $ExpectError + svariancetk( x.length, 1, false, 1 ); // $ExpectError + svariancetk( x.length, 1, null, 1 ); // $ExpectError + svariancetk( x.length, 1, undefined, 1 ); // $ExpectError + svariancetk( x.length, 1, [], 1 ); // $ExpectError + svariancetk( x.length, 1, {}, 1 ); // $ExpectError + svariancetk( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk( x.length, 1, x, '10' ); // $ExpectError + svariancetk( x.length, 1, x, true ); // $ExpectError + svariancetk( x.length, 1, x, false ); // $ExpectError + svariancetk( x.length, 1, x, null ); // $ExpectError + svariancetk( x.length, 1, x, undefined ); // $ExpectError + svariancetk( x.length, 1, x, [] ); // $ExpectError + svariancetk( x.length, 1, x, {} ); // $ExpectError + svariancetk( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + + svariancetk(); // $ExpectError + svariancetk( x.length ); // $ExpectError + svariancetk( x.length, 1 ); // $ExpectError + svariancetk( x.length, 1, x ); // $ExpectError + svariancetk( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( true, 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( false, 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( null, 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( [], 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, true ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, false ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, null ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + + svariancetk.ndarray(); // $ExpectError + svariancetk.ndarray( x.length ); // $ExpectError + svariancetk.ndarray( x.length, 1 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1 ); // $ExpectError + svariancetk.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/Makefile b/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/Makefile new file mode 100644 index 000000000000..ff5293d3059f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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/strided/svariancetk/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/example.c new file mode 100644 index 000000000000..9c8080f78e9e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/c/example.c @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svariancetk.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svariancetk( N, 1, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/index.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/index.js new file mode 100644 index 000000000000..4e89f58a31e2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var svariancetk = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +console.log( x ); + +var v = svariancetk( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/include.gypi b/lib/node_modules/@stdlib/stats/strided/svariancetk/include.gypi new file mode 100644 index 000000000000..26476a8c2655 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2020 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': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "variance", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "strided", + "strided array", + "typed", + "array", + "float32", + "float", + "single", + "float32array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/src/Makefile b/lib/node_modules/@stdlib/stats/strided/svariancetk/src/Makefile new file mode 100644 index 000000000000..dd720a3de8f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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/strided/svariancetk/src/addon.c b/lib/node_modules/@stdlib/stats/strided/svariancetk/src/addon.c new file mode 100644 index 000000000000..77ac7e6aca5d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/src/addon.c @@ -0,0 +1,64 @@ +/** +* @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/strided/svariancetk.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" +#include "stdlib/napi/argv_float.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancetk)( N, correction, X, strideX ), v ); + return v; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancetk_ndarray)( N, correction, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/src/main.c b/lib/node_modules/@stdlib/stats/strided/svariancetk/src/main.c new file mode 100644 index 000000000000..ae9f97cb83d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/src/main.c @@ -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. +*/ + +#include "stdlib/stats/strided/svariancetk.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svariancetk)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_svariancetk_ndarray)( N, correction, X, strideX, ox ); +} + +/** +* Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svariancetk_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; + double dN; + double n; + float S2; + float S; + float v; + + dN = (double)N; + n = dN - (double)correction; + if ( N <= 0 || n <= 0.0f ) { + return 0.0f / 0.0f; // NaN + } + if ( N == 1 || strideX == 0 ) { + return 0.0f; + } + ix = offsetX; + S2 = 0.0f; + S = 0.0f; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + S2 += v * v; + S += v; + ix += strideX; + } + return (double)(S2 - ( (float)((double)S/dN) * S ) ) / n; +} diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.js new file mode 100644 index 000000000000..4b8957331f7d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var svariancetk = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof svariancetk.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var svariancetk = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( svariancetk, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var svariancetk; + var main; + + main = require( './../lib/svariancetk.js' ); + + svariancetk = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( svariancetk, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.js new file mode 100644 index 000000000000..36b432ca4a2e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svariancetk = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( svariancetk.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancetk( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancetk( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = svariancetk( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.native.js new file mode 100644 index 000000000000..fc3d41f0e8c1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.ndarray.native.js @@ -0,0 +1,205 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var svariancetk = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( svariancetk instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( svariancetk.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancetk( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancetk( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = svariancetk( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.js new file mode 100644 index 000000000000..3b0e9d6b9e22 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svariancetk = require( './../lib/svariancetk.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( svariancetk.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 0, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 1, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancetk( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancetk( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = svariancetk( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.native.js b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.native.js new file mode 100644 index 000000000000..a4a5940f8ee5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svariancetk/test/test.svariancetk.native.js @@ -0,0 +1,209 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var svariancetk = tryRequire( resolve( __dirname, './../lib/svariancetk.native.js' ) ); +var opts = { + 'skip': ( svariancetk instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', opts, function test( t ) { + t.strictEqual( svariancetk.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 0, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svariancetk( x.length, 1, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svariancetk( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svariancetk( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svariancetk( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svariancetk( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svariancetk( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svariancetk( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = svariancetk( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From 8d3dbb693be9fb39a49d6b25953e1ba1b82ec4bb Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:16:13 +0530 Subject: [PATCH 18/26] remove: remove `stats/base/svariancetk` from namespace This commit removes the `svariancetk` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `stats/base/svariancetk` To migrate, users should access the same symbol via the `@stdlib/stats/strided/svariancetk` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 28 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------ 2 files changed, 37 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index 87558fdcea3f..a81bc06b12f0 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -127,7 +127,6 @@ import stdevtk = require( '@stdlib/stats/base/stdevtk' ); import stdevwd = require( '@stdlib/stats/base/stdevwd' ); import stdevyc = require( '@stdlib/stats/base/stdevyc' ); import svariance = require( '@stdlib/stats/base/svariance' ); -import svariancetk = require( '@stdlib/stats/base/svariancetk' ); import svariancewd = require( '@stdlib/stats/base/svariancewd' ); import svarianceyc = require( '@stdlib/stats/base/svarianceyc' ); import variance = require( '@stdlib/stats/base/variance' ); @@ -2980,33 +2979,6 @@ interface Namespace { */ svariance: typeof svariance; - /** - * Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = ns.svariancetk( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = ns.svariancetk.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - svariancetk: typeof svariancetk; - /** * Computes the variance of a single-precision floating-point strided array using Welford's algorithm. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index b077534762df..efcfe21fb1a7 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -999,15 +999,6 @@ setReadOnly( ns, 'stdevyc', require( '@stdlib/stats/base/stdevyc' ) ); */ setReadOnly( ns, 'svariance', require( '@stdlib/stats/base/svariance' ) ); -/** -* @name svariancetk -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/svariancetk} -*/ -setReadOnly( ns, 'svariancetk', require( '@stdlib/stats/base/svariancetk' ) ); - /** * @name svariancewd * @memberof ns From d29459f42ffb811574ad0f7b449f686df6e5daa9 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:16:27 +0530 Subject: [PATCH 19/26] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 8 ++++---- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- .../@stdlib/stats/base/snanvariancetk/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/variancetk/README.md | 4 ++-- .../@stdlib/stats/strided/dvariancetk/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/sstdevtk/README.md | 4 ++-- .../@stdlib/stats/strided/sstdevtk/lib/ndarray.js | 2 +- .../@stdlib/stats/strided/sstdevtk/manifest.json | 8 ++++---- .../@stdlib/stats/strided/sstdevtk/src/main.c | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 4e15c8e400ba..4c622ba0f20d 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2294,7 +2294,7 @@ ns.push({ '@stdlib/stats/strided/dnanvariancetk', '@stdlib/stats/strided/dstdevtk', '@stdlib/stats/strided/dvariance', - '@stdlib/stats/base/svariancetk', + '@stdlib/stats/strided/svariancetk', '@stdlib/stats/base/variancetk' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index e94d99b3c955..823a68c7047c 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1420,7 +1420,7 @@ ns.push({ '@stdlib/stats/base/nanvariancetk', '@stdlib/stats/base/snanstdevtk', '@stdlib/stats/base/snanvariance', - '@stdlib/stats/base/svariancetk' + '@stdlib/stats/strided/svariancetk' ] }); @@ -1666,7 +1666,7 @@ ns.push({ '@stdlib/stats/base/snanstdevtk', '@stdlib/stats/base/sstdev', '@stdlib/stats/base/stdevtk', - '@stdlib/stats/base/svariancetk' + '@stdlib/stats/strided/svariancetk' ] }); @@ -1935,8 +1935,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.svariancetk', - 'path': '@stdlib/stats/base/svariancetk', - 'value': require( '@stdlib/stats/base/svariancetk' ), + 'path': '@stdlib/stats/strided/svariancetk', + 'value': require( '@stdlib/stats/strided/svariancetk' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvariancetk', diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index a87d68ddc2ff..ebd143e9ed04 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -240,7 +240,7 @@ The namespace contains the following statistical functions: - [`svariance( N, correction, x, stride )`][@stdlib/stats/base/svariance]: calculate the variance of a single-precision floating-point strided array. - [`svariancech( N, correction, x, strideX )`][@stdlib/stats/strided/svariancech]: calculate the variance of a single-precision floating-point strided array using a one-pass trial mean algorithm. - [`svariancepn( N, correction, x, strideX )`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. -- [`svariancetk( N, correction, x, strideX )`][@stdlib/stats/base/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. +- [`svariancetk( N, correction, x, strideX )`][@stdlib/stats/strided/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. - [`svariancewd( N, correction, x, stride )`][@stdlib/stats/base/svariancewd]: calculate the variance of a single-precision floating-point strided array using Welford's algorithm. - [`svarianceyc( N, correction, x, strideX )`][@stdlib/stats/base/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`variance( N, correction, x, stride )`][@stdlib/stats/base/variance]: calculate the variance of a strided array. @@ -665,7 +665,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/strided/svariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancepn -[@stdlib/stats/base/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancetk +[@stdlib/stats/strided/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancetk [@stdlib/stats/base/svariancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancewd diff --git a/lib/node_modules/@stdlib/stats/base/snanvariancetk/README.md b/lib/node_modules/@stdlib/stats/base/snanvariancetk/README.md index 3a2a7e1afde2..ff5a885cbe7b 100644 --- a/lib/node_modules/@stdlib/stats/base/snanvariancetk/README.md +++ b/lib/node_modules/@stdlib/stats/base/snanvariancetk/README.md @@ -247,7 +247,7 @@ console.log( v ); - [`@stdlib/stats/base/nanvariancetk`][@stdlib/stats/base/nanvariancetk]: calculate the variance of a strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/base/snanstdevtk`][@stdlib/stats/base/snanstdevtk]: calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/base/snanvariance`][@stdlib/stats/base/snanvariance]: calculate the variance of a single-precision floating-point strided array ignoring NaN values. -- [`@stdlib/stats/base/svariancetk`][@stdlib/stats/base/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/svariancetk`][@stdlib/stats/strided/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. @@ -275,7 +275,7 @@ console.log( v ); [@stdlib/stats/base/snanvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariance -[@stdlib/stats/base/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancetk +[@stdlib/stats/strided/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancetk diff --git a/lib/node_modules/@stdlib/stats/base/variancetk/README.md b/lib/node_modules/@stdlib/stats/base/variancetk/README.md index a492985ae704..5da7483b93bd 100644 --- a/lib/node_modules/@stdlib/stats/base/variancetk/README.md +++ b/lib/node_modules/@stdlib/stats/base/variancetk/README.md @@ -183,7 +183,7 @@ var v = variancetk.ndarray( N, 1, x, 2, 1 ); - If `N <= 0`, both functions return `NaN`. - If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. - Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of returning a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the variance exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs. -- Depending on the environment, the typed versions ([`dvariancetk`][@stdlib/stats/strided/dvariancetk], [`svariancetk`][@stdlib/stats/base/svariancetk], etc.) are likely to be significantly more performant. +- Depending on the environment, the typed versions ([`dvariancetk`][@stdlib/stats/strided/dvariancetk], [`svariancetk`][@stdlib/stats/strided/svariancetk], etc.) are likely to be significantly more performant. @@ -257,7 +257,7 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray -[@stdlib/stats/base/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancetk +[@stdlib/stats/strided/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancetk [@ling:1974a]: https://doi.org/10.2307/2286154 diff --git a/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md b/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md index 8d63ca5d2030..f8aa2ee506f6 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvariancetk/README.md @@ -382,7 +382,7 @@ int main( void ) { - [`@stdlib/stats/strided/dnanvariancetk`][@stdlib/stats/strided/dnanvariancetk]: calculate the variance of a double-precision floating-point strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/strided/dstdevtk`][@stdlib/stats/strided/dstdevtk]: calculate the standard deviation of a double-precision floating-point strided array using a one-pass textbook algorithm. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. -- [`@stdlib/stats/base/svariancetk`][@stdlib/stats/base/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/svariancetk`][@stdlib/stats/strided/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. - [`@stdlib/stats/base/variancetk`][@stdlib/stats/base/variancetk]: calculate the variance of a strided array using a one-pass textbook algorithm. @@ -409,7 +409,7 @@ int main( void ) { [@stdlib/stats/strided/dvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dvariance -[@stdlib/stats/base/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancetk +[@stdlib/stats/strided/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancetk [@stdlib/stats/base/variancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variancetk diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevtk/README.md b/lib/node_modules/@stdlib/stats/strided/sstdevtk/README.md index 4ee16465c3ba..1e080c8daea4 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevtk/README.md +++ b/lib/node_modules/@stdlib/stats/strided/sstdevtk/README.md @@ -353,7 +353,7 @@ int main( void ) { - [`@stdlib/stats/base/snanstdevtk`][@stdlib/stats/base/snanstdevtk]: calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a one-pass textbook algorithm. - [`@stdlib/stats/base/sstdev`][@stdlib/stats/base/sstdev]: calculate the standard deviation of a single-precision floating-point strided array. - [`@stdlib/stats/base/stdevtk`][@stdlib/stats/base/stdevtk]: calculate the standard deviation of a strided array using a one-pass textbook algorithm. -- [`@stdlib/stats/base/svariancetk`][@stdlib/stats/base/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. +- [`@stdlib/stats/strided/svariancetk`][@stdlib/stats/strided/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. @@ -381,7 +381,7 @@ int main( void ) { [@stdlib/stats/base/stdevtk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevtk -[@stdlib/stats/base/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancetk +[@stdlib/stats/strided/svariancetk]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svariancetk diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevtk/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/sstdevtk/lib/ndarray.js index ea4dd05a113b..3bb74cac6d83 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevtk/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/sstdevtk/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var svariancetk = require( '@stdlib/stats/base/svariancetk' ).ndarray; +var svariancetk = require( '@stdlib/stats/strided/svariancetk' ).ndarray; var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevtk/manifest.json b/lib/node_modules/@stdlib/stats/strided/sstdevtk/manifest.json index 1c762ef1fad2..ef877e36cca1 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevtk/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/sstdevtk/manifest.json @@ -41,7 +41,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancetk", + "@stdlib/stats/strided/svariancetk", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -65,7 +65,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancetk" + "@stdlib/stats/strided/svariancetk" ] }, { @@ -83,7 +83,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancetk" + "@stdlib/stats/strided/svariancetk" ] }, { @@ -101,7 +101,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svariancetk" + "@stdlib/stats/strided/svariancetk" ] } ] diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevtk/src/main.c b/lib/node_modules/@stdlib/stats/strided/sstdevtk/src/main.c index 884624f1cf5a..c46fa07aeef4 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevtk/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/sstdevtk/src/main.c @@ -17,7 +17,7 @@ */ #include "stdlib/stats/strided/sstdevtk.h" -#include "stdlib/stats/base/svariancetk.h" +#include "stdlib/stats/strided/svariancetk.h" #include "stdlib/blas/base/shared.h" #include "stdlib/math/base/special/sqrtf.h" #include "stdlib/strided/base/stride2offset.h" From 7b3052a39a06304f990cb3c18c595930d3e73979 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:17:01 +0530 Subject: [PATCH 20/26] remove: remove `stats/base/svariancetk` This commit removes `@stdlib/stats/base/svariancetk` in favor of `@stdlib/stats/strided/svariancetk`. BREAKING CHANGE: remove `stats/base/svariancetk` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/svariancetk`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- 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 --- --- .../@stdlib/stats/base/svariancetk/README.md | 420 ------------------ .../base/svariancetk/benchmark/benchmark.js | 96 ---- .../svariancetk/benchmark/benchmark.native.js | 101 ----- .../benchmark/benchmark.ndarray.js | 96 ---- .../benchmark/benchmark.ndarray.native.js | 101 ----- .../base/svariancetk/benchmark/c/Makefile | 146 ------ .../benchmark/c/benchmark.length.c | 197 -------- .../stats/base/svariancetk/binding.gyp | 170 ------- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../equation_population_variance_textbook.svg | 81 ---- .../docs/img/equation_sample_mean.svg | 43 -- .../img/equation_unbiased_sample_variance.svg | 61 --- ...tion_unbiased_sample_variance_textbook.svg | 85 ---- .../stats/base/svariancetk/docs/repl.txt | 114 ----- .../base/svariancetk/docs/types/index.d.ts | 95 ---- .../stats/base/svariancetk/docs/types/test.ts | 187 -------- .../base/svariancetk/examples/c/Makefile | 146 ------ .../base/svariancetk/examples/c/example.c | 37 -- .../stats/base/svariancetk/examples/index.js | 30 -- .../stats/base/svariancetk/include.gypi | 53 --- .../include/stdlib/stats/base/svariancetk.h | 45 -- .../stats/base/svariancetk/lib/index.js | 68 --- .../stats/base/svariancetk/lib/main.js | 35 -- .../stats/base/svariancetk/lib/native.js | 35 -- .../stats/base/svariancetk/lib/ndarray.js | 76 ---- .../base/svariancetk/lib/ndarray.native.js | 53 --- .../stats/base/svariancetk/lib/svariancetk.js | 53 --- .../svariancetk/lib/svariancetk.native.js | 52 --- .../stats/base/svariancetk/manifest.json | 100 ----- .../stats/base/svariancetk/package.json | 81 ---- .../stats/base/svariancetk/src/Makefile | 70 --- .../stats/base/svariancetk/src/addon.c | 64 --- .../@stdlib/stats/base/svariancetk/src/main.c | 74 --- .../stats/base/svariancetk/test/test.js | 82 ---- .../base/svariancetk/test/test.ndarray.js | 196 -------- .../svariancetk/test/test.ndarray.native.js | 205 --------- .../base/svariancetk/test/test.svariancetk.js | 200 --------- .../test/test.svariancetk.native.js | 209 --------- 39 files changed, 4053 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/benchmark.length.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/binding.gyp delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance_textbook.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/example.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/include.gypi delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/include/stdlib/stats/base/svariancetk.h delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/svariancetk.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/lib/svariancetk.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/manifest.json delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/src/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/src/main.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.native.js diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/README.md b/lib/node_modules/@stdlib/stats/base/svariancetk/README.md deleted file mode 100644 index 50dc396ace88..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/README.md +++ /dev/null @@ -1,420 +0,0 @@ - - -# svariancetk - -> Calculate the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -After rearranging terms, the population [variance][variance] can be equivalently expressed as - - - -```math -\sigma^2 = \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i^2 - \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i \ \biggr)^2\ \biggr) -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -Similar to the population [variance][variance], after rearranging terms, the **unbiased sample variance** can be equivalently expressed as - - - -```math -s^2 = \frac{1}{n-1}\biggl(\ \sum_{i=0}^{n-1} x_i^2 - \frac{1}{n}\biggl(\ \sum_{i=0}^{n-1} x_i \ \biggr)^2\ \biggr) -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var svariancetk = require( '@stdlib/stats/base/svariancetk' ); -``` - -#### svariancetk( N, correction, x, strideX ) - -Computes the [variance][variance] of a single-precision floating-point strided array `x` using a one-pass textbook algorithm. - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - -var v = svariancetk( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); - -var v = svariancetk( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = svariancetk( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### svariancetk.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - -var v = svariancetk.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); - -var v = svariancetk.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of returning a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the variance exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var svariancetk = require( '@stdlib/stats/base/svariancetk' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float32' -}); -console.log( x ); - -var v = svariancetk( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/stats/base/svariancetk.h" -``` - -#### stdlib_strided_svariancetk( N, correction, \*X, strideX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm. - -```c -const float x[] = { 1.0f, -2.0f, 2.0f }; - -float v = stdlib_strided_svariancetk( 3, 1.0f, x, 1 ); -// returns ~4.3333f -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. - -```c -float stdlib_strided_svariancetk( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); -``` - -#### stdlib_strided_svariancetk_ndarray( N, correction, \*X, strideX, offsetX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. - -```c -const float x[] = { 1.0f, -2.0f, 2.0f }; - -float v = stdlib_strided_svariancetk_ndarray( 3, 1.0f, x, 1, 0 ); -// returns ~4.3333f -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **offsetX**: `[in] CBLAS_INT` starting index for `X`. - -```c -float stdlib_strided_svariancetk_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); -``` - -
- - - - - -
- -
- - - - - -
- -### Examples - -```c -#include "stdlib/stats/base/svariancetk.h" -#include - -int main( void ) { - // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; - - // Specify the number of elements: - const int N = 4; - - // Specify the stride length: - const int strideX = 2; - - // Compute the variance: - float v = stdlib_strided_svariancetk( N, 1.0f, x, strideX ); - - // Print the result: - printf( "sample variance: %f\n", v ); -} -``` - -
- - - -
- - - -* * * - -
- -## References - -- Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.js deleted file mode 100644 index 68820a10499a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var svariancetk = require( './../lib/svariancetk.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancetk( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.native.js deleted file mode 100644 index f2950786c9a4..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.native.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var pkg = require( './../package.json' ).name; - - -// VARIABLES // - -var svariancetk = tryRequire( resolve( __dirname, './../lib/svariancetk.native.js' ) ); -var opts = { - 'skip': ( svariancetk instanceof Error ) -}; -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancetk( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+'::native:len='+len, opts, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.js deleted file mode 100644 index 5fd2d978c543..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var svariancetk = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancetk( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.native.js deleted file mode 100644 index 4653bf3c9957..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/benchmark.ndarray.native.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var pkg = require( './../package.json' ).name; - - -// VARIABLES // - -var svariancetk = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( svariancetk instanceof Error ) -}; -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10.0, 10.0, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svariancetk( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+'::native:ndarray:len='+len, opts, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/Makefile deleted file mode 100644 index 7280962b4c4d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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.length.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/svariancetk/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/benchmark.length.c deleted file mode 100644 index be9104e27bb7..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/benchmark/c/benchmark.length.c +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svariancetk.h" -#include -#include -#include -#include -#include - -#define NAME "svariancetk" -#define ITERATIONS 1000000 -#define REPEATS 3 -#define MIN 1 -#define MAX 6 - -/** -* 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 iterations number of iterations -* @param elapsed elapsed time in seconds -*/ -static void print_results( int iterations, 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 [0,1). -* -* @return random number -*/ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark1( int iterations, int len ) { - double elapsed; - float x[ len ]; - float v; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; - } - v = 0.0f; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - // cppcheck-suppress uninitvar - v = stdlib_strided_svariancetk( len, 1.0f, x, 1 ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark2( int iterations, int len ) { - double elapsed; - float x[ len ]; - float v; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; - } - v = 0.0f; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - // cppcheck-suppress uninitvar - v = stdlib_strided_svariancetk_ndarray( len, 1.0f, x, 1, 0 ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int iter; - int len; - int i; - int j; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - count = 0; - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark1( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:ndarray:len=%d\n", NAME, len ); - elapsed = benchmark2( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - print_summary( count, count ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/binding.gyp b/lib/node_modules/@stdlib/stats/base/svariancetk/binding.gyp deleted file mode 100644 index 7d0005b2e390..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/binding.gyp +++ /dev/null @@ -1,170 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2020 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 -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance_textbook.svg b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance_textbook.svg deleted file mode 100644 index 923bd7a21462..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_population_variance_textbook.svg +++ /dev/null @@ -1,81 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i Superscript 2 Baseline minus StartFraction 1 Over upper N EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i Baseline right-parenthesis squared right-parenthesis - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg deleted file mode 100644 index ccf58f263bb0..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg +++ /dev/null @@ -1,85 +0,0 @@ - -s squared equals StartFraction 1 Over n minus 1 EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i Superscript 2 Baseline minus StartFraction 1 Over n EndFraction left-parenthesis sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i Baseline right-parenthesis squared right-parenthesis - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/repl.txt deleted file mode 100644 index 807fbf2a6c32..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/repl.txt +++ /dev/null @@ -1,114 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a single-precision floating-point strided array - using a one-pass textbook algorithm. - - The `N` and stride parameters determine which elements in `x` are accessed - at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Float32Array - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a single-precision floating-point strided array - using a one-pass textbook algorithm and alternative indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Float32Array - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/index.d.ts deleted file mode 100644 index 4e1d7827a817..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/index.d.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface describing `svariancetk`. -*/ -interface Routine { - /** - * Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = svariancetk( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: Float32Array, strideX: number ): number; - - /** - * Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = svariancetk.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* -* var v = svariancetk( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* -* var v = svariancetk.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var svariancetk: Routine; - - -// EXPORTS // - -export = svariancetk; diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/test.ts deleted file mode 100644 index 058418af092c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/docs/types/test.ts +++ /dev/null @@ -1,187 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -import svariancetk = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float32Array( 10 ); - - svariancetk( x.length, 1, x, 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk( '10', 1, x, 1 ); // $ExpectError - svariancetk( true, 1, x, 1 ); // $ExpectError - svariancetk( false, 1, x, 1 ); // $ExpectError - svariancetk( null, 1, x, 1 ); // $ExpectError - svariancetk( undefined, 1, x, 1 ); // $ExpectError - svariancetk( [], 1, x, 1 ); // $ExpectError - svariancetk( {}, 1, x, 1 ); // $ExpectError - svariancetk( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk( x.length, '10', x, 1 ); // $ExpectError - svariancetk( x.length, true, x, 1 ); // $ExpectError - svariancetk( x.length, false, x, 1 ); // $ExpectError - svariancetk( x.length, null, x, 1 ); // $ExpectError - svariancetk( x.length, undefined, x, 1 ); // $ExpectError - svariancetk( x.length, [], x, 1 ); // $ExpectError - svariancetk( x.length, {}, x, 1 ); // $ExpectError - svariancetk( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a Float32Array... -{ - const x = new Float32Array( 10 ); - - svariancetk( x.length, 1, 10, 1 ); // $ExpectError - svariancetk( x.length, 1, '10', 1 ); // $ExpectError - svariancetk( x.length, 1, true, 1 ); // $ExpectError - svariancetk( x.length, 1, false, 1 ); // $ExpectError - svariancetk( x.length, 1, null, 1 ); // $ExpectError - svariancetk( x.length, 1, undefined, 1 ); // $ExpectError - svariancetk( x.length, 1, [], 1 ); // $ExpectError - svariancetk( x.length, 1, {}, 1 ); // $ExpectError - svariancetk( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk( x.length, 1, x, '10' ); // $ExpectError - svariancetk( x.length, 1, x, true ); // $ExpectError - svariancetk( x.length, 1, x, false ); // $ExpectError - svariancetk( x.length, 1, x, null ); // $ExpectError - svariancetk( x.length, 1, x, undefined ); // $ExpectError - svariancetk( x.length, 1, x, [] ); // $ExpectError - svariancetk( x.length, 1, x, {} ); // $ExpectError - svariancetk( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float32Array( 10 ); - - svariancetk(); // $ExpectError - svariancetk( x.length ); // $ExpectError - svariancetk( x.length, 1 ); // $ExpectError - svariancetk( x.length, 1, x ); // $ExpectError - svariancetk( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( true, 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( false, 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( null, 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( [], 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, true ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, false ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, null ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float32Array( 10 ); - - svariancetk.ndarray(); // $ExpectError - svariancetk.ndarray( x.length ); // $ExpectError - svariancetk.ndarray( x.length, 1 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1 ); // $ExpectError - svariancetk.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/Makefile deleted file mode 100644 index ff5293d3059f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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/svariancetk/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/example.c deleted file mode 100644 index 9698c2e7f97e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/examples/c/example.c +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svariancetk.h" -#include - -int main( void ) { - // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; - - // Specify the number of elements: - const int N = 4; - - // Specify the stride length: - const int strideX = 2; - - // Compute the variance: - float v = stdlib_strided_svariancetk( N, 1, x, strideX ); - - // Print the result: - printf( "sample variance: %f\n", v ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/examples/index.js b/lib/node_modules/@stdlib/stats/base/svariancetk/examples/index.js deleted file mode 100644 index 4e89f58a31e2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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'; - -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var svariancetk = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float32' -}); -console.log( x ); - -var v = svariancetk( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/include.gypi b/lib/node_modules/@stdlib/stats/base/svariancetk/include.gypi deleted file mode 100644 index 26476a8c2655..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/include.gypi +++ /dev/null @@ -1,53 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2020 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': [ - '=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdmath", - "statistics", - "stats", - "mathematics", - "math", - "variance", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "strided", - "strided array", - "typed", - "array", - "float32", - "float", - "single", - "float32array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/src/Makefile b/lib/node_modules/@stdlib/stats/base/svariancetk/src/Makefile deleted file mode 100644 index dd720a3de8f2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/src/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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/svariancetk/src/addon.c b/lib/node_modules/@stdlib/stats/base/svariancetk/src/addon.c deleted file mode 100644 index 596ae385aad3..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/src/addon.c +++ /dev/null @@ -1,64 +0,0 @@ -/** -* @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/svariancetk.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/napi/export.h" -#include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_strided_float32array.h" -#include "stdlib/napi/create_double.h" -#include "stdlib/napi/argv_float.h" -#include - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) - STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancetk)( N, correction, X, strideX ), v ); - return v; -} - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon_method( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); - STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_svariancetk_ndarray)( N, correction, X, strideX, offsetX ), v ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/src/main.c b/lib/node_modules/@stdlib/stats/base/svariancetk/src/main.c deleted file mode 100644 index d7929c0e8ad6..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/src/main.c +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @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/svariancetk.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/strided/base/stride2offset.h" - -/** -* Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @return output value -*/ -float API_SUFFIX(stdlib_strided_svariancetk)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { - const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - return API_SUFFIX(stdlib_strided_svariancetk_ndarray)( N, correction, X, strideX, ox ); -} - -/** -* Computes the variance of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @param offsetX starting index for X -* @return output value -*/ -float API_SUFFIX(stdlib_strided_svariancetk_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - CBLAS_INT ix; - CBLAS_INT i; - double dN; - double n; - float S2; - float S; - float v; - - dN = (double)N; - n = dN - (double)correction; - if ( N <= 0 || n <= 0.0f ) { - return 0.0f / 0.0f; // NaN - } - if ( N == 1 || strideX == 0 ) { - return 0.0f; - } - ix = offsetX; - S2 = 0.0f; - S = 0.0f; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - S2 += v * v; - S += v; - ix += strideX; - } - return (double)(S2 - ( (float)((double)S/dN) * S ) ) / n; -} diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.js b/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.js deleted file mode 100644 index 4b8957331f7d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var svariancetk = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof svariancetk.ndarray, 'function', 'method is a function' ); - t.end(); -}); - -tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { - var svariancetk = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( svariancetk, mock, 'returns expected value' ); - t.end(); - - function tryRequire() { - return mock; - } - - function mock() { - // Mock... - } -}); - -tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { - var svariancetk; - var main; - - main = require( './../lib/svariancetk.js' ); - - svariancetk = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( svariancetk, main, 'returns expected value' ); - t.end(); - - function tryRequire() { - return new Error( 'Cannot find module' ); - } -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.js deleted file mode 100644 index 36b432ca4a2e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.js +++ /dev/null @@ -1,196 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svariancetk = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( svariancetk.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancetk( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancetk( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = svariancetk( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.native.js deleted file mode 100644 index fc3d41f0e8c1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.ndarray.native.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var svariancetk = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( svariancetk instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( svariancetk.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancetk( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancetk( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = svariancetk( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.js b/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.js deleted file mode 100644 index 3b0e9d6b9e22..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.js +++ /dev/null @@ -1,200 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svariancetk = require( './../lib/svariancetk.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( svariancetk.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 0, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 1, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancetk( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancetk( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = svariancetk( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.native.js b/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.native.js deleted file mode 100644 index a4a5940f8ee5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svariancetk/test/test.svariancetk.native.js +++ /dev/null @@ -1,209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var svariancetk = tryRequire( resolve( __dirname, './../lib/svariancetk.native.js' ) ); -var opts = { - 'skip': ( svariancetk instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svariancetk, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( svariancetk.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 0, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svariancetk( x.length, 1, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/(x.length-1) ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svariancetk( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svariancetk( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svariancetk( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svariancetk( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svariancetk( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svariancetk( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', opts, function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = svariancetk( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From 85ac23f4fbd4dc9f87032cc0f0cdee75a098b596 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:45:41 +0530 Subject: [PATCH 21/26] feat: add `stats/strided/svarianceyc` Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/strided/svarianceyc/README.md | 389 ++++++++++++++++++ .../svarianceyc/benchmark/benchmark.js | 96 +++++ .../svarianceyc/benchmark/benchmark.native.js | 101 +++++ .../benchmark/benchmark.ndarray.js | 96 +++++ .../benchmark/benchmark.ndarray.native.js | 101 +++++ .../strided/svarianceyc/benchmark/c/Makefile | 146 +++++++ .../benchmark/c/benchmark.length.c | 197 +++++++++ .../stats/strided/svarianceyc/binding.gyp | 170 ++++++++ .../docs/img/equation_population_mean.svg | 42 ++ .../docs/img/equation_population_variance.svg | 54 +++ .../docs/img/equation_sample_mean.svg | 43 ++ .../img/equation_unbiased_sample_variance.svg | 61 +++ .../stats/strided/svarianceyc/docs/repl.txt | 114 +++++ .../strided/svarianceyc/docs/types/index.d.ts | 95 +++++ .../strided/svarianceyc/docs/types/test.ts | 187 +++++++++ .../strided/svarianceyc/examples/c/Makefile | 146 +++++++ .../strided/svarianceyc/examples/c/example.c | 37 ++ .../strided/svarianceyc/examples/index.js | 30 ++ .../stats/strided/svarianceyc/include.gypi | 53 +++ .../stdlib/stats/strided/svarianceyc.h | 45 ++ .../stats/strided/svarianceyc/lib/index.js | 68 +++ .../stats/strided/svarianceyc/lib/main.js | 35 ++ .../stats/strided/svarianceyc/lib/native.js | 35 ++ .../stats/strided/svarianceyc/lib/ndarray.js | 86 ++++ .../strided/svarianceyc/lib/ndarray.native.js | 53 +++ .../strided/svarianceyc/lib/svarianceyc.js | 61 +++ .../svarianceyc/lib/svarianceyc.native.js | 52 +++ .../stats/strided/svarianceyc/manifest.json | 102 +++++ .../stats/strided/svarianceyc/package.json | 83 ++++ .../stats/strided/svarianceyc/src/Makefile | 70 ++++ .../stats/strided/svarianceyc/src/addon.c | 63 +++ .../stats/strided/svarianceyc/src/main.c | 86 ++++ .../stats/strided/svarianceyc/test/test.js | 82 ++++ .../strided/svarianceyc/test/test.ndarray.js | 196 +++++++++ .../svarianceyc/test/test.ndarray.native.js | 205 +++++++++ .../svarianceyc/test/test.svarianceyc.js | 200 +++++++++ .../test/test.svarianceyc.native.js | 209 ++++++++++ 37 files changed, 3889 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/benchmark.length.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_sample_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_unbiased_sample_variance.svg create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/include/stdlib/stats/strided/svarianceyc.h create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/svarianceyc.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/lib/svarianceyc.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.js create mode 100644 lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.native.js diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md b/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md new file mode 100644 index 000000000000..9b1a0d5c131c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/README.md @@ -0,0 +1,389 @@ + + +# svarianceyc + +> Calculate the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. + +
+ +The population [variance][variance] of a finite size population of size `N` is given by + + + +```math +\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 +``` + + + + + +where the population mean is given by + + + +```math +\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i +``` + + + + + +Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, + + + +```math +s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + + + + + +where the sample mean is given by + + + +```math +\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + + +The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. + +
+ + + +
+ +## Usage + +```javascript +var svarianceyc = require( '@stdlib/stats/strided/svarianceyc' ); +``` + +#### svarianceyc( N, correction, x, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array `x` using a one-pass algorithm proposed by Youngs and Cramer. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + +var v = svarianceyc( x.length, 1, x, 1 ); +// returns ~4.3333 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); + +var v = svarianceyc( 4, 1, x, 2 ); +// returns 6.25 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = svarianceyc( 4, 1, x1, 2 ); +// returns 6.25 +``` + +#### svarianceyc.ndarray( N, correction, x, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + +var v = svarianceyc.ndarray( x.length, 1, x, 1, 0 ); +// returns ~4.33333 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); + +var v = svarianceyc.ndarray( 4, 1, x, 2, 1 ); +// returns 6.25 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var svarianceyc = require( '@stdlib/stats/strided/svarianceyc' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +console.log( x ); + +var v = svarianceyc( x.length, 1, x, 1 ); +console.log( v ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/strided/svarianceyc.h" +``` + +#### stdlib_strided_svarianceyc( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svarianceyc( 3, 1, x, 1 ); +// returns ~4.3333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than 0 has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where c corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to 0 is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to 1 is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **x**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `x`. + +```c +float stdlib_strided_svarianceyc( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_svarianceyc_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_srange_ndarray( 3, 1, x, 1, 0 ); +// returns ~4.33333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction** `[in] float`: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +float stdlib_strided_svarianceyc_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/strided/svarianceyc.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svarianceyc( N, 1.0f, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} +``` + +
+ + + +
+ + + +* * * + +
+ +## References + +- Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826][@youngs:1971a]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.js new file mode 100644 index 000000000000..4f797d9a04b9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var svarianceyc = require( './../lib/svarianceyc.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svarianceyc( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.native.js new file mode 100644 index 000000000000..ac3eed32893a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.native.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var svarianceyc = tryRequire( resolve( __dirname, './../lib/svarianceyc.native.js' ) ); +var opts = { + 'skip': ( svarianceyc instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svarianceyc( x.length, 1, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..62bae635a6fc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var svarianceyc = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svarianceyc( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..3dbafab017de --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,101 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var svarianceyc = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( svarianceyc instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = svarianceyc( x.length, 1, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/Makefile new file mode 100644 index 000000000000..7280962b4c4d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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.length.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/strided/svarianceyc/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..6edd52b5a6d8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/benchmark/c/benchmark.length.c @@ -0,0 +1,197 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svarianceyc.h" +#include +#include +#include +#include +#include + +#define NAME "svarianceyc" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* 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 iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, 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 [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_svarianceyc( len, 1.0f, x, 1 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_svarianceyc_ndarray( len, 1.0f, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/binding.gyp b/lib/node_modules/@stdlib/stats/strided/svarianceyc/binding.gyp new file mode 100644 index 000000000000..7d0005b2e390 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2020 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 +} diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_mean.svg new file mode 100644 index 000000000000..4bbdf0d2a56f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_variance.svg new file mode 100644 index 000000000000..4130ba0750d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_population_variance.svg @@ -0,0 +1,54 @@ + +sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_sample_mean.svg new file mode 100644 index 000000000000..aea7a5f6687a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_sample_mean.svg @@ -0,0 +1,43 @@ + +x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_unbiased_sample_variance.svg new file mode 100644 index 000000000000..1ae1283e7fb1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/img/equation_unbiased_sample_variance.svg @@ -0,0 +1,61 @@ + +s squared equals StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/repl.txt new file mode 100644 index 000000000000..c8320f182444 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/repl.txt @@ -0,0 +1,114 @@ + +{{alias}}( N, correction, x, strideX ) + Computes the variance of a single-precision floating-point strided array + using a one-pass algorithm proposed by Youngs and Cramer. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float32Array + Input array. + + strideX: integer + Stride length. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > {{alias}}( x.length, 1, x, 1 ) + ~4.3333 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > {{alias}}( 3, 1, x, 2 ) + ~4.3333 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, 1, x1, 2 ) + ~4.3333 + + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) + Computes the variance of a single-precision floating-point strided array + using a one-pass algorithm proposed by Youngs and Cramer and alternative + indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + correction: number + Degrees of freedom adjustment. Setting this parameter to a value other + than `0` has the effect of adjusting the divisor during the calculation + of the variance according to `N - c` where `c` corresponds to the + provided degrees of freedom adjustment. When computing the variance of a + population, setting this parameter to `0` is the standard choice (i.e., + the provided array contains data constituting an entire population). + When computing the unbiased sample variance, setting this parameter to + `1` is the standard choice (i.e., the provided array contains data + sampled from a larger population; this is commonly referred to as + Bessel's correction). + + x: Float32Array + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + out: number + The variance. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + ~4.3333 + + // Using offset parameter: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + ~4.3333 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/index.d.ts new file mode 100644 index 000000000000..bbc7845b6ac5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/index.d.ts @@ -0,0 +1,95 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface describing `svarianceyc`. +*/ +interface Routine { + /** + * Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @returns variance + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + * + * var v = svarianceyc( x.length, 1, x, 1 ); + * // returns ~4.3333 + */ + ( N: number, correction: number, x: Float32Array, strideX: number ): number; + + /** + * Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param correction - degrees of freedom adjustment + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns variance + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); + * + * var v = svarianceyc.ndarray( x.length, 1, x, 1, 0 ); + * // returns ~4.3333 + */ + ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; +} + +/** +* Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* @param N - number of indexed elements +* @param correction - degrees of freedom adjustment +* @param x - input array +* @param strideX - stride length +* @returns variance +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +* +* var v = svarianceyc( x.length, 1, x, 1 ); +* // returns ~4.3333 +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); +* +* var v = svarianceyc.ndarray( x.length, 1, x, 1, 0 ); +* // returns ~4.3333 +*/ +declare var svarianceyc: Routine; + + +// EXPORTS // + +export = svarianceyc; diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/test.ts new file mode 100644 index 000000000000..1aa031631b87 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/docs/types/test.ts @@ -0,0 +1,187 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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. +*/ + +import svarianceyc = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc( x.length, 1, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc( '10', 1, x, 1 ); // $ExpectError + svarianceyc( true, 1, x, 1 ); // $ExpectError + svarianceyc( false, 1, x, 1 ); // $ExpectError + svarianceyc( null, 1, x, 1 ); // $ExpectError + svarianceyc( undefined, 1, x, 1 ); // $ExpectError + svarianceyc( [], 1, x, 1 ); // $ExpectError + svarianceyc( {}, 1, x, 1 ); // $ExpectError + svarianceyc( ( x: number ): number => x, 1, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc( x.length, '10', x, 1 ); // $ExpectError + svarianceyc( x.length, true, x, 1 ); // $ExpectError + svarianceyc( x.length, false, x, 1 ); // $ExpectError + svarianceyc( x.length, null, x, 1 ); // $ExpectError + svarianceyc( x.length, undefined, x, 1 ); // $ExpectError + svarianceyc( x.length, [], x, 1 ); // $ExpectError + svarianceyc( x.length, {}, x, 1 ); // $ExpectError + svarianceyc( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + svarianceyc( x.length, 1, 10, 1 ); // $ExpectError + svarianceyc( x.length, 1, '10', 1 ); // $ExpectError + svarianceyc( x.length, 1, true, 1 ); // $ExpectError + svarianceyc( x.length, 1, false, 1 ); // $ExpectError + svarianceyc( x.length, 1, null, 1 ); // $ExpectError + svarianceyc( x.length, 1, undefined, 1 ); // $ExpectError + svarianceyc( x.length, 1, [], 1 ); // $ExpectError + svarianceyc( x.length, 1, {}, 1 ); // $ExpectError + svarianceyc( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc( x.length, 1, x, '10' ); // $ExpectError + svarianceyc( x.length, 1, x, true ); // $ExpectError + svarianceyc( x.length, 1, x, false ); // $ExpectError + svarianceyc( x.length, 1, x, null ); // $ExpectError + svarianceyc( x.length, 1, x, undefined ); // $ExpectError + svarianceyc( x.length, 1, x, [] ); // $ExpectError + svarianceyc( x.length, 1, x, {} ); // $ExpectError + svarianceyc( x.length, 1, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + + svarianceyc(); // $ExpectError + svarianceyc( x.length ); // $ExpectError + svarianceyc( x.length, 1 ); // $ExpectError + svarianceyc( x.length, 1, x ); // $ExpectError + svarianceyc( x.length, 1, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray( '10', 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( true, 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( false, 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( null, 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( [], 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( {}, 1, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, true, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, false, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, null, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, [], 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, true ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, false ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, null ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, [] ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, {} ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + + svarianceyc.ndarray(); // $ExpectError + svarianceyc.ndarray( x.length ); // $ExpectError + svarianceyc.ndarray( x.length, 1 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1 ); // $ExpectError + svarianceyc.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/Makefile b/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/Makefile new file mode 100644 index 000000000000..ff5293d3059f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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/strided/svarianceyc/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/example.c new file mode 100644 index 000000000000..cc57c9af0399 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/c/example.c @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svarianceyc.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svarianceyc( N, 1.0f, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/index.js new file mode 100644 index 000000000000..8273e6e91f19 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var svarianceyc = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +console.log( x ); + +var v = svarianceyc( x.length, 1, x, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/include.gypi b/lib/node_modules/@stdlib/stats/strided/svarianceyc/include.gypi new file mode 100644 index 000000000000..26476a8c2655 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2020 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': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "variance", + "var", + "deviation", + "dispersion", + "sample variance", + "unbiased", + "stdev", + "std", + "standard deviation", + "youngs", + "cramer", + "strided", + "strided array", + "typed", + "array", + "float32", + "float", + "single", + "float32array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/Makefile b/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/Makefile new file mode 100644 index 000000000000..dd720a3de8f2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2020 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/strided/svarianceyc/src/addon.c b/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/addon.c new file mode 100644 index 000000000000..b8129d9998f5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/addon.c @@ -0,0 +1,63 @@ +/** +* @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/strided/svarianceyc.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" +#include "stdlib/napi/argv_float.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svarianceyc( N, correction, X, strideX ), v ); + return v; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svarianceyc_ndarray( N, correction, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/main.c b/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/main.c new file mode 100644 index 000000000000..2755b4fe7676 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/src/main.c @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/svarianceyc.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* ## Method +* +* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). +* +* ## References +* +* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svarianceyc)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_svarianceyc_ndarray)( N, correction, X, strideX, ox ); +} + + +/** +* Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index of X +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svarianceyc_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; + double di; + float sum; + double n; + float S; + float v; + float d; + + n = (double)N - (double)correction; + if ( N <= 0 || n <= 0.0f ) { + return 0.0f / 0.0f; // NaN + } + if ( N == 1 || strideX == 0 ) { + return 0.0f; + } + ix = offsetX; + sum = X[ ix ]; + ix += strideX; + S = 0.0f; + for ( i = 2; i <= N; i++ ) { + di = (double)i; + v = X[ ix ]; + sum += v; + d = (float)(di*(double)v) - sum; + S += (float)(1.0/(di*(di-1.0))) * d * d; + ix += strideX; + } + return (double)S / n; +} diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.js new file mode 100644 index 000000000000..1978fe90e910 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var svarianceyc = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof svarianceyc.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var svarianceyc = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( svarianceyc, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var svarianceyc; + var main; + + main = require( './../lib/svarianceyc.js' ); + + svarianceyc = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( svarianceyc, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.js new file mode 100644 index 000000000000..0ad58b76d89f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svarianceyc = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( svarianceyc.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 0, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 1, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = svarianceyc( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.native.js new file mode 100644 index 000000000000..5aa8b35322d9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.ndarray.native.js @@ -0,0 +1,205 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var svarianceyc = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( svarianceyc instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', opts, function test( t ) { + t.strictEqual( svarianceyc.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 0, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 1, x, 1, 0 ); + t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 1, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( -1, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( x.length, x.length+1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = svarianceyc( 4, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.js new file mode 100644 index 000000000000..b3958706e4b5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.js @@ -0,0 +1,200 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var svarianceyc = require( './../lib/svarianceyc.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( svarianceyc.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 0, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 1, x, 1 ); + t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = svarianceyc( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.native.js b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.native.js new file mode 100644 index 000000000000..36114f5da184 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/svarianceyc/test/test.svarianceyc.native.js @@ -0,0 +1,209 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var svarianceyc = tryRequire( resolve( __dirname, './../lib/svarianceyc.native.js' ) ); +var opts = { + 'skip': ( svarianceyc instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', opts, function test( t ) { + t.strictEqual( svarianceyc.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 0, x, 1 ); + t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = svarianceyc( x.length, 1, x, 1 ); + t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); + + x = new Float32Array( [ -4.0, -4.0 ] ); + v = svarianceyc( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Float32Array( [ NaN, 4.0 ] ); + v = svarianceyc( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = svarianceyc( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = svarianceyc( 4, 1, x, -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + v = svarianceyc( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', opts, function test( t ) { + var x0; + var x1; + var v; + + x0 = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = svarianceyc( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From 17d38ef962245e7c922613943dfb37bda3fcf329 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:47:31 +0530 Subject: [PATCH 22/26] remove: remove `stats/base/svarianceyc` from namespace This commit removes the `svarianceyc` symbol from the `@stdlib/stats/base` namespace due to a package migration. BREAKING CHANGE: remove `stats/base/svarianceyc` To migrate, users should access the same symbol via the `@stdlib/stats/strided/svarianceyc` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/docs/types/index.d.ts | 28 ------------------- .../@stdlib/stats/base/lib/index.js | 9 ------ 2 files changed, 37 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts index a81bc06b12f0..9cce7b57cc0c 100644 --- a/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/docs/types/index.d.ts @@ -128,7 +128,6 @@ import stdevwd = require( '@stdlib/stats/base/stdevwd' ); import stdevyc = require( '@stdlib/stats/base/stdevyc' ); import svariance = require( '@stdlib/stats/base/svariance' ); import svariancewd = require( '@stdlib/stats/base/svariancewd' ); -import svarianceyc = require( '@stdlib/stats/base/svarianceyc' ); import variance = require( '@stdlib/stats/base/variance' ); import variancech = require( '@stdlib/stats/base/variancech' ); import variancepn = require( '@stdlib/stats/base/variancepn' ); @@ -3006,33 +3005,6 @@ interface Namespace { */ svariancewd: typeof svariancewd; - /** - * Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = ns.svarianceyc( x.length, 1, x, 1 ); - * // returns ~4.3333 - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = ns.svarianceyc.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - svarianceyc: typeof svarianceyc; - /** * Computes the variance of a strided array. * diff --git a/lib/node_modules/@stdlib/stats/base/lib/index.js b/lib/node_modules/@stdlib/stats/base/lib/index.js index efcfe21fb1a7..919737d014a1 100644 --- a/lib/node_modules/@stdlib/stats/base/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/lib/index.js @@ -1008,15 +1008,6 @@ setReadOnly( ns, 'svariance', require( '@stdlib/stats/base/svariance' ) ); */ setReadOnly( ns, 'svariancewd', require( '@stdlib/stats/base/svariancewd' ) ); -/** -* @name svarianceyc -* @memberof ns -* @readonly -* @type {Function} -* @see {@link module:@stdlib/stats/base/svarianceyc} -*/ -setReadOnly( ns, 'svarianceyc', require( '@stdlib/stats/base/svarianceyc' ) ); - /** * @name variance * @memberof ns From 3ec0e0024c24e64ca7726f51f30bfe70c3b23201 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:47:45 +0530 Subject: [PATCH 23/26] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/namespace/lib/namespace/base/strided/d.js | 2 +- .../@stdlib/namespace/lib/namespace/base/strided/s.js | 8 ++++---- lib/node_modules/@stdlib/stats/base/README.md | 4 ++-- .../@stdlib/stats/base/snanvarianceyc/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/varianceyc/README.md | 4 ++-- .../@stdlib/stats/strided/dvarianceyc/README.md | 4 ++-- lib/node_modules/@stdlib/stats/strided/sstdevyc/README.md | 4 ++-- .../@stdlib/stats/strided/sstdevyc/lib/ndarray.js | 2 +- .../@stdlib/stats/strided/sstdevyc/manifest.json | 8 ++++---- .../@stdlib/stats/strided/sstdevyc/src/main.c | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js index 4c622ba0f20d..e540d39566a9 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/d.js @@ -2322,7 +2322,7 @@ ns.push({ '@stdlib/stats/strided/dnanvarianceyc', '@stdlib/stats/strided/dstdevyc', '@stdlib/stats/strided/dvariance', - '@stdlib/stats/base/svarianceyc', + '@stdlib/stats/strided/svarianceyc', '@stdlib/stats/base/varianceyc' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js index 823a68c7047c..afb44c93f1e6 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/base/strided/s.js @@ -1448,7 +1448,7 @@ ns.push({ '@stdlib/stats/base/nanvarianceyc', '@stdlib/stats/base/snanstdevyc', '@stdlib/stats/base/snanvariance', - '@stdlib/stats/base/svarianceyc' + '@stdlib/stats/strided/svarianceyc' ] }); @@ -1694,7 +1694,7 @@ ns.push({ '@stdlib/stats/base/snanstdevyc', '@stdlib/stats/base/sstdev', '@stdlib/stats/base/stdevyc', - '@stdlib/stats/base/svarianceyc' + '@stdlib/stats/strided/svarianceyc' ] }); @@ -1963,8 +1963,8 @@ ns.push({ ns.push({ 'alias': 'base.strided.svarianceyc', - 'path': '@stdlib/stats/base/svarianceyc', - 'value': require( '@stdlib/stats/base/svarianceyc' ), + 'path': '@stdlib/stats/strided/svarianceyc', + 'value': require( '@stdlib/stats/strided/svarianceyc' ), 'type': 'Function', 'related': [ '@stdlib/stats/strided/dvarianceyc', diff --git a/lib/node_modules/@stdlib/stats/base/README.md b/lib/node_modules/@stdlib/stats/base/README.md index ebd143e9ed04..45d585574d7a 100644 --- a/lib/node_modules/@stdlib/stats/base/README.md +++ b/lib/node_modules/@stdlib/stats/base/README.md @@ -242,7 +242,7 @@ The namespace contains the following statistical functions: - [`svariancepn( N, correction, x, strideX )`][@stdlib/stats/strided/svariancepn]: calculate the variance of a single-precision floating-point strided array using a two-pass algorithm. - [`svariancetk( N, correction, x, strideX )`][@stdlib/stats/strided/svariancetk]: calculate the variance of a single-precision floating-point strided array using a one-pass textbook algorithm. - [`svariancewd( N, correction, x, stride )`][@stdlib/stats/base/svariancewd]: calculate the variance of a single-precision floating-point strided array using Welford's algorithm. -- [`svarianceyc( N, correction, x, strideX )`][@stdlib/stats/base/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`svarianceyc( N, correction, x, strideX )`][@stdlib/stats/strided/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`variance( N, correction, x, stride )`][@stdlib/stats/base/variance]: calculate the variance of a strided array. - [`variancech( N, correction, x, stride )`][@stdlib/stats/base/variancech]: calculate the variance of a strided array using a one-pass trial mean algorithm. - [`variancepn( N, correction, x, stride )`][@stdlib/stats/base/variancepn]: calculate the variance of a strided array using a two-pass algorithm. @@ -669,7 +669,7 @@ console.log( objectKeys( ns ) ); [@stdlib/stats/base/svariancewd]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svariancewd -[@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc +[@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc [@stdlib/stats/base/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/variance diff --git a/lib/node_modules/@stdlib/stats/base/snanvarianceyc/README.md b/lib/node_modules/@stdlib/stats/base/snanvarianceyc/README.md index 95d262498567..1869d7937ca9 100644 --- a/lib/node_modules/@stdlib/stats/base/snanvarianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/snanvarianceyc/README.md @@ -246,7 +246,7 @@ console.log( v ); - [`@stdlib/stats/base/nanvarianceyc`][@stdlib/stats/base/nanvarianceyc]: calculate the variance of a strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/snanstdevyc`][@stdlib/stats/base/snanstdevyc]: calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/snanvariance`][@stdlib/stats/base/snanvariance]: calculate the variance of a single-precision floating-point strided array ignoring NaN values. -- [`@stdlib/stats/base/svarianceyc`][@stdlib/stats/base/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/svarianceyc`][@stdlib/stats/strided/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -274,7 +274,7 @@ console.log( v ); [@stdlib/stats/base/snanvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanvariance -[@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc +[@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index f158b8dd621e..1e4d0fe95ea4 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -182,7 +182,7 @@ var v = varianceyc.ndarray( N, 1, x, 2, 1 ); - If `N <= 0`, both functions return `NaN`. - If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. -- Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/strided/dvarianceyc], [`svarianceyc`][@stdlib/stats/base/svarianceyc], etc.) are likely to be significantly more performant. +- Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/strided/dvarianceyc], [`svarianceyc`][@stdlib/stats/strided/svarianceyc], etc.) are likely to be significantly more performant. @@ -256,7 +256,7 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray -[@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc +[@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc [@youngs:1971a]: https://doi.org/10.1080/00401706.1971.10488826 diff --git a/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md b/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md index 955f068b30b5..b38d69957124 100644 --- a/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dvarianceyc/README.md @@ -351,7 +351,7 @@ int main( void ) { - [`@stdlib/stats/strided/dnanvarianceyc`][@stdlib/stats/strided/dnanvarianceyc]: calculate the variance of a double-precision floating-point strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/strided/dstdevyc`][@stdlib/stats/strided/dstdevyc]: calculate the standard deviation of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/strided/dvariance`][@stdlib/stats/strided/dvariance]: calculate the variance of a double-precision floating-point strided array. -- [`@stdlib/stats/base/svarianceyc`][@stdlib/stats/base/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/svarianceyc`][@stdlib/stats/strided/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/varianceyc`][@stdlib/stats/base/varianceyc]: calculate the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -378,7 +378,7 @@ int main( void ) { [@stdlib/stats/strided/dvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dvariance -[@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc +[@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc [@stdlib/stats/base/varianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/varianceyc diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevyc/README.md b/lib/node_modules/@stdlib/stats/strided/sstdevyc/README.md index 04c1d2d90077..f44de3beb0af 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevyc/README.md +++ b/lib/node_modules/@stdlib/stats/strided/sstdevyc/README.md @@ -352,7 +352,7 @@ int main( void ) { - [`@stdlib/stats/base/snanstdevyc`][@stdlib/stats/base/snanstdevyc]: calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a one-pass algorithm proposed by Youngs and Cramer. - [`@stdlib/stats/base/sstdev`][@stdlib/stats/base/sstdev]: calculate the standard deviation of a single-precision floating-point strided array. - [`@stdlib/stats/base/stdevyc`][@stdlib/stats/base/stdevyc]: calculate the standard deviation of a strided array using a one-pass algorithm proposed by Youngs and Cramer. -- [`@stdlib/stats/base/svarianceyc`][@stdlib/stats/base/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. +- [`@stdlib/stats/strided/svarianceyc`][@stdlib/stats/strided/svarianceyc]: calculate the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. @@ -380,7 +380,7 @@ int main( void ) { [@stdlib/stats/base/stdevyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/stdevyc -[@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc +[@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/sstdevyc/lib/ndarray.js index 333fbc898402..ab0107a2512d 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevyc/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/sstdevyc/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var svarianceyc = require( '@stdlib/stats/base/svarianceyc' ).ndarray; +var svarianceyc = require( '@stdlib/stats/strided/svarianceyc' ).ndarray; var sqrtf = require( '@stdlib/math/base/special/sqrtf' ); diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevyc/manifest.json b/lib/node_modules/@stdlib/stats/strided/sstdevyc/manifest.json index 1994589d6149..2913d9453742 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevyc/manifest.json +++ b/lib/node_modules/@stdlib/stats/strided/sstdevyc/manifest.json @@ -41,7 +41,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svarianceyc", + "@stdlib/stats/strided/svarianceyc", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -65,7 +65,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svarianceyc" + "@stdlib/stats/strided/svarianceyc" ] }, { @@ -83,7 +83,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svarianceyc" + "@stdlib/stats/strided/svarianceyc" ] }, { @@ -101,7 +101,7 @@ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", "@stdlib/math/base/special/sqrtf", - "@stdlib/stats/base/svarianceyc" + "@stdlib/stats/strided/svarianceyc" ] } ] diff --git a/lib/node_modules/@stdlib/stats/strided/sstdevyc/src/main.c b/lib/node_modules/@stdlib/stats/strided/sstdevyc/src/main.c index 2053b455e1f0..da6bcc955d76 100644 --- a/lib/node_modules/@stdlib/stats/strided/sstdevyc/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/sstdevyc/src/main.c @@ -17,7 +17,7 @@ */ #include "stdlib/stats/strided/sstdevyc.h" -#include "stdlib/stats/base/svarianceyc.h" +#include "stdlib/stats/strided/svarianceyc.h" #include "stdlib/math/base/special/sqrtf.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" From 9b938de608e6ada0aca183a46d32872c2c7ec1c7 Mon Sep 17 00:00:00 2001 From: Aayush Khanna Date: Sun, 30 Mar 2025 09:48:20 +0530 Subject: [PATCH 24/26] remove: remove `stats/base/svarianceyc` This commit removes `@stdlib/stats/base/svarianceyc` in favor of `@stdlib/stats/strided/svarianceyc`. BREAKING CHANGE: remove `stats/base/svarianceyc` To migrate, users should update their require/import paths to use `@stdlib/stats/strided/svarianceyc`, which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/4797 --- 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 --- --- .../@stdlib/stats/base/svarianceyc/README.md | 389 ------------------ .../base/svarianceyc/benchmark/benchmark.js | 96 ----- .../svarianceyc/benchmark/benchmark.native.js | 101 ----- .../benchmark/benchmark.ndarray.js | 96 ----- .../benchmark/benchmark.ndarray.native.js | 101 ----- .../base/svarianceyc/benchmark/c/Makefile | 146 ------- .../benchmark/c/benchmark.length.c | 197 --------- .../stats/base/svarianceyc/binding.gyp | 170 -------- .../docs/img/equation_population_mean.svg | 42 -- .../docs/img/equation_population_variance.svg | 54 --- .../docs/img/equation_sample_mean.svg | 43 -- .../img/equation_unbiased_sample_variance.svg | 61 --- .../stats/base/svarianceyc/docs/repl.txt | 114 ----- .../base/svarianceyc/docs/types/index.d.ts | 95 ----- .../stats/base/svarianceyc/docs/types/test.ts | 187 --------- .../base/svarianceyc/examples/c/Makefile | 146 ------- .../base/svarianceyc/examples/c/example.c | 37 -- .../stats/base/svarianceyc/examples/index.js | 30 -- .../stats/base/svarianceyc/include.gypi | 53 --- .../include/stdlib/stats/base/svarianceyc.h | 45 -- .../stats/base/svarianceyc/lib/index.js | 68 --- .../stats/base/svarianceyc/lib/main.js | 35 -- .../stats/base/svarianceyc/lib/native.js | 35 -- .../stats/base/svarianceyc/lib/ndarray.js | 86 ---- .../base/svarianceyc/lib/ndarray.native.js | 53 --- .../stats/base/svarianceyc/lib/svarianceyc.js | 61 --- .../svarianceyc/lib/svarianceyc.native.js | 52 --- .../stats/base/svarianceyc/manifest.json | 102 ----- .../stats/base/svarianceyc/package.json | 83 ---- .../stats/base/svarianceyc/src/Makefile | 70 ---- .../stats/base/svarianceyc/src/addon.c | 63 --- .../@stdlib/stats/base/svarianceyc/src/main.c | 86 ---- .../stats/base/svarianceyc/test/test.js | 82 ---- .../base/svarianceyc/test/test.ndarray.js | 196 --------- .../svarianceyc/test/test.ndarray.native.js | 205 --------- .../base/svarianceyc/test/test.svarianceyc.js | 200 --------- .../test/test.svarianceyc.native.js | 209 ---------- 37 files changed, 3889 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/README.md delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/benchmark.length.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/binding.gyp delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_sample_mean.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_unbiased_sample_variance.svg delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/example.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/examples/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/include.gypi delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/include/stdlib/stats/base/svarianceyc.h delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/index.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/main.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/svarianceyc.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/lib/svarianceyc.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/manifest.json delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/package.json delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/src/Makefile delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/src/main.c delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.native.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.js delete mode 100644 lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.native.js diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/README.md b/lib/node_modules/@stdlib/stats/base/svarianceyc/README.md deleted file mode 100644 index 0f98c2bcf6c9..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/README.md +++ /dev/null @@ -1,389 +0,0 @@ - - -# svarianceyc - -> Calculate the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - -
- -The population [variance][variance] of a finite size population of size `N` is given by - - - -```math -\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2 -``` - - - - - -where the population mean is given by - - - -```math -\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i -``` - - - - - -Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`, - - - -```math -s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 -``` - - - - - -where the sample mean is given by - - - -```math -\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i -``` - - - - - -The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators. - -
- - - -
- -## Usage - -```javascript -var svarianceyc = require( '@stdlib/stats/base/svarianceyc' ); -``` - -#### svarianceyc( N, correction, x, strideX ) - -Computes the [variance][variance] of a single-precision floating-point strided array `x` using a one-pass algorithm proposed by Youngs and Cramer. - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - -var v = svarianceyc( x.length, 1, x, 1 ); -// returns ~4.3333 -``` - -The function has the following parameters: - -- **N**: number of indexed elements. -- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: stride length for `x`. - -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); - -var v = svarianceyc( 4, 1, x, 2 ); -// returns 6.25 -``` - -Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - - - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = svarianceyc( 4, 1, x1, 2 ); -// returns 6.25 -``` - -#### svarianceyc.ndarray( N, correction, x, strideX, offsetX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - -var v = svarianceyc.ndarray( x.length, 1, x, 1, 0 ); -// returns ~4.33333 -``` - -The function has the following additional parameters: - -- **offsetX**: starting index for `x`. - -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element - -```javascript -var Float32Array = require( '@stdlib/array/float32' ); - -var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); - -var v = svarianceyc.ndarray( 4, 1, x, 2, 1 ); -// returns 6.25 -``` - -
- - - -
- -## Notes - -- If `N <= 0`, both functions return `NaN`. -- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`. - -
- - - -
- -## Examples - - - -```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var svarianceyc = require( '@stdlib/stats/base/svarianceyc' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float32' -}); -console.log( x ); - -var v = svarianceyc( x.length, 1, x, 1 ); -console.log( v ); -``` - -
- - - - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/stats/base/svarianceyc.h" -``` - -#### stdlib_strided_svarianceyc( N, correction, \*X, strideX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - -```c -const float x[] = { 1.0f, -2.0f, 2.0f }; - -float v = stdlib_strided_svarianceyc( 3, 1, x, 1 ); -// returns ~4.3333f -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than 0 has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where c corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to 0 is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to 1 is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **x**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `x`. - -```c -float stdlib_strided_svarianceyc( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); -``` - -#### stdlib_strided_svarianceyc_ndarray( N, correction, \*X, strideX, offsetX ) - -Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. - -```c -const float x[] = { 1.0f, -2.0f, 2.0f }; - -float v = stdlib_strided_srange_ndarray( 3, 1, x, 1, 0 ); -// returns ~4.33333f -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction** `[in] float`: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **offsetX**: `[in] CBLAS_INT` starting index for `X`. - -```c -float stdlib_strided_svarianceyc_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); -``` - -
- - - - - -
- -
- - - - - -
- -### Examples - -```c -#include "stdlib/stats/base/svarianceyc.h" -#include - -int main( void ) { - // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; - - // Specify the number of elements: - const int N = 4; - - // Specify the stride length: - const int strideX = 2; - - // Compute the variance: - float v = stdlib_strided_svarianceyc( N, 1.0f, x, strideX ); - - // Print the result: - printf( "sample variance: %f\n", v ); -} -``` - -
- - - -
- - - -* * * - -
- -## References - -- Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826][@youngs:1971a]. - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.js deleted file mode 100644 index 4f797d9a04b9..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var svarianceyc = require( './../lib/svarianceyc.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svarianceyc( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.native.js deleted file mode 100644 index ac3eed32893a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.native.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var pkg = require( './../package.json' ).name; - - -// VARIABLES // - -var svarianceyc = tryRequire( resolve( __dirname, './../lib/svarianceyc.native.js' ) ); -var opts = { - 'skip': ( svarianceyc instanceof Error ) -}; -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svarianceyc( x.length, 1, x, 1 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+'::native:len='+len, opts, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.js deleted file mode 100644 index 62bae635a6fc..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,96 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var pkg = require( './../package.json' ).name; -var svarianceyc = require( './../lib/ndarray.js' ); - - -// VARIABLES // - -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svarianceyc( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.native.js deleted file mode 100644 index 3dbafab017de..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/benchmark.ndarray.native.js +++ /dev/null @@ -1,101 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var tryRequire = require( '@stdlib/utils/try-require' ); -var pkg = require( './../package.json' ).name; - - -// VARIABLES // - -var svarianceyc = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( svarianceyc instanceof Error ) -}; -var options = { - 'dtype': 'float32' -}; - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - return benchmark; - - function benchmark( b ) { - var v; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = svarianceyc( x.length, 1, x, 1, 0 ); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( v ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg+'::native:ndarray:len='+len, opts, f ); - } -} - -main(); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/Makefile deleted file mode 100644 index 7280962b4c4d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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.length.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/svarianceyc/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/benchmark.length.c deleted file mode 100644 index 58d05b4c6c9f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/benchmark/c/benchmark.length.c +++ /dev/null @@ -1,197 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svarianceyc.h" -#include -#include -#include -#include -#include - -#define NAME "svarianceyc" -#define ITERATIONS 1000000 -#define REPEATS 3 -#define MIN 1 -#define MAX 6 - -/** -* 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 iterations number of iterations -* @param elapsed elapsed time in seconds -*/ -static void print_results( int iterations, 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 [0,1). -* -* @return random number -*/ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark1( int iterations, int len ) { - double elapsed; - float x[ len ]; - float v; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; - } - v = 0.0f; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - // cppcheck-suppress uninitvar - v = stdlib_strided_svarianceyc( len, 1.0f, x, 1 ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; -} - -/** -* Runs a benchmark. -* -* @param iterations number of iterations -* @param len array length -* @return elapsed time in seconds -*/ -static double benchmark2( int iterations, int len ) { - double elapsed; - float x[ len ]; - float v; - double t; - int i; - - for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; - } - v = 0.0f; - t = tic(); - for ( i = 0; i < iterations; i++ ) { - // cppcheck-suppress uninitvar - v = stdlib_strided_svarianceyc_ndarray( len, 1.0f, x, 1, 0 ); - if ( v != v ) { - printf( "should not return NaN\n" ); - break; - } - } - elapsed = tic() - t; - if ( v != v ) { - printf( "should not return NaN\n" ); - } - return elapsed; -} - -/** -* Main execution sequence. -*/ -int main( void ) { - double elapsed; - int count; - int iter; - int len; - int i; - int j; - - // Use the current time to seed the random number generator: - srand( time( NULL ) ); - - print_version(); - count = 0; - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark1( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - for ( i = MIN; i <= MAX; i++ ) { - len = pow( 10, i ); - iter = ITERATIONS / pow( 10, i-1 ); - for ( j = 0; j < REPEATS; j++ ) { - count += 1; - printf( "# c::%s:ndarray:len=%d\n", NAME, len ); - elapsed = benchmark2( iter, len ); - print_results( iter, elapsed ); - printf( "ok %d benchmark finished\n", count ); - } - } - print_summary( count, count ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/binding.gyp b/lib/node_modules/@stdlib/stats/base/svarianceyc/binding.gyp deleted file mode 100644 index 7d0005b2e390..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/binding.gyp +++ /dev/null @@ -1,170 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2020 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 -} diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_mean.svg b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_mean.svg deleted file mode 100644 index 4bbdf0d2a56f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_mean.svg +++ /dev/null @@ -1,42 +0,0 @@ - -mu equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_variance.svg b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_variance.svg deleted file mode 100644 index 4130ba0750d2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_population_variance.svg +++ /dev/null @@ -1,54 +0,0 @@ - -sigma squared equals StartFraction 1 Over upper N EndFraction sigma-summation Underscript i equals 0 Overscript upper N minus 1 Endscripts left-parenthesis x Subscript i Baseline minus mu right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_sample_mean.svg b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_sample_mean.svg deleted file mode 100644 index aea7a5f6687a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_sample_mean.svg +++ /dev/null @@ -1,43 +0,0 @@ - -x overbar equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_unbiased_sample_variance.svg b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_unbiased_sample_variance.svg deleted file mode 100644 index 1ae1283e7fb1..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/img/equation_unbiased_sample_variance.svg +++ /dev/null @@ -1,61 +0,0 @@ - -s squared equals StartFraction 1 Over n minus 1 EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts left-parenthesis x Subscript i Baseline minus x overbar right-parenthesis squared - - - \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/repl.txt deleted file mode 100644 index c8320f182444..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/repl.txt +++ /dev/null @@ -1,114 +0,0 @@ - -{{alias}}( N, correction, x, strideX ) - Computes the variance of a single-precision floating-point strided array - using a one-pass algorithm proposed by Youngs and Cramer. - - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. - - Indexing is relative to the first index. To introduce an offset, use a typed - array view. - - If `N <= 0`, the function returns `NaN`. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Float32Array - Input array. - - strideX: integer - Stride length. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); - > {{alias}}( x.length, 1, x, 1 ) - ~4.3333 - - // Using `N` and stride parameters: - > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 3, 1, x, 2 ) - ~4.3333 - - // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) - ~4.3333 - - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) - Computes the variance of a single-precision floating-point strided array - using a one-pass algorithm proposed by Youngs and Cramer and alternative - indexing semantics. - - While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. - - Parameters - ---------- - N: integer - Number of indexed elements. - - correction: number - Degrees of freedom adjustment. Setting this parameter to a value other - than `0` has the effect of adjusting the divisor during the calculation - of the variance according to `N - c` where `c` corresponds to the - provided degrees of freedom adjustment. When computing the variance of a - population, setting this parameter to `0` is the standard choice (i.e., - the provided array contains data constituting an entire population). - When computing the unbiased sample variance, setting this parameter to - `1` is the standard choice (i.e., the provided array contains data - sampled from a larger population; this is commonly referred to as - Bessel's correction). - - x: Float32Array - Input array. - - strideX: integer - Stride length. - - offsetX: integer - Starting index. - - Returns - ------- - out: number - The variance. - - Examples - -------- - // Standard Usage: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) - ~4.3333 - - // Using offset parameter: - > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) - ~4.3333 - - See Also - -------- diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/index.d.ts deleted file mode 100644 index bbc7845b6ac5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/index.d.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface describing `svarianceyc`. -*/ -interface Routine { - /** - * Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = svarianceyc( x.length, 1, x, 1 ); - * // returns ~4.3333 - */ - ( N: number, correction: number, x: Float32Array, strideX: number ): number; - - /** - * Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. - * - * @param N - number of indexed elements - * @param correction - degrees of freedom adjustment - * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index - * @returns variance - * - * @example - * var Float32Array = require( '@stdlib/array/float32' ); - * - * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); - * - * var v = svarianceyc.ndarray( x.length, 1, x, 1, 0 ); - * // returns ~4.3333 - */ - ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; -} - -/** -* Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* @param N - number of indexed elements -* @param correction - degrees of freedom adjustment -* @param x - input array -* @param strideX - stride length -* @returns variance -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* -* var v = svarianceyc( x.length, 1, x, 1 ); -* // returns ~4.3333 -* -* @example -* var Float32Array = require( '@stdlib/array/float32' ); -* -* var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* -* var v = svarianceyc.ndarray( x.length, 1, x, 1, 0 ); -* // returns ~4.3333 -*/ -declare var svarianceyc: Routine; - - -// EXPORTS // - -export = svarianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/test.ts deleted file mode 100644 index 1aa031631b87..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/docs/types/test.ts +++ /dev/null @@ -1,187 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2020 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. -*/ - -import svarianceyc = require( './index' ); - - -// TESTS // - -// The function returns a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc( x.length, 1, x, 1 ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc( '10', 1, x, 1 ); // $ExpectError - svarianceyc( true, 1, x, 1 ); // $ExpectError - svarianceyc( false, 1, x, 1 ); // $ExpectError - svarianceyc( null, 1, x, 1 ); // $ExpectError - svarianceyc( undefined, 1, x, 1 ); // $ExpectError - svarianceyc( [], 1, x, 1 ); // $ExpectError - svarianceyc( {}, 1, x, 1 ); // $ExpectError - svarianceyc( ( x: number ): number => x, 1, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc( x.length, '10', x, 1 ); // $ExpectError - svarianceyc( x.length, true, x, 1 ); // $ExpectError - svarianceyc( x.length, false, x, 1 ); // $ExpectError - svarianceyc( x.length, null, x, 1 ); // $ExpectError - svarianceyc( x.length, undefined, x, 1 ); // $ExpectError - svarianceyc( x.length, [], x, 1 ); // $ExpectError - svarianceyc( x.length, {}, x, 1 ); // $ExpectError - svarianceyc( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a Float32Array... -{ - const x = new Float32Array( 10 ); - - svarianceyc( x.length, 1, 10, 1 ); // $ExpectError - svarianceyc( x.length, 1, '10', 1 ); // $ExpectError - svarianceyc( x.length, 1, true, 1 ); // $ExpectError - svarianceyc( x.length, 1, false, 1 ); // $ExpectError - svarianceyc( x.length, 1, null, 1 ); // $ExpectError - svarianceyc( x.length, 1, undefined, 1 ); // $ExpectError - svarianceyc( x.length, 1, [], 1 ); // $ExpectError - svarianceyc( x.length, 1, {}, 1 ); // $ExpectError - svarianceyc( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc( x.length, 1, x, '10' ); // $ExpectError - svarianceyc( x.length, 1, x, true ); // $ExpectError - svarianceyc( x.length, 1, x, false ); // $ExpectError - svarianceyc( x.length, 1, x, null ); // $ExpectError - svarianceyc( x.length, 1, x, undefined ); // $ExpectError - svarianceyc( x.length, 1, x, [] ); // $ExpectError - svarianceyc( x.length, 1, x, {} ); // $ExpectError - svarianceyc( x.length, 1, x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const x = new Float32Array( 10 ); - - svarianceyc(); // $ExpectError - svarianceyc( x.length ); // $ExpectError - svarianceyc( x.length, 1 ); // $ExpectError - svarianceyc( x.length, 1, x ); // $ExpectError - svarianceyc( x.length, 1, x, 1, 10 ); // $ExpectError -} - -// Attached to main export is an `ndarray` method which returns a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number -} - -// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( true, 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( false, 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( null, 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( [], 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, true, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, false, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, null, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, [], x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, true ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, false ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, null ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... -{ - const x = new Float32Array( 10 ); - - svarianceyc.ndarray(); // $ExpectError - svarianceyc.ndarray( x.length ); // $ExpectError - svarianceyc.ndarray( x.length, 1 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1 ); // $ExpectError - svarianceyc.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/Makefile deleted file mode 100644 index ff5293d3059f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/Makefile +++ /dev/null @@ -1,146 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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/svarianceyc/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/example.c deleted file mode 100644 index 487730dc1402..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/c/example.c +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svarianceyc.h" -#include - -int main( void ) { - // Create a strided array: - const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; - - // Specify the number of elements: - const int N = 4; - - // Specify the stride length: - const int strideX = 2; - - // Compute the variance: - float v = stdlib_strided_svarianceyc( N, 1.0f, x, strideX ); - - // Print the result: - printf( "sample variance: %f\n", v ); -} diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/index.js deleted file mode 100644 index 8273e6e91f19..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/examples/index.js +++ /dev/null @@ -1,30 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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'; - -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var svarianceyc = require( './../lib' ); - -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float32' -}); -console.log( x ); - -var v = svarianceyc( x.length, 1, x, 1 ); -console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/include.gypi b/lib/node_modules/@stdlib/stats/base/svarianceyc/include.gypi deleted file mode 100644 index 26476a8c2655..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/include.gypi +++ /dev/null @@ -1,53 +0,0 @@ -# @license Apache-2.0 -# -# Copyright (c) 2020 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': [ - '=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdmath", - "statistics", - "stats", - "mathematics", - "math", - "variance", - "var", - "deviation", - "dispersion", - "sample variance", - "unbiased", - "stdev", - "std", - "standard deviation", - "youngs", - "cramer", - "strided", - "strided array", - "typed", - "array", - "float32", - "float", - "single", - "float32array" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/src/Makefile b/lib/node_modules/@stdlib/stats/base/svarianceyc/src/Makefile deleted file mode 100644 index dd720a3de8f2..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/src/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2020 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/svarianceyc/src/addon.c b/lib/node_modules/@stdlib/stats/base/svarianceyc/src/addon.c deleted file mode 100644 index ec11ab8e854a..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/src/addon.c +++ /dev/null @@ -1,63 +0,0 @@ -/** -* @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/svarianceyc.h" -#include "stdlib/napi/export.h" -#include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_strided_float32array.h" -#include "stdlib/napi/create_double.h" -#include "stdlib/napi/argv_float.h" -#include - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svarianceyc( N, correction, X, strideX ), v ); - return v; -} - -/** -* Receives JavaScript callback invocation data. -* -* @param env environment under which the function is invoked -* @param info callback data -* @return Node-API value -*/ -static napi_value addon_method( napi_env env, napi_callback_info info ) { - STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); - STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svarianceyc_ndarray( N, correction, X, strideX, offsetX ), v ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/src/main.c b/lib/node_modules/@stdlib/stats/base/svarianceyc/src/main.c deleted file mode 100644 index abb8ba71ad76..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/src/main.c +++ /dev/null @@ -1,86 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/svarianceyc.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/strided/base/stride2offset.h" - -/** -* Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer. -* -* ## Method -* -* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). -* -* ## References -* -* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @return output value -*/ -float API_SUFFIX(stdlib_strided_svarianceyc)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { - CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - return API_SUFFIX(stdlib_strided_svarianceyc_ndarray)( N, correction, X, strideX, ox ); -} - - -/** -* Computes the variance of a single-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @param offsetX starting index of X -* @return output value -*/ -float API_SUFFIX(stdlib_strided_svarianceyc_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - CBLAS_INT ix; - CBLAS_INT i; - double di; - float sum; - double n; - float S; - float v; - float d; - - n = (double)N - (double)correction; - if ( N <= 0 || n <= 0.0f ) { - return 0.0f / 0.0f; // NaN - } - if ( N == 1 || strideX == 0 ) { - return 0.0f; - } - ix = offsetX; - sum = X[ ix ]; - ix += strideX; - S = 0.0f; - for ( i = 2; i <= N; i++ ) { - di = (double)i; - v = X[ ix ]; - sum += v; - d = (float)(di*(double)v) - sum; - S += (float)(1.0/(di*(di-1.0))) * d * d; - ix += strideX; - } - return (double)S / n; -} diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.js deleted file mode 100644 index 1978fe90e910..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.js +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var proxyquire = require( 'proxyquire' ); -var IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var svarianceyc = require( './../lib' ); - - -// VARIABLES // - -var opts = { - 'skip': IS_BROWSER -}; - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { - t.strictEqual( typeof svarianceyc.ndarray, 'function', 'method is a function' ); - t.end(); -}); - -tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { - var svarianceyc = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( svarianceyc, mock, 'returns expected value' ); - t.end(); - - function tryRequire() { - return mock; - } - - function mock() { - // Mock... - } -}); - -tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { - var svarianceyc; - var main; - - main = require( './../lib/svarianceyc.js' ); - - svarianceyc = proxyquire( './../lib', { - '@stdlib/utils/try-require': tryRequire - }); - - t.strictEqual( svarianceyc, main, 'returns expected value' ); - t.end(); - - function tryRequire() { - return new Error( 'Cannot find module' ); - } -}); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.js deleted file mode 100644 index 0ad58b76d89f..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.js +++ /dev/null @@ -1,196 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svarianceyc = require( './../lib/ndarray.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', function test( t ) { - t.strictEqual( svarianceyc.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 0, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 1, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = svarianceyc( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.native.js deleted file mode 100644 index 5aa8b35322d9..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.ndarray.native.js +++ /dev/null @@ -1,205 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var svarianceyc = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); -var opts = { - 'skip': ( svarianceyc instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 5', opts, function test( t ) { - t.strictEqual( svarianceyc.length, 5, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 0, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 1, x, 1, 0 ); - t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 1, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 0, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( -1, 1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, 2, 0 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, -2, 6 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 - ]); - - v = svarianceyc( 4, 1, x, 2, 1 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.js deleted file mode 100644 index b3958706e4b5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.js +++ /dev/null @@ -1,200 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var svarianceyc = require( './../lib/svarianceyc.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( svarianceyc.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 0, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 1, x, 1 ); - t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = svarianceyc( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.native.js b/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.native.js deleted file mode 100644 index 36114f5da184..000000000000 --- a/lib/node_modules/@stdlib/stats/base/svarianceyc/test/test.svarianceyc.native.js +++ /dev/null @@ -1,209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var Float32Array = require( '@stdlib/array/float32' ); -var tryRequire = require( '@stdlib/utils/try-require' ); - - -// VARIABLES // - -var svarianceyc = tryRequire( resolve( __dirname, './../lib/svarianceyc.native.js' ) ); -var opts = { - 'skip': ( svarianceyc instanceof Error ) -}; - - -// TESTS // - -tape( 'main export is a function', opts, function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof svarianceyc, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( svarianceyc.length, 4, 'has expected arity' ); - t.end(); -}); - -tape( 'the function calculates the population variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 0, x, 1 ); - t.strictEqual( v, float64ToFloat32( 53.5/x.length ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function calculates the sample variance of a strided array', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); - v = svarianceyc( x.length, 1, x, 1 ); - t.strictEqual( v, float64ToFloat32( 10.700000762939453 ), 'returns expected value' ); - - x = new Float32Array( [ -4.0, -4.0 ] ); - v = svarianceyc( x.length, 1, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Float32Array( [ NaN, 4.0 ] ); - v = svarianceyc( x.length, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 0, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( -1, 1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = svarianceyc( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, 2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var x; - var v; - - x = new Float32Array([ - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]); - - v = svarianceyc( 4, 1, x, -2 ); - - t.strictEqual( v, 6.25, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', opts, function test( t ) { - var x; - var v; - - x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - - v = svarianceyc( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function supports view offsets', opts, function test( t ) { - var x0; - var x1; - var v; - - x0 = new Float32Array([ - 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 - -2.0, - 2.0, // 2 - 3.0, - 4.0, // 3 - 6.0 - ]); - - x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - - v = svarianceyc( 4, 1, x1, 2 ); - t.strictEqual( v, 6.25, 'returns expected value' ); - - t.end(); -}); From 046574dd768ad6defd94f34af0228dfdad631c8c Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Thu, 3 Apr 2025 23:11:44 +0530 Subject: [PATCH 25/26] chore: clean up --- .../@stdlib/stats/base/dists/erlang/mgf/README.md | 9 +++++---- .../stats/base/dists/erlang/mgf/benchmark/benchmark.js | 5 +++-- .../base/dists/erlang/mgf/benchmark/benchmark.native.js | 5 +++-- .../stats/base/dists/erlang/mgf/benchmark/c/benchmark.c | 5 +++-- .../stats/base/dists/erlang/mgf/examples/c/example.c | 5 +++-- .../mgf/include/stdlib/stats/base/dists/erlang/mgf.h | 4 +++- .../@stdlib/stats/base/dists/erlang/mgf/lib/native.js | 8 -------- .../@stdlib/stats/base/dists/erlang/mgf/src/addon.c | 2 +- .../@stdlib/stats/base/dists/erlang/mgf/src/main.c | 6 +++--- .../stats/base/dists/erlang/mgf/test/test.native.js | 6 ------ 10 files changed, 24 insertions(+), 31 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md index e472c2f889e9..6918e4ff346e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/README.md @@ -199,11 +199,11 @@ double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); The function accepts the following arguments: - **t**: `[in] double` input value. -- **k**: `[in] double` shape parameter. +- **k**: `[in] int32_t` shape parameter. - **lambda**: `[in] double` rate parameter. ```c -double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ); +double stdlib_base_dists_erlang_mgf( const double t, const int32_t k, const double lambda ); ``` @@ -227,6 +227,7 @@ double stdlib_base_dists_erlang_mgf( const double t, const double k, const doubl ```c #include "stdlib/stats/base/dists/erlang/mgf.h" #include "stdlib/math/base/special/round.h" +#include #include #include @@ -237,7 +238,7 @@ static double random_uniform( const double min, const double max ) { int main( void ) { double lambda; - double k; + int32_t k; double t; double y; int i; @@ -247,7 +248,7 @@ int main( void ) { lambda = random_uniform( 0.0, 10.0 ) ; t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); - printf( "t: %lf, k: %lf, λ: %lf, M_X(t;k,λ): %lf\n", t, k, lambda, y ); + printf( "t: %lf, k: %d, λ: %lf, M_X(t;k,λ): %lf\n", t, k, lambda, y ); } } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js index 518f68070015..b5301c4c0609 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.js @@ -24,6 +24,7 @@ var bench = require( '@stdlib/bench' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -41,11 +42,11 @@ bench( pkg, function benchmark( b ) { var i; len = 100; - k = new Float64Array( len ); + k = new Int32Array( len ); lambda = new Float64Array( len ); t = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - k[ i ] = discreteUniform( 0.0, 100.0 ); + k[ i ] = discreteUniform( 1.0, 100.0 ); lambda[ i ] = uniform( EPS, 20.0 ); t[ i ] = uniform( 0.0, lambda[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js index 9e17e345d721..9610c636c5f9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/benchmark.native.js @@ -25,6 +25,7 @@ var bench = require( '@stdlib/bench' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var EPS = require( '@stdlib/constants/float64/eps' ); @@ -50,11 +51,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var i; len = 100; - k = new Float64Array( len ); + k = new Int32Array( len ); lambda = new Float64Array( len ); t = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - k[ i ] = discreteUniform( 0.0, 100.0 ); + k[ i ] = discreteUniform( 1.0, 100.0 ); lambda[ i ] = uniform( EPS, 20.0 ); t[ i ] = uniform( 0.0, lambda[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c index 1903ea5fb256..95e188f90fb2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/benchmark/c/benchmark.c @@ -19,6 +19,7 @@ #include "stdlib/stats/base/dists/erlang/mgf.h" #include "stdlib/math/base/special/ceil.h" #include "stdlib/constants/float64/eps.h" +#include #include #include #include @@ -96,14 +97,14 @@ static double random_uniform( const double min, const double max ) { static double benchmark( void ) { double elapsed; double lambda[ 100 ]; - double k[ 100 ]; + int32_t k[ 100 ]; double t[ 100 ]; double x; double y; int i; for ( i = 0; i < 100; i++ ) { - k[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) ); + k[ i ] = stdlib_base_ceil( random_uniform( 1.0, 100.0 ) ); lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); t[ i ] = random_uniform( 0.0, lambda[ i ] ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c index 1edd737230d6..9c840da884ed 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/examples/c/example.c @@ -18,6 +18,7 @@ #include "stdlib/stats/base/dists/erlang/mgf.h" #include "stdlib/math/base/special/round.h" +#include #include #include @@ -28,7 +29,7 @@ static double random_uniform( const double min, const double max ) { int main( void ) { double lambda; - double k; + int32_t k; double t; double y; int i; @@ -38,6 +39,6 @@ int main( void ) { lambda = random_uniform( 0.0, 10.0 ) ; t = random_uniform( 0.0, lambda ); y = stdlib_base_dists_erlang_mgf( t, k, lambda ); - printf( "t: %lf, k: %lf, λ: %1f, M_X(t;k,λ): %lf\n", t, k, lambda, y ); + printf( "t: %lf, k: %d, λ: %1f, M_X(t;k,λ): %lf\n", t, k, lambda, y ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h index 5e4ec9a72c83..f9d8b862360a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/include/stdlib/stats/base/dists/erlang/mgf.h @@ -19,6 +19,8 @@ #ifndef STDLIB_STATS_BASE_DISTS_ERLANG_MGF_H #define STDLIB_STATS_BASE_DISTS_ERLANG_MGF_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. */ @@ -29,7 +31,7 @@ extern "C" { /** * Evaluates the moment-generating function (mgf) for a Erlang distribution with parameters shape parameter `k` and rate parameter `lambda`. */ -double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ); +double stdlib_base_dists_erlang_mgf( const double t, const int32_t k, const double lambda ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js index e5dbfc08e06f..8660415f4dec 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/lib/native.js @@ -59,20 +59,12 @@ var addon = require( './../src/addon.node' ); * // returns NaN * * @example -* var y = mgf( 0.2, -2, 0.5 ); -* // returns NaN -* -* @example * var y = mgf( 0.2, 0.5, 0.5 ); * // returns NaN * * @example * var y = mgf( 0.2, 1, 0.0 ); * // returns NaN -* -* @example -* var y = mgf( 0.2, 1, -5.0 ); -* // returns NaN */ function mgf( t, k, lambda ) { return addon( t, k, lambda ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c index 99147bee52a9..57c1357ea413 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/addon.c @@ -20,4 +20,4 @@ #include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_erlang_mgf ) +STDLIB_MATH_BASE_NAPI_MODULE_DID_D( stdlib_base_dists_erlang_mgf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c index d445a5b86087..c20fd2780fa8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/src/main.c @@ -33,11 +33,11 @@ * double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 ); * // returns ~1.429 */ -double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ) { +double stdlib_base_dists_erlang_mgf( const double t, const int32_t k, const double lambda ) { if ( stdlib_base_is_nan( t ) || - !stdlib_base_is_nonnegative_integer( k ) || - isnan( lambda )|| + k <= 0.0 || + stdlib_base_is_nan( lambda )|| lambda < 0.0 || t >= lambda ) { diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js index 482ab1e26738..0b2ac6ee1a15 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.native.js @@ -66,12 +66,6 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f tape( 'if provided a negative `k`, the function returns `NaN`', opts, function test( t ) { var y; - y = mgf( 2.0, -1.0, 2.0 ); - t.equal( isnan( y ), true, 'returns NaN' ); - - y = mgf( 0.0, -1.0, 2.0 ); - t.equal( isnan( y ), true, 'returns NaN' ); - y = mgf( 2.0, NINF, 1.0 ); t.equal( isnan( y ), true, 'returns NaN' ); From ab6b9536db08ddda2e37009903344a6ff04d5f5b Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Thu, 3 Apr 2025 23:36:41 +0530 Subject: [PATCH 26/26] fix: native tests --- .../@stdlib/stats/base/dists/erlang/mgf/test/test.mgf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.mgf.js b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.mgf.js index 2448ea82e2f0..1f5386957286 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.mgf.js +++ b/lib/node_modules/@stdlib/stats/base/dists/erlang/mgf/test/test.mgf.js @@ -184,7 +184,7 @@ tape( 'the function evaluates the mgf for `x` given large rate parameter `lambda t.equal( y, expected[i], 'x: '+x[i]+', k:'+k[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { delta = abs( y - expected[ i ] ); - tol = 1250.0 * EPS * abs( expected[ i ] ); + tol = 3000.0 * EPS * abs( expected[ i ] ); t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. k: '+k[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); } }