From 2f833e4298e3386ec4f782e8a2b0e1c6cfa69cde Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 30 Jun 2025 19:17:26 +0000 Subject: [PATCH 01/16] feat: add blas/ext/base/ndarray/sindex-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 --- --- .../blas/ext/base/ndarray/sindex-of/README.md | 155 +++++++++++++++++ .../ndarray/sindex-of/benchmark/benchmark.js | 112 +++++++++++++ .../ext/base/ndarray/sindex-of/docs/repl.txt | 34 ++++ .../ndarray/sindex-of/docs/types/index.d.ts | 56 +++++++ .../base/ndarray/sindex-of/docs/types/test.ts | 70 ++++++++ .../base/ndarray/sindex-of/examples/index.js | 45 +++++ .../ext/base/ndarray/sindex-of/lib/index.js | 54 ++++++ .../ext/base/ndarray/sindex-of/lib/main.js | 99 +++++++++++ .../ext/base/ndarray/sindex-of/package.json | 65 +++++++ .../ext/base/ndarray/sindex-of/test/test.js | 158 ++++++++++++++++++ 10 files changed, 848 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md new file mode 100644 index 000000000000..3bb1a1a87e37 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md @@ -0,0 +1,155 @@ + + +# sindexOf + +> Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +``` + +#### sindexOf( arrays ) + +Returns the first index of a specified search element in a one-dimensional single-precision floating-point ndarray. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' +}); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +// returns 3 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. + +If the function is unable to find a search element, the function returns `-1`. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var searchElement = scalar2ndarray( 10.0, { + 'dtype': 'float32' +}); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +// returns -1 +``` + +
+ + + +
+ +## 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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 80.0, { + 'dtype': 'float32' +}); +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +console.log( 'From Index:', ndarray2array( fromIndex ) ); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js new file mode 100644 index 000000000000..0d1078cf601a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var sindexOf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var searchElement; + var fromIndex; + var xbuf; + var x; + + xbuf = uniform( len, 0.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + searchElement = scalar2ndarray( -10.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + return benchmark; + + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = sindexOf( [ x, searchElement, fromIndex ] ); + if ( !isInteger( idx ) ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( idx ) ) { + 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/ndarray/sindex-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt new file mode 100644 index 000000000000..640c282f2ffa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( arrays ) + Returns the first index of a search element in a one-dimensional + single-precision floating-point ndarray. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray, + a zero-dimensional ndarray containing the search element and + a zero-dimensional ndarray containing the from index. + + Returns + ------- + out: integer + Index. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0 ] ); + > var dt = 'float32'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var searchElement = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'float32' }); + > var fromIndex = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' }); + > {{alias}}( [ x, searchElement, fromIndex ] ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts new file mode 100644 index 000000000000..dcb7b753d8cb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* +* @param arrays - array-like object containing an input ndarray, a search element ndarray and a from index ndarray. +* @returns index +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = sindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ +declare function sindexOf = typedndarray>( arrays: [ T, T, T ] ): number; + + +// EXPORTS // + +export = sindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts new file mode 100644 index 000000000000..605065cab5ae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/test.ts @@ -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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import sindexOf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'float32' + }); + const fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + sindexOf( [ x, searchElement, fromIndex ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + sindexOf( '10' ); // $ExpectError + sindexOf( 10 ); // $ExpectError + sindexOf( true ); // $ExpectError + sindexOf( false ); // $ExpectError + sindexOf( null ); // $ExpectError + sindexOf( undefined ); // $ExpectError + sindexOf( [] ); // $ExpectError + sindexOf( {} ); // $ExpectError + sindexOf( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + const searchElement = scalar2ndarray( 0.0, { + 'dtype': 'float32' + }); + const fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + sindexOf(); // $ExpectError + sindexOf( [ x, searchElement, fromIndex ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js new file mode 100644 index 000000000000..42496dd072ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var sindexOf = require( './../lib' ); + +var xbuf = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var searchElement = scalar2ndarray( 80.0, { + 'dtype': 'float32' +}); +console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); + +var fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' +}); +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); + +var idx = sindexOf( [ x, searchElement, fromIndex ] ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js new file mode 100644 index 000000000000..5ed07125048d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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 search element in a one-dimensional single-precision floating-point ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/sindex-of +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = sindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js new file mode 100644 index 000000000000..75eb28e6c244 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/sindex-of' ).ndarray; +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); + + +// MAIN // + +/** +* Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray, a search element ndarray and a from index ndarray. +* @returns {integer} index +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var sindexOf = require( '@stdlib/blas/ext/base/ndarray/sindex-of' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var searchElement = scalar2ndarray( 2.0, { +* 'dtype': 'float32' +* }); +* +* var fromIndex = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var v = sindexOf( [ x, searchElement, fromIndex ] ); +* // returns 3 +*/ +function sindexOf( arrays ) { + var searchElement; + var fromIndex; + var stride; + var offset; + var idx; + var N; + var x; + + x = arrays[ 0 ]; + searchElement = ndarraylike2scalar( arrays[ 1 ] ); + fromIndex = ndarraylike2scalar( arrays[ 2 ] ); + + N = numelDimension( x, 0 ); + + if ( fromIndex >= 0 ) { + if ( fromIndex >= N ) { + return -1; + } + } else { + fromIndex += N; + if ( fromIndex < 0 ) { + fromIndex = 0; + } + } + + N -= fromIndex; + stride = getStride( x, 0 ); + offset = getOffset( x ) + ( stride*fromIndex ); + + idx = strided( N, searchElement, getData( x ), stride, offset ); + if ( idx >= 0 ) { + idx += fromIndex; + } + return idx; +} + + +// EXPORTS // + +module.exports = sindexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json new file mode 100644 index 000000000000..21d017200ce3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/sindex-of", + "version": "0.0.0", + "description": "Return the first index of a specified search element in a one-dimensional single-precision floating-point ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "array", + "index", + "search", + "get", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js new file mode 100644 index 000000000000..a463876f209c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js @@ -0,0 +1,158 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var sindexOf = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Float32Array} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sindexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the first index of an element which equals a provided search element', function test( t ) { + var searchElement; + var fromIndex; + var actual; + var x; + + x = vector( new Float32Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 6, 1, 0 ); + + // Nonnegative fromIndex... + searchElement = scalar2ndarray( 1.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 0, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 2, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 3, 'returns expected value' ); + + searchElement = scalar2ndarray( 4.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative fromIndex... + searchElement = scalar2ndarray( 3.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -1, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 5, 'returns expected value' ); + + searchElement = scalar2ndarray( 3.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -2, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 4, 'returns expected value' ); + + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -3, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, 3, 'returns expected value' ); + + searchElement = scalar2ndarray( 4.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( -4, { + 'dtype': 'generic' + }); + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided `fromIndex` parameter is greater than or equal to number of elements in the input ndarray', function test( t ) { + var searchElement; + var fromIndex; + var actual; + var x; + + x = vector( new Float32Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ), 6, 1, 0 ); + searchElement = scalar2ndarray( 2.0, { + 'dtype': 'float32' + }); + fromIndex = scalar2ndarray( 7, { + 'dtype': 'generic' + }); + + actual = sindexOf( [ x, searchElement, fromIndex ] ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); From 20df6cfa4d76113e59f594741b43eed94052fb08 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 1 Jul 2025 05:00:44 +0000 Subject: [PATCH 02/16] fix: cleanup --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/ndarray/sindex-of/README.md | 4 ++-- .../ext/base/ndarray/sindex-of/benchmark/benchmark.js | 8 ++++---- .../blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts | 4 ++-- .../@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js | 5 ++--- .../@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js | 6 +++--- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md index 3bb1a1a87e37..ff64a8e3570b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md @@ -94,7 +94,7 @@ var idx = sindexOf( [ x, searchElement, fromIndex ] ); ## 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. +- If `fromIndex` is greater than or equal to zero and less than the ndarray length, searching begins at that index and if `fromIndex` is greater than or equal to the array length, the function returns `-1`. Similarly, if `fromIndex` is negative, it is added to the array length, and, if the result is less than zero, searching begins at index `0`. @@ -128,7 +128,7 @@ console.log( 'Search Element:', ndarraylike2scalar( searchElement ) ); var fromIndex = scalar2ndarray( 0, { 'dtype': 'generic' }); -console.log( 'From Index:', ndarray2array( fromIndex ) ); +console.log( 'From Index:', ndarraylike2scalar( fromIndex ) ); var idx = sindexOf( [ x, searchElement, fromIndex ] ); console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js index 0d1078cf601a..918b142482a8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/benchmark/benchmark.js @@ -65,18 +65,18 @@ function createBenchmark( len ) { return benchmark; function benchmark( b ) { - var idx; + var out; var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - idx = sindexOf( [ x, searchElement, fromIndex ] ); - if ( !isInteger( idx ) ) { + out = sindexOf( [ x, searchElement, fromIndex ] ); + if ( out !== out ) { b.fail( 'should return an integer' ); } } b.toc(); - if ( !isInteger( idx ) ) { + if ( !isInteger( out ) ) { b.fail( 'should return an integer' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts index dcb7b753d8cb..1b8581081068 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -25,7 +25,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; /** * Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. * -* @param arrays - array-like object containing an input ndarray, a search element ndarray and a from index ndarray. +* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. * @returns index * * @example @@ -48,7 +48,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var v = sindexOf( [ x, searchElement, fromIndex ] ); * // returns 3 */ -declare function sindexOf = typedndarray>( arrays: [ T, T, T ] ): number; +declare function sindexOf( arrays: [ typedndarray, typedndarray, typedndarray ] ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js index 75eb28e6c244..6d5392336c12 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -33,7 +33,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); /** * Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. * -* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray, a search element ndarray and a from index ndarray. +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. * @returns {integer} index * * @example @@ -66,11 +66,10 @@ function sindexOf( arrays ) { var x; x = arrays[ 0 ]; + N = numelDimension( x, 0 ); searchElement = ndarraylike2scalar( arrays[ 1 ] ); fromIndex = ndarraylike2scalar( arrays[ 2 ] ); - N = numelDimension( x, 0 ); - if ( fromIndex >= 0 ) { if ( fromIndex >= N ) { return -1; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js index a463876f209c..129d4cbbee1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js @@ -125,14 +125,14 @@ tape( 'the function returns the first index of an element which equals a provide actual = sindexOf( [ x, searchElement, fromIndex ] ); t.strictEqual( actual, 3, 'returns expected value' ); - searchElement = scalar2ndarray( 4.0, { + searchElement = scalar2ndarray( 2.0, { 'dtype': 'float32' }); - fromIndex = scalar2ndarray( -4, { + fromIndex = scalar2ndarray( -7, { 'dtype': 'generic' }); actual = sindexOf( [ x, searchElement, fromIndex ] ); - t.strictEqual( actual, -1, 'returns expected value' ); + t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); From 1dbbb77849449439ac43a912a1e95eb48d7789fa Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 22:51:10 -0700 Subject: [PATCH 03/16] docs: organize description into a list Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md index ff64a8e3570b..e59e55a22f2a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md @@ -62,7 +62,11 @@ var idx = sindexOf( [ x, searchElement, fromIndex ] ); The function has the following parameters: -- **arrays**: array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the index from which to begin searching. If the function is unable to find a search element, the function returns `-1`. From ab43c9867cf3cecf6687fe43c4b52f751b1d18a0 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 22:59:42 -0700 Subject: [PATCH 04/16] docs: update copy Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md index e59e55a22f2a..caad8a6fbd0a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/README.md @@ -98,7 +98,7 @@ var idx = sindexOf( [ x, searchElement, fromIndex ] ); ## Notes -- If `fromIndex` is greater than or equal to zero and less than the ndarray length, searching begins at that index and if `fromIndex` is greater than or equal to the array length, the function returns `-1`. Similarly, if `fromIndex` is negative, it is added to the array length, and, if the result is less than zero, searching begins at index `0`. +- If a specified starting search index is negative, the function resolves the starting search index by counting backward from the last element (where `-1` refers to the last element). From dc75c723a981cd2fe15d5a32cd98d88af0ce7f83 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:01:56 -0700 Subject: [PATCH 05/16] docs: fix description Signed-off-by: Athan --- .../blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts index 1b8581081068..c69770858a5b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; /** -* Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. * * @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. * @returns index From 4d91d01efdfc876f1dd0f6f468b1aa2da6931e30 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:02:35 -0700 Subject: [PATCH 06/16] docs: fix missing comma Signed-off-by: Athan --- .../blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts index c69770858a5b..bec989142ff3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -25,7 +25,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; /** * Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. * -* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. +* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the from index. * @returns index * * @example From 9d2de5469f60ee5ced2c671d04504327657afe4b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:03:33 -0700 Subject: [PATCH 07/16] fix: add missing import Signed-off-by: Athan --- .../blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts index bec989142ff3..e3a6ead5fffb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { typedndarray } from '@stdlib/types/ndarray'; +import { float32ndarray, typedndarray } from '@stdlib/types/ndarray'; /** * Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. From 11b72d1a990f2a536eae35e4fac463ee65ef9fe1 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:03:45 -0700 Subject: [PATCH 08/16] fix: use correct type Signed-off-by: Athan --- .../blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts index e3a6ead5fffb..bc33e07060bf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -48,7 +48,7 @@ import { float32ndarray, typedndarray } from '@stdlib/types/ndarray'; * var v = sindexOf( [ x, searchElement, fromIndex ] ); * // returns 3 */ -declare function sindexOf( arrays: [ typedndarray, typedndarray, typedndarray ] ): number; +declare function sindexOf( arrays: [ float32ndarray, typedndarray, typedndarray ] ): number; // EXPORTS // From 5a942f30acda2ef078714821815dfd97ec6314f8 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:04:59 -0700 Subject: [PATCH 09/16] docs: fix description Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js index 6d5392336c12..c01ca8ee9688 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -31,7 +31,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); // MAIN // /** -* Return the first index of a search element in a one-dimensional single-precision floating-point ndarray. +* Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. * * @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. * @returns {integer} index From 6c8f5344bff94c1cd9dfb8c837cfc2aa09872972 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:05:21 -0700 Subject: [PATCH 10/16] docs: fix missing comma Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js index c01ca8ee9688..038ddca59f48 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -33,7 +33,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); /** * Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. * -* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element and a zero-dimensional ndarray containing the from index. +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the from index. * @returns {integer} index * * @example From e3044eaa532f4b784d5c4be5df76e620105935ae Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:06:07 -0700 Subject: [PATCH 11/16] docs: fix desc Signed-off-by: Athan --- .../blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts index bc33e07060bf..b17a1234ae11 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/types/index.d.ts @@ -25,7 +25,7 @@ import { float32ndarray, typedndarray } from '@stdlib/types/ndarray'; /** * Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. * -* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the from index. +* @param arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the index from which to begin searching * @returns index * * @example From 01a066738542ef6c41f86a4976ba19de295f0b62 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:06:35 -0700 Subject: [PATCH 12/16] docs: fix desc Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js index 038ddca59f48..23d3b8a37946 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -33,7 +33,7 @@ var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); /** * Returns the first index of a search element in a one-dimensional single-precision floating-point ndarray. * -* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the from index. +* @param {ArrayLikeObject} arrays - array-like object containing a one-dimensional input ndarray, a zero-dimensional ndarray containing the search element, and a zero-dimensional ndarray containing the index from which to begin searching * @returns {integer} index * * @example From 4ff93141a7ede81ca16a28c9c15a3c38e9fee504 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:10:21 -0700 Subject: [PATCH 13/16] refactor: simplify branching Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js index 23d3b8a37946..b3417b8cb951 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/lib/main.js @@ -70,17 +70,14 @@ function sindexOf( arrays ) { searchElement = ndarraylike2scalar( arrays[ 1 ] ); fromIndex = ndarraylike2scalar( arrays[ 2 ] ); - if ( fromIndex >= 0 ) { - if ( fromIndex >= N ) { - return -1; - } - } else { + if ( fromIndex < 0 ) { fromIndex += N; if ( fromIndex < 0 ) { fromIndex = 0; } + } else if ( fromIndex >= N ) { + return -1; } - N -= fromIndex; stride = getStride( x, 0 ); offset = getOffset( x ) + ( stride*fromIndex ); From ae72a49c285e0346c63f2c1a09edac545a8f3c43 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:13:13 -0700 Subject: [PATCH 14/16] test: update description Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js index 129d4cbbee1e..5d3bb296fabd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/test/test.js @@ -137,7 +137,7 @@ tape( 'the function returns the first index of an element which equals a provide t.end(); }); -tape( 'the function returns `-1` if provided `fromIndex` parameter is greater than or equal to number of elements in the input ndarray', function test( t ) { +tape( 'the function returns `-1` if provided a starting search index which is greater than or equal to number of elements in the input ndarray', function test( t ) { var searchElement; var fromIndex; var actual; From 730b42557a66c6ffa6f6ba298d278fbf84f86975 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:15:30 -0700 Subject: [PATCH 15/16] docs: update copy Signed-off-by: Athan --- .../ext/base/ndarray/sindex-of/docs/repl.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt index 640c282f2ffa..4b98e24e38cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt @@ -1,14 +1,17 @@ {{alias}}( arrays ) - Returns the first index of a search element in a one-dimensional - single-precision floating-point ndarray. + Returns the first index of a search element in a one-dimensional single- + precision floating-point ndarray. Parameters ---------- arrays: ArrayLikeObject - Array-like object containing a one-dimensional input ndarray, - a zero-dimensional ndarray containing the search element and - a zero-dimensional ndarray containing the from index. + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the search element. + - a zero-dimensional ndarray containing the index from which to begin + searching. Returns ------- @@ -24,9 +27,9 @@ > var ox = 0; > var ord = 'row-major'; > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); - > var searchElement = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'float32' }); - > var fromIndex = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' }); - > {{alias}}( [ x, searchElement, fromIndex ] ) + > var v = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': dt } ); + > var i = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' } ); + > {{alias}}( [ x, v, i ] ) 1 See Also From 1b1ee40ae5bf26fdc3c10a8ef8e4b4155f3d24ee Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Jun 2025 23:17:21 -0700 Subject: [PATCH 16/16] docs: add note Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt index 4b98e24e38cd..07304b0db424 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/sindex-of/docs/repl.txt @@ -3,6 +3,10 @@ Returns the first index of a search element in a one-dimensional single- precision floating-point ndarray. + If a specified starting search index is negative, the function resolves the + starting search index by counting backward from the last element (where `-1` + refers to the last element). + Parameters ---------- arrays: ArrayLikeObject