From 8a6c4d27626b5cf7c60fd93f0fa9b7f7b86a7bde Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 3 Dec 2025 15:08:34 +0530 Subject: [PATCH 1/5] stats/maxsorted --- .../@stdlib/stats/maxsorted/README.md | 271 +++++++ .../maxsorted/benchmark/benchmark.assign.js | 114 +++ .../stats/maxsorted/benchmark/benchmark.js | 108 +++ .../@stdlib/stats/maxsorted/docs/repl.txt | 76 ++ .../stats/maxsorted/docs/types/index.d.ts | 151 ++++ .../stats/maxsorted/docs/types/test.ts | 225 ++++++ .../@stdlib/stats/maxsorted/examples/index.js | 51 ++ .../@stdlib/stats/maxsorted/lib/index.js | 63 ++ .../@stdlib/stats/maxsorted/lib/main.js | 101 +++ .../@stdlib/stats/maxsorted/package.json | 67 ++ .../stats/maxsorted/test/test.assign.js | 717 +++++++++++++++++ .../@stdlib/stats/maxsorted/test/test.js | 39 + .../@stdlib/stats/maxsorted/test/test.main.js | 753 ++++++++++++++++++ 13 files changed, 2736 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/README.md create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/package.json create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js diff --git a/lib/node_modules/@stdlib/stats/maxsorted/README.md b/lib/node_modules/@stdlib/stats/maxsorted/README.md new file mode 100644 index 000000000000..e1eaf44f7b2d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/README.md @@ -0,0 +1,271 @@ + + +# maxsorted + +> Compute the maximum value along one or more sorted [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var maxsorted = require( '@stdlib/stats/maxsorted' ); +``` + +#### maxsorted( x\[, options] ) + +Computes the maximum value along one or more sorted [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0 ] ); + +var y = maxsorted( x ); +// returns + +var v = y.get(); +// 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]. +- **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 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 = maxsorted( x, { + 'dims': [ 0 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ 3.0, 4.0 ] + +y = maxsorted( x, { + 'dims': [ 1 ] +}); +// returns + +v = ndarray2array( y ); +// returns [ 2.0, 4.0 ] + +y = maxsorted( x, { + 'dims': [ 0, 1 ] +}); +// returns + +v = y.get(); +// returns 4.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 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 = maxsorted( x, { + 'dims': [ 0 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 3.0, 4.0 ] ] + +y = maxsorted( x, { + 'dims': [ 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 2.0 ], [ 4.0 ] ] + +y = maxsorted( x, { + 'dims': [ 0, 1 ], + 'keepdims': true +}); +// returns + +v = ndarray2array( y ); +// returns [ [ 4.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 y = maxsorted( x, { + 'dtype': 'float64' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'float64' +``` + +#### maxsorted.assign( x, out\[, options] ) + +Computes the maximum value along one or more sorted [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 y = zeros( [] ); + +var out = maxsorted.assign( x, y ); +// returns + +var v = out.get(); +// 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]. +- **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 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 maxsorted = require( '@stdlib/stats/maxsorted' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -10, 10, { + 'dtype': 'generic' +}); + +// Sort the array: +xbuf.sort( function compare( a, b ) { + return a - b; +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform a reduction: +var y = maxsorted( 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/maxsorted/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..185110b406bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js @@ -0,0 +1,114 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var maxsorted = 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.sort( function compare( a, b ) { + return a - b; + }); + x = new ndarray( options.dtype, x, [ 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 = maxsorted.assign( x, 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( pkg+':assign:dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js new file mode 100644 index 000000000000..1a13e4d16b5d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @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 maxsorted = 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.sort( function compare( a, b ) { + return a - b; + }); + 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 = maxsorted( x ); + 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( pkg+':dtype='+options.dtype+',len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt b/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt new file mode 100644 index 000000000000..81f112878065 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt @@ -0,0 +1,76 @@ + +{{alias}}( x[, options] ) + Computes the maximum absolute value along one or more sorted 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 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 y = {{alias}}( x ); + > var v = y.get() + 4.0 + + +{{alias}}.assign( x, out[, options] ) + Computes the maximum absolute 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 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 out = {{alias:@stdlib/ndarray/zeros}}( [] ); + > var y = {{alias}}.assign( x, out ) + + > var bool = ( out === y ) + true + > var v = out.get() + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts new file mode 100644 index 000000000000..1c28f0d2f3d4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts @@ -0,0 +1,151 @@ +/* +* @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 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 reduction on an ndarray. +*/ +interface Unary { + /** + * Computes the maximum absolute value along one or more sorted ndarray dimensions. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * + * var y = maxsorted( x ); + * // returns + * + * var v = y.get(); + * // returns 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 maximum absolute value along one or more sorted 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 array = require( '@stdlib/ndarray/array' ); + * var zeros = require( '@stdlib/ndarray/zeros' ); + * + * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var y = zeros( [] ); + * + * var out = maxsorted.assign( x, y ); + * // returns + * + * var v = out.get(); + * // returns 3.0 + * + * var bool = ( out === y ); + * // returns true + */ + assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; +} + +/** +* Computes the maximum absolute value along one or more sorted ndarray dimensions. +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ); +* +* var y = maxsorted( x ); +* // returns +* +* var v = y.get(); +* // returns 3.0 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = array( [ -1.0, 2.0, -3.0 ] ); +* var y = zeros( [] ); +* +* var out = maxsorted.assign( x, y ); +* // returns +* +* var v = out.get(); +* // returns 3.0 +* +* var bool = ( out === y ); +* // returns true +*/ +declare const maxsorted: Unary; + + +// EXPORTS // + +export = maxsorted; diff --git a/lib/node_modules/@stdlib/stats/maxsorted/docs/types/test.ts b/lib/node_modules/@stdlib/stats/maxsorted/docs/types/test.ts new file mode 100644 index 000000000000..bdfc73cc2a06 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/docs/types/test.ts @@ -0,0 +1,225 @@ +/* +* @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 space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import maxsorted = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + maxsorted( x ); // $ExpectType OutputArray + maxsorted( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + maxsorted( '5' ); // $ExpectError + maxsorted( 5 ); // $ExpectError + maxsorted( true ); // $ExpectError + maxsorted( false ); // $ExpectError + maxsorted( null ); // $ExpectError + maxsorted( void 0 ); // $ExpectError + maxsorted( {} ); // $ExpectError + maxsorted( ( x: number ): number => x ); // $ExpectError + + maxsorted( '5', {} ); // $ExpectError + maxsorted( 5, {} ); // $ExpectError + maxsorted( true, {} ); // $ExpectError + maxsorted( false, {} ); // $ExpectError + maxsorted( null, {} ); // $ExpectError + maxsorted( void 0, {} ); // $ExpectError + maxsorted( {}, {} ); // $ExpectError + maxsorted( ( 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' + }); + + maxsorted( x, '5' ); // $ExpectError + maxsorted( x, true ); // $ExpectError + maxsorted( x, false ); // $ExpectError + maxsorted( x, null ); // $ExpectError + maxsorted( x, [] ); // $ExpectError + maxsorted( 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' + }); + + maxsorted( x, { 'dtype': '5' } ); // $ExpectError + maxsorted( x, { 'dtype': 5 } ); // $ExpectError + maxsorted( x, { 'dtype': true } ); // $ExpectError + maxsorted( x, { 'dtype': false } ); // $ExpectError + maxsorted( x, { 'dtype': null } ); // $ExpectError + maxsorted( x, { 'dtype': [] } ); // $ExpectError + maxsorted( x, { 'dtype': {} } ); // $ExpectError + maxsorted( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `keepdims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + maxsorted( x, { 'keepdims': '5' } ); // $ExpectError + maxsorted( x, { 'keepdims': 5 } ); // $ExpectError + maxsorted( x, { 'keepdims': null } ); // $ExpectError + maxsorted( x, { 'keepdims': [] } ); // $ExpectError + maxsorted( x, { 'keepdims': {} } ); // $ExpectError + maxsorted( x, { 'keepdims': ( 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' + }); + + maxsorted( x, { 'dims': '5' } ); // $ExpectError + maxsorted( x, { 'dims': 5 } ); // $ExpectError + maxsorted( x, { 'dims': true } ); // $ExpectError + maxsorted( x, { 'dims': false } ); // $ExpectError + maxsorted( x, { 'dims': null } ); // $ExpectError + maxsorted( x, { 'dims': {} } ); // $ExpectError + maxsorted( 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' + }); + + maxsorted(); // $ExpectError + maxsorted( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + maxsorted.assign( x, x ); // $ExpectType float64ndarray + maxsorted.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' + }); + + maxsorted.assign( '5', x ); // $ExpectError + maxsorted.assign( 5, x ); // $ExpectError + maxsorted.assign( true, x ); // $ExpectError + maxsorted.assign( false, x ); // $ExpectError + maxsorted.assign( null, x ); // $ExpectError + maxsorted.assign( void 0, x ); // $ExpectError + maxsorted.assign( {}, x ); // $ExpectError + maxsorted.assign( ( x: number ): number => x, x ); // $ExpectError + + maxsorted.assign( '5', x, {} ); // $ExpectError + maxsorted.assign( 5, x, {} ); // $ExpectError + maxsorted.assign( true, x, {} ); // $ExpectError + maxsorted.assign( false, x, {} ); // $ExpectError + maxsorted.assign( null, x, {} ); // $ExpectError + maxsorted.assign( void 0, x, {} ); // $ExpectError + maxsorted.assign( {}, x, {} ); // $ExpectError + maxsorted.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' + }); + + maxsorted.assign( x, '5' ); // $ExpectError + maxsorted.assign( x, 5 ); // $ExpectError + maxsorted.assign( x, true ); // $ExpectError + maxsorted.assign( x, false ); // $ExpectError + maxsorted.assign( x, null ); // $ExpectError + maxsorted.assign( x, void 0 ); // $ExpectError + maxsorted.assign( x, ( x: number ): number => x ); // $ExpectError + + maxsorted.assign( x, '5', {} ); // $ExpectError + maxsorted.assign( x, 5, {} ); // $ExpectError + maxsorted.assign( x, true, {} ); // $ExpectError + maxsorted.assign( x, false, {} ); // $ExpectError + maxsorted.assign( x, null, {} ); // $ExpectError + maxsorted.assign( x, void 0, {} ); // $ExpectError + maxsorted.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' + }); + + maxsorted.assign( x, x, '5' ); // $ExpectError + maxsorted.assign( x, x, true ); // $ExpectError + maxsorted.assign( x, x, false ); // $ExpectError + maxsorted.assign( x, x, null ); // $ExpectError + maxsorted.assign( x, x, [] ); // $ExpectError + maxsorted.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' + }); + + maxsorted.assign( x, x, { 'dims': '5' } ); // $ExpectError + maxsorted.assign( x, x, { 'dims': 5 } ); // $ExpectError + maxsorted.assign( x, x, { 'dims': true } ); // $ExpectError + maxsorted.assign( x, x, { 'dims': false } ); // $ExpectError + maxsorted.assign( x, x, { 'dims': null } ); // $ExpectError + maxsorted.assign( x, x, { 'dims': {} } ); // $ExpectError + maxsorted.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' + }); + + maxsorted.assign(); // $ExpectError + maxsorted.assign( x ); // $ExpectError + maxsorted.assign( x, x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js b/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js new file mode 100644 index 000000000000..fdcd76a1c251 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js @@ -0,0 +1,51 @@ +/** +* @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 maxsorted = require( './../lib' ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -10, 10, { + 'dtype': 'generic' +}); + +// Sort the array: +xbuf.sort( function compare( a, b ) { + return a - b; +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Perform a reduction: +var y = maxsorted( 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/maxsorted/lib/index.js b/lib/node_modules/@stdlib/stats/maxsorted/lib/index.js new file mode 100644 index 000000000000..76e66057a66a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/lib/index.js @@ -0,0 +1,63 @@ +/** +* @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 maximum value along one or more sorted ndarray dimensions. +* +* @module @stdlib/stats/maxsorted +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var maxsorted = require( '@stdlib/stats/maxsorted' ); +* +* // Create a data buffer: +* 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 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform reduction: +* var out = maxsorted( x ); +* // returns +* +* var v = out.get(); +* // returns 11.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js b/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js new file mode 100644 index 000000000000..7d738a9cec78 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js @@ -0,0 +1,101 @@ +/** +* @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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gmaxsorted = require( '@stdlib/stats/base/ndarray/maxsorted' ); +var dmaxsorted = require( '@stdlib/stats/base/ndarray/dmaxsorted' ); +var smaxsorted = require( '@stdlib/stats/base/ndarray/smaxsorted' ); +var factory = require( '@stdlib/ndarray/base/unary-reduce-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', // input + 'float32' // input + ], + 'fcns': [ + dmaxsorted, + smaxsorted + ], + 'default': gmaxsorted +}; + + +// MAIN // + +/** +* Computes the maximum value along one or more sorted ndarray dimensions. +* +* @name maxsorted +* @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 {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions +* @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 ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* 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 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 4, 1 ]; +* +* // Define the index offset: +* var ox = 1; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform reduction: +* var out = maxsorted( x ); +* // returns +* +* var v = out.get(); +* // returns 11.0 +*/ +var maxsorted = factory( table, [ idtypes ], odtypes, policies ); + + +// EXPORTS // + +module.exports = maxsorted; diff --git a/lib/node_modules/@stdlib/stats/maxsorted/package.json b/lib/node_modules/@stdlib/stats/maxsorted/package.json new file mode 100644 index 000000000000..34d8f028c062 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/maxsorted", + "version": "0.0.0", + "description": "Compute the maximum absolute value along one or more sorted 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", + "maximum", + "max", + "range", + "extremes", + "domain", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js new file mode 100644 index 000000000000..14f371b6f273 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js @@ -0,0 +1,717 @@ +/** +* @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 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 maxsorted = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof maxsorted, '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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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( [], { + '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() { + maxsorted( 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( [], { + '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() { + maxsorted( 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 ], { + '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() { + maxsorted( 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( [], { + '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() { + maxsorted( 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( [], { + '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() { + maxsorted( 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 ], + [ 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' + }); + maxsorted( 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 ], + [ 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' + }); + maxsorted( 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 = [ + [], + [ 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' + }); + maxsorted( x, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +tape( 'the function performs a reduction on 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, { + 'shape': [] + }); + + actual = maxsorted( x, out ); + expected = 4.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on 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, { + 'shape': [] + }); + + actual = maxsorted( x, out ); + expected = 4.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on 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, { + 'shape': [] + }); + + actual = maxsorted( x, out, { + 'dims': [ 0, 1 ] + }); + expected = 4.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on 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, { + 'shape': [] + }); + + actual = maxsorted( x, out, { + 'dims': [ 0, 1 ] + }); + expected = 4.0; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on 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, { + 'shape': [ 2, 2 ] + }); + + actual = maxsorted( 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 performs a reduction on 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, { + 'shape': [ 2, 2 ] + }); + + actual = maxsorted( 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 reduction 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, { + 'shape': [ 2 ] + }); + + actual = maxsorted( x, out, { + 'dims': [ 0 ] + }); + expected = [ 3.0, 4.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, { + 'shape': [ 2 ] + }); + + actual = maxsorted( x, out, { + 'dims': [ 1 ] + }); + expected = [ 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 reduction 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, { + 'shape': [ 2 ] + }); + + actual = maxsorted( x, out, { + 'dims': [ 0 ] + }); + expected = [ 2.0, 4.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, { + 'shape': [ 2 ] + }); + + actual = maxsorted( x, out, { + 'dims': [ 1 ] + }); + expected = [ 3.0, 4.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/maxsorted/test/test.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.js new file mode 100644 index 000000000000..a4a61004d78e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/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 maxsorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof maxsorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( maxsorted, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js new file mode 100644 index 000000000000..db53d1d5b65b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js @@ -0,0 +1,753 @@ +/** +* @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 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 maxsorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof maxsorted, '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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `keepdims` option which is not a boolean', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + 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() { + maxsorted( x, { + 'keepdims': 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( 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() { + maxsorted( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function performs a reduction on 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 = maxsorted( x ); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on 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 = maxsorted( x ); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a reduction on 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 = maxsorted( x, { + 'dims': [ 0, 1 ] + }); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), 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 = maxsorted( x, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), 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 = maxsorted( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 1 ], '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 performs a reduction on 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 = maxsorted( x, { + 'dims': [ 0, 1 ] + }); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), 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 = maxsorted( x, { + 'dims': [ 0, 1 ], + 'keepdims': false + }); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), 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 = maxsorted( x, { + 'dims': [ 0, 1 ], + 'keepdims': true + }); + expected = [ [ 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 1 ], '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 performs a reduction on 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 = maxsorted( x, { + 'dims': [], + 'keepdims': false + }); + expected = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], '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 = maxsorted( x, { + 'dims': [], + 'keepdims': true + }); + expected = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], '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 performs a reduction on 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 = maxsorted( x, { + 'dims': [], + 'keepdims': false + }); + expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], '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 = maxsorted( x, { + 'dims': [], + 'keepdims': true + }); + expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2 ], '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 reduction 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 = maxsorted( x, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ 3.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], '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 = maxsorted( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ 3.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 2 ], '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 = maxsorted( x, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ 2.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], '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 = maxsorted( x, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ 2.0 ], [ 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], '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 reduction 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 = maxsorted( x, { + 'dims': [ 0 ], + 'keepdims': false + }); + expected = [ 2.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], '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 = maxsorted( x, { + 'dims': [ 0 ], + 'keepdims': true + }); + expected = [ [ 2.0, 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 1, 2 ], '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 = maxsorted( x, { + 'dims': [ 1 ], + 'keepdims': false + }); + expected = [ 3.0, 4.0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2 ], '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 = maxsorted( x, { + 'dims': [ 1 ], + 'keepdims': true + }); + expected = [ [ 3.0 ], [ 4.0 ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 1 ], '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 = maxsorted( x, { + 'dtype': 'float64' + }); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), 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 = maxsorted( x, { + 'dtype': 'float64' + }); + expected = 4.0; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'float64', 'returns expected value' ); + t.deepEqual( getShape( actual ), [], 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( actual.get(), expected, 'returns expected value' ); + + t.end(); +}); From b8b9d032bb193881ebf9d9099e311f3dec750cac Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 3 Dec 2025 16:00:19 +0530 Subject: [PATCH 2/5] fix: minor lintspace changes --- .../@stdlib/stats/maxsorted/README.md | 13 +--- .../maxsorted/benchmark/benchmark.assign.js | 7 +-- .../stats/maxsorted/benchmark/benchmark.js | 7 +-- .../@stdlib/stats/maxsorted/docs/repl.txt | 9 +-- .../stats/maxsorted/docs/types/index.d.ts | 14 ++--- .../@stdlib/stats/maxsorted/examples/index.js | 13 +--- .../@stdlib/stats/maxsorted/lib/main.js | 4 +- .../stats/maxsorted/test/test.assign.js | 62 ++----------------- 8 files changed, 30 insertions(+), 99 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/maxsorted/README.md b/lib/node_modules/@stdlib/stats/maxsorted/README.md index e1eaf44f7b2d..65051e389a68 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/README.md +++ b/lib/node_modules/@stdlib/stats/maxsorted/README.md @@ -209,21 +209,14 @@ The method accepts the following options: ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var linspace = require( '@stdlib/array/linspace' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var maxsorted = require( '@stdlib/stats/maxsorted' ); -// Generate an array of random numbers: -var xbuf = discreteUniform( 25, -10, 10, { - 'dtype': 'generic' -}); - -// Sort the array: -xbuf.sort( function compare( a, b ) { - return a - b; -}); +// Generate a sorted array: +var xbuf = linspace( -10.0, 10.0, 25 ); // Wrap in an ndarray: var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js index 185110b406bc..c9f0e938ea5d 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.assign.js @@ -23,7 +23,7 @@ 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 linspace = require( '@stdlib/array/linspace' ); var zeros = require( '@stdlib/array/zeros' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var pkg = require( './../package.json' ).name; @@ -50,10 +50,7 @@ function createBenchmark( len ) { var out; var x; - x = uniform( len, -50.0, 50.0, options ); - x.sort( function compare( a, b ) { - return a - b; - }); + x = linspace( -50.0, 50.0, len, options ); x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); out = new ndarray( options.dtype, zeros( 1, options.dtype ), [], [ 0 ], 0, 'row-major' ); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js index 1a13e4d16b5d..1b2b107886be 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/benchmark/benchmark.js @@ -23,7 +23,7 @@ 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 linspace = require( '@stdlib/array/linspace' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var pkg = require( './../package.json' ).name; var maxsorted = require( './../lib' ); @@ -46,10 +46,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = uniform( len, -50.0, 50.0, options ); - x.sort( function compare( a, b ) { - return a - b; - }); + var x = linspace( -50.0, 50.0, len, options ); x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' ); return benchmark; diff --git a/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt b/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt index 81f112878065..63dcb7772fef 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/maxsorted/docs/repl.txt @@ -1,6 +1,7 @@ {{alias}}( x[, options] ) - Computes the maximum absolute value along one or more sorted ndarray dimensions. + Computes the maximum value along one or more sorted ndarray + dimensions. Parameters ---------- @@ -29,14 +30,14 @@ Examples -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var y = {{alias}}( x ); > var v = y.get() 4.0 {{alias}}.assign( x, out[, options] ) - Computes the maximum absolute value along one or more ndarray dimensions + Computes the maximum value along one or more sorted ndarray dimensions and assigns results to a provided output ndarray. Parameters @@ -62,7 +63,7 @@ Examples -------- - > var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] ); + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); > var out = {{alias:@stdlib/ndarray/zeros}}( [] ); > var y = {{alias}}.assign( x, out ) diff --git a/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts index 1c28f0d2f3d4..786d4f77cbcc 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/maxsorted/docs/types/index.d.ts @@ -63,7 +63,7 @@ interface Options extends BaseOptions { */ interface Unary { /** - * Computes the maximum absolute value along one or more sorted ndarray dimensions. + * Computes the maximum value along one or more sorted ndarray dimensions. * * @param x - input ndarray * @param options - function options @@ -72,7 +72,7 @@ interface Unary { * @example * var array = require( '@stdlib/ndarray/array' ); * - * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var x = array( [ 1.0, 2.0, 3.0 ] ); * * var y = maxsorted( x ); * // returns @@ -83,7 +83,7 @@ interface Unary { ( 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 maximum absolute value along one or more sorted ndarray dimensions and assigns results to a provided output ndarray. + * Computes the maximum value along one or more sorted ndarray dimensions and assigns results to a provided output ndarray. * * @param x - input ndarray * @param out - output ndarray @@ -94,7 +94,7 @@ interface Unary { * var array = require( '@stdlib/ndarray/array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * - * var x = array( [ -1.0, 2.0, -3.0 ] ); + * var x = array( [ 1.0, 2.0, 3.0 ] ); * var y = zeros( [] ); * * var out = maxsorted.assign( x, y ); @@ -110,7 +110,7 @@ interface Unary { } /** -* Computes the maximum absolute value along one or more sorted ndarray dimensions. +* Computes the maximum value along one or more sorted ndarray dimensions. * * @param x - input ndarray * @param options - function options @@ -119,7 +119,7 @@ interface Unary { * @example * var array = require( '@stdlib/ndarray/array' ); * -* var x = array( [ -1.0, 2.0, -3.0 ] ); +* var x = array( [ 1.0, 2.0, 3.0 ] ); * * var y = maxsorted( x ); * // returns @@ -131,7 +131,7 @@ interface Unary { * var array = require( '@stdlib/ndarray/array' ); * var zeros = require( '@stdlib/ndarray/zeros' ); * -* var x = array( [ -1.0, 2.0, -3.0 ] ); +* var x = array( [ 1.0, 2.0, 3.0 ] ); * var y = zeros( [] ); * * var out = maxsorted.assign( x, y ); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js b/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js index fdcd76a1c251..f624b82ec6a7 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js @@ -18,21 +18,14 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var linspace = require( '@stdlib/array/linspace' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var maxsorted = require( './../lib' ); -// Generate an array of random numbers: -var xbuf = discreteUniform( 25, -10, 10, { - 'dtype': 'generic' -}); - -// Sort the array: -xbuf.sort( function compare( a, b ) { - return a - b; -}); +// Generate a sorted array: +var xbuf = linspace( -10.0, 10.0, 25 ); // Wrap in an ndarray: var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); diff --git a/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js b/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js index 7d738a9cec78..ff96ff100ac6 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var dtypes = require( '@stdlib/ndarray/dtypes' ); -var gmaxsorted = require( '@stdlib/stats/base/ndarray/maxsorted' ); +var maxsorted = require( '@stdlib/stats/base/ndarray/maxsorted' ); var dmaxsorted = require( '@stdlib/stats/base/ndarray/dmaxsorted' ); var smaxsorted = require( '@stdlib/stats/base/ndarray/smaxsorted' ); var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); @@ -44,7 +44,7 @@ var table = { dmaxsorted, smaxsorted ], - 'default': gmaxsorted + 'default': maxsorted }; diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js index 14f371b6f273..849b845330ae 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js @@ -586,56 +586,6 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m t.end(); }); -tape( 'the function performs a reduction on 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, { - 'shape': [ 2, 2 ] - }); - - actual = maxsorted( 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 performs a reduction on 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, { - 'shape': [ 2, 2 ] - }); - - actual = maxsorted( 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 reduction dimensions (row-major)', function test( t ) { var expected; var actual; @@ -643,7 +593,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct var out; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); out = emptyLike( x, { @@ -658,7 +608,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); out = emptyLike( x, { @@ -683,7 +633,7 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu var out; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 3.0, 2.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); out = emptyLike( x, { @@ -693,12 +643,12 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu actual = maxsorted( x, out, { 'dims': [ 0 ] }); - expected = [ 2.0, 4.0 ]; + expected = [ 3.0, 4.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 ]; + xbuf = [ 1.0, 3.0, 2.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); out = emptyLike( x, { @@ -708,7 +658,7 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu actual = maxsorted( x, out, { 'dims': [ 1 ] }); - expected = [ 3.0, 4.0 ]; + expected = [ 2.0, 4.0 ]; t.strictEqual( actual, out, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); From ed0325f038fe8553ed5f1c2b6cbcf9b9ce6c1751 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 3 Dec 2025 16:18:04 +0530 Subject: [PATCH 3/5] fix: linr error --- .../@stdlib/stats/maxsorted/lib/main.js | 4 +- .../@stdlib/stats/maxsorted/test/test.main.js | 40 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js b/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js index ff96ff100ac6..7d738a9cec78 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/lib/main.js @@ -21,7 +21,7 @@ // MODULES // var dtypes = require( '@stdlib/ndarray/dtypes' ); -var maxsorted = require( '@stdlib/stats/base/ndarray/maxsorted' ); +var gmaxsorted = require( '@stdlib/stats/base/ndarray/maxsorted' ); var dmaxsorted = require( '@stdlib/stats/base/ndarray/dmaxsorted' ); var smaxsorted = require( '@stdlib/stats/base/ndarray/smaxsorted' ); var factory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-factory' ); @@ -44,7 +44,7 @@ var table = { dmaxsorted, smaxsorted ], - 'default': maxsorted + 'default': gmaxsorted }; diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js index db53d1d5b65b..97378bd346c7 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js @@ -505,14 +505,14 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 1.0, 1.0, 1.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { 'dims': [], 'keepdims': false }); - expected = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; + expected = [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -520,14 +520,14 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, row-major 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 ]; + xbuf = [ 1.0, 1.0, 1.0, 1.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { 'dims': [], 'keepdims': true }); - expected = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; + expected = [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -544,14 +544,14 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, column-ma var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 1.0, 1.0, 1.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [], 'keepdims': false }); - expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + expected = [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -559,14 +559,14 @@ tape( 'the function performs a reduction on an ndarray (no dimensions, column-ma 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 ]; + xbuf = [ 1.0, 1.0, 1.0, 1.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [], 'keepdims': true }); - expected = [ [ 1.0, 3.0 ], [ 2.0, 4.0 ] ]; + expected = [ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -583,7 +583,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -598,7 +598,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 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 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -613,7 +613,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 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 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -628,7 +628,7 @@ tape( 'the function supports specifying reduction dimensions (row-major)', funct 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 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -652,11 +652,11 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 2.0, 4.0, 2.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { - 'dims': [ 0 ], + 'dims': [ 1 ], 'keepdims': false }); expected = [ 2.0, 4.0 ]; @@ -667,14 +667,14 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 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 ]; + xbuf = [ -1.0, -1.0, 4.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [ 0 ], 'keepdims': true }); - expected = [ [ 2.0, 4.0 ] ]; + expected = [ [ -1.0, 4.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -682,14 +682,14 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 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 ]; + xbuf = [ 4.0, 4.0, 4.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [ 1 ], 'keepdims': false }); - expected = [ 3.0, 4.0 ]; + expected = [ 4.0, 4.0 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -697,14 +697,14 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu 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 ]; + xbuf = [ 4.0, 4.0, 4.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [ 1 ], 'keepdims': true }); - expected = [ [ 3.0 ], [ 4.0 ] ]; + expected = [ [ 4.0 ], [ 4.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); From ff44fb7f325de9be8500979e5eb94bff4444a224 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 3 Dec 2025 18:24:15 +0530 Subject: [PATCH 4/5] fix: example updated --- .../@stdlib/stats/maxsorted/README.md | 12 +++---- .../@stdlib/stats/maxsorted/examples/index.js | 10 ++---- .../stats/maxsorted/test/test.assign.js | 6 ++-- .../@stdlib/stats/maxsorted/test/test.main.js | 34 +++++++++---------- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/maxsorted/README.md b/lib/node_modules/@stdlib/stats/maxsorted/README.md index 65051e389a68..77e1a96a48f4 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/README.md +++ b/lib/node_modules/@stdlib/stats/maxsorted/README.md @@ -209,17 +209,13 @@ The method accepts the following options: ```javascript -var linspace = require( '@stdlib/array/linspace' ); +var linspace = require( '@stdlib/blas/ext/linspace' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); var maxsorted = require( '@stdlib/stats/maxsorted' ); -// Generate a sorted array: -var xbuf = linspace( -10.0, 10.0, 25 ); - -// Wrap in an ndarray: -var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +// Generate a sorted ndarray: +var x = linspace( [ 5, 5 ], -10.0, 10.0 ); console.log( ndarray2array( x ) ); // Perform a reduction: @@ -228,7 +224,7 @@ var y = maxsorted( x, { }); // Resolve the output array data type: -var dt = getDType( y ); +var dt = String( getDType( y ) ); console.log( dt ); // Print the results: diff --git a/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js b/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js index f624b82ec6a7..15c24966dc4b 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/examples/index.js @@ -18,17 +18,13 @@ 'use strict'; -var linspace = require( '@stdlib/array/linspace' ); +var linspace = require( '@stdlib/blas/ext/linspace' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); var maxsorted = require( './../lib' ); -// Generate a sorted array: -var xbuf = linspace( -10.0, 10.0, 25 ); - -// Wrap in an ndarray: -var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +// Generate a sorted ndarray: +var x = linspace( [ 5, 5 ], -10.0, 10.0 ); console.log( ndarray2array( x ) ); // Perform a reduction: diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js index 849b845330ae..8a91b898b3ed 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js @@ -497,7 +497,7 @@ tape( 'the function performs a reduction on an ndarray (default, row-major)', fu var out; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); out = emptyLike( x, { @@ -543,7 +543,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo var out; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); out = emptyLike( x, { @@ -568,7 +568,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m var out; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); out = emptyLike( x, { diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js index 97378bd346c7..a2f2f738ed5a 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.main.js @@ -357,7 +357,7 @@ tape( 'the function performs a reduction on an ndarray (default, row-major)', fu var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x ); @@ -378,7 +378,7 @@ tape( 'the function performs a reduction on an ndarray (default, column-major)', var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x ); @@ -399,7 +399,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -413,7 +413,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -428,7 +428,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, row-majo t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -452,7 +452,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { @@ -466,7 +466,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { @@ -481,7 +481,7 @@ tape( 'the function performs a reduction on an ndarray (all dimensions, column-m t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { @@ -652,7 +652,7 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu var xbuf; var x; - xbuf = [ 2.0, 4.0, 2.0, 4.0 ]; + xbuf = [ 1.0, 3.0, 2.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { @@ -667,14 +667,14 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - xbuf = [ -1.0, -1.0, 4.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [ 0 ], 'keepdims': true }); - expected = [ [ -1.0, 4.0 ] ]; + expected = [ [ 2.0, 4.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -682,14 +682,14 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - xbuf = [ 4.0, 4.0, 4.0, 4.0 ]; + xbuf = [ 1.0, 3.0, 2.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [ 1 ], 'keepdims': false }); - expected = [ 4.0, 4.0 ]; + expected = [ 2.0, 4.0 ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -697,14 +697,14 @@ tape( 'the function supports specifying reduction dimensions (column-major)', fu t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); - xbuf = [ 4.0, 4.0, 4.0, 4.0 ]; + xbuf = [ 1.0, 3.0, 2.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { 'dims': [ 1 ], 'keepdims': true }); - expected = [ [ 4.0 ], [ 4.0 ] ]; + expected = [ [ 2.0 ], [ 4.0 ] ]; t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); @@ -721,7 +721,7 @@ tape( 'the function supports specifying the output array data type', function te var xbuf; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); actual = maxsorted( x, { @@ -735,7 +735,7 @@ tape( 'the function supports specifying the output array data type', function te t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); t.strictEqual( actual.get(), expected, 'returns expected value' ); - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); actual = maxsorted( x, { From ffaf8ad644afa7921098d3a2a5add88ad161b977 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 3 Dec 2025 21:13:30 -0800 Subject: [PATCH 5/5] test: sort test elements Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js index 8a91b898b3ed..b71c8541d3f1 100644 --- a/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js +++ b/lib/node_modules/@stdlib/stats/maxsorted/test/test.assign.js @@ -520,7 +520,7 @@ tape( 'the function performs a reduction on an ndarray (default, column-major)', var out; var x; - xbuf = [ -1.0, 2.0, -3.0, 4.0 ]; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); out = emptyLike( x, {