From 029a1583c90a644639f03b4ea7a011e4c45fc5f2 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 12 Nov 2025 01:16:33 +0530 Subject: [PATCH 1/5] feat: add stats/base/ndarray/smaxabssorted --- .../base/ndarray/smaxabssorted/README.md | 112 ++++++++++++ .../smaxabssorted/benchmark/benchmark.js | 102 +++++++++++ .../base/ndarray/smaxabssorted/docs/repl.txt | 32 ++++ .../smaxabssorted/docs/types/index.d.ts | 46 +++++ .../ndarray/smaxabssorted/docs/types/test.ts | 57 ++++++ .../ndarray/smaxabssorted/examples/index.js | 33 ++++ .../base/ndarray/smaxabssorted/lib/index.js | 45 +++++ .../base/ndarray/smaxabssorted/lib/main.js | 56 ++++++ .../base/ndarray/smaxabssorted/package.json | 72 ++++++++ .../base/ndarray/smaxabssorted/test/test.js | 173 ++++++++++++++++++ 10 files changed, 728 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md new file mode 100644 index 000000000000..8714ff612b54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md @@ -0,0 +1,112 @@ + + +# smaxabssorted + +> Compute the maximum absolute value of a sorted one-dimensional single-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var smaxabssorted = require( '@stdlib/stats/base/ndarray/smaxabssorted' ); +``` + +#### smaxabssorted( arrays ) + +Computes the maximum absolute value of a sorted one-dimensional single-precision floating-point ndarray. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = smaxabssorted( [ x ] ); +// returns 4.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var smaxabssorted = require( '@stdlib/stats/base/ndarray/smaxabssorted' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = smaxabssorted( [ x ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js new file mode 100644 index 000000000000..ea56c12be675 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var smaxabssorted = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = smaxabssorted( [ x ] ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + 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+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt new file mode 100644 index 000000000000..5337208568cf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( arrays ) + Computes the maximum absolute value of a sorted one-dimensional single-precision + floating-point ndarray. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Maximum absolute value. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > var dt = 'float32'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x ] ) + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts new file mode 100644 index 000000000000..69c0e07b2fc3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the maximum absolute value of a sorted one-dimensional single-precision floating-point ndarray. +* +* @param arrays - array-like object containing an input ndarray +* @returns maximum absolute value +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smaxabssorted( [ x ] ); +* // returns 4.0 +*/ +declare function smaxabssorted( arrays: [ float32ndarray ] ): number; + + +// EXPORTS // + +export = smaxabssorted; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/test.ts new file mode 100644 index 000000000000..7101ed25e8f8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @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 smaxabssorted = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + smaxabssorted( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + smaxabssorted( '10' ); // $ExpectError + smaxabssorted( 10 ); // $ExpectError + smaxabssorted( true ); // $ExpectError + smaxabssorted( false ); // $ExpectError + smaxabssorted( null ); // $ExpectError + smaxabssorted( undefined ); // $ExpectError + smaxabssorted( [] ); // $ExpectError + smaxabssorted( {} ); // $ExpectError + smaxabssorted( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + smaxabssorted(); // $ExpectError + smaxabssorted( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js new file mode 100644 index 000000000000..6c568c4f9138 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var smaxabssorted = require( './../lib' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = smaxabssorted( [ x ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js new file mode 100644 index 000000000000..01b895358208 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js @@ -0,0 +1,45 @@ +/** +* @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 absolute value of a sorted one-dimensional single-precision floating-point ndarray. +* +* @module @stdlib/stats/base/ndarray/smaxabssorted +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var smaxabssorted = require( '@stdlib/stats/base/ndarray/smaxabssorted' ); +* +* var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smaxabssorted( [ x ] ); +* // returns 4.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js new file mode 100644 index 000000000000..886375c2b89c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/stats/strided/smaxabssorted' ).ndarray; + + +// MAIN // + +/** +* Computes the maximum absolute value of a sorted one-dimensional single-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @returns {number} maximum value +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = smaxabssorted( [ x ] ); +* // returns 4.0 +*/ +function smaxabssorted( arrays ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = smaxabssorted; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json new file mode 100644 index 000000000000..0ea03d060b9b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/stats/base/ndarray/smaxabs", + "version": "0.0.0", + "description": "Compute the maximum absolute value of a one-dimensional single-precision floating-point ndarray.", + "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", + "sorted", + "mathematics", + "math", + "maximum", + "max", + "maxabs", + "absolute", + "absolute value", + "abs", + "range", + "extremes", + "domain", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js new file mode 100644 index 000000000000..fe6e82484abe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js @@ -0,0 +1,173 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var smaxabssorted = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof smaxabssorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( smaxabssorted.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the maximum absolute value of a sorted one-dimensional ndarray', function test( t ) { + var x; + var v; + + x = new Float32Array( [ -4.0, -2.0, 0.0, 1.0, 3.0, 5.0 ] ); + v = smaxabssorted( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = new Float32Array( [ -4.0, -5.0 ] ); + v = smaxabssorted( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); + v = smaxabssorted( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + v = smaxabssorted( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + v = smaxabssorted( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty vector, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [] ); + + v = smaxabssorted( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a vector containing a single element, the function returns that element', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0 ] ); + + v = smaxabssorted( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = smaxabssorted( [ vector( x, 4, 2, 0 ) ] ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = smaxabssorted( [ vector( x, 4, -2, 6 ) ] ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = smaxabssorted( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); From ef9de046e543a277ce0f0e477fb6143a67ae2102 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 12 Nov 2025 01:29:16 +0530 Subject: [PATCH 2/5] minor lint errors fixed --- .../@stdlib/stats/base/ndarray/smaxabssorted/README.md | 4 ++-- .../@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt | 4 ++-- .../stats/base/ndarray/smaxabssorted/docs/types/index.d.ts | 4 ++-- .../@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js | 4 ++-- .../@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js | 4 ++-- .../@stdlib/stats/base/ndarray/smaxabssorted/package.json | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md index 8714ff612b54..3c22ab6f3b0a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md @@ -44,11 +44,11 @@ Computes the maximum absolute value of a sorted one-dimensional single-precision var Float32Array = require( '@stdlib/array/float32' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +var xbuf = new Float32Array( [ -4.0, -1.0, 2.0, 3.0 ] ); var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); var v = smaxabssorted( [ x ] ); -// returns 4.0 +// returns 4 ``` The function has the following parameters: diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt index 5337208568cf..2600e39a8055 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Computes the maximum absolute value of a sorted one-dimensional single-precision - floating-point ndarray. + Computes the maximum absolute value of a sorted one-dimensional + single-precision floating-point ndarray. If provided an empty ndarray, the function returns `NaN`. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts index 69c0e07b2fc3..0aeb39276fb7 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts @@ -32,11 +32,11 @@ import { float32ndarray } from '@stdlib/types/ndarray'; * var Float32Array = require( '@stdlib/array/float32' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * -* var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +* var xbuf = new Float32Array( [ -4.0, -1.0, 2.0, 3.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smaxabssorted( [ x ] ); -* // returns 4.0 +* // returns 4 */ declare function smaxabssorted( arrays: [ float32ndarray ] ): number; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js index 01b895358208..1e1846533fcf 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js @@ -28,11 +28,11 @@ * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * var smaxabssorted = require( '@stdlib/stats/base/ndarray/smaxabssorted' ); * -* var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +* var xbuf = new Float32Array( [ -4.0, -1.0, 2.0, 3.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smaxabssorted( [ x ] ); -* // returns 4.0 +* // returns 4 */ // MODULES // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js index 886375c2b89c..f18653c2397b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js @@ -39,11 +39,11 @@ var strided = require( '@stdlib/stats/strided/smaxabssorted' ).ndarray; * var Float32Array = require( '@stdlib/array/float32' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * -* var xbuf = new Float32Array( [ -1.0, 3.0, -4.0, 2.0 ] ); +* var xbuf = new Float32Array( [ -4.0, -1.0, 2.0, 3.0 ] ); * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smaxabssorted( [ x ] ); -* // returns 4.0 +* // returns 4 */ function smaxabssorted( arrays ) { var x = arrays[ 0 ]; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json index 0ea03d060b9b..d02a7c633971 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/stats/base/ndarray/smaxabs", + "name": "@stdlib/stats/base/ndarray/smaxabssorted", "version": "0.0.0", - "description": "Compute the maximum absolute value of a one-dimensional single-precision floating-point ndarray.", + "description": "Compute the maximum absolute value of a sorted one-dimensional single-precision floating-point ndarray.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From dc592037901652ee339698fba8832596684a508d Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 12 Nov 2025 01:33:43 +0530 Subject: [PATCH 3/5] fix: add decimal point back to return values in doctests --- .../@stdlib/stats/base/ndarray/smaxabssorted/README.md | 2 +- .../stats/base/ndarray/smaxabssorted/docs/types/index.d.ts | 2 +- .../@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js | 2 +- .../@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md index 3c22ab6f3b0a..0e9cd81cea69 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md @@ -48,7 +48,7 @@ var xbuf = new Float32Array( [ -4.0, -1.0, 2.0, 3.0 ] ); var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); var v = smaxabssorted( [ x ] ); -// returns 4 +// returns 4.0 ``` The function has the following parameters: diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts index 0aeb39276fb7..93114db11a20 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/docs/types/index.d.ts @@ -36,7 +36,7 @@ import { float32ndarray } from '@stdlib/types/ndarray'; * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smaxabssorted( [ x ] ); -* // returns 4 +* // returns 4.0 */ declare function smaxabssorted( arrays: [ float32ndarray ] ): number; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js index 1e1846533fcf..079bceaabc29 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/index.js @@ -32,7 +32,7 @@ * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smaxabssorted( [ x ] ); -* // returns 4 +* // returns 4.0 */ // MODULES // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js index f18653c2397b..0d02f8b4feda 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/lib/main.js @@ -43,7 +43,7 @@ var strided = require( '@stdlib/stats/strided/smaxabssorted' ).ndarray; * var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = smaxabssorted( [ x ] ); -* // returns 4 +* // returns 4.0 */ function smaxabssorted( arrays ) { var x = arrays[ 0 ]; From 578914b37101997ca1cc87d1916cd357ca5b776e Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Thu, 13 Nov 2025 07:46:44 +0530 Subject: [PATCH 4/5] minor lintspace changes done --- .../@stdlib/stats/base/ndarray/smaxabssorted/README.md | 4 ++-- .../stats/base/ndarray/smaxabssorted/benchmark/benchmark.js | 4 ++-- .../stats/base/ndarray/smaxabssorted/examples/index.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md index 0e9cd81cea69..392944eae694 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/README.md @@ -76,12 +76,12 @@ The function has the following parameters: ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var linspace = require( '@stdlib/array/linspace' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var smaxabssorted = require( '@stdlib/stats/base/ndarray/smaxabssorted' ); -var xbuf = discreteUniform( 10, -50, 50, { +var xbuf = linspace( -50, 50, 10, { 'dtype': 'float32' }); var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js index ea56c12be675..f9b04af2b809 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); +var linspace = require( '@stdlib/array/linspace' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); @@ -49,7 +49,7 @@ function createBenchmark( len ) { var xbuf; var x; - xbuf = uniform( len, -10.0, 10.0, options ); + xbuf = linspace( -len/2, len/2, len, options ); x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); return benchmark; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js index 6c568c4f9138..3ed8b215bf58 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/examples/index.js @@ -18,12 +18,12 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var linspace = require( '@stdlib/array/linspace' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var smaxabssorted = require( './../lib' ); -var xbuf = discreteUniform( 10, -50, 50, { +var xbuf = linspace( -50, 50, 10, { 'dtype': 'float32' }); var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); From e0d87a977519c1a30d3eea3a9a4e62a82e92e1f5 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 13 Nov 2025 00:50:49 -0800 Subject: [PATCH 5/5] test: use single-precision utilities Signed-off-by: Athan --- .../stats/base/ndarray/smaxabssorted/test/test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js index fe6e82484abe..5713d71a01e0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/smaxabssorted/test/test.js @@ -21,8 +21,8 @@ // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var smaxabssorted = require( './../lib' ); @@ -72,15 +72,15 @@ tape( 'the function calculates the maximum absolute value of a sorted one-dimens x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); v = smaxabssorted( [ vector( x, 3, 1, 0 ) ] ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); x = new Float32Array( [ NaN ] ); v = smaxabssorted( [ vector( x, 1, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); x = new Float32Array( [ NaN, NaN ] ); v = smaxabssorted( [ vector( x, 2, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); }); @@ -92,7 +92,7 @@ tape( 'if provided an empty vector, the function returns `NaN`', function test( x = new Float32Array( [] ); v = smaxabssorted( [ vector( x, 0, 1, 0 ) ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); t.end(); });