diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/README.md b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/README.md new file mode 100644 index 000000000000..31a16e13db0f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/README.md @@ -0,0 +1,187 @@ + + +# glastIndexOf + +> Return the last index of a specified search element in a strided array. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var glastIndexOf = require( '@stdlib/blas/ext/base/glast-index-of' ); +``` + +#### glastIndexOf( N, searchElement, x, strideX ) + +Returns the last 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, 3.0, -1.0 ]; + +var idx = glastIndexOf( x.length, 3.0, x, 1 ); +// returns 6 +``` + +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 = glastIndexOf( 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, 3.0, 4.0, -1.0, 0.0 ]; + +var idx = glastIndexOf( 4, 3.0, x, 2 ); +// returns 2 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ -2.0, 3.0, -6.0, -4.0, 5.0, 3.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find index: +var idx = glastIndexOf( 3, 3.0, x1, 2 ); +// returns 2 +``` + +#### glastIndexOf.ndarray( N, searchElement, x, strideX, offsetX ) + +Returns the last 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, 3.0, -1.0, 0.0 ]; + +var idx = glastIndexOf.ndarray( x.length, 3.0, x, 1, 0 ); +// returns 5 +``` + +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, 0.0, -5.0, 4.0, 3.0, 3.0, -1.0 ]; + +var idx = glastIndexOf.ndarray( 3, 3.0, x, 1, x.length-3 ); +// 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. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var glastIndexOf = require( '@stdlib/blas/ext/base/glast-index-of' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = glastIndexOf.ndarray( x.length, 80.0, x, 1, 0 ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/benchmark/benchmark.js new file mode 100644 index 000000000000..b782b7106100 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-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 glastIndexOf = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'generic' ); + 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 = glastIndexOf( 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/glast-index-of/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..889cb5b1d0ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-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 glastIndexOf = 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, 'generic' ); + 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 = glastIndexOf( 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/glast-index-of/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/repl.txt new file mode 100644 index 000000000000..9113fe0a20ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/repl.txt @@ -0,0 +1,76 @@ + +{{alias}}( N, searchElement, x, strideX ) + Returns the last 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: any + 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, 3.0, x, 1 ) + 6 + + +{{alias}}.ndarray( N, searchElement, x, strideX, offsetX ) + Returns the last 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: any + 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, 3.0, x, 1, 0 ) + 6 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/types/index.d.ts new file mode 100644 index 000000000000..17810334cc3a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/types/index.d.ts @@ -0,0 +1,108 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `glastIndexOf`. +*/ +interface Routine { + /** + * Returns the last index of a specified search element in a strided array. + * + * ## Notes + * + * - If the function is unable to find a search element, the function returns `-1`. + * + * @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 = glastIndexOf( x.length, 2.0, x, 1 ); + * // returns 1 + */ + ( N: number, searchElement: unknown, x: InputArray, strideX: number ): number; + + /** + * Returns the last index of a specified search element in a strided array using alternative indexing semantics. + * + * ## Notes + * + * - If the function is unable to find a search element, the function returns `-1`. + * + * @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 = glastIndexOf.ndarray( x.length, 2.0, x, 1, 0 ); + * // returns 1 + */ + ndarray( N: number, searchElement: unknown, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Returns the last index of a specified search element in a strided array. +* +* ## Notes +* +* - If the function is unable to find a search element, the function returns `-1`. +* +* @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 = glastIndexOf( x.length, 2.0, x, 1 ); +* // returns 1 +* +* @example +* var x = [ 1.0, 2.0, 3.0, 4.0 ]; +* +* var idx = glastIndexOf.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 1 +*/ +declare var glastIndexOf: Routine; + + +// EXPORTS // + +export = glastIndexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/types/test.ts new file mode 100644 index 000000000000..12f2a2547460 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/docs/types/test.ts @@ -0,0 +1,131 @@ +/* +* @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 glastIndexOf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + glastIndexOf( x.length, 2.0, x, 1 ); // $ExpectType number + glastIndexOf( 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 ]; + + glastIndexOf( '1', 2.0, x, 1 ); // $ExpectError + glastIndexOf( true, 2.0, x, 1 ); // $ExpectError + glastIndexOf( false, 2.0, x, 1 ); // $ExpectError + glastIndexOf( null, 2.0, x, 1 ); // $ExpectError + glastIndexOf( {}, 2.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + glastIndexOf( 3, 1.0, 1, 1 ); // $ExpectError + glastIndexOf( 3, 1.0, true, 1 ); // $ExpectError + glastIndexOf( 3, 1.0, false, 1 ); // $ExpectError + glastIndexOf( 3, 1.0, null, 1 ); // $ExpectError + glastIndexOf( 3, 1.0, void 0, 1 ); // $ExpectError + glastIndexOf( 3, 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 ]; + + glastIndexOf( x.length, 2.0, x, '1' ); // $ExpectError + glastIndexOf( x.length, 2.0, x, true ); // $ExpectError + glastIndexOf( x.length, 2.0, x, false ); // $ExpectError + glastIndexOf( x.length, 2.0, x, null ); // $ExpectError + glastIndexOf( x.length, 2.0, x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + glastIndexOf(); // $ExpectError + glastIndexOf( 3, 2.0 ); // $ExpectError + glastIndexOf( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + glastIndexOf( 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 ]; + + glastIndexOf.ndarray( x.length, 2.0, x, 1, 0 ); // $ExpectType number + glastIndexOf.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 ]; + + glastIndexOf.ndarray( '1', 2.0, x, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( true, 2.0, x, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( false, 2.0, x, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( null, 2.0, x, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( {}, 2.0, x, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + glastIndexOf.ndarray( 3, 1.0, 1, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( 3, 1.0, true, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( 3, 1.0, false, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( 3, 1.0, null, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( 3, 1.0, void 0, 1, 1 ); // $ExpectError + glastIndexOf.ndarray( 3, 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 ]; + + glastIndexOf.ndarray( x.length, 2.0, x, '1', 1 ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, true, 1 ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, false, 1 ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, null, 1 ); // $ExpectError + glastIndexOf.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 ]; + + glastIndexOf.ndarray( x.length, 2.0, x, 1, '1' ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, 1, true ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, 1, false ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, 1, null ); // $ExpectError + glastIndexOf.ndarray( x.length, 2.0, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + glastIndexOf.ndarray(); // $ExpectError + glastIndexOf.ndarray( 3, 2.0 ); // $ExpectError + glastIndexOf.ndarray( 3, 2.0, new Float64Array( [ 1.0, 2.0, 3.0 ] ) ); // $ExpectError + glastIndexOf.ndarray( 3, 2.0, new Float64Array( [ 1.0, 2.0, 3.0 ] ), 1 ); // $ExpectError + glastIndexOf.ndarray( 3, 2.0, new Float64Array( [ 1.0, 2.0, 3.0 ] ), 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/examples/index.js new file mode 100644 index 000000000000..fad0ddb94efe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-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 glastIndexOf = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = glastIndexOf.ndarray( x.length, 80.0, x, 1, 0 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/index.js new file mode 100644 index 000000000000..609c672f07c0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-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 last index of a specified search element in a strided array. +* +* @module @stdlib/blas/ext/base/glast-index-of +* +* @example +* var glastIndexOf = require( '@stdlib/blas/ext/base/glast-index-of' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = glastIndexOf( x.length, 3.0, x, 1 ); +* // returns 7 +* +* @example +* var glastIndexOf = require( '@stdlib/blas/ext/base/glast-index-of' ); +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = glastIndexOf.ndarray( x.length, 3.0, x, 1, 0 ); +* // returns 7 +*/ + +// 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/glast-index-of/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/main.js new file mode 100644 index 000000000000..5de90ace2b92 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/main.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the last index of a specified search element in a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {integer} index +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = glastIndexOf( x.length, 3.0, x, 1 ); +* // returns 7 +*/ +function glastIndexOf( N, searchElement, x, strideX ) { + return ndarray( N, searchElement, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = glastIndexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/ndarray.js new file mode 100644 index 000000000000..1cc55de2dfd6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/lib/ndarray.js @@ -0,0 +1,67 @@ +/** +* @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 gindexOf = require( '@stdlib/blas/ext/base/gindex-of' ).ndarray; + + +// MAIN // + +/** +* Returns the last index of a specified search element in a strided array using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {integer} index +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ]; +* +* var idx = glastIndexOf( x.length, 3.0, x, 1, 0 ); +* // returns 7 +*/ +function glastIndexOf( N, searchElement, x, strideX, offsetX ) { + var idx; + + if ( N <= 0 ) { + return -1; + } + // Reverse the iteration order by flipping the stride and adjusting the offset: + offsetX += ( N-1 ) * strideX; + strideX *= -1; + + // Find the index of the search element in the reversed "view": + idx = gindexOf( N, searchElement, x, strideX, offsetX ); + if ( idx < 0 ) { + return idx; + } + // Convert the index from reversed "view" to an index in the original "view": + idx = N - 1 - idx; + return idx; +} + + +// EXPORTS // + +module.exports = glastIndexOf; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/package.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/package.json new file mode 100644 index 000000000000..94b28eb309e2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/base/glast-index-of", + "version": "0.0.0", + "description": "Return the last 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/glast-index-of/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.js new file mode 100644 index 000000000000..c497106ed7a1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-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 glastIndexOf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOf, '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 glastIndexOf.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.main.js new file mode 100644 index 000000000000..c8dcccab256e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.main.js @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var glastIndexOf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the last 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 = glastIndexOf( x.length, 1.0, x, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOf( x.length, 3.0, x, 1 ); + t.strictEqual( actual, 5, 'returns expected value' ); + + actual = glastIndexOf( x.length, 4.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOf( x.length, 1.0, x, -1 ); + t.strictEqual( actual, 5, 'returns expected value' ); + + actual = glastIndexOf( x.length, 2.0, x, -1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOf( x.length, 3.0, x, -1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( x.length, 4.0, x, -1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the last 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 = glastIndexOf( x.length, 1.0, x, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOf( x.length, 3.0, x, 1 ); + t.strictEqual( actual, 5, 'returns expected value' ); + + actual = glastIndexOf( x.length, 4.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOf( x.length, 1.0, x, -1 ); + t.strictEqual( actual, 5, 'returns expected value' ); + + actual = glastIndexOf( x.length, 2.0, x, -1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOf( x.length, 3.0, x, -1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( 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 = glastIndexOf( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOf( -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 `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = glastIndexOf( 0, 2.0, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOf( -1, 2.0, toAccessorArray( [ 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 = glastIndexOf( 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 = glastIndexOf( 1, NaN, toAccessorArray( [ NaN ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.ndarray.js new file mode 100644 index 000000000000..be2665328d63 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of/test/test.ndarray.js @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var glastIndexOf = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the last 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 = glastIndexOf( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( x.length-1, 2.0, x, 1, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOf( x.length-2, 3.0, x, 1, 2 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOf( x.length-2, 4.0, x, 1, 2 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOf( x.length, 1.0, x, -1, x.length-1 ); + t.strictEqual( actual, 5, 'returns expected value' ); + + actual = glastIndexOf( 3, 2.0, x, -2, x.length-1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( 3, 1.0, x, -2, x.length-2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOf( x.length, 4.0, x, -1, x.length-1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the last 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 = glastIndexOf( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( x.length-1, 2.0, x, 1, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOf( x.length-2, 3.0, x, 1, 2 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOf( x.length-2, 4.0, x, 1, 2 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOf( x.length, 1.0, x, -1, x.length-1 ); + t.strictEqual( actual, 5, 'returns expected value' ); + + actual = glastIndexOf( 3, 2.0, x, -2, x.length-1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = glastIndexOf( 3, 1.0, x, -2, x.length-2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOf( 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 = glastIndexOf( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOf( -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 an `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = glastIndexOf( 0, 2.0, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOf( -1, 2.0, toAccessorArray( [ 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 = glastIndexOf( 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 = glastIndexOf( 1, NaN, toAccessorArray( [ NaN ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +});