diff --git a/lib/node_modules/@stdlib/blas/base/igamax/README.md b/lib/node_modules/@stdlib/blas/base/igamax/README.md new file mode 100644 index 000000000000..3808c9435b4d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/README.md @@ -0,0 +1,165 @@ + + +# igamax + +> Find the index of the first element having the maximum absolute value. + +
+ +## Usage + +```javascript +var igamax = require( '@stdlib/blas/base/igamax' ); +``` + +#### igamax( N, x, strideX ) + +Finds the index of the first element having the maximum absolute value. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +var idx = igamax( x.length, x, 1 ); +// returns 3 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input array. +- **strideX**: index increment for `x`. + +The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to traverse every other value, + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +var idx = igamax( 4, x, 2 ); +// returns 2 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find index of element having the maximum absolute value: +var idx = igamax( 3, x1, 2 ); +// returns 2 +``` + +#### igamax.ndarray( N, x, strideX, offset ) + +Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; + +var idx = igamax.ndarray( x.length, x, 1, 0 ); +// returns 3 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a starting index. For example, to start from the second index, + +```javascript +var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + +var idx = igamax.ndarray( 5, x, 1, 1 ); +// returns 4 +``` + +
+ + + +
+ +## Notes + +- If `N < 1`, both functions return `-1`. +- `igamax()` corresponds to the [BLAS][blas] level 1 function [`idamax`][idamax] with the exception that this implementation works with any array type, not just Float64Arrays. Depending on the environment, the typed versions ([`idamax`][@stdlib/blas/base/idamax], [`isamax`][@stdlib/blas/base/isamax], etc.) are likely to be significantly more performant. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var igamax = require( '@stdlib/blas/base/igamax' ); + +var opts = { + 'dtype': 'generic' +}; +var x = discreteUniform( 10, -100, 100, opts ); +console.log( x ); + +var idx = igamax( x.length, x, 1 ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/igamax/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/igamax/benchmark/benchmark.js new file mode 100644 index 000000000000..60b2d7f55c65 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/benchmark/benchmark.js @@ -0,0 +1,91 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var igamax = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = igamax( x.length, x, 1 ); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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/blas/base/igamax/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/igamax/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..82c0ec813e6e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/benchmark/benchmark.ndarray.js @@ -0,0 +1,91 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var igamax = require( './../lib' ).ndarray; + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = igamax( x.length, x, 1, 0 ); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/igamax/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/igamax/docs/repl.txt new file mode 100644 index 000000000000..a68f491807ea --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/docs/repl.txt @@ -0,0 +1,89 @@ + +{{alias}}( N, x, strideX ) + Finds the index of the first element having the maximum absolute value. + + The `N` and `strideX` parameters determine which elements in `x` are + accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N < 1`, the function returns `-1`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0 ]; + > var idx = {{alias}}( x.length, x, 1 ) + 3 + + // Using `N` and `strideX` parameters: + > x = [ -2.0, 1.0, 3.0, -5.0 ]; + > idx = {{alias}}( 2, x, 2 ) + 1 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > idx = {{alias}}( 3, x1, 1 ) + 2 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Finds the index of the first element having the maximum absolute value using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offsetX` parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + First input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index of `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + // Standard Usage: + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; + > var idx = {{alias}}.ndarray( x.length, x, 1, 0 ) + 3 + + // Using an index offset: + > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; + > idx = {{alias}}.ndarray( 3, x, 2, 1 ) + 2 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/igamax/examples/index.js b/lib/node_modules/@stdlib/blas/base/igamax/examples/index.js new file mode 100644 index 000000000000..37aa655876aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/examples/index.js @@ -0,0 +1,31 @@ +/** +* @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 igamax = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var idx = igamax.ndarray( x.length, x, 1, 0 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/base/igamax/lib/accessors.js b/lib/node_modules/@stdlib/blas/base/igamax/lib/accessors.js new file mode 100644 index 000000000000..196cd382f80d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/lib/accessors.js @@ -0,0 +1,84 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); + + +// MAIN // + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {integer} index value +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* var idx = igamax( 5, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 4 +*/ +function igamax( N, x, strideX, offsetX ) { + var dmax; + var xbuf; + var idx; + var get; + var ix; + var i; + var v; + + // Cache references to array data: + xbuf = x.data; + + // Cache references to element accessors: + get = x.accessors[ 0 ]; + + idx = 0; + if ( N === 1 ) { + return idx; + } + dmax = abs( get( xbuf, offsetX ) ); + ix = offsetX + strideX; + for ( i = 1; i < N; i++ ) { + v = abs( get( xbuf, ix ) ); + if ( v > dmax ) { + idx = i; + dmax = v; + } + ix += strideX; + } + return idx; +} + + +// EXPORTS // + +module.exports = igamax; diff --git a/lib/node_modules/@stdlib/blas/base/igamax/lib/index.js b/lib/node_modules/@stdlib/blas/base/igamax/lib/index.js new file mode 100644 index 000000000000..3d8adc63e07b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* BLAS level 1 routine to find the index of the first element having the maximum absolute value. +* +* @module @stdlib/blas/base/igamax +* +* @example +* var igamax = require( '@stdlib/blas/base/igamax' ) +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* var idx = igamax( 5, x, 1 ); +* // returns 4 +* +* @example +* var igamax = require( '@stdlib/blas/base/igamax' ) +* +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* var idx = igamax( 5, x, 1, 0 ); +* // returns 4 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/base/igamax/lib/main.js b/lib/node_modules/@stdlib/blas/base/igamax/lib/main.js new file mode 100644 index 000000000000..3641bef1e4ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/lib/main.js @@ -0,0 +1,50 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - `x` stride length +* @returns {NumericArray} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* var idx = igamax( 5, x, 1 ); +* // returns 4 +*/ +function igamax( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = igamax; diff --git a/lib/node_modules/@stdlib/blas/base/igamax/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/igamax/lib/ndarray.js new file mode 100644 index 000000000000..e6724f2e0dde --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/lib/ndarray.js @@ -0,0 +1,80 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {integer} index value +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; +* +* var idx = igamax( 5, x, 1, 0 ); +* // returns 4 +*/ +function igamax( N, x, strideX, offsetX ) { + var smax; + var idx; + var ix; + var ox; + var v; + var i; + + if ( N < 1 ) { + return -1; + } + ox = arraylike2object( x ); + if ( ox.accessorProtocol ) { + return accessors( N, ox, strideX, offsetX ); + } + idx = 0; + if ( N === 1 ) { + return idx; + } + smax = abs( x[ offsetX ] ); + ix = offsetX + strideX; + for ( i = 1; i < N; i++ ) { + v = abs( x[ ix ] ); + if ( v > smax ) { + idx = i; + smax = v; + } + ix += strideX; + } + return idx; +} + + +// EXPORTS // + +module.exports = igamax; diff --git a/lib/node_modules/@stdlib/blas/base/igamax/package.json b/lib/node_modules/@stdlib/blas/base/igamax/package.json new file mode 100644 index 000000000000..ecd4ed6a4062 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/base/igamax", + "version": "0.0.0", + "description": "Find the index of the first element having the maximum absolute value.", + "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", + "mathematics", + "math", + "blas", + "level 1", + "amax", + "idamax", + "isamax", + "maximum", + "abs", + "absolute", + "find", + "index", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "integer" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/igamax/test/test.js b/lib/node_modules/@stdlib/blas/base/igamax/test/test.js new file mode 100644 index 000000000000..dbc172f84787 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 igamax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof igamax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof igamax.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/igamax/test/test.main.js b/lib/node_modules/@stdlib/blas/base/igamax/test/test.main.js new file mode 100644 index 000000000000..60811fd898bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/test/test.main.js @@ -0,0 +1,279 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var igamax = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof igamax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( igamax.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function finds the index of the element with the maximum absolute value', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + -0.3, // 2 + 0.5, // 3 + -0.1, // 4 + 6.0, + 6.0, + 6.0 + ]; + expected = 2; + + idx = igamax( 4, x, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + x = [ + 0.2, // 1 + -0.6, // 2 + 0.3, // 3 + 5.0, + 5.0 + ]; + expected = 1; + + idx = igamax( 3, x, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function finds the index of the element with the maximum absolute value (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + -0.3, // 2 + 0.5, // 3 + -0.1, // 4 + 6.0, + 6.0, + 6.0 + ]; + expected = 2; + + idx = igamax( 4, toAccessorArray( x ), 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + x = [ + 0.2, // 1 + -0.6, // 2 + 0.3, // 3 + 5.0, + 5.0 + ]; + expected = 1; + + idx = igamax( 3, toAccessorArray( x ), 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the function returns `-1`', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = -1; + + idx = igamax( 0, x, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the function returns `-1` (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = -1; + + idx = igamax( 0, toAccessorArray( x ), 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = 0; + + idx = igamax( 1, x, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0` (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = 0; + + idx = igamax( 1, toAccessorArray( x ), 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ]; + expected = 2; + + idx = igamax( 4, x, 2 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ]; + expected = 2; + + idx = igamax( 4, toAccessorArray( x ), 2 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var idx; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + + idx = igamax( x.length, x, -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + x = [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ]; + idx = igamax( 6, x, -3 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var idx; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + + idx = igamax( x.length, toAccessorArray( x ), -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + x = [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ]; + idx = igamax( 6, toAccessorArray( x ), -3 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var idx; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + expected = 2; + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + idx = igamax( 3, x1, 2 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/igamax/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/igamax/test/test.ndarray.js new file mode 100644 index 000000000000..939d978c46e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/igamax/test/test.ndarray.js @@ -0,0 +1,323 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var igamax = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof igamax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( igamax.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function finds the index of the element with the maximum absolute value', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + -0.3, // 2 + 0.5, // 3 + -0.1, // 4 + 6.0, + 6.0, + 6.0 + ]; + expected = 2; + + idx = igamax( 4, x, 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + x = [ + 0.2, // 1 + -0.6, // 2 + 0.3, // 3 + 5.0, + 5.0 + ]; + expected = 1; + + idx = igamax( 3, x, 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function finds the index of the element with the maximum absolute value (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + -0.3, // 2 + 0.5, // 3 + -0.1, // 4 + 6.0, + 6.0, + 6.0 + ]; + expected = 2; + + idx = igamax( 4, toAccessorArray( x ), 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + x = [ + 0.2, // 1 + -0.6, // 2 + 0.3, // 3 + 5.0, + 5.0 + ]; + expected = 1; + + idx = igamax( 3, toAccessorArray( x ), 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the function returns `-1`', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = -1; + + idx = igamax( 0, x, 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the function returns `-1` (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = -1; + + idx = igamax( 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0` (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, + 3.0 + ]; + expected = 0; + + idx = igamax( 1, toAccessorArray( x ), 1, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports accessing elements in reverse order', function test( t ) { + var idx; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + + idx = igamax( x.length, x, -1, x.length-1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + idx = igamax( 3, x, -1, x.length-4 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + x = [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ]; + idx = igamax( 6, x, -3, x.length-1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports accessing elements in reverse order (accessors)', function test( t ) { + var idx; + var x; + + x = [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ]; + + idx = igamax( x.length, toAccessorArray( x ), -1, x.length-1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + idx = igamax( 3, toAccessorArray( x ), -1, x.length-4 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + x = [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ]; + idx = igamax( 6, toAccessorArray( x ), -3, x.length-1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ]; + expected = 2; + + idx = igamax( 4, x, 2, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ]; + expected = 2; + + idx = igamax( 4, toAccessorArray( x ), 2, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an `x` offset', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, // 3 + 6.0 // 4 + ]; + expected = 4; + + idx = igamax( 5, x, 1, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying an `x` offset (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, // 3 + 6.0 // 4 + ]; + expected = 4; + + idx = igamax( 5, toAccessorArray( x ), 1, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]; + expected = 2; + + idx = igamax( 3, x, 2, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var expected; + var idx; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]; + expected = 2; + + idx = igamax( 3, toAccessorArray( x ), 2, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + t.end(); +});