From 3e435972efcc46bd7cb7c5d8d31b6f5ce7e97ce5 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:08:51 +0000 Subject: [PATCH 01/12] feat: add gindex-of --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/gindex-of/README.md | 184 ++++++++++++++++++ .../ext/base/gindex-of/benchmark/benchmark.js | 96 +++++++++ .../gindex-of/benchmark/benchmark.ndarray.js | 96 +++++++++ .../blas/ext/base/gindex-of/docs/repl.txt | 76 ++++++++ .../ext/base/gindex-of/docs/types/index.d.ts | 96 +++++++++ .../ext/base/gindex-of/docs/types/test.ts | 151 ++++++++++++++ .../blas/ext/base/gindex-of/examples/index.js | 30 +++ .../blas/ext/base/gindex-of/lib/accessors.js | 70 +++++++ .../blas/ext/base/gindex-of/lib/index.js | 57 ++++++ .../blas/ext/base/gindex-of/lib/main.js | 51 +++++ .../blas/ext/base/gindex-of/lib/ndarray.js | 70 +++++++ .../blas/ext/base/gindex-of/package.json | 66 +++++++ .../blas/ext/base/gindex-of/test/test.js | 38 ++++ .../blas/ext/base/gindex-of/test/test.main.js | 38 ++++ .../ext/base/gindex-of/test/test.ndarray.js | 38 ++++ 15 files changed, 1157 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.ndarray.js 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..69d776ad4fa6 --- /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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | 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 = dindexOf( x.length, 2.0, x, 1 ); + * // returns 1 + */ + ( N: number, searchElement: number, 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: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Returns the first index of a specified search element in a double-precision floating-point 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..85bf80a33c48 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/docs/types/test.ts @@ -0,0 +1,151 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +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 second argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf( x.length, '1', x, 1 ); // $ExpectError + gindexOf( x.length, true, x, 1 ); // $ExpectError + gindexOf( x.length, false, x, 1 ); // $ExpectError + gindexOf( x.length, null, x, 1 ); // $ExpectError + gindexOf( x.length, {}, 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 second argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOf.ndarray( x.length, '1', x, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, true, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, false, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, null, x, 1, 1 ); // $ExpectError + gindexOf.ndarray( x.length, {}, x, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +{ + 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..fc17ab90d9c1 --- /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 using alternative indexing semantics. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {number} 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..67a083e0c1ed --- /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) 2020 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 {number} 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..ebc81665de53 --- /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 {number} 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..57dd3149dbd0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.main.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 gfill = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gfill.length, 4, 'has expected arity' ); + 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..2c2166854f18 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of/test/test.ndarray.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 gfill = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gfill.length, 5, 'has expected arity' ); + t.end(); +}); From f102ab75fbb054c05af417143574a69fa50782f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Thu, 26 Jun 2025 19:16:04 +0000 Subject: [PATCH 02/12] chore: update copyright years --- lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 67a083e0c1ed..85790c37de64 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. From c2ffdfce996808123045274a240ef6e200ddd768 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 27 Jun 2025 07:08:56 +0000 Subject: [PATCH 03/12] test: add tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/gindex-of/test/test.main.js | 107 +++++++++++++++++- .../ext/base/gindex-of/test/test.ndarray.js | 107 +++++++++++++++++- 2 files changed, 208 insertions(+), 6 deletions(-) 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 index 57dd3149dbd0..3ef69836904a 100644 --- 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 @@ -21,18 +21,119 @@ // MODULES // var tape = require( 'tape' ); -var gfill = require( './../lib' ); +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 gfill, 'function', 'main export is a function' ); + 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( gfill.length, 4, 'has expected arity' ); + 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 index 2c2166854f18..9bd741a56b23 100644 --- 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 @@ -21,18 +21,119 @@ // MODULES // var tape = require( 'tape' ); -var gfill = require( './../lib/ndarray.js' ); +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 gfill, 'function', 'main export is a function' ); + 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( gfill.length, 5, 'has expected arity' ); + 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(); }); From db171998683d138297ab4e5c8237cdc0e924a681 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:28:24 -0700 Subject: [PATCH 04/12] docs: fix alias Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 69d776ad4fa6..71a4342688cc 100644 --- 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 @@ -43,7 +43,7 @@ interface Routine { * @example * var x = new [ 1.0, 2.0, 3.0, 4.0 ]; * - * var idx = dindexOf( x.length, 2.0, x, 1 ); + * var idx = gindexOf( x.length, 2.0, x, 1 ); * // returns 1 */ ( N: number, searchElement: number, x: InputArray, strideX: number ): number; From 1332647a8d4d153e140d5c4a7bb4dc146bcabfa0 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:28:59 -0700 Subject: [PATCH 05/12] docs: fix description Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 71a4342688cc..07fd2d57d1da 100644 --- 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 @@ -68,7 +68,7 @@ interface Routine { } /** -* Returns the first index of a specified search element in a double-precision floating-point strided array. +* Returns the first index of a specified search element in a strided array. * * @param N - number of indexed elements * @param searchElement - search element From aeb089f8bc4370c5f4009c5c319857a42e268da3 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:30:31 -0700 Subject: [PATCH 06/12] docs: fix comment Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gindex-of/docs/types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 85bf80a33c48..3388d74198b4 100644 --- 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 @@ -110,7 +110,7 @@ import gindexOf = require( './index' ); gindexOf.ndarray( x.length, {}, x, 1, 1 ); // $ExpectError } -// The compiler throws an error if the `ndarray` method is provided a third argument which is not a numeric array... +// 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 From 503d7a5d1089917cd8f650b498c939a9276a87b9 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:31:38 -0700 Subject: [PATCH 07/12] fix: update types to allow arrays of any type Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gindex-of/docs/types/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index 07fd2d57d1da..e89919feebcd 100644 --- 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 @@ -20,12 +20,12 @@ /// -import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; /** * Input array. */ -type InputArray = NumericArray | Collection | AccessorArrayLike; +type InputArray = Collection | AccessorArrayLike; /** * Interface describing `gindexOf`. @@ -46,7 +46,7 @@ interface Routine { * var idx = gindexOf( x.length, 2.0, x, 1 ); * // returns 1 */ - ( N: number, searchElement: number, x: InputArray, strideX: number ): number; + ( 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. @@ -64,7 +64,7 @@ interface Routine { * var idx = gindexOf.ndarray( x.length, 2.0, x, 1, 0 ); * // returns 1 */ - ndarray( N: number, searchElement: number, x: InputArray, strideX: number, offsetX: number ): number; + ndarray( N: number, searchElement: unknown, x: InputArray, strideX: number, offsetX: number ): number; } /** From b6e99b1bc56a69d0e27f160badcc6a28f989c424 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:32:44 -0700 Subject: [PATCH 08/12] test: remove obsolete tests Signed-off-by: Athan --- .../ext/base/gindex-of/docs/types/test.ts | 22 ------------------- 1 file changed, 22 deletions(-) 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 index 3388d74198b4..683dada8a225 100644 --- 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 @@ -41,17 +41,6 @@ import gindexOf = require( './index' ); gindexOf( {}, 2.0, x, 1 ); // $ExpectError } -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - var x = [ 1.0, 2.0, 3.0 ]; - - gindexOf( x.length, '1', x, 1 ); // $ExpectError - gindexOf( x.length, true, x, 1 ); // $ExpectError - gindexOf( x.length, false, x, 1 ); // $ExpectError - gindexOf( x.length, null, x, 1 ); // $ExpectError - gindexOf( x.length, {}, 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 @@ -99,17 +88,6 @@ import gindexOf = require( './index' ); gindexOf.ndarray( {}, 2.0, x, 1, 1 ); // $ExpectError } -// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... -{ - var x = [ 1.0, 2.0, 3.0 ]; - - gindexOf.ndarray( x.length, '1', x, 1, 1 ); // $ExpectError - gindexOf.ndarray( x.length, true, x, 1, 1 ); // $ExpectError - gindexOf.ndarray( x.length, false, x, 1, 1 ); // $ExpectError - gindexOf.ndarray( x.length, null, x, 1, 1 ); // $ExpectError - gindexOf.ndarray( x.length, {}, 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 From 07c786144e4d323e29a59407163220aabaec4e9f Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:33:56 -0700 Subject: [PATCH 09/12] docs: update description Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gindex-of/lib/accessors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index fc17ab90d9c1..6fac17cde6ff 100644 --- 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 @@ -21,7 +21,7 @@ // MAIN // /** -* Returns the first index of a specified search element in a strided array using alternative indexing semantics. +* Returns the first index of a specified search element in a strided array. * * @private * @param {PositiveInteger} N - number of indexed elements From 03d7130304b39ab928e3e6d3e767f6c8d89028ee Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:34:48 -0700 Subject: [PATCH 10/12] docs: fix type Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gindex-of/lib/accessors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 6fac17cde6ff..a2bd128f9877 100644 --- 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 @@ -25,7 +25,7 @@ * * @private * @param {PositiveInteger} N - number of indexed elements -* @param {number} searchElement - search element +* @param {*} searchElement - search element * @param {Object} x - input array object * @param {Collection} x.data - input array data * @param {Array} x.accessors - array element accessors From 72ce137c3ea8661dfd6a35cd196479478074b11c Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:35:15 -0700 Subject: [PATCH 11/12] docs: fix type Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 85790c37de64..7d2b5b34d392 100644 --- 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 @@ -30,7 +30,7 @@ var ndarray = require( './ndarray.js' ); * Returns the first index of a specified search element in a strided array. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} searchElement - search element +* @param {*} searchElement - search element * @param {Collection} x - input array * @param {integer} strideX - stride length * @returns {integer} index From e0615c9907b88346b494e5d5c113f83c978eb450 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 14:35:47 -0700 Subject: [PATCH 12/12] docs: fix type Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/gindex-of/lib/ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index ebc81665de53..bc7e8c4861a5 100644 --- 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 @@ -30,7 +30,7 @@ var accessors = require( './accessors.js' ); * 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 {number} searchElement - search element +* @param {*} searchElement - search element * @param {Collection} x - input array * @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index