From 80d5c16507ed3a96f4fa56e8299f95a81b8c9412 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Wed, 29 Jul 2026 13:11:22 +0530 Subject: [PATCH] feat: add stats/base/dists/wald/stdev --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/base/dists/wald/stdev/README.md | 254 ++++++++++++++++++ .../dists/wald/stdev/benchmark/benchmark.js | 59 ++++ .../wald/stdev/benchmark/benchmark.native.js | 69 +++++ .../dists/wald/stdev/benchmark/c/Makefile | 146 ++++++++++ .../dists/wald/stdev/benchmark/c/benchmark.c | 141 ++++++++++ .../stats/base/dists/wald/stdev/binding.gyp | 170 ++++++++++++ .../stdev/docs/img/equation_wald_stdev.svg | 29 ++ .../stats/base/dists/wald/stdev/docs/repl.txt | 40 +++ .../dists/wald/stdev/docs/types/index.d.ts | 61 +++++ .../base/dists/wald/stdev/docs/types/test.ts | 56 ++++ .../base/dists/wald/stdev/examples/c/Makefile | 146 ++++++++++ .../dists/wald/stdev/examples/c/example.c | 41 +++ .../base/dists/wald/stdev/examples/index.js | 32 +++ .../stats/base/dists/wald/stdev/include.gypi | 53 ++++ .../stdlib/stats/base/dists/wald/stdev.h | 38 +++ .../stats/base/dists/wald/stdev/lib/index.js | 43 +++ .../stats/base/dists/wald/stdev/lib/main.js | 75 ++++++ .../stats/base/dists/wald/stdev/lib/native.js | 63 +++++ .../stats/base/dists/wald/stdev/manifest.json | 81 ++++++ .../stats/base/dists/wald/stdev/package.json | 71 +++++ .../stats/base/dists/wald/stdev/src/Makefile | 70 +++++ .../stats/base/dists/wald/stdev/src/addon.c | 22 ++ .../stats/base/dists/wald/stdev/src/main.c | 44 +++ .../wald/stdev/test/fixtures/julia/REQUIRE | 3 + .../wald/stdev/test/fixtures/julia/data.json | 1 + .../wald/stdev/test/fixtures/julia/runner.jl | 73 +++++ .../stats/base/dists/wald/stdev/test/test.js | 117 ++++++++ .../base/dists/wald/stdev/test/test.native.js | 126 +++++++++ 28 files changed, 2124 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/img/equation_wald_stdev.svg create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/include/stdlib/stats/base/dists/wald/stdev.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/REQUIRE create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/data.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/runner.jl create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/README.md new file mode 100644 index 000000000000..7d65930eeaf9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/README.md @@ -0,0 +1,254 @@ + + +# Standard Deviation + +> [Wald][wald-distribution] distribution [standard deviation][standard-deviation]. + + + +
+ +The [standard deviation][standard-deviation] for a [Wald][wald-distribution] random variable with mean `μ` and shape parameter `λ > 0` is + + + +```math +\sigma = \sqrt{ \frac{\mu^{3}}{\lambda} } +``` + + + + + +
+ + + + + +
+ +## Usage + +```javascript +var stdev = require( '@stdlib/stats/base/dists/wald/stdev' ); +``` + +#### stdev( mu, lambda ) + +Returns the [standard deviation][standard-deviation] for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = stdev( 2.0, 1.0 ); +// returns ~2.828 + +y = stdev( 4.0, 2.0 ); +// returns ~5.657 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = stdev( NaN, 1.0 ); +// returns NaN + +y = stdev( 0.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`. + +```javascript +var y = stdev( 0.0, 1.0 ); +// returns NaN + +y = stdev( 1.0, 0.0 ); +// returns NaN + +y = stdev( -1.0, 1.0 ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var stdev = require( '@stdlib/stats/base/dists/wald/stdev' ); + +var opts = { + 'dtype': 'float64' +}; +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'μ: %0.4f, λ: %0.4f, SD(X;μ,λ): %0.4f', mu, lambda, stdev ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/stdev.h" +``` + +#### stdlib_base_dists_wald_stdev( mu, lambda ) + +Returns the [standard deviation][standard-deviation] for a [Wald][wald-distribution] distribution with mean parameter `mu` and shape parameter `lambda`. + +```c +double out = stdlib_base_dists_wald_stdev( 2.0, 1.0 ); +// returns ~2.828 +``` + +The function accepts the following arguments: + +- **mu**: `[in] double` mean parameter. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_wald_stdev( const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/stdev.h" +#include "stdlib/constants/float64/eps.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double lambda; + double mu; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + y = stdlib_base_dists_wald_stdev( mu, lambda ); + printf( "μ: %lf, λ: %lf, SD(X;μ,λ): %lf\n", mu, lambda, y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.js new file mode 100644 index 000000000000..3c48a9d9fa5a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; +var stdev = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var lambda; + var opts; + var mu; + var y; + var i; + + opts = { + 'dtype': 'float64' + }; + mu = uniform( 100, EPS, 100.0, opts ); + lambda = uniform( 100, EPS, 20.0, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = stdev( mu[ i % mu.length ], lambda[ i % lambda.length ] ); + 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/wald/stdev/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.native.js new file mode 100644 index 000000000000..6b153a904582 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/benchmark.native.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var stdev = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( stdev instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var arrayOpts; + var lambda; + var mu; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + mu = uniform( 100, EPS, 100.0, arrayOpts ); + lambda = uniform( 100, EPS, 20.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = stdev( mu[ i % mu.length ], lambda[ i % lambda.length ] ); + 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/wald/stdev/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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/wald/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/c/benchmark.c new file mode 100644 index 000000000000..84d2489c8223 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/benchmark/c/benchmark.c @@ -0,0 +1,141 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/wald/stdev.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "wald-stdev" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double lambda[ 100 ]; + double mu[ 100 ]; + double elapsed; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + mu[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 100.0 ); + lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_wald_stdev( mu[ i%100 ], lambda[ i%100 ] ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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/wald/stdev/docs/img/equation_wald_stdev.svg b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/img/equation_wald_stdev.svg new file mode 100644 index 000000000000..9b708a179275 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/img/equation_wald_stdev.svg @@ -0,0 +1,29 @@ + +sigma equals StartRoot StartFraction mu cubed Over lamda EndFraction EndRoot + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/repl.txt new file mode 100644 index 000000000000..99e8f2d8b16e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( μ, λ ) + Returns the standard deviation of a Wald distribution with mean `μ` and + shape parameter `λ`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `μ <= 0` or `λ <= 0`, the function returns `NaN`. + + Parameters + ---------- + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + out: number + Standard deviation. + + Examples + -------- + > var y = {{alias}}( 2.0, 1.0 ) + ~2.828 + > y = {{alias}}( 4.0, 2.0 ) + ~5.657 + > y = {{alias}}( NaN, 1.0 ) + NaN + > y = {{alias}}( 1.0, NaN ) + NaN + > y = {{alias}}( 0.0, 1.0 ) + NaN + > y = {{alias}}( 1.0, 0.0 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/index.d.ts new file mode 100644 index 000000000000..9735e8dcfae3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/index.d.ts @@ -0,0 +1,61 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 + +/** +* Returns the standard deviation for a Wald distribution with mean `mu` and shape parameter `lambda`. +* +* ## Notes +* +* - If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`. +* +* @param mu - mean parameter +* @param lambda - shape parameter +* @returns standard deviation +* +* @example +* var y = stdev( 2.0, 1.0 ); +* // returns ~2.828 +* +* @example +* var y = stdev( 4.0, 2.0 ); +* // returns ~5.657 +* +* @example +* var y = stdev( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = stdev( 1.0, NaN ); +* // returns NaN +* +* @example +* var y = stdev( 0.0, 1.0 ); +* // returns NaN +* +* @example +* var y = stdev( 1.0, 0.0 ); +* // returns NaN +*/ +declare function stdev( mu: number, lambda: number ): number; + + +// EXPORTS // + +export = stdev; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/test.ts new file mode 100644 index 000000000000..2819c7179ee4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 stdev = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + stdev( 2, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + stdev( true, 3 ); // $ExpectError + stdev( false, 2 ); // $ExpectError + stdev( '5', 1 ); // $ExpectError + stdev( [], 1 ); // $ExpectError + stdev( {}, 2 ); // $ExpectError + stdev( ( x: number ): number => x, 2 ); // $ExpectError + + stdev( 9, true ); // $ExpectError + stdev( 9, false ); // $ExpectError + stdev( 5, '5' ); // $ExpectError + stdev( 8, [] ); // $ExpectError + stdev( 9, {} ); // $ExpectError + stdev( 8, ( x: number ): number => x ); // $ExpectError + + stdev( [], true ); // $ExpectError + stdev( {}, false ); // $ExpectError + stdev( false, '5' ); // $ExpectError + stdev( {}, [] ); // $ExpectError + stdev( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + stdev(); // $ExpectError + stdev( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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/wald/stdev/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/example.c new file mode 100644 index 000000000000..43981956bb9d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/c/example.c @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/wald/stdev.h" +#include "stdlib/constants/float64/eps.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double lambda; + double mu; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + y = stdlib_base_dists_wald_stdev( mu, lambda ); + printf( "μ: %lf, λ: %lf, SD(X;μ,λ): %lf\n", mu, lambda, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/index.js new file mode 100644 index 000000000000..ad5134474a28 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/examples/index.js @@ -0,0 +1,32 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var stdev = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'μ: %0.4f, λ: %0.4f, SD(X;μ,λ): %0.4f', mu, lambda, stdev ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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", + "distribution", + "dist", + "inverse gaussian", + "wald", + "continuous", + "standard deviation", + "stdev", + "sd", + "spread", + "dispersion", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/addon.c new file mode 100644 index 000000000000..87243f318c61 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/wald/stdev.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_wald_stdev ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/main.c new file mode 100644 index 000000000000..e6ba98a83600 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/src/main.c @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/wald/stdev.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/sqrt.h" + +/** +* Returns the standard deviation for a Wald distribution with mean parameter `mu` and shape parameter `lambda`. +* +* @param mu mean parameter +* @param lambda shape parameter +* @return standard deviation +* +* @example +* double y = stdlib_base_dists_wald_stdev( 2.0, 1.0 ); +* // returns ~2.828 +*/ +double stdlib_base_dists_wald_stdev( const double mu, const double lambda ) { + if ( + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( lambda ) || + lambda <= 0.0 || + mu <= 0.0 + ) { + return 0.0 / 0.0; // NaN + } + return stdlib_base_sqrt( ( mu * mu * mu ) / lambda ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/REQUIRE @@ -0,0 +1,3 @@ +Distributions 0.23.8 +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/data.json new file mode 100644 index 000000000000..abe3a633fe63 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"mu":[1.4936445904895663,1.2088305335491896,4.119022002676502,1.813592167571187,1.1543082708958536,3.9900788660161197,1.9171489072032273,1.9351124130189419,3.709870448336005,3.17773118452169,4.827794285491109,4.868438622914255,3.886410139501095,0.7404745179228485,1.5226819070521742,2.9704542965628207,4.671130991308019,1.4839896217454225,2.9439981556497514,3.7936485134996474,3.2667519100941718,3.339429284213111,3.0876966095529497,3.1838038384448737,3.3853328072000295,3.1676560274790972,2.9841756001114845,5.148431370733306,3.7057916384655982,3.783916446380317,5.087376742856577,4.1587584600783885,3.829262074548751,5.374191812705249,5.02425601426512,1.6613338149618357,5.285840783733875,5.207950939191505,4.4658737275749445,4.345590701093897,4.075161589542404,0.8470769675914198,3.2843206224497408,3.1722339808475226,2.939819297287613,4.597022217465565,3.3568533656653017,4.706311907619238,1.575166491791606,3.9265395626425743,1.8135797751601785,3.7124986522831023,2.804771459894255,1.4588525409344584,1.3829866989981383,1.9431862626224756,1.2332820526789874,3.948544197017327,2.394118433119729,3.156284886179492,4.640569339506328,1.7639840575866401,5.2084718476980925,2.2959772620815784,5.009561350569129,2.593112018192187,4.190089539159089,4.633396109100431,0.5302653422113508,4.882807626388967,4.640625983709469,4.3944291800726205,2.2840992682613432,4.567691670497879,2.491451452486217,3.1095575152430683,0.6927511941175908,1.0750604392960668,2.5150233386084437,3.64656900241971,1.9281058963388205,2.0779364737682045,1.041930126491934,3.9765573835466057,1.1554168125148863,3.1181561779230833,2.8081628407817334,2.835437312722206,4.389527611900121,2.8655733990017325,3.545483558671549,0.9193973541259766,3.6659709941595793,3.447883768938482,3.568205240415409,1.0177670356351882,5.414835086092353,1.987328129587695,0.7486293518450111,1.350498704239726],"lambda":[4.356053981371224,4.208358586672693,3.5443080506753177,4.69727126522921,3.261452601198107,3.036426956439391,4.789083623234182,3.7513565410859884,1.934683632478118,4.587191610969603,2.3766399034298957,1.049079910060391,1.7678021696861834,4.481559416651725,2.7317811163607986,0.47368152290582655,3.6186245921067894,0.44165701712481675,1.6485019562765957,1.5607592264655978,4.885345959244296,0.9006263431161642,1.726657359302044,4.098735770583152,3.1684675893280656,3.382990452134982,0.9987570274621248,3.0845651448704303,2.8650225604884327,5.012645522272214,0.2071664656046778,0.5752090794499963,3.300497003272176,3.772580571146682,4.072612512297928,3.530605494650081,0.7135603250004351,3.527003819961101,1.829690048377961,1.7138485539704562,4.3869077599607404,3.017764192679897,1.7008850641082973,1.5185752300545574,1.03064354499802,3.5628409205470235,4.816923127416521,0.2738514460157603,3.078836544789374,1.0888236038386823,4.571382425399497,0.11326489262282849,0.5547948902472853,0.6588153516873717,1.0582567575853319,4.230951184779405,4.376549408677965,4.262482059327885,4.840093316650018,4.865473847510293,2.5126063473522664,4.703536362992599,0.5148042621091008,1.8284270795062185,2.278270003059879,4.191665439773351,2.861608922155574,0.451294195279479,4.8159010812174525,4.67727774977684,4.517610686505213,4.4463901407085356,2.4232715367339552,0.9170548127964139,2.9083341906312854,4.550363869545981,2.6503908656537534,3.7069190758280457,3.4211335458327086,1.0453905432019384,3.412369160121307,4.5667652016505595,2.8582588500808925,0.18998852339573205,0.9424380025826394,4.768434256454929,1.0017576754558832,1.3334752723108978,4.849143837252631,4.638865782087668,0.7525500537827611,1.11010435144417,3.6087439382914455,2.1384371699765325,4.231593210622668,1.7160389338620008,4.411468556988984,3.8936968018766493,3.0863700177520514,3.351351531362161],"expected":[0.874629817419301,0.6478758068686506,4.44043418212841,1.1269032377287658,0.6867160147513817,4.573943552135372,1.2129909462638655,1.3898410243597248,5.137278819817117,2.6448575924462476,6.880839728786123,10.487700185530985,5.762435993590637,0.3009889813395892,1.1368177127880308,7.438598014970425,5.307149286836295,2.720218112944569,3.934246498398447,5.91449515300664,2.671324015712072,6.430371351610718,4.129037711095623,2.806044099138877,3.499269733965815,3.065184620247668,5.158300498998482,6.651436027555661,4.214610769087204,3.287598776796373,25.210480430457167,11.182339661376536,4.1246107021878515,6.414317935032747,5.580474088945091,1.1396218329034054,14.386520500840186,6.328450121917625,6.977034908130973,6.919695872684489,3.927697206404412,0.4487884374903815,4.563844484340184,4.584897843846856,4.965085261609058,5.221757367963094,2.802294009486689,19.510281713154406,1.126669091941684,7.456520272128767,1.1423027406030657,21.25454430594155,6.306377921908338,2.1708771077283893,1.5809985794203771,1.3168995219867141,0.6546779281528711,3.8003554927103473,1.6838041602388696,2.5421532177827317,6.306591093913021,1.0802635704956733,16.56702069470329,2.5728386534418015,7.428428600958853,2.039569979897426,5.070255149722976,14.84633550389068,0.17595478644540874,4.988934948985121,4.703384136588385,4.368676853084332,2.217539790773492,10.194067931797619,2.305985059468975,2.570542732237109,0.35416933950047186,0.5789522798562089,2.1563935074357596,6.810631306280054,1.4493334644251705,1.4016644475642737,0.6290817912686668,18.192701640250863,1.27932718632482,2.5214995556953155,4.701669451268889,4.13463895307511,4.176323621838797,2.2522230658267035,7.695653729072092,0.8367061706109952,3.6949239405436094,4.378049606412195,3.276595151149492,0.7838067553096135,5.999102156147267,1.4197873568201314,0.36870266806690655,0.857296924128921]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..65be11e78179 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/fixtures/julia/runner.jl @@ -0,0 +1,73 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2026 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 Distributions: std, InverseGaussian +import JSON + +""" + gen( mu, lambda, name ) + +Generate fixture data and write to file. + +# Arguments + +* `mu`: mean parameter +* `lambda`: shape parameter +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> mu = rand( 1000 ) .* 5.0 .+ 0.5; +julia> lambda = rand( 1000 ) .* 5.0 .+ 0.1; +julia> gen( mu, lambda, "data.json" ); +``` +""" +function gen( mu, lambda, name ) + z = Array{Float64}( undef, length(mu) ); + for i in eachindex(mu) + z[ i ] = std( InverseGaussian( mu[i], lambda[i] ) ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("mu", mu), + ("lambda", lambda), + ("expected", z) + ]); + + # Based on the script directory, create an output filepath: + filepath = joinpath( dir, name ); + + # Write the data to the output filepath as JSON: + outfile = open( filepath, "w" ); + write( outfile, JSON.json(data) ); + write( outfile, "\n" ); + close( outfile ); +end + +# Get the filename: +file = @__FILE__; + +# Extract the directory in which this file resides: +dir = dirname( file ); + +# Generate fixtures: +mu = rand( 100 ) .* 5.0 .+ 0.5; +lambda = rand( 100 ) .* 5.0 .+ 0.1; +gen( mu, lambda, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.js new file mode 100644 index 000000000000..85dafa76bee5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.js @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var stdev = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stdev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = stdev( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = stdev( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = stdev( NaN, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function returns `NaN`', function test( t ) { + var y; + + y = stdev( 0.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( -1.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `lambda`, the function returns `NaN`', function test( t ) { + var y; + + y = stdev( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the standard deviation of a Wald distribution', function test( t ) { + var expected; + var lambda; + var mu; + var y; + var i; + + expected = data.expected; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < mu.length; i++ ) { + y = stdev( mu[i], lambda[i] ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'within tolerance. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.native.js new file mode 100644 index 000000000000..6cde70d2c72f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/stdev/test/test.native.js @@ -0,0 +1,126 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var stdev = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( stdev instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stdev, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y = stdev( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = stdev( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = stdev( NaN, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = stdev( 0.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( -1.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `lambda`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = stdev( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = stdev( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the standard deviation of a Wald distribution', opts, function test( t ) { + var expected; + var lambda; + var mu; + var y; + var i; + + expected = data.expected; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < mu.length; i++ ) { + y = stdev( mu[i], lambda[i] ); + t.strictEqual( isAlmostSameValue( y, expected[i], 1 ), true, 'within tolerance. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + t.end(); +});