diff --git a/lib/node_modules/@stdlib/blas/base/izamax/README.md b/lib/node_modules/@stdlib/blas/base/izamax/README.md new file mode 100644 index 000000000000..dac84f4d1f4e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/README.md @@ -0,0 +1,172 @@ + + +# izamax + +> Find the index of the first element having the maximum absolute value. + +
+ +## Usage + +```javascript +var izamax = require( '@stdlib/blas/base/izamax' ); +``` + +#### izamax( N, x, strideX ) + +Finds the index of the first element having the maximum absolute value. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var idx = izamax( x.length, x, 1 ); +// returns 1 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Complex128Array`][@stdlib/array/complex128]. +- **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 Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var idx = izamax( 2, x, 2 ); +// returns 1 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +// Initial array: +var x0 = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create an offset view: +var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find index of element having the maximum absolute value: +var idx = izamax( 2, x1, 1 ); +// returns 1 +``` + +#### izamax.ndarray( N, x, strideX, offset ) + +Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + +```javascript +var Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var idx = izamax.ndarray( x.length, x, 1, 0 ); +// returns 1 +``` + +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 Complex128Array = require( '@stdlib/array/complex128' ); + +var x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ); + +var idx = izamax.ndarray( 3, x, 1, 1 ); +// returns 2 +``` + +
+ + + +
+ +## Notes + +- If `N < 1`, both functions return `-1`. +- `izamax()` corresponds to the [BLAS][blas] level 1 function [`izamax`][izamax]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var izamax = require( '@stdlib/blas/base/izamax' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +// Generate random input arrays: +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var idx = izamax( x.length, x, 1 ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/izamax/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/izamax/benchmark/benchmark.js new file mode 100644 index 000000000000..8ef43e210efd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var izamax = require( './../lib/izamax.js' ); + + +// 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; + + x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = izamax( 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 // + +/** +* 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/blas/base/izamax/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/izamax/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..42ed0a56fc30 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var pkg = require( './../package.json' ).name; +var izamax = require( './../lib/ndarray.js' ); + + +// 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; + + x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = izamax( 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 // + +/** +* 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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/izamax/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/izamax/docs/repl.txt new file mode 100644 index 000000000000..d225d760548b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/docs/repl.txt @@ -0,0 +1,91 @@ + +{{alias}}( N, x, strideX ) + Finds the index of the first element having maximum |Re(.)| + |Im(.)|. + + 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: Complex128Array + Input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + // Standard Usage: + > var x; + > x = new {{alias:@stdlib/array/complex128}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0 ] ); + > var idx = {{alias}}( x.length, x, 1 ) + 1 + + // Using `N` and `strideX` parameters: + > x = new {{alias:@stdlib/array/complex128}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0 ] ); + > idx = {{alias}}( 2, x, 2 ) + 1 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var x1 = new {{alias:@stdlib/array/complex128}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > idx = {{alias}}( 2, x1, 1 ) + 1 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Finds the index of the first element having maximum |Re(.)| + |Im(.)| 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: Complex128Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index of `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + // Standard Usage: + > var x; + > x = new {{alias:@stdlib/array/complex128}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0 ] ); + > var idx = {{alias}}.ndarray( x.length, x, 1, 0 ) + 1 + + // Using an index offset: + > x = new {{alias:@stdlib/array/complex128}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > idx = {{alias}}.ndarray( 2, x, 1, 1 ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/izamax/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/izamax/docs/types/index.d.ts new file mode 100644 index 000000000000..56f84a6239c2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/docs/types/index.d.ts @@ -0,0 +1,96 @@ +/* +* @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 { Complex128Array } from '@stdlib/types/array'; + +/** +* Interface describing `izamax`. +*/ +interface Routine { + /** + * Finds the index of the first element having the maximum absolute value. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @returns index value + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + * + * var idx = izamax( x.length, x, 1 ); + * // returns 1 + */ + ( N: number, x: Complex128Array, strideX: number ): number; + + /** + * Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @returns index value + * + * @example + * var Complex128Array = require( '@stdlib/array/complex128' ); + * + * var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + * + * var idx = izamax.ndarray( x.length, x, 1, 0 ); + * // returns 1 + */ + ndarray( N: number, x: Complex128Array, strideX: number, offsetX: number ): number; +} + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length for `x` +* @returns index value +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var idx = izamax( x.length, x, 1 ); +* // returns 1 +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var idx = izamax.ndarray( x.length, x, 1, 0 ); +* // returns 1 +*/ +declare var izamax: Routine; + + +// EXPORTS // + +export = izamax; diff --git a/lib/node_modules/@stdlib/blas/base/izamax/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/izamax/docs/types/test.ts new file mode 100644 index 000000000000..76d4f66f7a41 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/docs/types/test.ts @@ -0,0 +1,158 @@ +/* +* @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. +*/ + +import Complex128Array = require( '@stdlib/array/complex128' ); +import izamax = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Complex128Array( 10 ); + + izamax( x.length, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + izamax( '10', x, 1 ); // $ExpectError + izamax( true, x, 1 ); // $ExpectError + izamax( false, x, 1 ); // $ExpectError + izamax( null, x, 1 ); // $ExpectError + izamax( undefined, x, 1 ); // $ExpectError + izamax( [], x, 1 ); // $ExpectError + izamax( {}, x, 1 ); // $ExpectError + izamax( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + izamax( x.length, 10, 1 ); // $ExpectError + izamax( x.length, '10', 1 ); // $ExpectError + izamax( x.length, true, 1 ); // $ExpectError + izamax( x.length, false, 1 ); // $ExpectError + izamax( x.length, null, 1 ); // $ExpectError + izamax( x.length, undefined, 1 ); // $ExpectError + izamax( x.length, [], 1 ); // $ExpectError + izamax( x.length, {}, 1 ); // $ExpectError + izamax( x.length, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + izamax( x.length, x, '10' ); // $ExpectError + izamax( x.length, x, true ); // $ExpectError + izamax( x.length, x, false ); // $ExpectError + izamax( x.length, x, null ); // $ExpectError + izamax( x.length, x, undefined ); // $ExpectError + izamax( x.length, x, [] ); // $ExpectError + izamax( x.length, x, {} ); // $ExpectError + izamax( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + + izamax(); // $ExpectError + izamax( x.length ); // $ExpectError + izamax( x.length, x ); // $ExpectError + izamax( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Complex128Array( 10 ); + + izamax.ndarray( x.length, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + izamax.ndarray( '10', x, 1, 0 ); // $ExpectError + izamax.ndarray( true, x, 1, 0 ); // $ExpectError + izamax.ndarray( false, x, 1, 0 ); // $ExpectError + izamax.ndarray( null, x, 1, 0 ); // $ExpectError + izamax.ndarray( undefined, x, 1, 0 ); // $ExpectError + izamax.ndarray( [], x, 1, 0 ); // $ExpectError + izamax.ndarray( {}, x, 1, 0 ); // $ExpectError + izamax.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Complex128Array... +{ + const x = new Complex128Array( 10 ); + + izamax.ndarray( x.length, 10, 1, 0 ); // $ExpectError + izamax.ndarray( x.length, '10', 1, 0 ); // $ExpectError + izamax.ndarray( x.length, true, 1, 0 ); // $ExpectError + izamax.ndarray( x.length, false, 1, 0 ); // $ExpectError + izamax.ndarray( x.length, null, 1, 0 ); // $ExpectError + izamax.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + izamax.ndarray( x.length, [], 1, 0 ); // $ExpectError + izamax.ndarray( x.length, {}, 1, 0 ); // $ExpectError + izamax.ndarray( x.length, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + izamax.ndarray( x.length, x, '10', 0 ); // $ExpectError + izamax.ndarray( x.length, x, true, 0 ); // $ExpectError + izamax.ndarray( x.length, x, false, 0 ); // $ExpectError + izamax.ndarray( x.length, x, null, 0 ); // $ExpectError + izamax.ndarray( x.length, x, undefined, 0 ); // $ExpectError + izamax.ndarray( x.length, x, [], 0 ); // $ExpectError + izamax.ndarray( x.length, x, {}, 0 ); // $ExpectError + izamax.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Complex128Array( 10 ); + + izamax.ndarray( x.length, x, 1, '10' ); // $ExpectError + izamax.ndarray( x.length, x, 1, true ); // $ExpectError + izamax.ndarray( x.length, x, 1, false ); // $ExpectError + izamax.ndarray( x.length, x, 1, null ); // $ExpectError + izamax.ndarray( x.length, x, 1, undefined ); // $ExpectError + izamax.ndarray( x.length, x, 1, [] ); // $ExpectError + izamax.ndarray( x.length, x, 1, {} ); // $ExpectError + izamax.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Complex128Array( 10 ); + + izamax.ndarray(); // $ExpectError + izamax.ndarray( x.length ); // $ExpectError + izamax.ndarray( x.length, x ); // $ExpectError + izamax.ndarray( x.length, x, 1 ); // $ExpectError + izamax.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/izamax/examples/index.js b/lib/node_modules/@stdlib/blas/base/izamax/examples/index.js new file mode 100644 index 000000000000..df409cc6226f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/examples/index.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'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var izamax = require( './../lib' ); + +function rand() { + return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); +} + +// Generate random input arrays: +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); + +var idx = izamax( x.length, x, 1 ); +console.log( idx ); + +idx = izamax.ndarray( x.length, x, 1, 0 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/base/izamax/lib/index.js b/lib/node_modules/@stdlib/blas/base/izamax/lib/index.js new file mode 100644 index 000000000000..1b60757e5c4e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/lib/index.js @@ -0,0 +1,68 @@ +/** +* @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 maximum |Re(.)| + |Im(.)|. +* +* @module @stdlib/blas/base/izamax +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var izamax = require( '@stdlib/blas/base/izamax' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var idx = izamax( x.length, x, 1 ); +* // returns 1 +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var izamax = require( '@stdlib/blas/base/izamax' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var idx = izamax.ndarray( x.length, x, 1, 0 ); +* // returns 1 +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var izamax; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + izamax = main; +} else { + izamax = tmp; +} + + +// EXPORTS // + +module.exports = izamax; + +// exports: { "ndarray": "izamax.ndarray" } diff --git a/lib/node_modules/@stdlib/blas/base/izamax/lib/izamax.js b/lib/node_modules/@stdlib/blas/base/izamax/lib/izamax.js new file mode 100644 index 000000000000..536bdf898877 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/lib/izamax.js @@ -0,0 +1,53 @@ +/** +* @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 {Complex128Array} x - input array +* @param {integer} strideX - `x` stride length +* @returns {integer} index value +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var idx = izamax( x.length, x, 1 ); +* // returns 1 +*/ +function izamax( N, x, strideX ) { + var ox = stride2offset( N, strideX ); + return ndarray( N, x, strideX, ox ); +} + + +// EXPORTS // + +module.exports = izamax; diff --git a/lib/node_modules/@stdlib/blas/base/izamax/lib/main.js b/lib/node_modules/@stdlib/blas/base/izamax/lib/main.js new file mode 100644 index 000000000000..4e6037fb5a26 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/lib/main.js @@ -0,0 +1,35 @@ +/** +* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var izamax = require( './izamax.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( izamax, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = izamax; diff --git a/lib/node_modules/@stdlib/blas/base/izamax/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/izamax/lib/ndarray.js new file mode 100644 index 000000000000..2d1980012bd5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/lib/ndarray.js @@ -0,0 +1,75 @@ +/** +* @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 dcabs1 = require( '@stdlib/blas/base/dcabs1' ); + + +// MAIN // + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Complex128Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {integer} index value +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* +* var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* var idx = izamax( x.length, x, 1, 0 ); +* // returns 1 +*/ +function izamax( N, x, strideX, offsetX ) { + var max; + var idx; + var ix; + var v; + var i; + + if ( N < 1 ) { + return -1; + } + idx = 0; + if ( N === 1 ) { + return idx; + } + max = dcabs1( x.get( offsetX ) ); + ix = offsetX + strideX; + for ( i = 1; i < N; i++ ) { + v = dcabs1( x.get( ix ) ); + if ( v > max ) { + idx = i; + max = v; + } + ix += strideX; + } + return idx; +} + + +// EXPORTS // + +module.exports = izamax; diff --git a/lib/node_modules/@stdlib/blas/base/izamax/package.json b/lib/node_modules/@stdlib/blas/base/izamax/package.json new file mode 100644 index 000000000000..f0a5e24abbd6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/blas/base/izamax", + "version": "0.0.0", + "description": "Find the index of the first element having maximum |Re(.)| + |Im(.)|", + "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", + "izamax", + "maximum", + "dcabs1", + "absolute", + "find", + "index", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "complex128", + "complex", + "complex128array" + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/izamax/test/test.izamax.js b/lib/node_modules/@stdlib/blas/base/izamax/test/test.izamax.js new file mode 100644 index 000000000000..ac7f9e6b7dd0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/test/test.izamax.js @@ -0,0 +1,182 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var izamax = require( './../lib/izamax.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof izamax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( izamax.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 = new Complex128Array([ + 0.1, // 0 + -0.3, // 0 + 0.5, // 1 + -0.1, // 1 + -0.2, // 2 + 0.6, // 2 + -0.4, // 3 + 0.9 // 3 + ]); + expected = 3; + + idx = izamax( 4, x, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.2, // 0 + -0.6, // 0 + 0.3, // 1 + 0.6, // 1 + 5.0, + 5.0 + ]); + expected = 1; + + idx = izamax( 2, 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 = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = -1; + + idx = izamax( 0, 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 = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0; + + idx = izamax( 1, 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 = new Complex128Array([ + 0.1, // 0 + 4.0, // 0 + -0.3, + 6.0, + -0.5, // 1 + 7.0, // 1 + -0.1, + 3.0 + ]); + expected = 1; + + idx = izamax( 2, x, 2 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var idx; + var x; + + x = new Complex128Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + expected = 1; + + idx = izamax( x.length, x, -1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + // eslint-disable-next-line max-len + x = new Complex128Array( [ 0.1, 4.0, 999.0, 999.0, -0.3, 6.0, 999.0, 999.0, -0.5, 7.0, 999.0, 999.0, -0.1, 3.0 ] ); + expected = 1; + + idx = izamax( 4, x, -2 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var idx; + var x0; + var x1; + + x0 = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 0 + 5.0, // 1 + 6.0, // 1 + 7.0, // 2 + 8.0 // 2 + ]); + x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + expected = 2; + + idx = izamax( 3, x1, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/izamax/test/test.js b/lib/node_modules/@stdlib/blas/base/izamax/test/test.js new file mode 100644 index 000000000000..c1ac86a56ee4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var izamax = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof izamax, '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 izamax.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var izamax = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( izamax, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var izamax; + var main; + + main = require( './../lib/izamax.js' ); + + izamax = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( izamax, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/blas/base/izamax/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/izamax/test/test.ndarray.js new file mode 100644 index 000000000000..0d41fdecfb97 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/izamax/test/test.ndarray.js @@ -0,0 +1,202 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +var izamax = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof izamax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( izamax.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 = new Complex128Array([ + 0.1, // 0 + -0.3, // 0 + 0.5, // 1 + -0.1, // 1 + -0.2, // 2 + 0.6, // 2 + -0.4, // 3 + 0.9 // 3 + ]); + expected = 3; + + idx = izamax( 4, x, 1, 0 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + x = new Complex128Array([ + 0.2, // 0 + -0.6, // 0 + 0.3, // 1 + 0.6, // 1 + 5.0, + 5.0 + ]); + expected = 1; + + idx = izamax( 2, 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 = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = -1; + + idx = izamax( 0, 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`', function test( t ) { + var expected; + var idx; + var x; + + x = new Complex128Array([ + 1.0, + 2.0, + 3.0, + 4.0 + ]); + expected = 0; + + idx = izamax( 1, 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 = new Complex128Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + + idx = izamax( x.length, x, -1, x.length-1 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + idx = izamax( 2, x, -1, x.length-2 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + // eslint-disable-next-line max-len + x = new Complex128Array( [ 0.1, 4.0, 999.0, 999.0, -0.3, 6.0, 999.0, 999.0, -0.5, 7.0, 999.0, 999.0, -0.1, 3.0 ] ); + idx = izamax( 4, x, -2, x.length-1 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var idx; + var x; + + x = new Complex128Array([ + 0.1, // 0 + 4.0, // 0 + -0.3, + 6.0, + -0.5, // 1 + 7.0, // 1 + -0.1, + 3.0 + ]); + expected = 1; + + idx = izamax( 2, 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 = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 0 + 5.0, // 1 + 6.0, // 1 + 7.0, // 2 + 8.0 // 2 + ]); + expected = 2; + + idx = izamax( 3, 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 = new Complex128Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 0 + 5.0, + 6.0, + 7.0, // 1 + 8.0 // 1 + ]); + expected = 1; + + idx = izamax( 2, x, 2, 1 ); + t.strictEqual( idx, expected, 'returns expected value' ); + + t.end(); +});