From 6cb1706f55daaea49c41229910e2c629ff137493 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 9 Apr 2026 23:45:02 +0500 Subject: [PATCH 1/3] feat: add blas/ext/base/gwhere --- .../@stdlib/blas/ext/base/gwhere/README.md | 198 +++++ .../ext/base/gwhere/benchmark/benchmark.js | 107 +++ .../gwhere/benchmark/benchmark.ndarray.js | 107 +++ .../blas/ext/base/gwhere/docs/repl.txt | 131 ++++ .../ext/base/gwhere/docs/types/index.d.ts | 120 +++ .../blas/ext/base/gwhere/docs/types/test.ts | 344 +++++++++ .../blas/ext/base/gwhere/examples/index.js | 41 + .../blas/ext/base/gwhere/lib/accessors.js | 99 +++ .../@stdlib/blas/ext/base/gwhere/lib/index.js | 61 ++ .../@stdlib/blas/ext/base/gwhere/lib/main.js | 59 ++ .../blas/ext/base/gwhere/lib/ndarray.js | 91 +++ .../@stdlib/blas/ext/base/gwhere/package.json | 69 ++ .../@stdlib/blas/ext/base/gwhere/test/test.js | 38 + .../blas/ext/base/gwhere/test/test.main.js | 521 +++++++++++++ .../blas/ext/base/gwhere/test/test.ndarray.js | 719 ++++++++++++++++++ 15 files changed, 2705 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md b/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md new file mode 100644 index 000000000000..15799d2f530f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md @@ -0,0 +1,198 @@ + + +# gwhere + +> Take elements from one of two strided arrays depending on a condition. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gwhere = require( '@stdlib/blas/ext/base/gwhere' ); +``` + +#### gwhere( N, condition, strideC, x, strideX, y, strideY ) + +Takes elements from one of two strided arrays depending on a condition. + +```javascript +var condition = [ 1, 0, 1 ]; +var x = [ 1.0, 2.0, 3.0 ]; +var y = [ 4.0, 5.0, 6.0 ]; + +var out = gwhere( 3, condition, 1, x, 1, y, 1 ); +// returns [ 1.0, 5.0, 3.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **condition**: condition array. +- **strideC**: stride length for `condition`. +- **x**: first input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **y**: second input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideY**: stride length for `y`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to select from every other element: + +```javascript +var condition = [ 1, 0, 0, 1, 1, 0 ]; +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + +var out = gwhere( 3, condition, 2, x, 2, y, 2 ); +// returns [ 1.0, 9.0, 5.0 ] +``` + +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 arrays... +var condition0 = new Float64Array( [ 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] ); +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Create offset views... +var condition1 = new Float64Array( condition0.buffer, condition0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var out = gwhere( 3, condition1, 2, x1, 2, y1, 2 ); +// returns [ 2.0, 4.0, 6.0 ] +``` + + + +#### gwhere.ndarray( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY, offsetY ) + + + +Takes elements from one of two strided arrays depending on a condition using alternative indexing semantics. + +```javascript +var condition = [ 1, 0, 1 ]; +var x = [ 1.0, 2.0, 3.0 ]; +var y = [ 4.0, 5.0, 6.0 ]; + +var out = gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); +// returns [ 1.0, 5.0, 3.0 ] +``` + +The function has the following additional parameters: + +- **offsetC**: starting index for `condition`. +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +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 select from every other element starting from the second element: + +```javascript +var condition = [ 0, 1, 0, 0, 0, 1 ]; +var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + +var out = gwhere.ndarray( 3, condition, 2, 1, x, 2, 1, y, 2, 1 ); +// returns [ 2.0, 10.0, 6.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return an empty array. +- 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]). +- Both functions return a new generic `Array`. To assign results to a specific output array, use [`@stdlib/array/base/where`][@stdlib/array/base/where]. + +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gwhere = require( '@stdlib/blas/ext/base/gwhere' ); + +var condition = bernoulli( 20, 0.5, { + 'dtype': 'generic' +}); +var x = discreteUniform( 20, 0, 100, { + 'dtype': 'generic' +}); +var y = discreteUniform( 20, -100, 0, { + 'dtype': 'generic' +}); +console.log( condition ); +console.log( x ); +console.log( y ); + +var out = gwhere( condition.length, condition, 1, x, 1, y, 1 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js new file mode 100644 index 000000000000..4461cc79dddc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js @@ -0,0 +1,107 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gwhere = 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 condition = bernoulli( len, 0.5, options ); + var x = uniform( len, -100, 100, options ); + var y = uniform( len, -100, 100, options ); + 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++ ) { + condition[ i%len ] = ( condition[ i%len ] + 1 ) % 2; + out = gwhere( len, condition, 1, x, 1, y, 1 ); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + 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/gwhere/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6136d6c767f2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js @@ -0,0 +1,107 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gwhere = 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 condition = bernoulli( len, 0.5, options ); + var x = uniform( len, -100, 100, options ); + var y = uniform( len, -100, 100, options ); + 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++ ) { + condition[ i%len ] = ( condition[ i%len ] + 1 ) % 2; + out = gwhere( len, condition, 1, 0, x, 1, 0, y, 1, 0 ); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + 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/gwhere/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt new file mode 100644 index 000000000000..f7f4fe4e3cb7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt @@ -0,0 +1,131 @@ + +{{alias}}( N, condition, strideC, x, strideX, y, strideY ) + Takes elements from one of two strided arrays depending on a condition. + + 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 an empty array. + + Parameters + ---------- + N: integer + Number of indexed elements. + + condition: Array|TypedArray + Condition array. + + strideC: integer + Stride length for `condition`. + + x: Array|TypedArray + First input array. + + strideX: integer + Stride length for `x`. + + y: Array|TypedArray + Second input array. + + strideY: integer + Stride length for `y`. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + // Standard Usage: + > var condition = [ 1, 0, 1 ]; + > var x = [ 1.0, 2.0, 3.0 ]; + > var y = [ 4.0, 5.0, 6.0 ]; + > var out = {{alias}}( 3, condition, 1, x, 1, y, 1 ) + [ 1.0, 5.0, 3.0 ] + + // Using `N` and stride parameters: + > condition = [ 1, 0, 0, 1, 1, 0 ]; + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + > out = {{alias}}( 3, condition, 2, x, 2, y, 2 ) + [ 1.0, 9.0, 5.0 ] + + // Using view offsets: + > var c0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 0.0, 1.0 ] ); + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y0 = new {{alias:@stdlib/array/float64}}( [ 5.0, 6.0, 7.0, 8.0 ] ); + > var c1 = new {{alias:@stdlib/array/float64}}( c0.buffer, c0.BYTES_PER_ELEMENT*1 ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); + > out = {{alias}}( 2, c1, 1, x1, 1, y1, 1 ) + [ 2.0, 7.0 ] + + +{{alias}}.ndarray( N, c, sc, oc, x, sx, ox, y, sy, oy ) + Takes elements from one of two strided arrays depending on a condition + 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. + + c: Array|TypedArray + Condition array. + + sc: integer + Stride length for `condition`. + + oc: integer + Starting index for `condition`. + + x: Array|TypedArray + First input array. + + sx: integer + Stride length for `x`. + + ox: integer + Starting index for `x`. + + y: Array|TypedArray + Second input array. + + sy: integer + Stride length for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + // Standard Usage: + > var condition = [ 1, 0, 1 ]; + > var x = [ 1.0, 2.0, 3.0 ]; + > var y = [ 4.0, 5.0, 6.0 ]; + > var out = {{alias}}.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ) + [ 1.0, 5.0, 3.0 ] + + // Advanced indexing: + > condition = [ 0, 1, 0, 0, 0, 1 ]; + > x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + > y = [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; + > out = {{alias}}.ndarray( 3, condition, 2, 1, x, 2, 1, y, 2, 1 ) + [ 2.0, 10.0, 6.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts new file mode 100644 index 000000000000..b18b5f2cbcce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts @@ -0,0 +1,120 @@ +/* +* @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 `gwhere`. +*/ +interface Routine { + /** + * Takes elements from one of two strided arrays depending on a condition. + * + * @param N - number of indexed elements + * @param condition - condition array + * @param strideC - stride length for `condition` + * @param x - first input array + * @param strideX - stride length for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @returns output array + * + * @example + * var condition = [ 1, 0, 1 ]; + * var x = [ 1.0, 2.0, 3.0 ]; + * var y = [ 4.0, 5.0, 6.0 ]; + * + * var out = gwhere( 3, condition, 1, x, 1, y, 1 ); + * // returns [ 1.0, 5.0, 3.0 ] + */ + ( N: number, condition: InputArray, strideC: number, x: InputArray, strideX: number, y: InputArray, strideY: number ): OutputArray; + + /** + * Takes elements from one of two strided arrays depending on a condition using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param condition - condition array + * @param strideC - stride length for `condition` + * @param offsetC - starting index for `condition` + * @param x - first input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @returns output array + * + * @example + * var condition = [ 1, 0, 1 ]; + * var x = [ 1.0, 2.0, 3.0 ]; + * var y = [ 4.0, 5.0, 6.0 ]; + * + * var out = gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); + * // returns [ 1.0, 5.0, 3.0 ] + */ + ndarray( N: number, condition: InputArray, strideC: number, offsetC: number, x: InputArray, strideX: number, offsetX: number, y: InputArray, strideY: number, offsetY: number ): OutputArray; +} + +/** +* Takes elements from one of two strided arrays depending on a condition. +* +* @param N - number of indexed elements +* @param condition - condition array +* @param strideC - stride length for `condition` +* @param x - first input array +* @param strideX - stride length for `x` +* @param y - second input array +* @param strideY - stride length for `y` +* @returns output array +* +* @example +* var condition = [ 1, 0, 1 ]; +* var x = [ 1.0, 2.0, 3.0 ]; +* var y = [ 4.0, 5.0, 6.0 ]; +* +* var out = gwhere( 3, condition, 1, x, 1, y, 1 ); +* // returns [ 1.0, 5.0, 3.0 ] +* +* @example +* var condition = [ 1, 0, 1 ]; +* var x = [ 1.0, 2.0, 3.0 ]; +* var y = [ 4.0, 5.0, 6.0 ]; +* +* var out = gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); +* // returns [ 1.0, 5.0, 3.0 ] +*/ +declare var gwhere: Routine; + + +// EXPORTS // + +export = gwhere; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts new file mode 100644 index 000000000000..77011b941f1f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts @@ -0,0 +1,344 @@ +/* +* @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 gwhere = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( 3, condition, 1, x, 1, y, 1 ); // $ExpectType float64Array + gwhere( 3, condition, 1, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( '10', condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( true, condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( false, condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( null, condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( undefined, condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( [], condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( {}, condition, 1, x, 1, y, 1 ); // $ExpectError + gwhere( ( x: number ): number => x, condition, 1, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( 3, 10, 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, '10', 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, true, 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, false, 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, null, 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, undefined, 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, {}, 1, x, 1, y, 1 ); // $ExpectError + gwhere( 3, ( x: number ): number => x, 1, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( 3, condition, '10', x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, true, x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, false, x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, null, x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, undefined, x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, [], x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, {}, x, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const condition = [ 1, 0, 1 ]; + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( 3, condition, 1, 10, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, '10', 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, true, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, false, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, null, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, undefined, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, {}, 1, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( 3, condition, 1, x, '10', y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, true, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, false, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, null, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, undefined, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, [], y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, {}, y, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a collection... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + + gwhere( 3, condition, 1, x, 1, 10, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, '10', 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, true, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, false, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, null, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, undefined, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, {}, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere( 3, condition, 1, x, 1, y, '10' ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, true ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, false ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, null ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, undefined ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, [] ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, {} ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere(); // $ExpectError + gwhere( 3 ); // $ExpectError + gwhere( 3, condition ); // $ExpectError + gwhere( 3, condition, 1 ); // $ExpectError + gwhere( 3, condition, 1, x ); // $ExpectError + gwhere( 3, condition, 1, x, 1 ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y ); // $ExpectError + gwhere( 3, condition, 1, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns an array... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectType float64Array + gwhere.ndarray( 3, condition, 1, 0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( '10', condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( true, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( false, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( null, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( undefined, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( [], condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( {}, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( ( x: number ): number => x, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, 10, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, '10', 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, true, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, false, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, null, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, undefined, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, {}, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, ( x: number ): number => x, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, '10', 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, true, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, false, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, null, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, undefined, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, [], 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, {}, 0, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, ( x: number ): number => x, 0, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, '10', x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, true, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, false, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, null, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, [], x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, {}, x, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a collection... +{ + const condition = [ 1, 0, 1 ]; + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, 10, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, '10', 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, true, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, false, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, null, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, undefined, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, {}, 1, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, x, '10', 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, true, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, false, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, null, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, undefined, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, [], 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, {}, 0, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, x, 1, '10', y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, true, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, false, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, null, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, undefined, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, [], y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, {}, y, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a collection... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, 10, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, '10', 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, true, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, false, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, null, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, undefined, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, {}, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, '10', 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, true, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, false, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, null, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, undefined, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, [], 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, {}, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, '10' ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, true ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, false ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, null ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, undefined ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, [] ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, {} ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const condition = [ 1, 0, 1 ]; + const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + + gwhere.ndarray(); // $ExpectError + gwhere.ndarray( 3 ); // $ExpectError + gwhere.ndarray( 3, condition ); // $ExpectError + gwhere.ndarray( 3, condition, 1 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1 ); // $ExpectError + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/examples/index.js new file mode 100644 index 000000000000..6be7d6efab76 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/examples/index.js @@ -0,0 +1,41 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gwhere = require( './../lib' ); + +var condition = bernoulli( 20, 0.5, { + 'dtype': 'generic' +}); +console.log( condition ); + +var x = discreteUniform( 20, 0, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var y = discreteUniform( 20, -100, 0, { + 'dtype': 'generic' +}); +console.log( y ); + +var out = gwhere( condition.length, condition, 1, x, 1, y, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js new file mode 100644 index 000000000000..0245ad58bf95 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js @@ -0,0 +1,99 @@ +/** +* @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 // + +/** +* Takes elements from one of two strided arrays depending on a condition. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} condition - condition array object +* @param {Collection} condition.data - condition array data +* @param {Array} condition.accessors - array element accessors +* @param {integer} strideC - stride length for `condition` +* @param {NonNegativeInteger} offsetC - starting index for `condition` +* @param {Object} x - first input array object +* @param {Collection} x.data - first 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} y - second input array object +* @param {Collection} y.data - second input array data +* @param {Array} y.accessors - array element accessors +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Array} out - output array +* @returns {Array} output array +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var condition = [ 1, 0, 1 ]; +* var x = [ 1.0, 2.0, 3.0 ]; +* var y = [ 4.0, 5.0, 6.0 ]; +* var out = [ 0.0, 0.0, 0.0 ]; +* +* gwhere( 3, arraylike2object( toAccessorArray( condition ) ), 1, 0, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0, out ); +* // out => [ 1.0, 5.0, 3.0 ] +*/ +function gwhere( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params + var cbuf; + var xbuf; + var ybuf; + var cget; + var xget; + var yget; + var ic; + var ix; + var iy; + var i; + + // Cache references to array data: + cbuf = condition.data; + xbuf = x.data; + ybuf = y.data; + + // Cache references to element accessors: + cget = condition.accessors[ 0 ]; + xget = x.accessors[ 0 ]; + yget = y.accessors[ 0 ]; + + ic = offsetC; + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + if ( cget( cbuf, ic ) ) { + out[ i ] = xget( xbuf, ix ); + } else { + out[ i ] = yget( ybuf, iy ); + } + ic += strideC; + ix += strideX; + iy += strideY; + } + return out; +} + + +// EXPORTS // + +module.exports = gwhere; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/index.js new file mode 100644 index 000000000000..c11d13b2a7a3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/index.js @@ -0,0 +1,61 @@ +/** +* @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'; + +/** +* Take elements from one of two strided arrays depending on a condition. +* +* @module @stdlib/blas/ext/base/gwhere +* +* @example +* var gwhere = require( '@stdlib/blas/ext/base/gwhere' ); +* +* var condition = [ 1, 0, 1 ]; +* var x = [ 1.0, 2.0, 3.0 ]; +* var y = [ 4.0, 5.0, 6.0 ]; +* +* var out = gwhere( 3, condition, 1, x, 1, y, 1 ); +* // returns [ 1.0, 5.0, 3.0 ] +* +* @example +* var gwhere = require( '@stdlib/blas/ext/base/gwhere' ); +* +* var condition = [ 1, 0, 1, 0 ]; +* var x = [ 1.0, 2.0, 3.0, 4.0 ]; +* var y = [ 5.0, 6.0, 7.0, 8.0 ]; +* +* var out = gwhere.ndarray( 4, condition, 1, 0, x, 1, 0, y, 1, 0 ); +* // returns [ 1.0, 6.0, 3.0, 8.0 ] +*/ + +// 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/gwhere/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js new file mode 100644 index 000000000000..8dc9e9bd282f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.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'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Takes elements from one of two strided arrays depending on a condition. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} condition - condition array +* @param {integer} strideC - stride length for `condition` +* @param {Collection} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {Collection} y - second input array +* @param {integer} strideY - stride length for `y` +* @returns {Array} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var y = [ 4.0, 5.0, 6.0 ]; +* var condition = [ 1, 0, 1 ]; +* +* var out = gwhere( 3, condition, 1, x, 1, y, 1 ); +* // returns [ 1.0, 5.0, 3.0 ] +*/ +function gwhere( N, condition, strideC, x, strideX, y, strideY ) { + var oc = stride2offset( N, strideC ); + var ox = stride2offset( N, strideX ); + var oy = stride2offset( N, strideY ); + return ndarray( N, condition, strideC, oc, x, strideX, ox, y, strideY, oy ); +} + + +// EXPORTS // + +module.exports = gwhere; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js new file mode 100644 index 000000000000..26fcbc7a0141 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.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'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Takes elements from one of two strided arrays depending on a condition. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} condition - condition array +* @param {integer} strideC - stride length for `condition` +* @param {NonNegativeInteger} offsetC - starting index for `condition` +* @param {Collection} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @returns {Array} output array +* +* @example +* var x = [ 1.0, 2.0, 3.0 ]; +* var y = [ 4.0, 5.0, 6.0 ]; +* var condition = [ 1, 0, 1 ]; +* +* var out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); +* // returns [ 1.0, 5.0, 3.0 ] +*/ +function gwhere( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len + var out; + var oc; + var ox; + var oy; + var ic; + var ix; + var iy; + var i; + + out = []; + if ( N <= 0 ) { + return out; + } + oc = arraylike2object( condition ); + ox = arraylike2object( x ); + oy = arraylike2object( y ); + if ( oc.accessorProtocol || ox.accessorProtocol || oy.accessorProtocol ) { + return accessors( N, oc, strideC, offsetC, ox, strideX, offsetX, oy, strideY, offsetY, out ); // eslint-disable-line max-len + } + ic = offsetC; + ix = offsetX; + iy = offsetY; + for ( i = 0; i < N; i++ ) { + if ( condition[ ic ] ) { + out.push( x[ ix ] ); + } else { + out.push( y[ iy ] ); + } + ic += strideC; + ix += strideX; + iy += strideY; + } + return out; +} + + +// EXPORTS // + +module.exports = gwhere; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/package.json b/lib/node_modules/@stdlib/blas/ext/base/gwhere/package.json new file mode 100644 index 000000000000..a1cfbf2011ee --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gwhere", + "version": "0.0.0", + "description": "Take elements from one of two strided arrays depending on a condition.", + "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", + "where", + "condition", + "conditional", + "select", + "ternary", + "strided", + "strided array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.js new file mode 100644 index 000000000000..0419572eec7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/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 gwhere = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gwhere, '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 gwhere.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js new file mode 100644 index 000000000000..4255f0ffaa4d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js @@ -0,0 +1,521 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var gwhere = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gwhere, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gwhere.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 1, 0, 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + out = gwhere( 5, condition, 1, x, 1, y, 1 ); + expected = [ 1.0, 7.0, 3.0, 9.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (all true)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 1, 1, 1 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( 3, condition, 1, x, 1, y, 1 ); + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (all false)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 0, 0, 0 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( 3, condition, 1, x, 1, y, 1 ); + expected = [ 4.0, 5.0, 6.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (truthy/falsy)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ true, false, 'a', '', 5, 0, null ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + y = [ 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ]; + + out = gwhere( 7, condition, 1, x, 1, y, 1 ); + expected = [ 1.0, 9.0, 3.0, 11.0, 5.0, 13.0, 14.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 1, 0, 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + out = gwhere( 5, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + expected = [ 1.0, 7.0, 3.0, 9.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = [ 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( 3, condition, 1, x, 1, y, 1 ); + + t.notEqual( out, x, 'returns a new array' ); + t.notEqual( out, y, 'returns a new array' ); + t.strictEqual( out instanceof Array, true, 'returns an Array' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns an empty array', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = [ 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( -1, condition, 1, x, 1, y, 1 ); + t.deepEqual( out, [], 'returns expected value' ); + + out = gwhere( 0, condition, 1, x, 1, y, 1 ); + t.deepEqual( out, [], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `condition` stride', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, + 0, // 1 + 1, + 1 // 2 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, condition, 2, x, 1, y, 1 ); + expected = [ 1.0, 7.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `condition` stride (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, + 0, // 1 + 1, + 1 // 2 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + expected = [ 1.0, 7.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, // 1 + 1, // 2 + 0, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, condition, 1, x, 2, y, 1 ); + expected = [ 1.0, 7.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, // 1 + 1, // 2 + 0, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); + expected = [ 1.0, 7.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, // 0 + 1, // 1 + 0, // 2 + 1, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]; + + out = gwhere( 3, condition, 1, x, 1, y, 2 ); + expected = [ 6.0, 2.0, 10.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, // 0 + 1, // 1 + 0, // 2 + 1, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 2 ); + expected = [ 6.0, 2.0, 10.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 2 + 0, + 0, // 1 + 1, + 1 // 0 + ]; + x = [ + 1.0, // 2 + 2.0, // 1 + 3.0, // 0 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]; + + out = gwhere( 3, condition, -2, x, -1, y, -1 ); + expected = [ 3.0, 7.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 2 + 0, + 0, // 1 + 1, + 1 // 0 + ]; + x = [ + 1.0, // 2 + 2.0, // 1 + 3.0, // 0 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), -2, toAccessorArray( x ), -1, toAccessorArray( y ), -1 ); + expected = [ 3.0, 7.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, + 0, // 1 + 1, + 1, // 2 + 0 + ]; + x = [ + 1.0, // 2 + 2.0, // 1 + 3.0, // 0 + 4.0, + 5.0, + 6.0 + ]; + y = [ + 7.0, // 0 + 8.0, + 9.0, // 1 + 10.0, + 11.0, // 2 + 12.0 + ]; + + out = gwhere( 3, condition, 2, x, -1, y, 2 ); + expected = [ 3.0, 9.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var condition0; + var condition1; + var expected; + var out; + var x0; + var y0; + var x1; + var y1; + + // Initial arrays... + condition0 = new Float64Array( [ 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] ); + x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + + // Create offset views... + condition1 = new Float64Array( condition0.buffer, condition0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + out = gwhere( 3, condition1, 2, x1, 2, y1, 2 ); + expected = [ 2.0, 4.0, 6.0 ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js new file mode 100644 index 000000000000..ff99217d41d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js @@ -0,0 +1,719 @@ +/** +* @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 gwhere = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gwhere, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 10', function test( t ) { + t.strictEqual( gwhere.length, 10, 'has expected arity' ); + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 1, 0, 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + out = gwhere( 5, condition, 1, 0, x, 1, 0, y, 1, 0 ); + expected = [ 1.0, 7.0, 3.0, 9.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (all true)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 1, 1, 1 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); + expected = [ 1.0, 2.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (all false)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 0, 0, 0 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); + expected = [ 4.0, 5.0, 6.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (truthy/falsy)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ true, false, 'a', '', 5, 0, null ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]; + y = [ 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0 ]; + + out = gwhere( 7, condition, 1, 0, x, 1, 0, y, 1, 0 ); + expected = [ 1.0, 9.0, 3.0, 11.0, 5.0, 13.0, 14.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function selects elements from `x` or `y` based on a condition (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ 1, 0, 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; + + out = gwhere( 5, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + expected = [ 1.0, 7.0, 3.0, 9.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new array', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = [ 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); + + t.notEqual( out, x, 'returns a new array' ); + t.notEqual( out, y, 'returns a new array' ); + t.strictEqual( out instanceof Array, true, 'returns an Array' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns an empty array', function test( t ) { + var condition; + var out; + var x; + var y; + + condition = [ 1, 0, 1 ]; + x = [ 1.0, 2.0, 3.0 ]; + y = [ 4.0, 5.0, 6.0 ]; + + out = gwhere( -1, condition, 1, 0, x, 1, 0, y, 1, 0 ); + t.deepEqual( out, [], 'returns expected value' ); + + out = gwhere( 0, condition, 1, 0, x, 1, 0, y, 1, 0 ); + t.deepEqual( out, [], 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `condition` stride', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, + 0, // 1 + 1, + 1 // 2 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, condition, 2, 0, x, 1, 0, y, 1, 0 ); + expected = [ 1.0, 7.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `condition` stride (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, + 0, // 1 + 1, + 1 // 2 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 2, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + expected = [ 1.0, 7.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, // 1 + 1, // 2 + 0, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, condition, 1, 0, x, 2, 0, y, 1, 0 ); + expected = [ 1.0, 7.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, // 1 + 1, // 2 + 0, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]; + y = [ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0 ); + expected = [ 1.0, 7.0, 5.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, // 0 + 1, // 1 + 0, // 2 + 1, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]; + + out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 2, 0 ); + expected = [ 6.0, 2.0, 10.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` stride (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, // 0 + 1, // 1 + 0, // 2 + 1, + 0 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 0 + 7.0, + 8.0, // 1 + 9.0, + 10.0 // 2 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0 ); + expected = [ 6.0, 2.0, 10.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 2 + 0, + 0, // 1 + 1, + 1 // 0 + ]; + x = [ + 1.0, // 2 + 2.0, // 1 + 3.0, // 0 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]; + + out = gwhere( 3, condition, -2, 4, x, -1, 2, y, -1, 2 ); + expected = [ 3.0, 7.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 2 + 0, + 0, // 1 + 1, + 1 // 0 + ]; + x = [ + 1.0, // 2 + 2.0, // 1 + 3.0, // 0 + 4.0, + 5.0 + ]; + y = [ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), -2, 4, toAccessorArray( x ), -1, 2, toAccessorArray( y ), -1, 2 ); + expected = [ 3.0, 7.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `condition` offset', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, + 1, // 0 + 0, + 0, // 1 + 0, + 1 // 2 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0, + 6.0 + ]; + y = [ + 7.0, // 0 + 8.0, // 1 + 9.0, // 2 + 10.0, + 11.0, + 12.0 + ]; + + out = gwhere( 3, condition, 2, 1, x, 1, 0, y, 1, 0 ); + expected = [ 1.0, 8.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `condition` offset (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, + 1, // 0 + 0, + 0, // 1 + 0, + 1 // 2 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0, + 6.0 + ]; + y = [ + 7.0, // 0 + 8.0, // 1 + 9.0, // 2 + 10.0, + 11.0, + 12.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 2, 1, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + expected = [ 1.0, 8.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, // 1 + 1, // 2 + 0 + ]; + x = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0, // 2 + 0.0, + 4.0 + ]; + y = [ + 5.0, // 0 + 6.0, // 1 + 7.0, // 2 + 8.0 + ]; + + out = gwhere( 3, condition, 1, 0, x, 2, 1, y, 1, 0 ); + expected = [ 1.0, 6.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, // 1 + 1, // 2 + 0 + ]; + x = [ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0, // 2 + 0.0, + 4.0 + ]; + y = [ + 5.0, // 0 + 6.0, // 1 + 7.0, // 2 + 8.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 ); + expected = [ 1.0, 6.0, 3.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` offset', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, // 0 + 1, // 1 + 0, // 2 + 1 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0 + ]; + y = [ + 0.0, + 5.0, // 0 + 0.0, + 6.0, // 1 + 0.0, + 7.0, // 2 + 0.0, + 8.0 + ]; + + out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 2, 1 ); + expected = [ 5.0, 2.0, 7.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `y` offset (accessors)', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 0, // 0 + 1, // 1 + 0, // 2 + 1 + ]; + x = [ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0 + ]; + y = [ + 0.0, + 5.0, // 0 + 0.0, + 6.0, // 1 + 0.0, + 7.0, // 2 + 0.0, + 8.0 + ]; + + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 1 ); + expected = [ 5.0, 2.0, 7.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var condition; + var expected; + var out; + var x; + var y; + + condition = [ + 1, // 0 + 0, + 0, // 1 + 1, + 1, // 2 + 0 + ]; + x = [ + 1.0, // 2 + 2.0, // 1 + 3.0, // 0 + 4.0, + 5.0, + 6.0 + ]; + y = [ + 7.0, // 0 + 8.0, + 9.0, // 1 + 10.0, + 11.0, // 2 + 12.0 + ]; + + out = gwhere( 3, condition, 2, 0, x, -1, 2, y, 2, 0 ); + expected = [ 3.0, 9.0, 1.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + + t.end(); +}); From 66e919e35b49073b09638e6ec35ac272c04a07c1 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 15 Apr 2026 09:35:49 +0500 Subject: [PATCH 2/3] refactor: apply suggestions from code review --- .../@stdlib/blas/ext/base/gwhere/README.md | 10 +-- .../ext/base/gwhere/benchmark/benchmark.js | 1 - .../gwhere/benchmark/benchmark.ndarray.js | 1 - .../blas/ext/base/gwhere/docs/repl.txt | 4 +- .../ext/base/gwhere/docs/types/index.d.ts | 65 +++++++++++++++---- .../blas/ext/base/gwhere/docs/types/test.ts | 8 +-- .../blas/ext/base/gwhere/lib/accessors.js | 40 ++++++++---- .../@stdlib/blas/ext/base/gwhere/lib/main.js | 2 +- .../blas/ext/base/gwhere/lib/ndarray.js | 13 ++-- .../blas/ext/base/gwhere/test/test.main.js | 35 +++++++--- .../blas/ext/base/gwhere/test/test.ndarray.js | 56 +++++++++++----- 11 files changed, 166 insertions(+), 69 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md b/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md index 15799d2f530f..1ba75be01015 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/README.md @@ -135,7 +135,7 @@ var out = gwhere.ndarray( 3, condition, 2, 1, x, 2, 1, y, 2, 1 ); - If `N <= 0`, both functions return an empty array. - 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]). -- Both functions return a new generic `Array`. To assign results to a specific output array, use [`@stdlib/array/base/where`][@stdlib/array/base/where]. +- Depending on the environment, the typed versions ([`dwhere`][@stdlib/blas/ext/base/dwhere], [`swhere`][@stdlib/blas/ext/base/swhere], etc.) are likely to be significantly more performant. @@ -155,14 +155,14 @@ var gwhere = require( '@stdlib/blas/ext/base/gwhere' ); var condition = bernoulli( 20, 0.5, { 'dtype': 'generic' }); +console.log( condition ); var x = discreteUniform( 20, 0, 100, { 'dtype': 'generic' }); +console.log( x ); var y = discreteUniform( 20, -100, 0, { 'dtype': 'generic' }); -console.log( condition ); -console.log( x ); console.log( y ); var out = gwhere( condition.length, condition, 1, x, 1, y, 1 ); @@ -191,7 +191,9 @@ console.log( out ); [@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor -[@stdlib/array/base/where]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/where +[@stdlib/blas/ext/base/dwhere]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dwhere + +[@stdlib/blas/ext/base/swhere]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/swhere diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js index 4461cc79dddc..697ece826987 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.js @@ -64,7 +64,6 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - condition[ i%len ] = ( condition[ i%len ] + 1 ) % 2; out = gwhere( len, condition, 1, x, 1, y, 1 ); if ( !isArray( out ) ) { b.fail( 'should return an array' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js index 6136d6c767f2..c7c617794dae 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/benchmark/benchmark.ndarray.js @@ -64,7 +64,6 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - condition[ i%len ] = ( condition[ i%len ] + 1 ) % 2; out = gwhere( len, condition, 1, 0, x, 1, 0, y, 1, 0 ); if ( !isArray( out ) ) { b.fail( 'should return an array' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt index f7f4fe4e3cb7..365f98dc6d0e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/repl.txt @@ -82,10 +82,10 @@ Condition array. sc: integer - Stride length for `condition`. + Stride length for `c`. oc: integer - Starting index for `condition`. + Starting index for `c`. x: Array|TypedArray First input array. diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts index b18b5f2cbcce..c1c3bc1bb203 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/index.d.ts @@ -22,20 +22,34 @@ import { Collection, AccessorArrayLike } from '@stdlib/types/array'; -/** -* Input array. -*/ -type InputArray = Collection | AccessorArrayLike; - -/** -* Output array. -*/ -type OutputArray = Collection | AccessorArrayLike; - /** * Interface describing `gwhere`. */ interface Routine { + /** + * Takes elements from one of two strided arrays depending on a condition. + * + * @param N - number of indexed elements + * @param condition - condition array + * @param strideC - stride length for `condition` + * @param x - first input array + * @param strideX - stride length for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @returns output array + * + * @example + * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * + * var condition = [ 1, 0, 1 ]; + * var x = [ 1.0, 2.0, 3.0 ]; + * var y = [ 4.0, 5.0, 6.0 ]; + * + * var out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + * // returns + */ + ( N: number, condition: AccessorArrayLike, strideC: number, x: AccessorArrayLike, strideX: number, y: AccessorArrayLike, strideY: number ): AccessorArrayLike; + /** * Takes elements from one of two strided arrays depending on a condition. * @@ -56,7 +70,34 @@ interface Routine { * var out = gwhere( 3, condition, 1, x, 1, y, 1 ); * // returns [ 1.0, 5.0, 3.0 ] */ - ( N: number, condition: InputArray, strideC: number, x: InputArray, strideX: number, y: InputArray, strideY: number ): OutputArray; + ( N: number, condition: Collection, strideC: number, x: Collection, strideX: number, y: Collection, strideY: number ): Collection; + + /** + * Takes elements from one of two strided arrays depending on a condition using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param condition - condition array + * @param strideC - stride length for `condition` + * @param offsetC - starting index for `condition` + * @param x - first input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @returns output array + * + * @example + * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * + * var condition = [ 1, 0, 1 ]; + * var x = [ 1.0, 2.0, 3.0 ]; + * var y = [ 4.0, 5.0, 6.0 ]; + * + * var out = gwhere.ndarray( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + * // returns + */ + ndarray( N: number, condition: AccessorArrayLike, strideC: number, offsetC: number, x: AccessorArrayLike, strideX: number, offsetX: number, y: AccessorArrayLike, strideY: number, offsetY: number ): AccessorArrayLike; /** * Takes elements from one of two strided arrays depending on a condition using alternative indexing semantics. @@ -81,7 +122,7 @@ interface Routine { * var out = gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); * // returns [ 1.0, 5.0, 3.0 ] */ - ndarray( N: number, condition: InputArray, strideC: number, offsetC: number, x: InputArray, strideX: number, offsetX: number, y: InputArray, strideY: number, offsetY: number ): OutputArray; + ndarray( N: number, condition: Collection, strideC: number, offsetC: number, x: Collection, strideX: number, offsetX: number, y: Collection, strideY: number, offsetY: number ): Collection; } /** diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts index 77011b941f1f..dcf338628c26 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/docs/types/test.ts @@ -28,8 +28,8 @@ import gwhere = require( './index' ); const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); - gwhere( 3, condition, 1, x, 1, y, 1 ); // $ExpectType float64Array - gwhere( 3, condition, 1, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray + gwhere( 3, condition, 1, x, 1, y, 1 ); // $ExpectType Collection + gwhere( 3, new AccessorArray( condition ), 1, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArrayLike } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -163,8 +163,8 @@ import gwhere = require( './index' ); const x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); const y = new Float64Array( [ 4.0, 5.0, 6.0 ] ); - gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectType float64Array - gwhere.ndarray( 3, condition, 1, 0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray + gwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); // $ExpectType Collection + gwhere.ndarray( 3, new AccessorArray( condition ), 1, 0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArrayLike } // 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/gwhere/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js index 0245ad58bf95..e3510392636c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js @@ -18,13 +18,19 @@ 'use strict'; +// MODULES // + +var AccessorArray = require( '@stdlib/array/base/accessor' ); +var zeros = require( '@stdlib/array/base/zeros' ); + + // MAIN // /** * Takes elements from one of two strided arrays depending on a condition. * * @private -* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} N - number of indexed elements * @param {Object} condition - condition array object * @param {Collection} condition.data - condition array data * @param {Array} condition.accessors - array element accessors @@ -40,33 +46,43 @@ * @param {Array} y.accessors - array element accessors * @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` -* @param {Array} out - output array -* @returns {Array} output array +* @returns {AccessorArray} output array * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * -* var condition = [ 1, 0, 1 ]; -* var x = [ 1.0, 2.0, 3.0 ]; -* var y = [ 4.0, 5.0, 6.0 ]; -* var out = [ 0.0, 0.0, 0.0 ]; +* var condition = arraylike2object( toAccessorArray( [ 1, 0, 1 ] ) ); +* var x = arraylike2object( toAccessorArray( [ 1.0, 2.0, 3.0 ] ) ); +* var y = arraylike2object( toAccessorArray( [ 4.0, 5.0, 6.0 ] ) ); +* +* var out = gwhere( 3, condition, 1, 0, x, 1, 0, y, 1, 0 ); +* // returns * -* gwhere( 3, arraylike2object( toAccessorArray( condition ) ), 1, 0, arraylike2object( toAccessorArray( x ) ), 1, 0, arraylike2object( toAccessorArray( y ) ), 1, 0, out ); -* // out => [ 1.0, 5.0, 3.0 ] +* var v = out.get( 0 ); +* // returns 1.0 +* +* v = out.get( 1 ); +* // returns 5.0 +* +* v = out.get( 2 ); +* // returns 3.0 */ -function gwhere( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params +function gwhere( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len var cbuf; var xbuf; var ybuf; var cget; var xget; var yget; + var out; var ic; var ix; var iy; var i; + out = new AccessorArray( zeros( N ) ); + // Cache references to array data: cbuf = condition.data; xbuf = x.data; @@ -82,9 +98,9 @@ function gwhere( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY iy = offsetY; for ( i = 0; i < N; i++ ) { if ( cget( cbuf, ic ) ) { - out[ i ] = xget( xbuf, ix ); + out.set( xget( xbuf, ix ), i ); } else { - out[ i ] = yget( ybuf, iy ); + out.set( yget( ybuf, iy ), i ); } ic += strideC; ix += strideX; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js index 8dc9e9bd282f..b36e1691b0c7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js @@ -29,7 +29,7 @@ var ndarray = require( './ndarray.js' ); /** * Takes elements from one of two strided arrays depending on a condition. * -* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} N - number of indexed elements * @param {Collection} condition - condition array * @param {integer} strideC - stride length for `condition` * @param {Collection} x - first input array diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js index 26fcbc7a0141..f93e7e94b1eb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js @@ -21,6 +21,7 @@ // MODULES // var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var zeros = require( '@stdlib/array/base/zeros' ); var accessors = require( './accessors.js' ); @@ -29,7 +30,7 @@ var accessors = require( './accessors.js' ); /** * Takes elements from one of two strided arrays depending on a condition. * -* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} N - number of indexed elements * @param {Collection} condition - condition array * @param {integer} strideC - stride length for `condition` * @param {NonNegativeInteger} offsetC - starting index for `condition` @@ -59,24 +60,24 @@ function gwhere( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY var iy; var i; - out = []; if ( N <= 0 ) { - return out; + return zeros( 0 ); } oc = arraylike2object( condition ); ox = arraylike2object( x ); oy = arraylike2object( y ); if ( oc.accessorProtocol || ox.accessorProtocol || oy.accessorProtocol ) { - return accessors( N, oc, strideC, offsetC, ox, strideX, offsetX, oy, strideY, offsetY, out ); // eslint-disable-line max-len + return accessors( N, oc, strideC, offsetC, ox, strideX, offsetX, oy, strideY, offsetY ); // eslint-disable-line max-len } + out = zeros( N ); ic = offsetC; ix = offsetX; iy = offsetY; for ( i = 0; i < N; i++ ) { if ( condition[ ic ] ) { - out.push( x[ ix ] ); + out[ i ] = x[ ix ]; } else { - out.push( y[ iy ] ); + out[ i ] = y[ iy ]; } ic += strideC; ix += strideX; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js index 4255f0ffaa4d..5a5a9b6f3410 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.main.js @@ -117,14 +117,17 @@ tape( 'the function selects elements from `x` or `y` based on a condition (acces var out; var x; var y; + var i; condition = [ 1, 0, 1, 0, 1 ]; x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; - out = gwhere( 5, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + out = gwhere( 5, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); // eslint-disable-line max-len expected = [ 1.0, 7.0, 3.0, 9.0, 5.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -208,6 +211,7 @@ tape( 'the function supports a `condition` stride (accessors)', function test( t var out; var x; var y; + var i; condition = [ 1, // 0 @@ -231,9 +235,11 @@ tape( 'the function supports a `condition` stride (accessors)', function test( t 10.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); + out = gwhere( 3, toAccessorArray( condition ), 2, toAccessorArray( x ), 1, toAccessorArray( y ), 1 ); // eslint-disable-line max-len expected = [ 1.0, 7.0, 3.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -280,6 +286,7 @@ tape( 'the function supports an `x` stride (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 1, // 0 @@ -303,9 +310,11 @@ tape( 'the function supports an `x` stride (accessors)', function test( t ) { 10.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); + out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 2, toAccessorArray( y ), 1 ); // eslint-disable-line max-len expected = [ 1.0, 7.0, 5.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -352,6 +361,7 @@ tape( 'the function supports a `y` stride (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 0, // 0 @@ -375,9 +385,11 @@ tape( 'the function supports a `y` stride (accessors)', function test( t ) { 10.0 // 2 ]; - out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 2 ); + out = gwhere( 3, toAccessorArray( condition ), 1, toAccessorArray( x ), 1, toAccessorArray( y ), 2 ); // eslint-disable-line max-len expected = [ 6.0, 2.0, 10.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -424,6 +436,7 @@ tape( 'the function supports negative strides (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 1, // 2 @@ -447,9 +460,11 @@ tape( 'the function supports negative strides (accessors)', function test( t ) { 10.0 ]; - out = gwhere( 3, toAccessorArray( condition ), -2, toAccessorArray( x ), -1, toAccessorArray( y ), -1 ); + out = gwhere( 3, toAccessorArray( condition ), -2, toAccessorArray( x ), -1, toAccessorArray( y ), -1 ); // eslint-disable-line max-len expected = [ 3.0, 7.0, 1.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js index ff99217d41d3..f9b6f56262c8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/test/test.ndarray.js @@ -116,14 +116,17 @@ tape( 'the function selects elements from `x` or `y` based on a condition (acces var out; var x; var y; + var i; condition = [ 1, 0, 1, 0, 1 ]; x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; y = [ 6.0, 7.0, 8.0, 9.0, 10.0 ]; - out = gwhere( 5, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + out = gwhere( 5, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len expected = [ 1.0, 7.0, 3.0, 9.0, 5.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -207,6 +210,7 @@ tape( 'the function supports a `condition` stride (accessors)', function test( t var out; var x; var y; + var i; condition = [ 1, // 0 @@ -230,9 +234,11 @@ tape( 'the function supports a `condition` stride (accessors)', function test( t 10.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 2, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + out = gwhere( 3, toAccessorArray( condition ), 2, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len expected = [ 1.0, 7.0, 3.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -279,6 +285,7 @@ tape( 'the function supports an `x` stride (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 1, // 0 @@ -302,9 +309,11 @@ tape( 'the function supports an `x` stride (accessors)', function test( t ) { 10.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0 ); + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 2, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len expected = [ 1.0, 7.0, 5.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -351,6 +360,7 @@ tape( 'the function supports a `y` stride (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 0, // 0 @@ -374,9 +384,11 @@ tape( 'the function supports a `y` stride (accessors)', function test( t ) { 10.0 // 2 ]; - out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0 ); + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 0 ); // eslint-disable-line max-len expected = [ 6.0, 2.0, 10.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -423,6 +435,7 @@ tape( 'the function supports negative strides (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 1, // 2 @@ -446,9 +459,11 @@ tape( 'the function supports negative strides (accessors)', function test( t ) { 10.0 ]; - out = gwhere( 3, toAccessorArray( condition ), -2, 4, toAccessorArray( x ), -1, 2, toAccessorArray( y ), -1, 2 ); + out = gwhere( 3, toAccessorArray( condition ), -2, 4, toAccessorArray( x ), -1, 2, toAccessorArray( y ), -1, 2 ); // eslint-disable-line max-len expected = [ 3.0, 7.0, 1.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -498,6 +513,7 @@ tape( 'the function supports a `condition` offset (accessors)', function test( t var out; var x; var y; + var i; condition = [ 0, @@ -524,9 +540,11 @@ tape( 'the function supports a `condition` offset (accessors)', function test( t 12.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 2, 1, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); + out = gwhere( 3, toAccessorArray( condition ), 2, 1, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len expected = [ 1.0, 8.0, 3.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -574,6 +592,7 @@ tape( 'the function supports an `x` offset (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 1, // 0 @@ -598,9 +617,11 @@ tape( 'the function supports an `x` offset (accessors)', function test( t ) { 8.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 ); + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 ); // eslint-disable-line max-len expected = [ 1.0, 6.0, 3.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); @@ -648,6 +669,7 @@ tape( 'the function supports a `y` offset (accessors)', function test( t ) { var out; var x; var y; + var i; condition = [ 0, // 0 @@ -672,9 +694,11 @@ tape( 'the function supports a `y` offset (accessors)', function test( t ) { 8.0 ]; - out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 1 ); + out = gwhere( 3, toAccessorArray( condition ), 1, 0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 1 ); // eslint-disable-line max-len expected = [ 5.0, 2.0, 7.0 ]; - t.deepEqual( out, expected, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( out.get( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); From 5d4bc0532a4e974a940b585fbfd2bd262048d00f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 15 Apr 2026 13:07:12 +0500 Subject: [PATCH 3/3] docs: apply suggestions from code review Co-authored-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js | 2 +- lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js | 2 +- lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js index e3510392636c..3f7319858bf0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/accessors.js @@ -30,7 +30,7 @@ var zeros = require( '@stdlib/array/base/zeros' ); * Takes elements from one of two strided arrays depending on a condition. * * @private -* @param {NonNegativeInteger} N - number of indexed elements +* @param {PositiveInteger} N - number of indexed elements * @param {Object} condition - condition array object * @param {Collection} condition.data - condition array data * @param {Array} condition.accessors - array element accessors diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js index b36e1691b0c7..8dc9e9bd282f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/main.js @@ -29,7 +29,7 @@ var ndarray = require( './ndarray.js' ); /** * Takes elements from one of two strided arrays depending on a condition. * -* @param {NonNegativeInteger} N - number of indexed elements +* @param {PositiveInteger} N - number of indexed elements * @param {Collection} condition - condition array * @param {integer} strideC - stride length for `condition` * @param {Collection} x - first input array diff --git a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js index f93e7e94b1eb..da1bce8eb459 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gwhere/lib/ndarray.js @@ -30,7 +30,7 @@ var accessors = require( './accessors.js' ); /** * Takes elements from one of two strided arrays depending on a condition. * -* @param {NonNegativeInteger} N - number of indexed elements +* @param {PositiveInteger} N - number of indexed elements * @param {Collection} condition - condition array * @param {integer} strideC - stride length for `condition` * @param {NonNegativeInteger} offsetC - starting index for `condition`