diff --git a/lib/node_modules/@stdlib/stats/mskmin/README.md b/lib/node_modules/@stdlib/stats/mskmin/README.md new file mode 100644 index 000000000000..d277de023d5d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/README.md @@ -0,0 +1,254 @@ + + +# mskmin + +> Compute the minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions according to a mask. + +
+ +## Usage + +```javascript +var mskmin = require( '@stdlib/stats/mskmin' ); +``` + +#### mskmin( x, mask\[, options] ) + +Computes the minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions according to a mask. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); +var mask = array( [ 0.0, 0.0, 0.0 ] ); + +var y = mskmin( x, mask ); +// returns [ -3.0 ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform a reduction. If not provided, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`. + +By default, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform a reduction over specific dimensions, provide a `dims` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] + +var mask = array( [ 0.0, 0.0, 0.0, 0.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +// returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + +var y = mskmin( x, mask, { + 'dims': [ 0 ] +}); +// returns [ -3.0, 2.0 ] + +y = mskmin( x, mask, { + 'dims': [ 1 ] +}); +// returns [ -1.0, -3.0 ] + +y = mskmin( x, mask, { + 'dims': [ 0, 1 ] +}); +// returns [ -3.0 ] +``` + +By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] + +var mask = array( [ 0.0, 0.0, 0.0, 0.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +// returns [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] + +var y = mskmin( x, mask, { + 'dims': [ 0 ], + 'keepdims': true +}); +// returns [ [ -3.0, 2.0 ] ] + +y = mskmin( x, mask, { + 'dims': [ 1 ], + 'keepdims': true +}); +// returns [ [ -1.0 ], [ -3.0 ] ] + +y = mskmin( x, mask, { + 'dims': [ 0, 1 ], + 'keepdims': true +}); +// returns [ [ -3.0 ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ], { + 'dtype': 'generic' +}); +var mask = array( [ 0.0, 0.0, 0.0 ], { + 'dtype': 'generic' +}); + +var y = mskmin( x, mask, { + 'dtype': 'float64' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'float64' +``` + +#### mskmin.assign( x, mask, out\[, options] ) + +Computes the minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); +var mask = array( [ 0.0, 0.0, 0.0 ] ); +var y = zeros( [] ); + +var out = mskmin.assign( x, mask, y ); +// returns [ -3.0 ] + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform a reduction. If not provided, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor]. +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var mskmin = require( '@stdlib/stats/mskmin' ); + +// Generate an array of random numbers: +var x = uniform( [ 5, 5 ], 0.0, 20.0 ); +var mask = zeros( [ 5, 5 ], { + 'dtype': 'float64' +}); +console.log( ndarray2array( x ) ); + +// Perform a reduction: +var y = mskmin( x, mask, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/mskmin/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/mskmin/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..4219d45a7426 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/benchmark/benchmark.assign.js @@ -0,0 +1,114 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var mskmin = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var out; + var x; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + mask = new ndarray( options.dtype, zeros( len, options.dtype ), [ len ], [ 1 ], 0, 'row-major' ); + out = new ndarray( options.dtype, zeros( 1, options.dtype ), [], [ 0 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = mskmin.assign( x, mask, out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/mskmin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/mskmin/benchmark/benchmark.js new file mode 100644 index 000000000000..8a175e50b0d8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var format = require( '@stdlib/string/format' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var mskmin = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask; + var x; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + mask = new ndarray( options.dtype, zeros( len, options.dtype ), [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = mskmin( x, mask ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get() ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/mskmin/docs/repl.txt b/lib/node_modules/@stdlib/stats/mskmin/docs/repl.txt new file mode 100644 index 000000000000..fe1bc2d79cca --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/docs/repl.txt @@ -0,0 +1,81 @@ + +{{alias}}( x, mask[, options] ) + Computes the minimum value along one or more ndarray dimensions according + to a mask. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + mask: ndarray + Mask array. Must have a real-valued or "generic" data type. + + options: Object (optional) + Function options. + + options.dtype: string|DataType (optional) + Output array data type. Must be a real-valued or "generic" data type. + + options.dims: Array (optional) + List of dimensions over which to perform a reduction. If not provided, + the function performs a reduction over all elements in a provided input + ndarray. + + options.keepdims: boolean (optional) + Boolean indicating whether the reduced dimensions should be included in + the returned ndarray as singleton dimensions. Default: false. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var m = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 1.0, 0.0 ] ); + > var y = {{alias}}( x, m ) + [ -4.0 ] + + +{{alias}}.assign( x, mask, out[, options] ) + Computes the minimum value along one or more ndarray dimensions and assigns + results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + mask: ndarray + Mask array. Must have a real-valued or "generic" data type. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform a reduction. If not provided, + the function performs a reduction over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var m = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 1.0, 0.0 ] ); + > var out = {{alias:@stdlib/ndarray/zeros}}( [] ); + > var y = {{alias}}.assign( x, m, out ) + [ -4.0 ] + > var bool = ( out === y ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/mskmin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/mskmin/docs/types/index.d.ts new file mode 100644 index 000000000000..4105fa97425b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/docs/types/index.d.ts @@ -0,0 +1,105 @@ +/* +* @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 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { RealAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Mask array. +*/ +type MaskArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform a reduction. + */ + dims?: ArrayLike; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; + + /** + * Boolean indicating whether the reduced dimensions should be included in the returned array as singleton dimensions. Default: `false`. + */ + keepdims?: boolean; +} + +/** +* Interface for performing a binary reduction on ndarrays. +*/ +interface Binary { + /** + * Computes the minimum value along one or more ndarray dimensions according to a mask. + * + * @param x - input ndarray + * @param mask - mask ndarray + * @param options - function options + * @returns output ndarray + */ + ( x: InputArray, mask: MaskArray, options?: Options ): OutputArray; + + /** + * Computes the masked minimum value along one or more ndarray dimensions and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param mask - mask ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + */ + assign = OutputArray>( x: InputArray, mask: MaskArray, out: V, options?: BaseOptions ): V; +} + +/** +* Computes the minimum value along one or more ndarray dimensions according to a mask. +* +* @param x - input ndarray +* @param mask - mask ndarray +* @param options - function options +* @returns output ndarray +*/ +declare const mskmin: Binary; + + +// EXPORTS // + +export = mskmin; diff --git a/lib/node_modules/@stdlib/stats/mskmin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/mskmin/docs/types/test.ts new file mode 100644 index 000000000000..fe82b10fda61 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/docs/types/test.ts @@ -0,0 +1,100 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import mskmin = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const m = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + mskmin( x, m ); // $ExpectType OutputArray + mskmin( x, m, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const m = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + mskmin(); // $ExpectError + mskmin( x ); // $ExpectError + mskmin( x, m, {}, {} ); // $ExpectError + mskmin( '5', m ); // $ExpectError + mskmin( x, '5' ); // $ExpectError + mskmin( x, m, '5' ); // $ExpectError + + mskmin( x, m, { 'dtype': 'foo' } ); // $ExpectError + mskmin( x, m, { 'keepdims': 1 } ); // $ExpectError + mskmin( x, m, { 'dims': '5' } ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const m = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'float64' + }); + + mskmin.assign( x, m, out ); // $ExpectType float64ndarray + mskmin.assign( x, m, out, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided invalid arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const m = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = zeros( [], { + 'dtype': 'float64' + }); + + mskmin.assign(); // $ExpectError + mskmin.assign( x ); // $ExpectError + mskmin.assign( x, m ); // $ExpectError + mskmin.assign( x, m, out, {}, {} ); // $ExpectError + mskmin.assign( '5', m, out ); // $ExpectError + mskmin.assign( x, '5', out ); // $ExpectError + mskmin.assign( x, m, '5' ); // $ExpectError + mskmin.assign( x, m, out, '5' ); // $ExpectError + mskmin.assign( x, m, out, { 'dims': '5' } ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/mskmin/examples/index.js b/lib/node_modules/@stdlib/stats/mskmin/examples/index.js new file mode 100644 index 000000000000..1f3ac3f2e654 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/examples/index.js @@ -0,0 +1,46 @@ +/** +* @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/uniform' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var mskmin = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = uniform( [ 5, 5 ], 0.0, 20.0 ); +console.log( ndarray2array( x ) ); + +// Create a mask ndarray: +var m = zeros( [ 5, 5 ], { + 'dtype': 'float64' +}); + +// Perform a reduction: +var y = mskmin( x, m, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/stats/mskmin/lib/index.js b/lib/node_modules/@stdlib/stats/mskmin/lib/index.js new file mode 100644 index 000000000000..413d4131f1db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/lib/index.js @@ -0,0 +1,62 @@ +/** +* @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'; + +/** +* Compute the minimum value along one or more ndarray dimensions according to a mask. +* +* @module @stdlib/stats/mskmin +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var mskmin = require( '@stdlib/stats/mskmin' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.0 ] ); +* var mbuf = new Float64Array( xbuf.length ); +* +* // Define the shape of the input arrays: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create input ndarrays: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* var m = new ndarray( 'float64', mbuf, sh, sx, ox, 'row-major' ); +* +* // Perform reduction: +* var out = mskmin( x, m ); +* // returns [ 2.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/stats/mskmin/lib/main.js b/lib/node_modules/@stdlib/stats/mskmin/lib/main.js new file mode 100644 index 000000000000..489f6ec03bba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/lib/main.js @@ -0,0 +1,104 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gmskmin = require( '@stdlib/stats/base/ndarray/mskmin' ); +var dmskmin = require( '@stdlib/stats/base/ndarray/dmskmin' ); +var smskmin = require( '@stdlib/stats/base/ndarray/smskmin' ); +var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'real_and_generic' ); +var odtypes = dtypes( 'real_and_generic' ); +var policies = { + 'output': 'real_and_generic', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', + 'uint8', // x, mask + 'float32', + 'uint8' // x, mask + ], + 'fcns': [ + dmskmin, + smskmin + ], + 'default': gmskmin +}; + + +// MAIN // + +/** +* Computes the minimum value along one or more ndarray dimensions according to a mask. +* +* @name mskmin +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} mask - mask ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction +* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 0.0, 2.0, 3.0, 0.0, 0.0, 6.0, 7.0, 0.0, 0.0, 10.0, 11.0, 0.0 ] ); +* var mbuf = new Float64Array( xbuf.length ); +* +* // Define the shape of the input arrays: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create input ndarrays: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* var m = new ndarray( 'float64', mbuf, sh, sx, ox, 'row-major' ); +* +* // Perform reduction: +* var out = mskmin( x, m ); +* // returns [ 2.0 ] +*/ +var mskmin = factory( table, [ idtypes, idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = mskmin; diff --git a/lib/node_modules/@stdlib/stats/mskmin/package.json b/lib/node_modules/@stdlib/stats/mskmin/package.json new file mode 100644 index 000000000000..6e260a94ec94 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/stats/mskmin", + "version": "0.0.0", + "description": "Compute the minimum value along one or more ndarray dimensions according to a mask.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "minimum", + "masked", + "mask", + "mskmin", + "range", + "extremes", + "domain", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/mskmin/test/test.assign.js b/lib/node_modules/@stdlib/stats/mskmin/test/test.assign.js new file mode 100644 index 000000000000..c968a453f5ea --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/test/test.assign.js @@ -0,0 +1,189 @@ +/** +* @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 Uint8Array = require( '@stdlib/array/uint8' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var mskmin = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var mask; + var out; + var i; + + mask = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = zeros( [], { + 'dtype': 'float64' + }); + values = [ '5', 5, NaN, true, false, null, void 0, [], {}, function noop() {} ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws when provided '+values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskmin( value, mask, out ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = zeros( [], { + 'dtype': 'float64' + }); + values = [ '5', 5, NaN, true, false, null, void 0, [], {}, function noop() {} ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws when provided '+values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskmin( x, value, out ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid output ndarray', function test( t ) { + var values; + var mask; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ '5', 5, NaN, true, false, null, void 0, [], {}, function noop() {} ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws when provided '+values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskmin( x, mask, value ); + }; + } +}); + +tape( 'the function assigns results to an output ndarray', function test( t ) { + var mbuf; + var xbuf; + var out; + var ret; + var m; + var x; + + xbuf = [ 1.0, -2.0, -4.0, 2.0 ]; + mbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + m = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + out = zeros( [], { + 'dtype': 'generic' + }); + + ret = mskmin( x, m, out ); + t.strictEqual( ret, out, 'returns provided output ndarray' ); + t.strictEqual( out.get(), -2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws if inputs have unsupported dtypes', function test( t ) { + var mask; + var out; + var x; + + x = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + out = zeros( [], { + 'dtype': 'float64' + }); + t.throws( badX, TypeError, 'throws for unsupported x dtype' ); + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + mask = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + t.throws( badMask, TypeError, 'throws for unsupported mask dtype' ); + t.end(); + + function badX() { + mskmin( x, mask, out ); + } + function badMask() { + mskmin( x, mask, out ); + } +}); + +tape( 'the function supports uint8 mask ndarrays', function test( t ) { + var mbuf; + var xbuf; + var out; + var ret; + var m; + var x; + + xbuf = [ 1.0, -2.0, -4.0, 2.0 ]; + mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + m = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + out = zeros( [], { + 'dtype': 'float64' + }); + + ret = mskmin( x, m, out ); + t.strictEqual( ret, out, 'returns provided output ndarray' ); + t.strictEqual( out.get(), -2.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/mskmin/test/test.js b/lib/node_modules/@stdlib/stats/mskmin/test/test.js new file mode 100644 index 000000000000..d55cb71cecad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/test/test.js @@ -0,0 +1,39 @@ +/** +* @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 isMethod = require( '@stdlib/assert/is-method' ); +var mskmin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( mskmin, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/mskmin/test/test.main.js b/lib/node_modules/@stdlib/stats/mskmin/test/test.main.js new file mode 100644 index 000000000000..a8f9a58ab92f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/mskmin/test/test.main.js @@ -0,0 +1,198 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var mskmin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var mask; + var i; + + mask = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws when provided '+values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskmin( value, mask ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws when provided '+values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + mskmin( x, value ); + }; + } +}); + +tape( 'the function throws an error if either input has an unsupported data type', function test( t ) { + var mask; + var x; + + x = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + mask = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + t.throws( badX, TypeError, 'throws for unsupported x dtype' ); + + x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + mask = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + t.throws( badMask, TypeError, 'throws for unsupported mask dtype' ); + t.end(); + + function badX() { + mskmin( x, mask ); + } + function badMask() { + mskmin( x, mask ); + } +}); + +tape( 'the function computes minimum values according to a mask', function test( t ) { + var mbuf; + var xbuf; + var out; + var m; + var x; + + xbuf = [ 1.0, -2.0, -4.0, 2.0 ]; + mbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + m = new ndarray( 'generic', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + out = mskmin( x, m ); + t.strictEqual( out.get(), -2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports reducing along specified dimensions', function test( t ) { + var mbuf; + var xbuf; + var out; + var m; + var x; + + xbuf = [ + 1.0, + -2.0, + 5.0, + -6.0 + ]; + mbuf = [ + 0.0, + 1.0, + 0.0, + 0.0 + ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + m = new ndarray( 'generic', mbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = mskmin( x, m, { + 'dims': [ 1 ] + }); + t.strictEqual( isndarrayLike( out ), true, 'returns an ndarray' ); + t.deepEqual( getShape( out ), [ 2 ], 'returns expected shape' ); + t.deepEqual( ndarray2array( out ), [ 1.0, -6.0 ], 'returns expected values' ); + t.end(); +}); + +tape( 'the function supports uint8 mask ndarrays', function test( t ) { + var mbuf; + var xbuf; + var out; + var m; + var x; + + xbuf = [ 1.0, -2.0, -4.0, 2.0 ]; + mbuf = new Uint8Array( [ 0, 0, 1, 0 ] ); + x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + m = new ndarray( 'uint8', mbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + out = mskmin( x, m ); + t.strictEqual( out.get(), -2.0, 'returns expected value' ); + t.end(); +});