diff --git a/lib/node_modules/@stdlib/stats/cumin/README.md b/lib/node_modules/@stdlib/stats/cumin/README.md new file mode 100644 index 000000000000..fb304b01585b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/README.md @@ -0,0 +1,225 @@ + + +# cumin + +> Compute the cumulative minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var cumin = require( '@stdlib/stats/cumin' ); +``` + +#### cumin( x\[, options] ) + +Computes the cumulative minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); + +var y = cumin( x ); +// returns + +var arr = ndarray2array( y ); +// returns [ -1.0, -1.0, -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]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation 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]. + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var v = ndarray2array( x ); +// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] + +var y = cumin( x, { + 'dims': [ 0 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ [ -1.0, 2.0 ], [ -3.0, 2.0 ] ] + +y = cumin( x, { + 'dims': [ 1 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ [ -1.0, -1.0 ], [ -3.0, -3.0 ] ] + +y = cumin( x, { + 'dims': [ 0, 1 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ [ -1.0, -1.0 ], [ -3.0, -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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ -1.0, 2.0, -3.0 ], { + 'dtype': 'generic' +}); + +var y = cumin( x, { + 'dtype': 'float64' +}); +// returns + +var dt = getDType( y ); +// returns 'float64' +``` + +#### cumin.assign( x, out\[, options] ) + +Computes the cumulative minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var array = require( '@stdlib/ndarray/array' ); +var zerosLike = require( '@stdlib/ndarray/zeros-like' ); + +var x = array( [ -1.0, 2.0, -3.0 ] ); +var y = zerosLike( x ); + +var out = cumin.assign( x, y ); +// returns + +var v = ndarray2array( out ); +// returns [ -1.0, -1.0, -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]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- Both functions iterate over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of 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 the same [data type][@stdlib/ndarray/dtypes] as the input [ndarray][@stdlib/ndarray/ctor]. 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var cumin = require( '@stdlib/stats/cumin' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, 0, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +var y = cumin( x, { + '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/cumin/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/cumin/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..99ab0f0fee2a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/benchmark/benchmark.assign.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'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 zerosLike = require( '@stdlib/ndarray/zeros-like' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var cumin = 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 out; + var x; + + x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); + + out = zerosLike( x ); + + 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 = cumin.assign( x, out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/cumin/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/cumin/benchmark/benchmark.js new file mode 100644 index 000000000000..e78e06488c9d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var cumin = 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 x = uniform( len, -50.0, 50.0, options ); + x = new ndarray( options.dtype, x, [ 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 = cumin( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/cumin/docs/repl.txt b/lib/node_modules/@stdlib/stats/cumin/docs/repl.txt new file mode 100644 index 000000000000..cb1da818f9f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/docs/repl.txt @@ -0,0 +1,72 @@ + +{{alias}}( x[, options] ) + Computes the cumulative minimum value along one or more ndarray dimensions. + + Parameters + ---------- + x: ndarray + Input array. Must have a real-valued or "generic" data type. + + options: Object (optional) + Function options. + + options.dtype: string (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 operation. If not provided, the + function performs the operation 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 y = {{alias}}( x ); + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ -1.0, -1.0, -3.0, -4.0 ] + + +{{alias}}.assign( x, out[, options] ) + Computes the cumulative 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. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation 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 out = {{alias:@stdlib/ndarray/zeros-like}}( x ); + > var y = {{alias}}.assign( x, out ) + + > var bool = ( out === y ) + true + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ -1.0, -1.0, -3.0, -4.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/cumin/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/cumin/docs/types/index.d.ts new file mode 100644 index 000000000000..cb0559a57fb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/docs/types/index.d.ts @@ -0,0 +1,150 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { RealAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; +} + +/** +* Interface for performing an operation on an ndarray. +*/ +interface Unary { + /** + * Computes the cumulative minimum value along one or more ndarray dimensions. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * + * var y = cumin( x ); + * // returns + * + * var arr = ndarray2array( y ); + * // returns [ -1.0, -1.0, -3.0 ] + */ + ( x: InputArray, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + + /** + * Computes the cumulative minimum value along one or more ndarray dimensions and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var zerosLike = require( '@stdlib/ndarray/zeros-like' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zerosLike( x ); + * + * var out = cumin.assign( x, y ); + * // returns + * + * var bool = ( out === y ); + * // returns true + * + * var arr = ndarray2array( out ); + * // returns [ -1.0, -1.0, -3.0 ] + */ + assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; +} + +/** +* Computes the cumulative minimum value along one or more ndarray dimensions. +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ); +* +* var y = cumin( x ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ -1.0, -1.0, -3.0 ] +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var zerosLike = require( '@stdlib/ndarray/zeros-like' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ); +* var y = zerosLike( x ); +* +* var out = cumin.assign( x, y ); +* // returns +* +* var bool = ( out === y ); +* // returns true +* +* var arr = ndarray2array( out ); +* // returns [ -1.0, -1.0, -3.0 ] +*/ +declare const cumin: Unary; + + +// EXPORTS // + +export = cumin; diff --git a/lib/node_modules/@stdlib/stats/cumin/docs/types/test.ts b/lib/node_modules/@stdlib/stats/cumin/docs/types/test.ts new file mode 100644 index 000000000000..3732feb56fa3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/docs/types/test.ts @@ -0,0 +1,211 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import cumin = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin( x ); // $ExpectType OutputArray + cumin( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + cumin( '5' ); // $ExpectError + cumin( 5 ); // $ExpectError + cumin( true ); // $ExpectError + cumin( false ); // $ExpectError + cumin( null ); // $ExpectError + cumin( void 0 ); // $ExpectError + cumin( {} ); // $ExpectError + cumin( ( x: number ): number => x ); // $ExpectError + + cumin( '5', {} ); // $ExpectError + cumin( 5, {} ); // $ExpectError + cumin( true, {} ); // $ExpectError + cumin( false, {} ); // $ExpectError + cumin( null, {} ); // $ExpectError + cumin( void 0, {} ); // $ExpectError + cumin( {}, {} ); // $ExpectError + cumin( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin( x, '5' ); // $ExpectError + cumin( x, true ); // $ExpectError + cumin( x, false ); // $ExpectError + cumin( x, null ); // $ExpectError + cumin( x, [] ); // $ExpectError + cumin( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin( x, { 'dtype': '5' } ); // $ExpectError + cumin( x, { 'dtype': 5 } ); // $ExpectError + cumin( x, { 'dtype': true } ); // $ExpectError + cumin( x, { 'dtype': false } ); // $ExpectError + cumin( x, { 'dtype': null } ); // $ExpectError + cumin( x, { 'dtype': [] } ); // $ExpectError + cumin( x, { 'dtype': {} } ); // $ExpectError + cumin( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin( x, { 'dims': '5' } ); // $ExpectError + cumin( x, { 'dims': 5 } ); // $ExpectError + cumin( x, { 'dims': true } ); // $ExpectError + cumin( x, { 'dims': false } ); // $ExpectError + cumin( x, { 'dims': null } ); // $ExpectError + cumin( x, { 'dims': {} } ); // $ExpectError + cumin( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin(); // $ExpectError + cumin( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin.assign( x, x ); // $ExpectType float64ndarray + cumin.assign( x, x, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin.assign( '5', x ); // $ExpectError + cumin.assign( 5, x ); // $ExpectError + cumin.assign( true, x ); // $ExpectError + cumin.assign( false, x ); // $ExpectError + cumin.assign( null, x ); // $ExpectError + cumin.assign( void 0, x ); // $ExpectError + cumin.assign( {}, x ); // $ExpectError + cumin.assign( ( x: number ): number => x, x ); // $ExpectError + + cumin.assign( '5', x, {} ); // $ExpectError + cumin.assign( 5, x, {} ); // $ExpectError + cumin.assign( true, x, {} ); // $ExpectError + cumin.assign( false, x, {} ); // $ExpectError + cumin.assign( null, x, {} ); // $ExpectError + cumin.assign( void 0, x, {} ); // $ExpectError + cumin.assign( {}, x, {} ); // $ExpectError + cumin.assign( ( x: number ): number => x, x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin.assign( x, '5' ); // $ExpectError + cumin.assign( x, 5 ); // $ExpectError + cumin.assign( x, true ); // $ExpectError + cumin.assign( x, false ); // $ExpectError + cumin.assign( x, null ); // $ExpectError + cumin.assign( x, void 0 ); // $ExpectError + cumin.assign( x, ( x: number ): number => x ); // $ExpectError + + cumin.assign( x, '5', {} ); // $ExpectError + cumin.assign( x, 5, {} ); // $ExpectError + cumin.assign( x, true, {} ); // $ExpectError + cumin.assign( x, false, {} ); // $ExpectError + cumin.assign( x, null, {} ); // $ExpectError + cumin.assign( x, void 0, {} ); // $ExpectError + cumin.assign( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin.assign( x, x, '5' ); // $ExpectError + cumin.assign( x, x, true ); // $ExpectError + cumin.assign( x, x, false ); // $ExpectError + cumin.assign( x, x, null ); // $ExpectError + cumin.assign( x, x, [] ); // $ExpectError + cumin.assign( x, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin.assign( x, x, { 'dims': '5' } ); // $ExpectError + cumin.assign( x, x, { 'dims': 5 } ); // $ExpectError + cumin.assign( x, x, { 'dims': true } ); // $ExpectError + cumin.assign( x, x, { 'dims': false } ); // $ExpectError + cumin.assign( x, x, { 'dims': null } ); // $ExpectError + cumin.assign( x, x, { 'dims': {} } ); // $ExpectError + cumin.assign( x, x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cumin.assign(); // $ExpectError + cumin.assign( x ); // $ExpectError + cumin.assign( x, x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/cumin/examples/index.js b/lib/node_modules/@stdlib/stats/cumin/examples/index.js new file mode 100644 index 000000000000..de211b0d7216 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/examples/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var cumin = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, 0, 20, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform operation: +var y = cumin( x, { + '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/cumin/lib/index.js b/lib/node_modules/@stdlib/stats/cumin/lib/index.js new file mode 100644 index 000000000000..5d325f20fae1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/lib/index.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the cumulative minimum value along one or more ndarray dimensions. +* +* @module @stdlib/stats/cumin +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var cumin = require( '@stdlib/stats/cumin' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = cumin( x ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ [ [ 1.0, 1.0 ] ], [ [ -3.0, -3.0 ] ], [ [ -5.0, -5.0 ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/stats/cumin/lib/main.js b/lib/node_modules/@stdlib/stats/cumin/lib/main.js new file mode 100644 index 000000000000..4fb1ce4e66aa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/lib/main.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable array-element-newline */ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gcumin = require( '@stdlib/stats/base/ndarray/cumin' ); +var dcumin = require( '@stdlib/stats/base/ndarray/dcumin' ); +var scumin = require( '@stdlib/stats/base/ndarray/scumin' ); +var factory = require( '@stdlib/ndarray/base/unary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'real_and_generic' ); +var odtypes = dtypes( 'real_and_generic' ); +var policies = { + 'output': 'same', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', 'float64', // input, output + 'float32', 'float32' // input, output + ], + 'fcns': [ + dcumin, + scumin + ], + 'default': gcumin +}; + + +// MAIN // + +/** +* Computes the cumulative minimum value along one or more ndarray dimensions. +* +* @name cumin +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction +* @param {string} [options.dtype] - output ndarray data type +* @throws {TypeError} first 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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0, 6.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = cumin( x ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ [ [ 1.0, 1.0 ] ], [ [ -3.0, -3.0 ] ], [ [ -5.0, -5.0 ] ] ] +*/ +var cumin = factory( table, [ idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = cumin; diff --git a/lib/node_modules/@stdlib/stats/cumin/package.json b/lib/node_modules/@stdlib/stats/cumin/package.json new file mode 100644 index 000000000000..26dc125004f3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/stats/cumin", + "version": "0.0.0", + "description": "Compute the cumulative minimum value along one or more ndarray dimensions.", + "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", + "cumulative", + "minimum", + "min", + "range", + "extremes", + "domain", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/cumin/test/test.assign.js b/lib/node_modules/@stdlib/stats/cumin/test/test.assign.js new file mode 100644 index 000000000000..77c016f10824 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/test/test.assign.js @@ -0,0 +1,702 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var empty = require( '@stdlib/ndarray/empty' ); +var emptyLike = require( '@stdlib/ndarray/empty-like' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var cumin = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cumin, '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 out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (options)', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value, out, {} ); + }; + } +}); + +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': 'generic' + }); + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, out, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (default)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 2, 2, 2 ], + [ 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + cumin( x, out ); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (all dimensions)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 2, 2, 2 ], + [ 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + cumin( x, out, { + 'dims': [ 0, 1 ] + }); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (some dimensions)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 2, 2, 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + cumin( x, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out ); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out ); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [ 0, 1 ] + }); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [ 0, 1 ] + }); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 2.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [ 1 ] + }); + expected = [ [ -1.0, -1.0 ], [ -3.0, -3.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ -1.0, -3.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cumin( x, out, { + 'dims': [ 1 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 2.0 ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/cumin/test/test.js b/lib/node_modules/@stdlib/stats/cumin/test/test.js new file mode 100644 index 000000000000..9c94430c422d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/test/test.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isMethod = require( '@stdlib/assert/is-method' ); +var cumin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cumin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( cumin, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/cumin/test/test.main.js b/lib/node_modules/@stdlib/stats/cumin/test/test.main.js new file mode 100644 index 000000000000..b73482045fd5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/cumin/test/test.main.js @@ -0,0 +1,568 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Float64Array = require( '@stdlib/array/float64' ); +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 getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var cumin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cumin, '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 i; + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object having a supported data type (options)', function test( t ) { + var values; + var i; + + values = [ + empty( [ 2, 2 ], { + 'dtype': 'bool' + }) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + 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 an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cumin( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cumin( x ); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cumin( x ); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cumin( x, { + 'dims': [ 0, 1 ] + }); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cumin( x, { + 'dims': [ 0, 1 ] + }); + expected = [ -1.0, -1.0, -3.0, -3.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cumin( x, { + 'dims': [] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the cumulative maximum value over elements in an ndarray (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cumin( x, { + 'dims': [] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cumin( x, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, 2.0 ], [ -3.0, 2.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cumin( x, { + 'dims': [ 1 ] + }); + expected = [ [ -1.0, -1.0 ], [ -3.0, -3.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cumin( x, { + 'dims': [ 0 ] + }); + expected = [ [ -1.0, -3.0 ], [ -1.0, -3.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cumin( x, { + 'dims': [ 1 ] + }); + expected = [ [ -1.0, -3.0 ], [ 2.0, 2.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cumin( x, { + 'dtype': 'float64' + }); + expected = new Float64Array( [ -1.0, -1.0, -3.0, -3.0 ] ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cumin( x, { + 'dtype': 'float64' + }); + expected = new Float64Array( [ -1.0, -1.0, -3.0, -3.0 ] ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( getDType( actual ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameFloat64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +});