From 2f6586cb5e1e61c21c33924b10f072d09318c127 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 17 May 2026 22:59:23 +0500 Subject: [PATCH 1/2] feat: add blas/ext/base/gcusome --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/gcusome/README.md | 180 +++++++ .../ext/base/gcusome/benchmark/benchmark.js | 104 ++++ .../gcusome/benchmark/benchmark.ndarray.js | 104 ++++ .../blas/ext/base/gcusome/docs/repl.txt | 118 +++++ .../ext/base/gcusome/docs/types/index.d.ts | 112 +++++ .../blas/ext/base/gcusome/docs/types/test.ts | 268 +++++++++++ .../blas/ext/base/gcusome/examples/index.js | 32 ++ .../blas/ext/base/gcusome/lib/accessors.js | 91 ++++ .../blas/ext/base/gcusome/lib/index.js | 59 +++ .../@stdlib/blas/ext/base/gcusome/lib/main.js | 54 +++ .../blas/ext/base/gcusome/lib/ndarray.js | 88 ++++ .../blas/ext/base/gcusome/package.json | 71 +++ .../blas/ext/base/gcusome/test/test.js | 38 ++ .../blas/ext/base/gcusome/test/test.main.js | 386 +++++++++++++++ .../ext/base/gcusome/test/test.ndarray.js | 446 ++++++++++++++++++ 15 files changed, 2151 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md new file mode 100644 index 000000000000..d1c8e1545b2d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md @@ -0,0 +1,180 @@ + + +# gcusome + +> Cumulatively test whether at least `k` elements in a strided array are truthy. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gcusome = require( '@stdlib/blas/ext/base/gcusome' ); +``` + +#### gcusome( N, k, x, strideX, out, strideOut ) + +Cumulatively tests whether at least `k` elements in a strided array are truthy. + +```javascript +var x = [ 0, 0, 1, 1, 1 ]; +var out = [ false, false, false, false, false ]; + +gcusome( x.length, 2, x, 1, out, 1 ); +// out => [ false, false, false, true, true ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **k**: minimum number of truthy elements. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideOut**: stride length for `out`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to test every other element: + +```javascript +var x = [ 0, 0, 1, 0, 1, 0, 1, 0 ]; +var out = [ false, false, false, false ]; + +gcusome( 4, 2, x, 2, out, 1 ); +// out => [ false, false, true, true ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Uint8Array = require( '@stdlib/array/uint8' ); + +// Initial arrays... +var x0 = new Uint8Array( [ 0, 0, 1, 0, 1, 1 ] ); +var o0 = new Uint8Array( x0.length ); + +// Create offset views... +var x1 = new Uint8Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var o1 = new Uint8Array( o0.buffer, o0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +gcusome( 3, 2, x1, 2, o1, 1 ); +// o0 => [ 0, 0, 0, 0, 0, 0 ] +``` + +#### gcusome.ndarray( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) + +Cumulatively tests whether at least `k` elements in a strided array are truthy using alternative indexing semantics. + +```javascript +var x = [ 0, 0, 1, 1, 1 ]; +var out = [ false, false, false, false, false ]; + +gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); +// out => [ false, false, false, true, true ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetOut**: starting index for `out`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to test every other element starting from the second element and to store results starting from the last element: + +```javascript +var x = [ 0, 0, 1, 1, 1 ]; +var out = [ false, false, false, false, false ]; + +gcusome.ndarray( 3, 2, x, 1, 2, out, -1, out.length-1 ); +// out => [ false, false, true, true, false ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `out` unchanged. +- 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 filled = require( '@stdlib/array/base/filled' ); +var gcusome = require( '@stdlib/blas/ext/base/gcusome' ); + +var x = bernoulli( 10, 0.5, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = filled( false, x.length ); +gcusome( x.length, 2, x, 1, out, 1 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js new file mode 100644 index 000000000000..229fb56300d8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js @@ -0,0 +1,104 @@ +/** +* @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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var filled = require( '@stdlib/array/base/filled' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcusome = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = filled( false, len ); + var x = bernoulli( len, 0.5, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = gcusome( len, len-1, x, 1, out, 1 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + 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/gcusome/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..dabf1d72c2b9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js @@ -0,0 +1,104 @@ +/** +* @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 bernoulli = require( '@stdlib/random/array/bernoulli' ); +var filled = require( '@stdlib/array/base/filled' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gcusome = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out = filled( false, len ); + var x = bernoulli( len, 0.5, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = gcusome( len, len-1, x, 1, 0, out, 1, 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + 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/gcusome/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt new file mode 100644 index 000000000000..1d06eee6741f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt @@ -0,0 +1,118 @@ + +{{alias}}( N, k, x, strideX, out, strideOut ) + Cumulatively tests whether at least `k` elements in a strided array are + truthy. + + The `N` and stride parameters determine which elements in the strided arrays + 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 `out` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Minimum number of truthy elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + out: ArrayLikeObject + Output array. + + strideOut: integer + Stride length for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 0, 0, 1, 1, 1 ]; + > var out = [ false, false, false, false, false ]; + > {{alias}}( x.length, 2, x, 1, out, 1 ) + [ false, false, false, true, true ] + + // Using `N` and stride parameters: + > x = [ 0, 1, 0, 1, 0, 1 ]; + > out = [ false, false, false ]; + > {{alias}}( 3, 2, x, 2, out, 1 ) + [ false, false, false ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/uint8}}( [ 0, 0, 1, 0, 1, 1 ] ); + > var o0 = new {{alias:@stdlib/array/uint8}}( x0.length ); + > var x1 = new {{alias:@stdlib/array/uint8}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var o1 = new {{alias:@stdlib/array/uint8}}( o0.buffer, o0.BYTES_PER_ELEMENT*3 ); + > {{alias}}( 3, 2, x1, 2, o1, 1 ) + [ 0, 0, 0 ] + > o0 + [ 0, 0, 0, 0, 0, 0 ] + + +{{alias}}.ndarray( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) + Cumulatively tests whether at least `k` elements in a strided array are + truthy using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + k: integer + Minimum number of truthy elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + out: ArrayLikeObject + Output array. + + strideOut: integer + Stride length for `out`. + + offsetOut: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + // Standard Usage: + > var x = [ 0, 0, 1, 1, 1 ]; + > var out = [ false, false, false, false, false ]; + > {{alias}}.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ) + [ false, false, false, true, true ] + + // Advanced indexing: + > x = [ 0, 0, 1, 1, 1 ]; + > out = [ false, false, false, false, false ]; + > {{alias}}.ndarray( 3, 2, x, 1, 2, out, -1, out.length-1 ) + [ false, false, true, true, false ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts new file mode 100644 index 000000000000..75e9fd219a2a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts @@ -0,0 +1,112 @@ +/* +* @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; + +/** +* Output array. +*/ +type OutputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gcusome`. +*/ +interface Routine { + /** + * Cumulatively tests whether at least `k` elements in a strided array are truthy. + * + * @param N - number of indexed elements + * @param k - minimum number of truthy elements + * @param x - input array + * @param strideX - stride length for `x` + * @param out - output array + * @param strideOut - stride length for `out` + * @returns output array + * + * @example + * var x = [ 0, 0, 1, 1, 1 ]; + * var out = [ false, false, false, false, false ]; + * + * gcusome( x.length, 2, x, 1, out, 1 ); + * // out => [ false, false, false, true, true ] + */ + = OutputArray>( N: number, k: number, x: InputArray, strideX: number, out: U, strideOut: number ): U; + + /** + * Cumulatively tests whether at least `k` elements in a strided array are truthy using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param k - minimum number of truthy elements + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var x = [ 0, 0, 1, 1, 1 ]; + * var out = [ false, false, false, false, false ]; + * + * gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); + * // out => [ false, false, false, true, true ] + */ + ndarray = OutputArray>( N: number, k: number, x: InputArray, strideX: number, offsetX: number, out: U, strideOut: number, offsetOut: number ): U; +} + +/** +* Cumulatively tests whether at least `k` elements in a strided array are truthy. +* +* @param N - number of indexed elements +* @param k - minimum number of truthy elements +* @param x - input array +* @param strideX - stride length for `x` +* @param out - output array +* @param strideOut - stride length for `out` +* @returns output array +* +* @example +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome( x.length, 2, x, 1, out, 1 ); +* // out => [ false, false, false, true, true ] +* +* @example +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); +* // out => [ false, false, false, true, true ] +*/ +declare var gcusome: Routine; + + +// EXPORTS // + +export = gcusome; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts new file mode 100644 index 000000000000..a7a5097fc0d5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts @@ -0,0 +1,268 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import gcusome = require( './index' ); + + +// TESTS // + +// The function returns an output array... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome( x.length, 2, x, 1, out, 1 ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome( '10', 2, x, 1, out, 1 ); // $ExpectError + gcusome( true, 2, x, 1, out, 1 ); // $ExpectError + gcusome( false, 2, x, 1, out, 1 ); // $ExpectError + gcusome( null, 2, x, 1, out, 1 ); // $ExpectError + gcusome( undefined, 2, x, 1, out, 1 ); // $ExpectError + gcusome( [], 2, x, 1, out, 1 ); // $ExpectError + gcusome( {}, 2, x, 1, out, 1 ); // $ExpectError + gcusome( ( x: number ): number => x, 2, x, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome( x.length, '10', x, 1, out, 1 ); // $ExpectError + gcusome( x.length, true, x, 1, out, 1 ); // $ExpectError + gcusome( x.length, false, x, 1, out, 1 ); // $ExpectError + gcusome( x.length, null, x, 1, out, 1 ); // $ExpectError + gcusome( x.length, undefined, x, 1, out, 1 ); // $ExpectError + gcusome( x.length, [], x, 1, out, 1 ); // $ExpectError + gcusome( x.length, {}, x, 1, out, 1 ); // $ExpectError + gcusome( x.length, ( x: number ): number => x, x, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + const out = [ false, false, false, false ]; + + gcusome( 4, 2, 10, 1, out, 1 ); // $ExpectError + gcusome( 4, 2, true, 1, out, 1 ); // $ExpectError + gcusome( 4, 2, false, 1, out, 1 ); // $ExpectError + gcusome( 4, 2, null, 1, out, 1 ); // $ExpectError + gcusome( 4, 2, undefined, 1, out, 1 ); // $ExpectError + gcusome( 4, 2, {}, 1, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome( x.length, 2, x, '10', out, 1 ); // $ExpectError + gcusome( x.length, 2, x, true, out, 1 ); // $ExpectError + gcusome( x.length, 2, x, false, out, 1 ); // $ExpectError + gcusome( x.length, 2, x, null, out, 1 ); // $ExpectError + gcusome( x.length, 2, x, undefined, out, 1 ); // $ExpectError + gcusome( x.length, 2, x, [], out, 1 ); // $ExpectError + gcusome( x.length, 2, x, {}, out, 1 ); // $ExpectError + gcusome( x.length, 2, x, ( x: number ): number => x, out, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const x = [ 0, 0, 1, 1 ]; + + gcusome( x.length, 2, x, 1, 10, 1 ); // $ExpectError + gcusome( x.length, 2, x, 1, true, 1 ); // $ExpectError + gcusome( x.length, 2, x, 1, false, 1 ); // $ExpectError + gcusome( x.length, 2, x, 1, null, 1 ); // $ExpectError + gcusome( x.length, 2, x, 1, undefined, 1 ); // $ExpectError + gcusome( x.length, 2, x, 1, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome( x.length, 2, x, 1, out, '10' ); // $ExpectError + gcusome( x.length, 2, x, 1, out, true ); // $ExpectError + gcusome( x.length, 2, x, 1, out, false ); // $ExpectError + gcusome( x.length, 2, x, 1, out, null ); // $ExpectError + gcusome( x.length, 2, x, 1, out, undefined ); // $ExpectError + gcusome( x.length, 2, x, 1, out, [] ); // $ExpectError + gcusome( x.length, 2, x, 1, out, {} ); // $ExpectError + gcusome( x.length, 2, x, 1, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome(); // $ExpectError + gcusome( x.length ); // $ExpectError + gcusome( x.length, 2 ); // $ExpectError + gcusome( x.length, 2, x ); // $ExpectError + gcusome( x.length, 2, x, 1 ); // $ExpectError + gcusome( x.length, 2, x, 1, out ); // $ExpectError + gcusome( x.length, 2, x, 1, out, 1, 10 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns an output array... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); // $ExpectType boolean[] +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( '10', 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( true, 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( false, 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( null, 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( undefined, 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( [], 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( {}, 2, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( ( x: number ): number => x, 2, x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( x.length, '10', x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, true, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, false, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, null, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, undefined, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, [], x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, {}, x, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, ( x: number ): number => x, x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + const out = [ false, false, false, false ]; + + gcusome.ndarray( 4, 2, 10, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( 4, 2, true, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( 4, 2, false, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( 4, 2, null, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( 4, 2, undefined, 1, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( 4, 2, {}, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( x.length, 2, x, '10', 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, true, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, false, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, null, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, undefined, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, [], 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, {}, 0, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( x.length, 2, x, 1, '10', out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, true, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, false, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, null, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, undefined, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, [], out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, {}, out, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a collection... +{ + const x = [ 0, 0, 1, 1 ]; + + gcusome.ndarray( x.length, 2, x, 1, 0, 10, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, true, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, false, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, null, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, undefined, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( x.length, 2, x, 1, 0, out, '10', 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, true, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, false, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, null, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, undefined, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, [], 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, {}, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, '10' ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, true ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, false ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, null ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, undefined ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, [] ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, {} ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = [ 0, 0, 1, 1 ]; + const out = [ false, false, false, false ]; + + gcusome.ndarray(); // $ExpectError + gcusome.ndarray( x.length ); // $ExpectError + gcusome.ndarray( x.length, 2 ); // $ExpectError + gcusome.ndarray( x.length, 2, x ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1 ); // $ExpectError + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/examples/index.js new file mode 100644 index 000000000000..76e78b99f9b0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 filled = require( '@stdlib/array/base/filled' ); +var gcusome = require( './../lib' ); + +var x = bernoulli( 10, 0.5, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = filled( false, x.length ); +gcusome( x.length, 2, x, 1, out, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js new file mode 100644 index 000000000000..3b24a2962e05 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js @@ -0,0 +1,91 @@ +/** +* @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'; + +// MAIN // + +/** +* Cumulatively tests whether at least `k` elements in a strided array are truthy. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} k - minimum number of truthy elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} out - output array object +* @param {Collection} out.data - output array data +* @param {Array} out.accessors - array element accessors +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Object} output array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome( 5, 2, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( out ) ), 1, 0 ); +* // out => [ false, false, false, true, true ] +*/ +function gcusome( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) { + var xbuf; + var obuf; + var get; + var set; + var flg; + var cnt; + var ix; + var io; + var i; + + // Cache reference to array data: + xbuf = x.data; + obuf = out.data; + + // Cache reference to the element accessors: + get = x.accessors[ 0 ]; + set = out.accessors[ 1 ]; + + flg = ( k <= 0 ); + cnt = k; + ix = offsetX; + io = offsetOut; + for ( i = 0; i < N; i++ ) { + if ( !flg && get( xbuf, ix ) ) { + cnt -= 1; + if ( cnt <= 0 ) { + flg = true; + } + } + set( obuf, io, flg ); + ix += strideX; + io += strideOut; + } + return out; +} + + +// EXPORTS // + +module.exports = gcusome; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/index.js new file mode 100644 index 000000000000..54b9346b604e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/index.js @@ -0,0 +1,59 @@ +/** +* @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'; + +/** +* Cumulatively test whether at least `k` elements in a strided array are truthy. +* +* @module @stdlib/blas/ext/base/gcusome +* +* @example +* var gcusome = require( '@stdlib/blas/ext/base/gcusome' ); +* +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome( x.length, 2, x, 1, out, 1 ); +* // out => [ false, false, false, true, true ] +* +* @example +* var gcusome = require( '@stdlib/blas/ext/base/gcusome' ); +* +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); +* // out => [ false, false, false, true, true ] +*/ + +// 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/gcusome/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/main.js new file mode 100644 index 000000000000..761017d75242 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/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 // + +/** +* Cumulatively tests whether at least `k` elements in a strided array are truthy. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} k - minimum number of truthy elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @returns {Collection} output array +* +* @example +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome( x.length, 2, x, 1, out, 1 ); +* // out => [ false, false, false, true, true ] +*/ +function gcusome( N, k, x, strideX, out, strideOut ) { + return ndarray( N, k, x, strideX, stride2offset( N, strideX ), out, strideOut, stride2offset( N, strideOut ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gcusome; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js new file mode 100644 index 000000000000..5088674e1697 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js @@ -0,0 +1,88 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least `k` elements in a strided array are truthy using alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {integer} k - minimum number of truthy elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output array +* +* @example +* var x = [ 0, 0, 1, 1, 1 ]; +* var out = [ false, false, false, false, false ]; +* +* gcusome( 5, 2, x, 1, 0, out, 1, 0 ); +* // out => [ false, false, false, true, true ] +*/ +function gcusome( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) { + var flg; + var cnt; + var xo; + var oo; + var ix; + var io; + var i; + + if ( N <= 0 ) { + return out; + } + xo = arraylike2object( x ); + oo = arraylike2object( out ); + if ( xo.accessorProtocol || oo.accessorProtocol ) { + accessors( N, k, xo, strideX, offsetX, oo, strideOut, offsetOut ); + return out; + } + flg = ( k <= 0 ); + cnt = k; + ix = offsetX; + io = offsetOut; + for ( i = 0; i < N; i++ ) { + if ( !flg && x[ ix ] ) { + cnt -= 1; + if ( cnt <= 0 ) { + flg = true; + } + } + out[ io ] = flg; + ix += strideX; + io += strideOut; + } + return out; +} + + +// EXPORTS // + +module.exports = gcusome; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/package.json b/lib/node_modules/@stdlib/blas/ext/base/gcusome/package.json new file mode 100644 index 000000000000..3cc593d625d1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/blas/ext/base/gcusome", + "version": "0.0.0", + "description": "Cumulatively test whether at least k elements in a strided array are truthy.", + "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", + "cumulative", + "some", + "truthy", + "test", + "strided", + "strided array", + "typed", + "array", + "ndarray", + "vector", + "gcusome" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.js new file mode 100644 index 000000000000..3c4dd33e5820 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/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 gcusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcusome, '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 gcusome.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js new file mode 100644 index 000000000000..9f6f7c4a2e24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js @@ -0,0 +1,386 @@ +/** +* @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 gcusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gcusome.length, 6, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 0, 0, 1, 1, 1 ]; + y = [ false, false, false, false, false ]; + + out = gcusome( x.length, 2, x, 1, y, 1 ); + + t.strictEqual( out, y, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 0, 0, 1, 1, 1 ]; + y = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + out = gcusome( 0, 2, x, 1, y, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = gcusome( -4, 2, x, 1, y, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ 0, 0, 1, 1, 1 ]; + y = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + gcusome( 0, 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + gcusome( -4, 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `k` elements are truthy', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, false, true, true ]; + + gcusome( x.length, 2, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 0, 0, 1, 1, 1 ]; + out = [ false, false, false, false, false ]; + expected = [ false, false, false, true, true ]; + + gcusome( x.length, 2, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1, 1, 1, 0, 0 ]; + out = [ false, false, false, false, false ]; + expected = [ false, true, true, true, true ]; + + gcusome( x.length, 2, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 0, 0, 0, 0, 0 ]; + out = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + gcusome( x.length, 2, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `k` elements are truthy (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, false, true, true ]; + + gcusome( x.length, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 0, 0, 0, 0, 0 ]; + out = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + gcusome( x.length, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true`', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ true, true, true ]; + + gcusome( x.length, 0, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ true, true, true ]; + + gcusome( x.length, 0, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` greater than `N`, the function returns an output array where all elements are `false`', function test( t ) { + var expected; + var out; + var x; + + x = [ 1, 1, 1 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 5, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` greater than `N`, the function returns an output array where all elements are `false` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1, 1, 1 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 5, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 0 + 999, + 0, // 1 + 999, + 1, // 2 + 999, + 1 // 3 + ]; + out = [ false, false, false, false ]; + expected = [ false, false, false, true ]; + + gcusome( 4, 2, x, 2, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 0 + 999, + 0, // 1 + 999, + 1, // 2 + 999, + 1 // 3 + ]; + out = [ false, false, false, false ]; + expected = [ false, false, false, true ]; + + gcusome( 4, 2, toAccessorArray( x ), 2, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `out` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ + false, // 0 + 999, + false, // 1 + 999, + false, // 2 + 999, + false // 3 + ]; + expected = [ + false, + 999, + false, + 999, + true, + 999, + true + ]; + + gcusome( 4, 2, x, 1, out, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `out` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ + false, // 0 + 999, + false, // 1 + 999, + false, // 2 + 999, + false // 3 + ]; + expected = [ + false, + 999, + false, + 999, + true, + 999, + true + ]; + + gcusome( 4, 2, toAccessorArray( x ), 1, toAccessorArray( out ), 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 3 + 0, // 2 + 1, // 1 + 1 // 0 + ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( 4, 2, x, -1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 3 + 0, // 2 + 1, // 1 + 1 // 0 + ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( 4, 2, toAccessorArray( x ), -1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `out` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ true, true, false, false ]; + + gcusome( 4, 2, x, 1, out, -1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `out` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ true, true, false, false ]; + + gcusome( 4, 2, toAccessorArray( x ), 1, toAccessorArray( out ), -1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js new file mode 100644 index 000000000000..bfb099ea8eef --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js @@ -0,0 +1,446 @@ +/** +* @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 gcusome = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gcusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gcusome.length, 8, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array', function test( t ) { + var out; + var x; + var y; + + x = [ 0, 0, 1, 1, 1 ]; + y = [ false, false, false, false, false ]; + + out = gcusome( x.length, 2, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { + var expected; + var out; + var x; + var y; + + x = [ 0, 0, 1, 1, 1 ]; + y = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + out = gcusome( 0, 2, x, 1, 0, y, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + out = gcusome( -4, 2, x, 1, 0, y, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged (accessors)', function test( t ) { + var expected; + var x; + var y; + + x = [ 0, 0, 1, 1, 1 ]; + y = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + gcusome( 0, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + gcusome( -4, 2, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + t.deepEqual( y, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `k` elements are truthy', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, false, true, true ]; + + gcusome( x.length, 2, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 0, 0, 1, 1, 1 ]; + out = [ false, false, false, false, false ]; + expected = [ false, false, false, true, true ]; + + gcusome( x.length, 2, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 1, 1, 1, 0, 0 ]; + out = [ false, false, false, false, false ]; + expected = [ false, true, true, true, true ]; + + gcusome( x.length, 2, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 0, 0, 0, 0, 0 ]; + out = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + gcusome( x.length, 2, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `k` elements are truthy (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, false, true, true ]; + + gcusome( x.length, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + x = [ 0, 0, 0, 0, 0 ]; + out = [ false, false, false, false, false ]; + expected = [ false, false, false, false, false ]; + + gcusome( x.length, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true`', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ true, true, true ]; + + gcusome( x.length, 0, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ true, true, true ]; + + gcusome( x.length, 0, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` greater than `N`, the function returns an output array where all elements are `false`', function test( t ) { + var expected; + var out; + var x; + + x = [ 1, 1, 1 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 5, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `k` greater than `N`, the function returns an output array where all elements are `false` (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 1, 1, 1 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 5, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 0 + 999, + 0, // 1 + 999, + 1, // 2 + 999, + 1 // 3 + ]; + out = [ false, false, false, false ]; + expected = [ false, false, false, true ]; + + gcusome( 4, 2, x, 2, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 0 + 999, + 0, // 1 + 999, + 1, // 2 + 999, + 1 // 3 + ]; + out = [ false, false, false, false ]; + expected = [ false, false, false, true ]; + + gcusome( 4, 2, toAccessorArray( x ), 2, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `out` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ + false, // 0 + 999, + false, // 1 + 999, + false, // 2 + 999, + false // 3 + ]; + expected = [ + false, + 999, + false, + 999, + true, + 999, + true + ]; + + gcusome( 4, 2, x, 1, 0, out, 2, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `out` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ + false, // 0 + 999, + false, // 1 + 999, + false, // 2 + 999, + false // 3 + ]; + expected = [ + false, + 999, + false, + 999, + true, + 999, + true + ]; + + gcusome( 4, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 2, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 3 + 0, // 2 + 1, // 1 + 1 // 0 + ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( 4, 2, x, -1, 3, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ + 0, // 3 + 0, // 2 + 1, // 1 + 1 // 0 + ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( 4, 2, toAccessorArray( x ), -1, 3, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `out` stride', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ true, true, false, false ]; + + gcusome( 4, 2, x, 1, 0, out, -1, 3 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `out` stride (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1, 1 ]; + out = [ false, false, false, false ]; + expected = [ true, true, false, false ]; + + gcusome( 4, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), -1, 3 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 0, 1, 1, 1 ]; + out = [ false, false, false ]; + expected = [ false, true, true ]; + + gcusome( 3, 2, x, 1, 2, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 0, 1, 1, 1 ]; + out = [ false, false, false ]; + expected = [ false, true, true ]; + + gcusome( 3, 2, toAccessorArray( x ), 1, 2, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `out` offset', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1 ]; + out = [ 999, 999, false, false, false ]; + expected = [ 999, 999, false, false, true ]; + + gcusome( 3, 2, x, 1, 0, out, 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `out` offset (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 1 ]; + out = [ 999, 999, false, false, false ]; + expected = [ 999, 999, false, false, true ]; + + gcusome( 3, 2, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 2 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); From 581c0950bbd961dc59d5d9c19971ac264ef5d18d Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 19 May 2026 00:44:18 +0500 Subject: [PATCH 2/2] refactor: docs, tests, bench --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/gcusome/README.md | 12 +-- .../ext/base/gcusome/benchmark/benchmark.js | 9 +- .../gcusome/benchmark/benchmark.ndarray.js | 9 +- .../blas/ext/base/gcusome/docs/repl.txt | 16 ++-- .../ext/base/gcusome/docs/types/index.d.ts | 6 +- .../blas/ext/base/gcusome/docs/types/test.ts | 16 ++-- .../blas/ext/base/gcusome/lib/accessors.js | 2 +- .../@stdlib/blas/ext/base/gcusome/lib/main.js | 4 +- .../blas/ext/base/gcusome/lib/ndarray.js | 10 +- .../blas/ext/base/gcusome/test/test.main.js | 68 ++++++++++++- .../ext/base/gcusome/test/test.ndarray.js | 96 ++++++++++++++++++- 11 files changed, 201 insertions(+), 47 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md index d1c8e1545b2d..0d0eab4c5001 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/README.md @@ -57,7 +57,7 @@ The function has the following parameters: - **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. - **strideOut**: stride length for `out`. -The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to test every other element: +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to cumulatively test every other element: ```javascript var x = [ 0, 0, 1, 0, 1, 0, 1, 0 ]; @@ -103,14 +103,14 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetOut**: starting index for `out`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to test every other element starting from the second element and to store results starting from the last element: +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to cumulatively test every other element starting from the third element: ```javascript -var x = [ 0, 0, 1, 1, 1 ]; -var out = [ false, false, false, false, false ]; +var x = [ 0, 0, 1, 0, 1, 0, 1, 0 ]; +var out = [ false, false, false ]; -gcusome.ndarray( 3, 2, x, 1, 2, out, -1, out.length-1 ); -// out => [ false, false, true, true, false ] +gcusome.ndarray( 3, 2, x, 2, 2, out, 1, 0 ); +// out => [ false, true, true ] ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js index 229fb56300d8..f79d93cf3a2d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ); var filled = require( '@stdlib/array/base/filled' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); @@ -63,13 +64,13 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { v = gcusome( len, len-1, x, 1, out, 1 ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); + if ( typeof v[ i%len ] !== 'boolean' ) { + b.fail( 'should return boolean' ); } } b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); + if ( !isBoolean( v[ i%len ] ) ) { + b.fail( 'should return boolean' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js index dabf1d72c2b9..9f4f2d9ee9dd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/benchmark/benchmark.ndarray.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ); var filled = require( '@stdlib/array/base/filled' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); @@ -63,13 +64,13 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { v = gcusome( len, len-1, x, 1, 0, out, 1, 0 ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); + if ( typeof v[ i%len ] !== 'boolean' ) { + b.fail( 'should return boolean' ); } } b.toc(); - if ( typeof v !== 'object' ) { - b.fail( 'should return an object' ); + if ( !isBoolean( v[ i%len ] ) ) { + b.fail( 'should return boolean' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt index 1d06eee6741f..c38289155666 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/repl.txt @@ -45,10 +45,10 @@ [ false, false, false, true, true ] // Using `N` and stride parameters: - > x = [ 0, 1, 0, 1, 0, 1 ]; - > out = [ false, false, false ]; - > {{alias}}( 3, 2, x, 2, out, 1 ) - [ false, false, false ] + > x = [ 0, 0, 1, 0, 1, 0, 1, 0 ]; + > out = [ false, false, false, false ]; + > {{alias}}( 4, 2, x, 2, out, 1 ) + [ false, false, true, true ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/uint8}}( [ 0, 0, 1, 0, 1, 1 ] ); @@ -109,10 +109,10 @@ [ false, false, false, true, true ] // Advanced indexing: - > x = [ 0, 0, 1, 1, 1 ]; - > out = [ false, false, false, false, false ]; - > {{alias}}.ndarray( 3, 2, x, 1, 2, out, -1, out.length-1 ) - [ false, false, true, true, false ] + > x = [ 0, 0, 1, 0, 1, 0, 1, 0 ]; + > out = [ false, false, false ]; + > {{alias}}.ndarray( 3, 2, x, 2, 2, out, 1, 0 ) + [ false, true, true ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts index 75e9fd219a2a..461458d236d2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/index.d.ts @@ -25,7 +25,7 @@ import { Collection, AccessorArrayLike } from '@stdlib/types/array'; /** * Input array. */ -type InputArray = Collection | AccessorArrayLike; +type InputArray = Collection | AccessorArrayLike; /** * Output array. @@ -54,7 +54,7 @@ interface Routine { * gcusome( x.length, 2, x, 1, out, 1 ); * // out => [ false, false, false, true, true ] */ - = OutputArray>( N: number, k: number, x: InputArray, strideX: number, out: U, strideOut: number ): U; + = OutputArray>( N: number, k: number, x: InputArray, strideX: number, out: U, strideOut: number ): U; /** * Cumulatively tests whether at least `k` elements in a strided array are truthy using alternative indexing semantics. @@ -76,7 +76,7 @@ interface Routine { * gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); * // out => [ false, false, false, true, true ] */ - ndarray = OutputArray>( N: number, k: number, x: InputArray, strideX: number, offsetX: number, out: U, strideOut: number, offsetOut: number ): U; + ndarray = OutputArray>( N: number, k: number, x: InputArray, strideX: number, offsetX: number, out: U, strideOut: number, offsetOut: number ): U; } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts index a7a5097fc0d5..f82501842fb1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/docs/types/test.ts @@ -18,17 +18,20 @@ /* eslint-disable space-in-parens */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import BooleanArray = require( '@stdlib/array/bool' ); import gcusome = require( './index' ); // TESTS // -// The function returns an output array... +// The function returns a boolean array... { const x = [ 0, 0, 1, 1 ]; - const out = [ false, false, false, false ]; + const out = new BooleanArray( 4 ); - gcusome( x.length, 2, x, 1, out, 1 ); // $ExpectType boolean[] + gcusome( x.length, 2, x, 1, out, 1 ); // $ExpectType BooleanArray + gcusome( x.length, 2, new AccessorArray( x ), 1, new AccessorArray( [ false, false, false, false ] ), 1 ); // $ExpectType AccessorArray } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -129,12 +132,13 @@ import gcusome = require( './index' ); gcusome( x.length, 2, x, 1, out, 1, 10 ); // $ExpectError } -// Attached to the main export is an `ndarray` method which returns an output array... +// Attached to the main export is an `ndarray` method which returns a boolean array... { const x = [ 0, 0, 1, 1 ]; - const out = [ false, false, false, false ]; + const out = new BooleanArray( 4 ); - gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); // $ExpectType boolean[] + gcusome.ndarray( x.length, 2, x, 1, 0, out, 1, 0 ); // $ExpectType BooleanArray + gcusome.ndarray( x.length, 2, new AccessorArray( x ), 1, 0, new AccessorArray( [ false, false, false, false ] ), 1, 0 ); // $ExpectType AccessorArray } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js index 3b24a2962e05..50a4667e1200 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/accessors.js @@ -67,7 +67,7 @@ function gcusome( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) { get = x.accessors[ 0 ]; set = out.accessors[ 1 ]; - flg = ( k <= 0 ); + flg = false; cnt = k; ix = offsetX; io = offsetOut; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/main.js index 761017d75242..fc5f1d77b084 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/main.js @@ -45,7 +45,9 @@ var ndarray = require( './ndarray.js' ); * // out => [ false, false, false, true, true ] */ function gcusome( N, k, x, strideX, out, strideOut ) { - return ndarray( N, k, x, strideX, stride2offset( N, strideX ), out, strideOut, stride2offset( N, strideOut ) ); // eslint-disable-line max-len + var ox = stride2offset( N, strideX ); + var oo = stride2offset( N, strideOut ); + return ndarray( N, k, x, strideX, ox, out, strideOut, oo ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js index 5088674e1697..940fc92d27f0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/lib/ndarray.js @@ -49,7 +49,7 @@ var accessors = require( './accessors.js' ); function gcusome( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) { var flg; var cnt; - var xo; + var ox; var oo; var ix; var io; @@ -58,13 +58,13 @@ function gcusome( N, k, x, strideX, offsetX, out, strideOut, offsetOut ) { if ( N <= 0 ) { return out; } - xo = arraylike2object( x ); + ox = arraylike2object( x ); oo = arraylike2object( out ); - if ( xo.accessorProtocol || oo.accessorProtocol ) { - accessors( N, k, xo, strideX, offsetX, oo, strideOut, offsetOut ); + if ( ox.accessorProtocol || oo.accessorProtocol ) { + accessors( N, k, ox, strideX, offsetX, oo, strideOut, offsetOut ); return out; } - flg = ( k <= 0 ); + flg = false; cnt = k; ix = offsetX; io = offsetOut; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js index 9f6f7c4a2e24..1d89155dbc8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.main.js @@ -48,7 +48,21 @@ tape( 'the function returns a reference to the output array', function test( t ) out = gcusome( x.length, 2, x, 1, y, 1 ); - t.strictEqual( out, y, 'returns expected value' ); + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + +tape( 'the function returns a reference to the output array (accessors)', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 0, 0, 1, 1, 1 ] ); + y = toAccessorArray( [ false, false, false, false, false ] ); + + out = gcusome( x.length, 2, x, 1, y, 1 ); + + t.strictEqual( out, y, 'same reference' ); t.end(); }); @@ -147,33 +161,47 @@ tape( 'the function cumulatively tests whether at least `k` elements are truthy t.end(); }); -tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true`', function test( t ) { +tape( 'if provided a `k` equal to `0`, the function sets output elements to `true` upon encountering the first truthy element', function test( t ) { var expected; var out; var x; - x = [ 0, 0, 0 ]; + x = [ 1, 0, 0 ]; out = [ false, false, false ]; expected = [ true, true, true ]; gcusome( x.length, 0, x, 1, out, 1 ); t.deepEqual( out, expected, 'returns expected value' ); + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 0, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); }); -tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true` (accessors)', function test( t ) { +tape( 'if provided a `k` equal to `0`, the function sets output elements to `true` upon encountering the first truthy element (accessors)', function test( t ) { var expected; var out; var x; - x = [ 0, 0, 0 ]; + x = [ 1, 0, 0 ]; out = [ false, false, false ]; expected = [ true, true, true ]; gcusome( x.length, 0, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); t.deepEqual( out, expected, 'returns expected value' ); + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 0, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); }); @@ -207,6 +235,36 @@ tape( 'if provided a `k` greater than `N`, the function returns an output array t.end(); }); +tape( 'the function cumulatively tests whether at least `k` elements are truthy (k=1)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 0, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( x.length, 1, x, 1, out, 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `k` elements are truthy (k=1, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 0, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( x.length, 1, toAccessorArray( x ), 1, toAccessorArray( out ), 1 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an `x` stride', function test( t ) { var expected; var out; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js index bfb099ea8eef..c16964f5ccf9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusome/test/test.ndarray.js @@ -52,6 +52,20 @@ tape( 'the function returns a reference to the output array', function test( t ) t.end(); }); +tape( 'the function returns a reference to the output array (accessors)', function test( t ) { + var out; + var x; + var y; + + x = toAccessorArray( [ 0, 0, 1, 1, 1 ] ); + y = toAccessorArray( [ false, false, false, false, false ] ); + + out = gcusome( x.length, 2, x, 1, 0, y, 1, 0 ); + + t.strictEqual( out, y, 'same reference' ); + t.end(); +}); + tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the output array unchanged', function test( t ) { var expected; var out; @@ -147,33 +161,47 @@ tape( 'the function cumulatively tests whether at least `k` elements are truthy t.end(); }); -tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true`', function test( t ) { +tape( 'if provided a `k` equal to `0`, the function sets output elements to `true` upon encountering the first truthy element', function test( t ) { var expected; var out; var x; - x = [ 0, 0, 0 ]; + x = [ 1, 0, 0 ]; out = [ false, false, false ]; expected = [ true, true, true ]; gcusome( x.length, 0, x, 1, 0, out, 1, 0 ); t.deepEqual( out, expected, 'returns expected value' ); + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 0, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); }); -tape( 'if provided a `k` equal to `0`, the function returns an output array where all elements are `true` (accessors)', function test( t ) { +tape( 'if provided a `k` equal to `0`, the function sets output elements to `true` upon encountering the first truthy element (accessors)', function test( t ) { var expected; var out; var x; - x = [ 0, 0, 0 ]; + x = [ 1, 0, 0 ]; out = [ false, false, false ]; expected = [ true, true, true ]; gcusome( x.length, 0, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); t.deepEqual( out, expected, 'returns expected value' ); + x = [ 0, 0, 0 ]; + out = [ false, false, false ]; + expected = [ false, false, false ]; + + gcusome( x.length, 0, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); }); @@ -207,6 +235,36 @@ tape( 'if provided a `k` greater than `N`, the function returns an output array t.end(); }); +tape( 'the function cumulatively tests whether at least `k` elements are truthy (k=1)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 0, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( x.length, 1, x, 1, 0, out, 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least `k` elements are truthy (k=1, accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 0, 1 ]; + out = [ false, false, false, false ]; + expected = [ false, true, true, true ]; + + gcusome( x.length, 1, toAccessorArray( x ), 1, 0, toAccessorArray( out ), 1, 0 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an `x` stride', function test( t ) { var expected; var out; @@ -444,3 +502,33 @@ tape( 'the function supports an `out` offset (accessors)', function test( t ) { t.end(); }); + +tape( 'the function supports complex access patterns', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 0, 1, 0, 1 ]; + out = [ false, false, false, false, false, false ]; + expected = [ false, true, false, true, false, false ]; + + gcusome( 3, 2, x, 2, 1, out, -2, 5 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var expected; + var out; + var x; + + x = [ 0, 1, 0, 1, 0, 1 ]; + out = [ false, false, false, false, false, false ]; + expected = [ false, true, false, true, false, false ]; + + gcusome( 3, 2, toAccessorArray( x ), 2, 1, toAccessorArray( out ), -2, 5 ); + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +});