diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/README.md b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/README.md new file mode 100644 index 000000000000..d501ea777bcc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/README.md @@ -0,0 +1,186 @@ + + +# glastIndexOfFalsy + +> Return the index of the last falsy element in a strided array. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var glastIndexOfFalsy = require( '@stdlib/blas/ext/base/glast-index-of-falsy' ); +``` + +#### glastIndexOfFalsy( N, x, strideX ) + +Returns the index of the last falsy element in a strided array. + +```javascript +var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; + +var idx = glastIndexOfFalsy( x.length, x, 1 ); +// returns 4 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input array. +- **strideX**: stride length. + +If the function is unable to find a falsy element, the function returns `-1`. + +```javascript +var x = [ 1.0, 2.0, 3.0, 4.0 ]; + +var idx = glastIndexOfFalsy( x.length, 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 = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; + +var idx = glastIndexOfFalsy( 4, 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( [ 1.0, 3.0, 1.0, 0.0, 2.0, 1.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find index... +var idx = glastIndexOfFalsy( 3, x1, 2 ); +// returns 1 +``` + +#### glastIndexOfFalsy.ndarray( N, x, strideX, offsetX ) + +Returns the index of the last falsy element in a strided array using alternative indexing semantics. + +```javascript +var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; + +var idx = glastIndexOfFalsy.ndarray( x.length, x, 1, 0 ); +// returns 4 +``` + +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 = [ 1.0, 3.0, 0.0, 2.0, 4.0, 1.0, 3.0, 0.0 ]; + +var idx = glastIndexOfFalsy.ndarray( 3, x, 1, x.length-3 ); +// returns 2 +``` + +
+ + + + + +
+ +## Notes + +- If unable to find a falsy element, both functions return `-1`. +- 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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var glastIndexOfFalsy = require( '@stdlib/blas/ext/base/glast-index-of-falsy' ); + +var x = bernoulli( 10, 0.7, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = glastIndexOfFalsy( x.length, x, 1 ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/benchmark/benchmark.js new file mode 100644 index 000000000000..e12206309440 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ones = require( '@stdlib/array/ones' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var glastIndexOfFalsy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = ones( 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 = glastIndexOfFalsy( x.length, 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( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..0dcd561c08ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/benchmark/benchmark.ndarray.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 ones = require( '@stdlib/array/ones' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var glastIndexOfFalsy = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = ones( 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 = glastIndexOfFalsy( x.length, 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( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/repl.txt new file mode 100644 index 000000000000..d306a5a2193b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/repl.txt @@ -0,0 +1,70 @@ + +{{alias}}( N, x, strideX ) + Returns the index of the last falsy 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. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + > var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ]; + > var idx = {{alias}}( x.length, x, 1 ) + 4 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Returns the index of the last falsy 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. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + > var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0 ]; + > var idx = {{alias}}.ndarray( x.length, x, 1, 0 ) + 4 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/types/index.d.ts new file mode 100644 index 000000000000..fb1af7939758 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/types/index.d.ts @@ -0,0 +1,105 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 `glastIndexOfFalsy`. +*/ +interface Routine { + /** + * Returns the index of the last falsy element in a strided array. + * + * ## Notes + * + * - If unable to find a falsy element, the function returns `-1`. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @returns index + * + * @example + * var x = [ 0.0, 2.0, 0.0, 1.0 ]; + * + * var idx = glastIndexOfFalsy( x.length, x, 1 ); + * // returns 2 + */ + ( N: number, x: InputArray, strideX: number ): number; + + /** + * Returns the index of the last falsy element in a strided array using alternative indexing semantics. + * + * ## Notes + * + * - If unable to find a falsy element, the function returns `-1`. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns index + * + * @example + * var x = [ 0.0, 2.0, 0.0, 1.0 ]; + * + * var idx = glastIndexOfFalsy.ndarray( x.length, x, 1, 0 ); + * // returns 2 + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Returns the index of the last falsy element in a strided array. +* +* ## Notes +* +* - If unable to find a falsy element, the function returns `-1`. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length +* @returns index +* +* @example +* var x = [ 0.0, 2.0, 0.0, 1.0 ]; +* +* var idx = glastIndexOfFalsy( x.length, x, 1 ); +* // returns 2 +* +* @example +* var x = [ 0.0, 2.0, 0.0, 1.0 ]; +* +* var idx = glastIndexOfFalsy.ndarray( x.length, x, 1, 0 ); +* // returns 2 +*/ +declare var glastIndexOfFalsy: Routine; + + +// EXPORTS // + +export = glastIndexOfFalsy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/types/test.ts new file mode 100644 index 000000000000..a8a4aea7f3fe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/docs/types/test.ts @@ -0,0 +1,129 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 glastIndexOfFalsy = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + glastIndexOfFalsy( x.length, x, 1 ); // $ExpectType number + glastIndexOfFalsy( x.length, 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 ]; + + glastIndexOfFalsy( '1', x, 1 ); // $ExpectError + glastIndexOfFalsy( true, x, 1 ); // $ExpectError + glastIndexOfFalsy( false, x, 1 ); // $ExpectError + glastIndexOfFalsy( null, x, 1 ); // $ExpectError + glastIndexOfFalsy( {}, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + glastIndexOfFalsy( x.length, 1, 1 ); // $ExpectError + glastIndexOfFalsy( x.length, true, 1 ); // $ExpectError + glastIndexOfFalsy( x.length, false, 1 ); // $ExpectError + glastIndexOfFalsy( x.length, null, 1 ); // $ExpectError + glastIndexOfFalsy( x.length, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + glastIndexOfFalsy( x.length, x, '1' ); // $ExpectError + glastIndexOfFalsy( x.length, x, true ); // $ExpectError + glastIndexOfFalsy( x.length, x, false ); // $ExpectError + glastIndexOfFalsy( x.length, x, null ); // $ExpectError + glastIndexOfFalsy( x.length, x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + glastIndexOfFalsy(); // $ExpectError + glastIndexOfFalsy( 3 ); // $ExpectError + glastIndexOfFalsy( 3, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + glastIndexOfFalsy( 3, [ 1.0, 2.0, 3.0 ], 1, {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + glastIndexOfFalsy.ndarray( x.length, x, 1, 0 ); // $ExpectType number + glastIndexOfFalsy.ndarray( x.length, 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 ]; + + glastIndexOfFalsy.ndarray( '1', x, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( true, x, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( false, x, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( null, x, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( {}, x, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + glastIndexOfFalsy.ndarray( x.length, 1, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, true, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, false, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, null, 1, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, {}, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + glastIndexOfFalsy.ndarray( x.length, x, '1', 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, true, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, false, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, null, 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, {}, 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 ]; + + glastIndexOfFalsy.ndarray( x.length, x, 1, '1' ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, 1, true ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, 1, false ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, 1, null ); // $ExpectError + glastIndexOfFalsy.ndarray( x.length, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + glastIndexOfFalsy.ndarray(); // $ExpectError + glastIndexOfFalsy.ndarray( 3 ); // $ExpectError + glastIndexOfFalsy.ndarray( 3, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + glastIndexOfFalsy.ndarray( 3, [ 1.0, 2.0, 3.0 ], 1 ); // $ExpectError + glastIndexOfFalsy.ndarray( 3, [ 1.0, 2.0, 3.0 ], 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/examples/index.js new file mode 100644 index 000000000000..a225d9205895 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var glastIndexOfFalsy = require( './../lib' ); + +var x = bernoulli( 10, 0.7, { + 'dtype': 'generic' +}); +console.log( x ); + +var idx = glastIndexOfFalsy( x.length, x, 1 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/index.js new file mode 100644 index 000000000000..4a6374435700 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 index of the last falsy element in a strided array. +* +* @module @stdlib/blas/ext/base/glast-index-of-falsy +* +* @example +* var glastIndexOfFalsy = require( '@stdlib/blas/ext/base/glast-index-of-falsy' ); +* +* var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; +* +* var idx = glastIndexOfFalsy( x.length, x, 1 ); +* // returns 4 +* +* @example +* var glastIndexOfFalsy = require( '@stdlib/blas/ext/base/glast-index-of-falsy' ); +* +* var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; +* +* var idx = glastIndexOfFalsy.ndarray( x.length, x, 1, 0 ); +* // returns 4 +*/ + +// 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-falsy/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/main.js new file mode 100644 index 000000000000..6aea672e4c17 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/main.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 index of the last falsy element in a strided array. +* +* ## Notes +* +* - If unable to find a falsy element, the function returns `-1`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {integer} index +* +* @example +* var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; +* +* var idx = glastIndexOfFalsy( x.length, x, 1 ); +* // returns 4 +*/ +function glastIndexOfFalsy( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = glastIndexOfFalsy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/ndarray.js new file mode 100644 index 000000000000..79d672073976 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/lib/ndarray.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 gindexOfFalsy = require( '@stdlib/blas/ext/base/gindex-of-falsy' ).ndarray; + + +// MAIN // + +/** +* Returns the index of the last falsy element in a strided array using alternative indexing semantics. +* +* ## Notes +* +* - If unable to find a falsy element, the function returns `-1`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {integer} index +* +* @example +* var x = [ 1.0, 3.0, 0.0, 2.0, 0.0, 4.0, 1.0, 3.0 ]; +* +* var idx = glastIndexOfFalsy( x.length, x, 1, 0 ); +* // returns 4 +*/ +function glastIndexOfFalsy( N, 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 first falsy element in the reversed "view": + idx = gindexOfFalsy( N, x, strideX, offsetX ); + if ( idx < 0 ) { + return idx; + } + // Convert the index from reversed "view" to an index in the original "view": + return N - 1 - idx; +} + + +// EXPORTS // + +module.exports = glastIndexOfFalsy; diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/package.json b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/package.json new file mode 100644 index 000000000000..d525f4426f3d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/glast-index-of-falsy", + "version": "0.0.0", + "description": "Return the index of the last falsy 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", + "falsy", + "get", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.js new file mode 100644 index 000000000000..e89114099d2e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 glastIndexOfFalsy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfFalsy, '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 glastIndexOfFalsy.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.main.js new file mode 100644 index 000000000000..806e8fffbe33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.main.js @@ -0,0 +1,157 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 glastIndexOfFalsy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfFalsy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( glastIndexOfFalsy.length, 3, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the last falsy element', function test( t ) { + var actual; + var x; + + x = [ 2.0, 0.0, 3.0, 0.0, 0.0, 4.0 ]; + + // Nonnegative stride... + actual = glastIndexOfFalsy( x.length, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOfFalsy( x.length, x, -1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, -2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the last falsy element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 0.0, 3.0, 0.0, 0.0, 4.0 ] ); + + // Nonnegative stride... + actual = glastIndexOfFalsy( x.length, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOfFalsy( x.length, x, -1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, -2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function ignores truthy elements (e.g., non-zero values)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 0.0, 5.0, 0.0, 2.0 ]; + + actual = glastIndexOfFalsy( x.length, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function ignores truthy elements (e.g., non-zero values) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 0.0, 5.0, 0.0, 2.0 ] ); + + actual = glastIndexOfFalsy( x.length, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if unable to find a falsy element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + + actual = glastIndexOfFalsy( x.length, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if unable to find a falsy element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0 ] ); + + actual = glastIndexOfFalsy( x.length, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter which is less than or equal to zero', function test( t ) { + var actual; + + actual = glastIndexOfFalsy( 0, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOfFalsy( -1, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter which is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = glastIndexOfFalsy( 0, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOfFalsy( -1, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.ndarray.js new file mode 100644 index 000000000000..fb34329438e4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/glast-index-of-falsy/test/test.ndarray.js @@ -0,0 +1,199 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 glastIndexOfFalsy = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof glastIndexOfFalsy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( glastIndexOfFalsy.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the last falsy element', function test( t ) { + var actual; + var x; + + x = [ 2.0, 0.0, 3.0, 0.0, 0.0, 4.0 ]; + + // Nonnegative stride... + actual = glastIndexOfFalsy( x.length, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( x.length-1, x, 1, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOfFalsy( x.length-2, x, 1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOfFalsy( 1, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOfFalsy( x.length, x, -1, x.length-1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, -2, x.length-1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, -2, x.length-2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the last falsy element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 0.0, 3.0, 0.0, 0.0, 4.0 ] ); + + // Nonnegative stride... + actual = glastIndexOfFalsy( x.length, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( x.length-1, x, 1, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + actual = glastIndexOfFalsy( x.length-2, x, 1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOfFalsy( 1, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + // Negative stride... + actual = glastIndexOfFalsy( x.length, x, -1, x.length-1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, -2, x.length-1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = glastIndexOfFalsy( 3, x, -2, x.length-2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter', function test( t ) { + var actual; + var x; + + x = [ 0.0, 2.0, 3.0, 0.0, 4.0, 0.0 ]; + + actual = glastIndexOfFalsy( 3, x, 1, 3 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 0.0, 2.0, 3.0, 0.0, 4.0, 0.0 ] ); + + actual = glastIndexOfFalsy( 3, x, 1, 3 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function ignores truthy elements (e.g., non-zero values)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 0.0, 5.0, 0.0, 2.0 ]; + + actual = glastIndexOfFalsy( x.length, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function ignores truthy elements (e.g., non-zero values) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 0.0, 5.0, 0.0, 2.0 ] ); + + actual = glastIndexOfFalsy( x.length, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if unable to find a falsy element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0 ]; + + actual = glastIndexOfFalsy( x.length, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if unable to find a falsy element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0 ] ); + + actual = glastIndexOfFalsy( x.length, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an `N` parameter which is less than or equal to zero', function test( t ) { + var actual; + + actual = glastIndexOfFalsy( 0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOfFalsy( -1, [ 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 which is less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = glastIndexOfFalsy( 0, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = glastIndexOfFalsy( -1, toAccessorArray( [ 1.0, 2.0, 3.0 ] ), 1, 0 ); // eslint-disable-line max-len + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +});