diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/README.md b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/README.md new file mode 100644 index 000000000000..f3eb1da3664a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/README.md @@ -0,0 +1,239 @@ + + +# Median + +> [Anglit][anglit-distribution] distribution [median][median]. + + + +
+ +The [median][median] for an [anglit][anglit-distribution] random variable with location parameter `μ` and scale parameter `σ > 0` is + + + +```math +\mathop{\mathrm{Median}}\left( X \right) = \mu +``` + + + +
+ + + + + +
+ +## Usage + +```javascript +var median = require( '@stdlib/stats/base/dists/anglit/median' ); +``` + +#### median( mu, sigma ) + +Returns the [median][median] for an [anglit][anglit-distribution] distribution with parameters `mu` (location) and `sigma` (scale). + +```javascript +var y = median( 2.0, 1.0 ); +// returns 2.0 + +y = median( 0.0, 1.0 ); +// returns 0.0 + +y = median( -1.0, 4.0 ); +// returns -1.0 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = median( NaN, 1.0 ); +// returns NaN + +y = median( 0.0, NaN ); +// returns NaN +``` + +If provided `sigma <= 0`, the function returns `NaN`. + +```javascript +var y = median( 0.0, 0.0 ); +// returns NaN + +y = median( 0.0, -1.0 ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var median = require( '@stdlib/stats/base/dists/anglit/median' ); + +var opts = { + 'dtype': 'float64' +}; +var mu = uniform( 10, -5.0, 5.0, opts ); +var sigma = uniform( 10, 0.1, 20.0, opts ); + +logEachMap( 'µ: %lf, σ: %lf, Median(X;µ,σ): %lf', mu, sigma, median ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/anglit/median.h" +``` + +#### stdlib_base_dists_anglit_median( mu, sigma ) + +Returns the median of an anglit distribution. + +```c +double out = stdlib_base_dists_anglit_median( 0.0, 1.0 ); +// returns 0.0 +``` + +The function accepts the following arguments: + +- **mu**: `[in] double` location parameter. +- **sigma**: `[in] double` scale parameter. + +```c +double stdlib_base_dists_anglit_median( const double mu, const double sigma ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/anglit/median.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 sigma; + double mu; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( -5.0, 5.0 ); + sigma = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_anglit_median( mu, sigma ); + printf( "µ: %lf, σ: %lf, Median(X;µ,σ): %lf\n", mu, sigma, y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/benchmark/benchmark.js new file mode 100644 index 000000000000..18fa4fd9d0bb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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 median = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var sigma; + var opts; + var mu; + var y; + var i; + + opts = { + 'dtype': 'float64' + }; + mu = uniform( 100, -50.0, 50.0, opts ); + sigma = uniform( 100, EPS, 20.0, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = median( mu[ i % mu.length ], sigma[ i % sigma.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/anglit/median/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/benchmark/benchmark.native.js new file mode 100644 index 000000000000..f7d082463f19 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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 EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var median = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( median instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var sigma; + var opts; + var mu; + var y; + var i; + + opts = { + 'dtype': 'float64' + }; + mu = uniform( 100, -50.0, 50.0, opts ); + sigma = uniform( 100, EPS, 20.0, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = median( mu[ i % mu.length ], sigma[ i % sigma.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/anglit/median/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/benchmark/c/benchmark.c new file mode 100644 index 000000000000..a4a2ea1c5388 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "anglit-median" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double sigma[ 100 ]; + double mu[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + mu[ i ] = random_uniform( -50.0, 50.0 ); + sigma[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_anglit_median( mu[ i%100 ], sigma[ 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/anglit/median/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/repl.txt new file mode 100644 index 000000000000..e4ffa3d60d48 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}( μ, σ ) + Returns the median of an anglit distribution with location parameter `μ` + and scale parameter `σ`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `σ <= 0`, the function returns `NaN`. + + Parameters + ---------- + μ: number + Location parameter. + + σ: number + Scale parameter. + + Returns + ------- + out: number + Median. + + Examples + -------- + > var y = {{alias}}( 0.0, 1.0 ) + 0.0 + > y = {{alias}}( 4.0, 2.0 ) + 4.0 + > y = {{alias}}( NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN ) + NaN + > y = {{alias}}( 0.0, 0.0 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/types/index.d.ts new file mode 100644 index 000000000000..b84227fdb0f4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/types/index.d.ts @@ -0,0 +1,57 @@ +/* +* @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 median for an anglit distribution with location parameter `mu` and scale parameter `sigma`. +* +* ## Notes +* +* - If provided `sigma <= 0`, the function returns `NaN`. +* +* @param mu - location parameter +* @param sigma - scale parameter +* @returns median +* +* @example +* var y = median( 0.0, 1.0 ); +* // returns 0.0 +* +* @example +* var y = median( 5.0, 2.0 ); +* // returns 5.0 +* +* @example +* var y = median( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = median( 0.0, NaN ); +* // returns NaN +* +* @example +* var y = median( 0.0, 0.0 ); +* // returns NaN +*/ +declare function median( mu: number, sigma: number ): number; + + +// EXPORTS // + +export = median; diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/docs/types/test.ts new file mode 100644 index 000000000000..fb2749cfd950 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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 median = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + median( 0, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + median( true, 3 ); // $ExpectError + median( false, 2 ); // $ExpectError + median( '5', 1 ); // $ExpectError + median( [], 1 ); // $ExpectError + median( {}, 2 ); // $ExpectError + median( ( x: number ): number => x, 2 ); // $ExpectError + + median( 9, true ); // $ExpectError + median( 9, false ); // $ExpectError + median( 5, '5' ); // $ExpectError + median( 8, [] ); // $ExpectError + median( 9, {} ); // $ExpectError + median( 8, ( x: number ): number => x ); // $ExpectError + + median( [], true ); // $ExpectError + median( {}, false ); // $ExpectError + median( false, '5' ); // $ExpectError + median( {}, [] ); // $ExpectError + median( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + median(); // $ExpectError + median( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/examples/c/example.c new file mode 100644 index 000000000000..075b02e92d22 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median.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 sigma; + double mu; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( -5.0, 5.0 ); + sigma = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_anglit_median( mu, sigma ); + printf( "µ: %lf, σ: %lf, Median(X;µ,σ): %lf\n", mu, sigma, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/examples/index.js new file mode 100644 index 000000000000..9cb7f310d1e7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/examples/index.js @@ -0,0 +1,31 @@ +/** +* @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 median = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var mu = uniform( 10, -5.0, 5.0, opts ); +var sigma = uniform( 10, 0.1, 20.0, opts ); + +logEachMap( 'µ: %lf, σ: %lf, Median(X;µ,σ): %lf', mu, sigma, median ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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", + "anglit", + "continuous", + "median", + "location", + "center", + "percentile", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/src/addon.c new file mode 100644 index 000000000000..f0c97acca6bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/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/anglit/median.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_anglit_median ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/src/main.c new file mode 100644 index 000000000000..ac35f1d3e5ac --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/src/main.c @@ -0,0 +1,42 @@ +/** +* @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/anglit/median.h" +#include "stdlib/math/base/assert/is_nan.h" + +/** +* Returns the median for an anglit distribution with location parameter `mu` and scale parameter `sigma`. +* +* @param mu location parameter +* @param sigma scale parameter +* @return median +* +* @example +* double y = stdlib_base_dists_anglit_median( 0.0, 1.0 ); +* // returns 0.0 +*/ +double stdlib_base_dists_anglit_median( const double mu, const double sigma ) { + if ( + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( sigma ) || + sigma <= 0.0 + ) { + return 0.0/0.0; // NaN + } + return mu; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/fixtures/python/data.json b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/fixtures/python/data.json new file mode 100644 index 000000000000..1f533eb87a44 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/fixtures/python/data.json @@ -0,0 +1 @@ +{"mu": [0.14565113582979716, 2.4273503966625913, 3.5812200122359528, -1.146378804524212, -1.099635543487485, -3.1399137441672242, -4.742186503791669, -3.16415300831295, -4.3943056188441485, 1.0747391255723837, 3.3833477722499463, 4.277473054373161, 3.0092260884000375, -0.5236739681840863, 3.62790344169629, -4.759331853244023, -3.905579884889241, 3.7320115857040648, -3.1447822621422725, 0.0790846968727692, 4.440372174298018, 1.524684523120488, -0.049331330612220725, -1.9598434633908903, -1.9550782946216128, -3.0367038003273183, -0.0947350845062136, -1.7838588514206655, -3.7779449658915745, -2.9131910922923088, -2.9312946007311105, -1.4383446398179558, 3.5774107110026225, -3.0898599520257344, 2.9234612699824876, -0.11839151744961285, -2.5301300328549168, 1.0784288363138206, 1.7149294564340138, 2.312647916888567, -0.7376904531805737, -1.5449512794701015, -1.315947621267287, -2.8125107715303965, -3.1712497078522905, -1.2110979094394212, 0.9187896393442525, -1.7106780720004133, 2.0300466414945006, 4.931074471947104, -0.9468604364264834, -1.1200405043496686, 2.932046205938395, 4.581954138975137, -1.72194603029179, -4.34120799843501, 3.9725992868979088, 1.323007854707706, 3.0517072197430224, -3.3380941439584455, -0.49698302376063896, -4.352903754436297, -1.1781037986364695, 3.399762643745042, 1.7300257431152044, 1.1217405569747179, -2.4376729550534315, -0.4167846254350156, 4.433388018645717, 2.3581483242150316, -2.7316907669819326, -2.336331131101126, 2.9815191295413443, 3.87917116481529, -1.6978916478438721, 0.760415921773312, -4.331682390228565, 3.58772717121356, -3.134672922648135, 4.681046102791981, 2.248516229650269, -3.792270511254375, 2.8266606725207746, -4.464347651045099, -3.5003867810117004, -3.610335500152706, -4.5668642624632305, -3.3667712981121687, -1.1133595681019393, 0.7286784769128118, -4.47307855426454, -4.344380641650933, -3.2615672855637823, 0.8247808424419194, 1.2813282666754784, -3.0603707887107534, 3.2284535315811933, -2.1064240356341655, 3.065356213801925, -0.9497124957169909], "sigma": [2.389921061510469, 0.1967573999708666, 0.15308239674296675, 4.50177846057304, 1.2273126781756027, 4.305719297167959, 1.3681421095182955, 3.9596758918948263, 4.931891227933964, 1.2599891689952554, 3.6241630212370533, 3.024055752928542, 4.8891860638058775, 1.413232088272965, 0.22997030603431168, 3.2582397742109297, 3.1158129380898387, 2.0440592447929085, 2.6945746021691077, 3.7459219847338927, 2.208273369311919, 3.123635954071634, 1.6711214553705462, 0.42381601291127, 2.3061901080732774, 0.5097022804573775, 2.5505590060556065, 2.8805277297016847, 4.935304110772474, 3.435066328837723, 2.19776451404497, 4.002496048232911, 2.0734819366788417, 4.713709561659016, 4.901204502773536, 0.14226215602889836, 0.6725044030556393, 1.334873696122053, 2.9862730360883063, 0.07304649879287249, 1.6290472176901856, 0.23952559786241778, 1.0751491776072204, 1.2043123018896968, 4.023246572965306, 1.226817571375246, 1.9448140904033278, 0.36402587824777566, 2.078994507554278, 3.656999621465431, 0.5476759093672201, 2.545656226488262, 2.2379488621754633, 4.378710040175211, 3.9634036715382552, 1.5578508923568257, 4.261967973548948, 1.5296259904736975, 0.06373037743129194, 0.6843903852154504, 0.06969837261005195, 4.92762639482531, 4.971239766363992, 4.735033509725898, 3.4786465671033016, 0.5096640676346026, 3.7954956848385546, 2.5802337524716172, 2.498130773638083, 0.10247362051323149, 0.754523035037703, 2.1913640931370852, 1.8703616441834765, 2.212675431550957, 1.8828132760480798, 0.32426324490876846, 0.9663233380827985, 2.580118583215219, 0.6491013733315099, 1.0533335580853498, 3.644712281597567, 0.7453068777267252, 1.1588455890312594, 0.9991600048528815, 1.9374141925911526, 4.491113761223134, 3.5779367407394216, 2.9219718142339746, 4.904321845579688, 3.33197588233468, 4.133636979750258, 4.806242611818218, 3.0753362244443823, 3.2944658440976884, 2.9910695279968396, 0.9803321261415621, 1.0625069328030128, 4.996012965426747, 2.6321058884505666, 0.30187053669974206], "expected": [0.14565113582979716, 2.4273503966625913, 3.5812200122359528, -1.146378804524212, -1.099635543487485, -3.1399137441672242, -4.742186503791669, -3.16415300831295, -4.3943056188441485, 1.0747391255723837, 3.3833477722499463, 4.277473054373161, 3.0092260884000375, -0.5236739681840863, 3.62790344169629, -4.759331853244023, -3.905579884889241, 3.7320115857040648, -3.1447822621422725, 0.0790846968727692, 4.440372174298018, 1.524684523120488, -0.049331330612220725, -1.9598434633908903, -1.9550782946216128, -3.0367038003273183, -0.0947350845062136, -1.7838588514206655, -3.7779449658915745, -2.9131910922923088, -2.9312946007311105, -1.4383446398179558, 3.5774107110026225, -3.0898599520257344, 2.9234612699824876, -0.11839151744961285, -2.5301300328549168, 1.0784288363138206, 1.7149294564340138, 2.312647916888567, -0.7376904531805737, -1.5449512794701015, -1.315947621267287, -2.8125107715303965, -3.1712497078522905, -1.2110979094394212, 0.9187896393442525, -1.7106780720004133, 2.0300466414945006, 4.931074471947104, -0.9468604364264834, -1.1200405043496686, 2.932046205938395, 4.581954138975137, -1.72194603029179, -4.34120799843501, 3.9725992868979088, 1.323007854707706, 3.0517072197430224, -3.3380941439584455, -0.49698302376063896, -4.352903754436297, -1.1781037986364695, 3.399762643745042, 1.7300257431152044, 1.1217405569747179, -2.4376729550534315, -0.4167846254350156, 4.433388018645717, 2.3581483242150316, -2.7316907669819326, -2.336331131101126, 2.9815191295413443, 3.87917116481529, -1.6978916478438721, 0.760415921773312, -4.331682390228565, 3.58772717121356, -3.134672922648135, 4.681046102791981, 2.248516229650269, -3.792270511254375, 2.8266606725207746, -4.464347651045099, -3.5003867810117004, -3.610335500152706, -4.5668642624632305, -3.3667712981121687, -1.1133595681019393, 0.7286784769128118, -4.47307855426454, -4.344380641650933, -3.2615672855637823, 0.8247808424419194, 1.2813282666754784, -3.0603707887107534, 3.2284535315811933, -2.1064240356341655, 3.065356213801925, -0.9497124957169909]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/fixtures/python/runner.py b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/fixtures/python/runner.py new file mode 100644 index 000000000000..59d3072d7c17 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/fixtures/python/runner.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# +# @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. + +"""Generate fixtures.""" + +import os +import json +import numpy as np +from scipy.stats import anglit + +# Get the file path: +FILE = os.path.realpath(__file__) + +# Extract the directory in which this file resides: +DIR = os.path.dirname(FILE) + + +def gen(loc, sigma, name): + """Generate fixture data and write to file. + + # Arguments + + * `loc`: location parameter + * `sigma`: scale parameter + * `name::str`: output filename + + # Examples + + ``` python + python> loc = np.random.rand(1000) * 10.0 - 5.0 + python> sigma = np.random.rand(1000) * 5.0 + 0.01 + python> gen(loc, sigma, "data.json") + ``` + """ + z = np.array(anglit.median(loc=loc, scale=sigma)) + # Canonicalize values to the analytic median (loc) when numerically close. + z = np.where(np.isclose(z, loc), loc, z) + + # Store data to be written to file as a dictionary: + data = { + "mu": loc.tolist(), + "sigma": sigma.tolist(), + "expected": z.tolist() + } + + # Based on the script directory, create an output filepath: + filepath = os.path.join(DIR, name) + + # Write the data to the output filepath as JSON: + with open(filepath, "w", encoding="utf-8") as outfile: + json.dump(data, outfile) + + # Include trailing newline: + with open(filepath, "a", encoding="utf-8") as outfile: + outfile.write("\n") + + +def main(): + """Generate fixture data.""" + loc = np.random.rand(100) * 10.0 - 5.0 + sigma = np.random.rand(100) * 5.0 + 0.01 + gen(loc, sigma, "data.json") + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/test.js new file mode 100644 index 000000000000..3b181784c95f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/test.js @@ -0,0 +1,92 @@ +/** +* @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 PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var median = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/python/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof median, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = median( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = median( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `sigma`, the function returns `NaN`', function test( t ) { + var y; + + y = median( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the median of an anglit distribution', function test( t ) { + var expected; + var sigma; + var mu; + var y; + var i; + + expected = data.expected; + mu = data.mu; + sigma = data.sigma; + for ( i = 0; i < mu.length; i++ ) { + y = median( mu[i], sigma[i] ); + if ( expected[i] !== null ) { + t.strictEqual( y, expected[i], 'returns expected value' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/test.native.js new file mode 100644 index 000000000000..411612179254 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/anglit/median/test/test.native.js @@ -0,0 +1,101 @@ +/** +* @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 PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// FIXTURES // + +var data = require( './fixtures/python/data.json' ); + + +// VARIABLES // + +var median = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( median instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof median, '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 = median( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = median( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `sigma`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = median( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = median( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the median of an anglit distribution', opts, function test( t ) { + var expected; + var sigma; + var mu; + var y; + var i; + + expected = data.expected; + mu = data.mu; + sigma = data.sigma; + for ( i = 0; i < mu.length; i++ ) { + y = median( mu[i], sigma[i] ); + if ( expected[i] !== null ) { + t.strictEqual( y, expected[i], 'returns expected value' ); + } + } + t.end(); +});