diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/README.md new file mode 100644 index 000000000000..0dc7f79c49cc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/README.md @@ -0,0 +1,184 @@ + + +# gindexOf + +> Return the first index of a specified search element in a strided array. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var gindexOf = require( '@stdlib/blas/ext/base/gindex-of' ); +``` + +#### gindexOf( N, searchElement, x, strideX ) + +Returns the first index of a specified search element in a strided array. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; + +var idx = gindexOf( x.length, 3.0, x, 1 ); +// returns 2 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **searchElement**: search element. +- **x**: input array. +- **strideX**: stride length. + +If the function is unable to find a search element, the function returns `-1`. + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; + +var idx = gindexOf( x.length, 8.0, x, 1 ); +// returns -1 +``` + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to search every other element: + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; + +var idx = gindexOf( 4, -1.0, x, 2 ); +// returns 3 +``` + +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... +var idx = gindexOf( 3, -6.0, x1, 2 ); +// returns 2 +``` + +#### gindexOf.ndarray( N, searchElement, x, strideX, offsetX ) + +Returns the first index of a specified search element in a strided array 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 = gindexOf.ndarray( x.length, 3.0, x, 1, 0 ); +// returns 2 +``` + +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 access only the last three elements of the strided array: + +```javascript +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; + +var idx = gindexOf.ndarray( 3, 3.0, x, 1, x.length-3 ); +// returns 2 +``` + +
+ + + + + +
+ +## Notes + +- When searching for a search element, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same. + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gindexOf = require( '@stdlib/blas/ext/base/gindex-of' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = gindexOf( x.length, 80.0, x, 1 ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.js new file mode 100644 index 000000000000..e32791dfe386 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var pkg = require( './../package.json' ).name; +var gindexOf = require( './../lib/main.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gindexOf( x.length, len+1, x, 1 ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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/ext/base/gindex-of/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..cc23229fb23d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.ndarray.js @@ -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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var pkg = require( './../package.json' ).name; +var gindexOf = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gindexOf( x.length, len+1, x, 1, 0 ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + 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/ext/base/gindex-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/repl.txt new file mode 100644 index 000000000000..1c34e5a7d62d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/repl.txt @@ -0,0 +1,76 @@ + +{{alias}}( N, searchElement, x, strideX ) + Returns the first index of a specified search element in a strided array. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + if `N <= 0`, the function returns `-1`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + searchElement: number + Search element. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; + > var idx = {{alias}}( x.length, 1.0, x, 1 ) + 1 + + +{{alias}}( N, searchElement, x, strideX, offsetX ) + Returns the first index of a specified search element in a strided array + using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a + starting index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + searchElement: number + Search element. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; + > var idx = {{alias}}.ndarray( x.length, 1.0, x, 1, 0 ) + 1 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/index.d.ts new file mode 100644 index 000000000000..e89919feebcd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/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 { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gindexOf`. +*/ +interface Routine { + /** + * Returns the first index of a specified search element in a strided array. + * + * @param N - number of indexed elements + * @param searchElement - search element + * @param x - input array + * @param strideX - stride length + * @returns index + * + * @example + * var x = new [ 1.0, 2.0, 3.0, 4.0 ]; + * + * var idx = gindexOf( x.length, 2.0, x, 1 ); + * // returns 1 + */ + ( N: number, searchElement: unknown, x: InputArray, strideX: number ): number; + + /** + * Returns the first index of a specified search element in a strided array using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param searchElement - search element + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns index + * + * @example + * var x = [ 1.0, 2.0, 3.0, 4.0 ]; + * + * var idx = gindexOf.ndarray( x.length, 2.0, x, 1, 0 ); + * // returns 1 + */ + ndarray( N: number, searchElement: unknown, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Returns the first index of a specified search element in a strided array. +* +* @param N - number of indexed elements +* @param searchElement - search element +* @param x - input array +* @param strideX - stride length +* @returns index +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0 ]; +* +* var idx = gindexOf( x.length, 2.0, x, 1 ); +* // returns 1 +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0 ]; +* +* var idx = gindexOf.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 1 +*/ +declare var gindexOf: Routine; + + +// EXPORTS // + +export = gindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/test.ts new file mode 100644 index 000000000000..683dada8a225 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/test.ts @@ -0,0 +1,129 @@ +/* +* @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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import gindexOf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf( x.length, 2.0, x, 1 ); // $ExpectType number + gindexOf( x.length, 2.0, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf( '1', 2.0, x, 1 ); // $ExpectError + gindexOf( true, 2.0, x, 1 ); // $ExpectError + gindexOf( false, 2.0, x, 1 ); // $ExpectError + gindexOf( null, 2.0, x, 1 ); // $ExpectError + gindexOf( {}, 2.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + gindexOf( x.length, 1.0, '1', 1 ); // $ExpectError + gindexOf( x.length, 1.0, true, 1 ); // $ExpectError + gindexOf( x.length, 1.0, false, 1 ); // $ExpectError + gindexOf( x.length, 1.0, null, 1 ); // $ExpectError + gindexOf( x.length, 1.0, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf( x.length, 2.0, x, '1' ); // $ExpectError + gindexOf( x.length, 2.0, x, true ); // $ExpectError + gindexOf( x.length, 2.0, x, false ); // $ExpectError + gindexOf( x.length, 2.0, x, null ); // $ExpectError + gindexOf( x.length, 2.0, x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + gindexOf(); // $ExpectError + gindexOf( 3, 2.0 ); // $ExpectError + gindexOf( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOf( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf.ndarray( x.length, 2.0, x, 1, 0 ); // $ExpectType number + gindexOf.ndarray( x.length, 2.0, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf.ndarray( '1', 2.0, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( true, 2.0, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( false, 2.0, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( null, 2.0, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( {}, 2.0, x, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + gindexOf.ndarray( x.length, 1.0, '1', 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 1.0, true, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 1.0, false, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 1.0, null, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 1.0, {}, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf.ndarray( x.length, 2.0, x, '1', 1 ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, true, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, false, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, null, 1 ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf.ndarray( x.length, 2.0, x, 1, '1' ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, 1, true ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, 1, false ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, 1, null ); // $ExpectError + gindexOf.ndarray( x.length, 2.0, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + gindexOf.ndarray(); // $ExpectError + gindexOf.ndarray( 3, 2.0 ); // $ExpectError + gindexOf.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOf.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); // $ExpectError + gindexOf.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/examples/index.js new file mode 100644 index 000000000000..fe94024352b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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 gindexOf = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = gindexOf( x.length, 80.0, x, 1 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/accessors.js new file mode 100644 index 000000000000..a2bd128f9877 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/accessors.js @@ -0,0 +1,70 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns the first index of a specified search element in a strided array. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {integer} index +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* var idx = gindexOf( x.length, 3.0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 2 +*/ +function gindexOf( N, searchElement, x, strideX, offsetX ) { + var xbuf; + var get; + var ix; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessors: + get = x.accessors[ 0 ]; + + ix = offsetX; + for ( i = 0; i < N; i++ ) { + if ( get( xbuf, ix ) === searchElement ) { + return i; + } + ix += strideX; + } + return -1; +} + + +// EXPORTS // + +module.exports = gindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/index.js new file mode 100644 index 000000000000..49d1e66d14ff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/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'; + +/** +* Return the first index of a specified search element in a strided array. +* +* @module @stdlib/blas/ext/base/gindex-of +* +* @example +* var gindexOf = require( '@stdlib/blas/ext/base/gindex-of' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = gindexOf( x.length, 3.0, x, 1 ); +* // returns 2 +* +* @example +* var gindexOf = require( '@stdlib/blas/ext/base/gindex-of' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = gindexOf.ndarray( x.length, 3.0, x, 1, 0 ); +* // returns 2 +*/ + +// 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/ext/base/gindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/main.js new file mode 100644 index 000000000000..7d2b5b34d392 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/main.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the first index of a specified search element in a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {integer} index +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = gindexOf( x.length, 3.0, x, 1 ); +* // returns 2 +*/ +function gindexOf( N, searchElement, x, strideX ) { + return ndarray( N, searchElement, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/ndarray.js new file mode 100644 index 000000000000..bc7e8c4861a5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/ndarray.js @@ -0,0 +1,70 @@ +/** +* @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 accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns the first index of a specified search element in a strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {integer} index +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = gindexOf( x.length, 3.0, x, 1, 0 ); +* // returns 2 +*/ +function gindexOf( N, searchElement, x, strideX, offsetX ) { + var ix; + var o; + var i; + + if ( N <= 0 ) { + return -1; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, searchElement, o, strideX, offsetX ); + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + if ( x[ ix ] === searchElement ) { + return i; + } + ix += strideX; + } + return -1; +} + + +// EXPORTS // + +module.exports = gindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/package.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/package.json new file mode 100644 index 000000000000..210d203603d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/base/gindex-of", + "version": "0.0.0", + "description": "Return the first index of a specified search element in a strided array.", + "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", + "extended", + "search", + "index", + "get", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.js new file mode 100644 index 000000000000..a4271d9c969c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/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 gindexOf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOf, '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 gindexOf.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.main.js new file mode 100644 index 000000000000..3ef69836904a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.main.js @@ -0,0 +1,139 @@ +/** +* @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 gindexOf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gindexOf.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + // Nonnegative stride... + actual = gindexOf( x.length, 1.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOf( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 3.0, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = gindexOf( x.length, 1.0, x, -1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOf( x.length, 2.0, x, -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 3.0, x, -1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, -1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + // Nonnegative stride... + actual = gindexOf( x.length, 1.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOf( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 3.0, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = gindexOf( x.length, 1.0, x, -1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOf( x.length, 2.0, x, -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 3.0, x, -1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, -1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided `N` parameter is less than or equal to zero', function test( t ) { + var actual; + + actual = gindexOf( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOf( -1, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { + var actual; + + actual = gindexOf( 1, NaN, [ NaN ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided a search element equal to `NaN` (accessors)', function test( t ) { + var actual; + + actual = gindexOf( 1, NaN, toAccessorArray( [ NaN ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.ndarray.js new file mode 100644 index 000000000000..9bd741a56b23 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.ndarray.js @@ -0,0 +1,139 @@ +/** +* @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 gindexOf = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gindexOf.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + // Nonnegative stride... + actual = gindexOf( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOf( x.length, 2.0, x, 1, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOf( x.length, 3.0, x, 1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, 1, 2 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = gindexOf( x.length, 1.0, x, -1, x.length-1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOf( 3, 2.0, x, -2, x.length-1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOf( 3, 1.0, x, -2, x.length-2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, -1, x.length-1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + // Nonnegative stride... + actual = gindexOf( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOf( x.length, 2.0, x, 1, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOf( x.length, 3.0, x, 1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, 1, 2 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = gindexOf( x.length, 1.0, x, -1, x.length-1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOf( 3, 2.0, x, -2, x.length-1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOf( 3, 1.0, x, -2, x.length-2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOf( x.length, 4.0, x, -1, x.length-1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter is less than or equal to zero', function test( t ) { + var actual; + + actual = gindexOf( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOf( -1, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided a search element equal to `NaN`', function test( t ) { + var actual; + + actual = gindexOf( 1, NaN, [ NaN ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided a search element equal to `NaN` (accessors)', function test( t ) { + var actual; + + actual = gindexOf( 1, NaN, toAccessorArray( [ NaN ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +});