diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/README.md new file mode 100644 index 000000000000..20e5ff6c3115 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/README.md @@ -0,0 +1,254 @@ + + +# Skewness + +> [Wald][wald-distribution] distribution [skewness][skewness]. + + + +
+ +The [skewness][skewness] of a [Wald][wald-distribution] random variable with mean `μ` and shape parameter `λ > 0` is + + + +```math +\mathop{\mathrm{skew}}\left( X \right) = 3 \sqrt{\frac{\mu}{\lambda}} +``` + + + + + +
+ + + + + +
+ +## Usage + +```javascript +var skewness = require( '@stdlib/stats/base/dists/wald/skewness' ); +``` + +#### skewness( mu, lambda ) + +Returns the [skewness][skewness] for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = skewness( 2.0, 1.0 ); +// returns ~4.243 + +y = skewness( 1.0, 1.0 ); +// returns 3.0 + +y = skewness( 0.0, 1.0 ); +// returns NaN +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = skewness( NaN, 1.0 ); +// returns NaN + +y = skewness( 0.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`. + +```javascript +var y = skewness( 0.0, 0.0 ); +// returns NaN + +y = skewness( 0.0, -1.0 ); +// returns NaN + +y = skewness( -1.0, 0.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 skewness = require( '@stdlib/stats/base/dists/wald/skewness' ); + +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, Skewness(X;µ,λ): %0.4f', mu, lambda, skewness ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/skewness.h" +``` + +#### stdlib_base_dists_wald_skewness( mu, lambda ) + +Returns the [skewness][skewness] of a [Wald][wald-distribution] distribution with mean `mu` and shape parameter `lambda`. + +```c +double out = stdlib_base_dists_wald_skewness( 2.0, 1.0 ); +// returns ~4.243 +``` + +The function accepts the following arguments: + +- **mu**: `[in] double` mean. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_wald_skewness( const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/skewness.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double lambda; + double mu; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( 0.1, 5.0 ); + lambda = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_wald_skewness( mu, lambda ); + printf( "µ: %.4f, λ: %.4f, Skewness(X;µ,λ): %.4f\n", mu, lambda, y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/benchmark/benchmark.js new file mode 100644 index 000000000000..f8ec00a2e03c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 skewness = 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 = skewness( 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/skewness/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/benchmark/benchmark.native.js new file mode 100644 index 000000000000..afe1e1a0c79b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 skewness = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( skewness 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 = skewness( 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/skewness/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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/skewness/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/benchmark/c/benchmark.c new file mode 100644 index 000000000000..40c36d44b2b7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/benchmark/c/benchmark.c @@ -0,0 +1,140 @@ +/** +* @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/skewness.h" +#include +#include +#include +#include + +#define NAME "wald-skewness" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmark results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * (max - min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double mu[ 100 ]; + double lambda[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + mu[ i ] = random_uniform( 0.1, 10.0 ); + lambda[ i ] = random_uniform( 0.1, 10.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_wald_skewness( 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/skewness/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/binding.gyp new file mode 100644 index 000000000000..f343843f5bd2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 for the add-on: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Set optimization level: + '-O3', + ], + + # C specific flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific 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 flags: + 'cflags': [ + # Generate position-independent code (PIC): + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target + + # Target to copy the add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Specify the target type: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be built before moving to a standard location: + '<(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 + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/repl.txt new file mode 100644 index 000000000000..e2656d44ce7d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/repl.txt @@ -0,0 +1,39 @@ + +{{alias}}( μ, λ ) + Returns the skewness 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 + Skewness. + + Examples + -------- + > var y = {{alias}}( 4.0, 2.0 ) + ~4.243 + > y = {{alias}}( 1.0, 1.0 ) + 3.0 + > y = {{alias}}( 0.0, 1.0 ) + NaN + > y = {{alias}}( 1.0, 0.0 ) + NaN + > y = {{alias}}( NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN ) + NaN + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/types/index.d.ts new file mode 100644 index 000000000000..e5428ab40a1b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 skewness of 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 +* @param lambda - shape parameter +* @returns skewness +* +* @example +* var y = skewness( 5.0, 2.0 ); +* // returns ~4.743 +* +* @example +* var y = skewness( 1.0, 1.0 ); +* // returns 3.0 +* +* @example +* var y = skewness( 0.0, 1.0 ); +* // returns NaN +* +* @example +* var y = skewness( 1.0, 0.0 ); +* // returns NaN +* +* @example +* var y = skewness( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = skewness( 0.0, NaN ); +* // returns NaN +*/ +declare function skewness( mu: number, lambda: number ): number; + + +// EXPORTS // + +export = skewness; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/docs/types/test.ts new file mode 100644 index 000000000000..be5fe1fb0235 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 skewness = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + skewness( 5, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + skewness( true, 3 ); // $ExpectError + skewness( false, 2 ); // $ExpectError + skewness( '5', 1 ); // $ExpectError + skewness( [], 1 ); // $ExpectError + skewness( {}, 2 ); // $ExpectError + skewness( ( x: number ): number => x, 2 ); // $ExpectError + + skewness( 9, true ); // $ExpectError + skewness( 9, false ); // $ExpectError + skewness( 5, '5' ); // $ExpectError + skewness( 8, [] ); // $ExpectError + skewness( 9, {} ); // $ExpectError + skewness( 8, ( x: number ): number => x ); // $ExpectError + + skewness( [], true ); // $ExpectError + skewness( {}, false ); // $ExpectError + skewness( false, '5' ); // $ExpectError + skewness( {}, [] ); // $ExpectError + skewness( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + skewness(); // $ExpectError + skewness( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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/skewness/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/examples/c/example.c new file mode 100644 index 000000000000..ae5b51159712 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/examples/c/example.c @@ -0,0 +1,40 @@ +/** +* @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/skewness.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * (max - min) ); +} + +int main( void ) { + double mu; + double lambda; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( 0.1, 10.0 ); + lambda = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_wald_skewness( mu, lambda ); + printf( "µ: %.4f, λ: %.4f, Mean(X;µ,λ): %.4f\n", mu, lambda, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/examples/index.js new file mode 100644 index 000000000000..8a8b7dc3b360 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 skewness = 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, skewness(X;µ,λ): %0.4f', mu, lambda, skewness ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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", + "moments", + "wald", + "inverse gaussian", + "inverse-gaussian", + "continuous", + "skewness", + "asymmetry", + "shape", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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/skewness/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/src/addon.c new file mode 100644 index 000000000000..e2d8f30f4f19 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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/skewness.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_wald_skewness ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/src/main.c new file mode 100644 index 000000000000..eb3e54bfd098 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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/skewness.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/sqrt.h" + +/** +* Returns the skewness for a Wald distribution with mean `mu` and shape parameter `lambda`. +* +* @param mu mean +* @param lambda shape parameter +* @return skewness +* +* @example +* double y = stdlib_base_dists_wald_skewness( 5.0, 2.0 ); +* // returns ~4.743 +*/ +double stdlib_base_dists_wald_skewness( const double mu, const double lambda ) { + if ( + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( lambda ) || + mu <= 0.0 || + lambda <= 0.0 + ) { + return 0.0/0.0; // NaN + } + return 3.0 * stdlib_base_sqrt( mu / lambda ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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/skewness/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/fixtures/julia/data.json new file mode 100644 index 000000000000..678206236c00 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[1.8001127100408947,6.60345916766498,4.744786320622099,5.1409370744500755,2.817715333096361,4.412849265604714,4.052815453286427,3.3831488686246898,4.766013674173579,4.650154666223604,4.506460033438271,1.686301432693246,5.487795730371866,3.7978508712779075,6.808049274301827,3.7500260645836474,4.143062000676884,3.662750257594592,3.081816834558629,3.2322005812434087,3.6353182994115825,2.6117293733120652,5.389826698994897,3.9449772918156647,3.04558935402639,3.7570789429495974,4.609169088581761,1.8595291477046003,3.7161378361375674,1.5304259711620927,2.0086081777163685,4.421091507082496,1.7503765772320694,2.516770715474001,3.4519407259760406,4.777598169877546,3.0475929645983646,4.767983834892113,4.358445449153358,6.899840048926189,3.3184034251550623,3.5333048944184697,3.9111545479758174,2.2539929683992552,10.69730595403215,3.509951407154185,2.29709150825654,2.7813264645354874,8.17513082299846,3.540036332669115,2.792213394395399,8.834097885653488,4.189527332431366,5.045165252444418,3.7486922670410303,3.696087175913859,5.210784096444956,3.5685135306792146,4.367258240385365,8.849867745798335,2.8590412399782004,3.888472654984648,3.0078523129654706,2.463223588797109,4.47977430476627,6.091153301290284,1.4820483936351927,12.554489239773396,6.833443480925151,5.830612475084531,5.699167569908145,3.5984613647818335,2.134250917414274,2.055386386231741,3.1665596464714723,2.3503683948902583,5.344770167300359,6.377020813462458,5.490135660890077,8.73673538828137,4.194196755858767,2.8236200578555923,3.1388423203090907,1.7968619579734677,4.1221659759236156,4.975059430357519,6.243195083226972,2.7378697670392524,1.1164829292976028,3.6034918244231404,4.202828724990132,3.70112066948111,4.493544010674009,4.1874117001858515,6.872480841248698,5.735349941291528,2.970444533653999,4.265559000361125,6.222330651715551,6.161593836811996],"lambda":[3.25284316463199,0.9027625640980764,4.090612758045264,2.9999638457944053,3.002940469398644,4.227551095591315,2.766601913943147,1.240442554561217,3.5109646371196885,3.1246816208985995,2.0920779013662347,1.611250229353447,2.7818083239924327,3.4795741213379863,2.0048000619288002,5.104905087329686,2.4569859782377397,5.171454864014924,3.4840653942561506,2.701186320297121,2.899820075702395,4.163002341211083,1.344688941660735,2.8599222584342665,4.822788108451253,1.4571924259001607,2.4384891485312448,3.490831889003224,1.479508693378302,5.258660907382155,4.895943527854397,2.6304035645633537,3.0436522944830484,3.0187672437770185,4.340026333952016,1.0745301780432492,4.0176009842703175,1.062093584998381,4.405118466626204,1.320007984846839,4.351178554175254,5.253156803438819,2.843381565258129,3.2315775009905954,0.7186125614814982,4.541536801259744,4.256716082229229,5.431642206656574,0.9427970403663412,4.234180019868364,3.398190153917744,0.7927191733916956,2.480612722801476,0.8443197236251933,4.42269602237103,4.305177611923048,0.6352112239031983,1.8072871101599453,2.4685569986159086,0.9658447986436431,4.245926525507043,1.1611042884298164,4.275148717829811,3.4428253065659336,3.119726671553988,1.3328253267473884,4.459537177191674,0.5930491825572588,0.8255885739057718,2.0705839538808863,0.5204938618524203,3.9178641179065745,4.937562511019078,3.572951536571119,3.3786852028860848,4.840772371591905,1.892174365033723,1.913620360478331,2.0385785901773854,1.1174612487213815,5.214999357187094,3.4812818859855232,3.2379689418801947,2.0302583785620216,3.589029373854044,2.056318187982969,1.002546977179854,2.960937025931656,4.721729463529798,5.0862525557112725,2.8822304689797216,5.430119378590753,3.1812056569039284,3.5300197999828193,1.8783018565896858,1.4292781149696805,3.835385989085406,3.3151866944163206,1.9311696391559425,2.201831654233437],"mu":[1.171170195093368,4.373952127529011,10.23243929824197,8.809638498045118,2.6491005566457755,9.147123483472347,5.0491447394601465,1.5775254129458078,8.861240298265876,7.507546994643975,4.720699872012542,0.5090857031232239,9.308518534193428,5.576470353668192,10.324616720070745,7.97652508035936,4.686008085858069,7.708765670057944,3.6766935638137173,3.135513249351642,4.258076189301067,3.1551534988284073,4.340391723879843,4.945392133578853,4.9704803748450095,2.2854674307326146,5.756037293745734,1.3411964820918416,2.2701713588870938,1.368539420916623,2.194746390253777,5.712666654776843,1.0361330198914949,2.124586528372639,5.746144124325655,2.725180966487402,4.1460851484285195,2.682809434548414,9.297759584168293,6.982518500660425,5.323812624993505,7.286854284064105,4.832841905973791,1.8242198625738644,9.13694750097398,6.216737593201908,2.4956792461631956,4.668663591550009,7.001081341486458,5.895793280347573,2.943759865640489,6.8738692549968015,4.83778444261498,2.387894950341259,6.905643620885003,6.534810160075157,1.9163808033322312,2.5571684487759034,5.231405636002325,8.405013145908928,3.8562999326914067,1.9506835340312696,4.2975578772585425,2.3210267562905424,6.956428171667295,5.494520361179457,1.0883586902191562,10.385951729005875,4.283515845370594,7.821295413134402,1.87843406667436,5.636902829387689,2.4989700495157203,1.6771486902880113,3.7642682644246745,2.9712830737079705,6.005880881543179,8.646671157441011,6.827333242384649,9.477380711654641,10.193171934238798,3.083963273739024,3.5446157938899674,0.7283468232333452,6.77618808347783,5.655152925063713,4.341862179073717,2.4661088034389906,0.6539774372875646,7.338418811591539,5.656783783253794,8.264819204853993,7.137189630714612,6.877426477504747,9.85711796418698,5.223890648721434,3.760187164492798,6.702200071093865,8.307762772487772,9.288118236852245]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..341c69a501cd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/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 JSON + +""" + gen( mu, lambda, name ) + +Generate fixture data for the skewness of a Wald (Inverse Gaussian) +distribution and write to file. + +# Arguments + +- `mu`: mean parameter +- `lambda`: shape parameter +- `name::AbstractString`: output filename + +# Examples + +``` julia +julia> mu = rand( 1000 ) .* 10.0 .+ 0.1; +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] = 3.0 * sqrt( 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 fixture values: +mu = rand( 100 ) .* 10.0 .+ 0.5; +lambda = rand( 100 ) .* 5.0 .+ 0.5; +gen( mu, lambda, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/test.js new file mode 100644 index 000000000000..a6263e8951fa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/test.js @@ -0,0 +1,121 @@ +/** +* @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 skewness = 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 skewness, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = skewness( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = skewness( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = skewness( NaN, 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 = skewness( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NaN, NINF ); + 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 = skewness( 0.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( -1.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the skewness 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 = skewness( mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 20 ), '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/skewness/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/test.native.js new file mode 100644 index 000000000000..0ffe1e7652d5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/skewness/test/test.native.js @@ -0,0 +1,130 @@ +/** +* @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 tryRequire = require( '@stdlib/utils/try-require' ); +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' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var skewness = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( skewness instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof skewness, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y = skewness( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = skewness( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = skewness( NaN, 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 = skewness( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NaN, NINF ); + 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 = skewness( 0.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( -1.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = skewness( NINF, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the skewness 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 = skewness( mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 20 ), 'within tolerance. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +});