From 873fafbbeec589fc7f5e923e178e339e503a908f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 29 Aug 2026 16:38:26 +0500 Subject: [PATCH 1/8] feat: add blas/ext/cuany --- .../@stdlib/blas/ext/cuany/README.md | 198 ++++++ .../ext/cuany/benchmark/benchmark.assign.js | 112 +++ .../blas/ext/cuany/benchmark/benchmark.js | 104 +++ .../@stdlib/blas/ext/cuany/docs/repl.txt | 70 ++ .../blas/ext/cuany/docs/types/index.d.ts | 134 ++++ .../@stdlib/blas/ext/cuany/docs/types/test.ts | 211 ++++++ .../@stdlib/blas/ext/cuany/examples/index.js | 42 ++ .../@stdlib/blas/ext/cuany/lib/index.js | 60 ++ .../@stdlib/blas/ext/cuany/lib/main.js | 104 +++ .../@stdlib/blas/ext/cuany/package.json | 66 ++ .../blas/ext/cuany/test/test.assign.js | 649 ++++++++++++++++++ .../@stdlib/blas/ext/cuany/test/test.js | 39 ++ .../@stdlib/blas/ext/cuany/test/test.main.js | 527 ++++++++++++++ 13 files changed, 2316 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/cuany/test/test.main.js diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/README.md b/lib/node_modules/@stdlib/blas/ext/cuany/README.md new file mode 100644 index 000000000000..5c0f3bc9abe9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/README.md @@ -0,0 +1,198 @@ + + +# cuany + +> Cumulatively test whether at least one element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions is truthy. + +
+ +## Usage + +```javascript +var cuany = require( '@stdlib/blas/ext/cuany' ); +``` + +#### cuany( x\[, options] ) + +Cumulatively tests whether at least one element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions is truthy. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); + +var y = cuany( x ); +// returns [ false, false, true, true ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a boolean or "generic" [data type][@stdlib/ndarray/dtypes]. + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 0.0, 0.0, 1.0, 0.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var y = cuany( x, { + 'dims': [ 0 ] +}); +// returns [ [ false, false ], [ true, false ] ] + +y = cuany( x, { + 'dims': [ 1 ] +}); +// returns [ [ false, false ], [ true, true ] ] + +y = cuany( x, { + 'dims': [ 0, 1 ] +}); +// returns [ [ false, false ], [ true, true ] ] +``` + +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); + +var y = cuany( x, { + 'dtype': 'generic' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'generic' +``` + +#### cuany.assign( x, out\[, options] ) + +Cumulatively tests whether at least one element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions is truthy and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var falses = require( '@stdlib/ndarray/falses' ); + +var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); +var y = falses( [ 4 ] ); + +var out = cuany.assign( x, y ); +// returns [ false, false, true, true ] + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **out**: output [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- Both functions iterate over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the operation. +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a boolean or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. +- Both functions explicitly treat `NaN` values as falsy. + +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/bernoulli' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cuany = require( '@stdlib/blas/ext/cuany' ); + +// Generate an ndarray of random numbers: +var x = bernoulli( [ 5, 5 ], 0.3, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var y = cuany( x, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..01a7b4bad32e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var falsesLike = require( '@stdlib/ndarray/falses-like' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var cuany = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var out; + var x; + + x = zeros( [ len ], options ); + + out = falsesLike( x, { + 'dtype': 'bool' + }); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = cuany.assign( x, out ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isBoolean( o.get( i%len ) ) ) { + b.fail( 'should return a boolean' ); + } + 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:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js new file mode 100644 index 000000000000..3f7e15f12dba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var cuany = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = zeros( [ len ], options ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = cuany( x ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isBoolean( o.get( i%len ) ) ) { + b.fail( 'should return a boolean' ); + } + 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:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/cuany/docs/repl.txt new file mode 100644 index 000000000000..f50f90b23485 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/repl.txt @@ -0,0 +1,70 @@ + +{{alias}}( x[, options] ) + Cumulatively tests whether at least one element along one or more ndarray + dimensions is truthy. + + Parameters + ---------- + x: ndarray + Input array. + + options: Object (optional) + Function options. + + options.dtype: string|DataType (optional) + Output array data type. Must be a boolean or "generic" data type. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 1.0, 0.0 ] ); + > var y = {{alias}}( x ) + [ false, false, true, true ] + + +{{alias}}.assign( x, out[, options] ) + Cumulatively tests whether at least one element along one or more ndarray + dimensions is truthy and assigns results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + out: ndarray + Output array. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 1.0, 0.0 ] ); + > var out = {{alias:@stdlib/ndarray/falses}}( [ 4 ] ); + > var y = {{alias}}.assign( x, out ) + [ false, false, true, true ] + > var bool = ( out === y ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts new file mode 100644 index 000000000000..3ab918aa938e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts @@ -0,0 +1,134 @@ +/* +* @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 { ArrayLike } from '@stdlib/types/array'; +import { BooleanAndGenericDataType as DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* Interface defining options. +*/ +interface Options extends BaseOptions { + /** + * Output array data type. + */ + dtype?: DataType; +} + +/** +* Interface for performing an operation on an ndarray. +*/ +interface Unary { + /** + * Cumulatively tests whether at least one element along one or more ndarray dimensions is truthy. + * + * @param x - input ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); + * + * var y = cuany( x ); + * // returns [ false, false, true, true ] + */ + ( x: InputArray, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + + /** + * Cumulatively tests whether at least one element along one or more ndarray dimensions is truthy and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param out - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var falses = require( '@stdlib/ndarray/falses' ); + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); + * var y = falses( [ 4 ] ); + * + * var out = cuany.assign( x, y ); + * // returns [ false, false, true, true ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; +} + +/** +* Cumulatively tests whether at least one element along one or more ndarray dimensions is truthy. +* +* @param x - input ndarray +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); +* +* var y = cuany( x ); +* // returns [ false, false, true, true ] +* +* @example +* var falses = require( '@stdlib/ndarray/falses' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 0.0, 1.0, 0.0 ] ); +* var y = falses( [ 4 ] ); +* +* var out = cuany.assign( x, y ); +* // returns [ false, false, true, true ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const cuany: Unary; + + +// EXPORTS // + +export = cuany; diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts new file mode 100644 index 000000000000..de973e8b2825 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts @@ -0,0 +1,211 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +/// + +import zeros = require( '@stdlib/ndarray/zeros' ); +import cuany = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany( x ); // $ExpectType OutputArray + cuany( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + cuany( '5' ); // $ExpectError + cuany( 5 ); // $ExpectError + cuany( true ); // $ExpectError + cuany( false ); // $ExpectError + cuany( null ); // $ExpectError + cuany( void 0 ); // $ExpectError + cuany( {} ); // $ExpectError + cuany( ( x: number ): number => x ); // $ExpectError + + cuany( '5', {} ); // $ExpectError + cuany( 5, {} ); // $ExpectError + cuany( true, {} ); // $ExpectError + cuany( false, {} ); // $ExpectError + cuany( null, {} ); // $ExpectError + cuany( void 0, {} ); // $ExpectError + cuany( {}, {} ); // $ExpectError + cuany( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany( x, '5' ); // $ExpectError + cuany( x, true ); // $ExpectError + cuany( x, false ); // $ExpectError + cuany( x, null ); // $ExpectError + cuany( x, [] ); // $ExpectError + cuany( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany( x, { 'dtype': '5' } ); // $ExpectError + cuany( x, { 'dtype': 5 } ); // $ExpectError + cuany( x, { 'dtype': true } ); // $ExpectError + cuany( x, { 'dtype': false } ); // $ExpectError + cuany( x, { 'dtype': null } ); // $ExpectError + cuany( x, { 'dtype': [] } ); // $ExpectError + cuany( x, { 'dtype': {} } ); // $ExpectError + cuany( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany( x, { 'dims': '5' } ); // $ExpectError + cuany( x, { 'dims': 5 } ); // $ExpectError + cuany( x, { 'dims': true } ); // $ExpectError + cuany( x, { 'dims': false } ); // $ExpectError + cuany( x, { 'dims': null } ); // $ExpectError + cuany( x, { 'dims': {} } ); // $ExpectError + cuany( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany(); // $ExpectError + cuany( x, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany.assign( x, x ); // $ExpectType float64ndarray + cuany.assign( x, x, {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany.assign( '5', x ); // $ExpectError + cuany.assign( 5, x ); // $ExpectError + cuany.assign( true, x ); // $ExpectError + cuany.assign( false, x ); // $ExpectError + cuany.assign( null, x ); // $ExpectError + cuany.assign( void 0, x ); // $ExpectError + cuany.assign( {}, x ); // $ExpectError + cuany.assign( ( x: number ): number => x, x ); // $ExpectError + + cuany.assign( '5', x, {} ); // $ExpectError + cuany.assign( 5, x, {} ); // $ExpectError + cuany.assign( true, x, {} ); // $ExpectError + cuany.assign( false, x, {} ); // $ExpectError + cuany.assign( null, x, {} ); // $ExpectError + cuany.assign( void 0, x, {} ); // $ExpectError + cuany.assign( {}, x, {} ); // $ExpectError + cuany.assign( ( x: number ): number => x, x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany.assign( x, '5' ); // $ExpectError + cuany.assign( x, 5 ); // $ExpectError + cuany.assign( x, true ); // $ExpectError + cuany.assign( x, false ); // $ExpectError + cuany.assign( x, null ); // $ExpectError + cuany.assign( x, void 0 ); // $ExpectError + cuany.assign( x, ( x: number ): number => x ); // $ExpectError + + cuany.assign( x, '5', {} ); // $ExpectError + cuany.assign( x, 5, {} ); // $ExpectError + cuany.assign( x, true, {} ); // $ExpectError + cuany.assign( x, false, {} ); // $ExpectError + cuany.assign( x, null, {} ); // $ExpectError + cuany.assign( x, void 0, {} ); // $ExpectError + cuany.assign( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an object... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany.assign( x, x, '5' ); // $ExpectError + cuany.assign( x, x, true ); // $ExpectError + cuany.assign( x, x, false ); // $ExpectError + cuany.assign( x, x, null ); // $ExpectError + cuany.assign( x, x, [] ); // $ExpectError + cuany.assign( x, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany.assign( x, x, { 'dims': '5' } ); // $ExpectError + cuany.assign( x, x, { 'dims': 5 } ); // $ExpectError + cuany.assign( x, x, { 'dims': true } ); // $ExpectError + cuany.assign( x, x, { 'dims': false } ); // $ExpectError + cuany.assign( x, x, { 'dims': null } ); // $ExpectError + cuany.assign( x, x, { 'dims': {} } ); // $ExpectError + cuany.assign( x, x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cuany.assign(); // $ExpectError + cuany.assign( x ); // $ExpectError + cuany.assign( x, x, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/examples/index.js b/lib/node_modules/@stdlib/blas/ext/cuany/examples/index.js new file mode 100644 index 000000000000..9c12532325dc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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/bernoulli' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var cuany = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = bernoulli( [ 5, 5 ], 0.3, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var y = cuany( x, { + 'dims': [ 0 ] +}); + +// Resolve the output array data type: +var dt = getDType( y ); +console.log( dt ); + +// Print the results: +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/lib/index.js b/lib/node_modules/@stdlib/blas/ext/cuany/lib/index.js new file mode 100644 index 000000000000..dc299fd7eef3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/lib/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Cumulatively test whether at least one element along one or more ndarray dimensions is truthy. +* +* @module @stdlib/blas/ext/cuany +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var cuany = require( '@stdlib/blas/ext/cuany' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 4.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = cuany( x ); +* // returns [ [ [ false, false ] ], [ [ false, true ] ], [ [ true, true ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/lib/main.js b/lib/node_modules/@stdlib/blas/ext/cuany/lib/main.js new file mode 100644 index 000000000000..1305676892e7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/lib/main.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable array-element-newline */ + +'use strict'; + +// MODULES // + +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var gcuany = require( '@stdlib/blas/ext/base/ndarray/gcuany' ); +var dcuany = require( '@stdlib/blas/ext/base/ndarray/dcuany' ); +var scuany = require( '@stdlib/blas/ext/base/ndarray/scuany' ); +var factory = require( '@stdlib/ndarray/base/unary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes = dtypes( 'all' ); +var odtypes = dtypes( 'boolean_and_generic' ); +var policies = { + 'output': 'boolean_and_generic', + 'casting': 'none' +}; +var table = { + 'types': [ + 'float64', 'bool', // input, output + 'float32', 'bool' // input, output + + // FIXME: add specialized support for `ccuany` and `zcuany` once the corresponding packages are implemented + ], + 'fcns': [ + dcuany, + scuany + ], + 'default': gcuany +}; +var options = { + 'strictTraversalOrder': true +}; + + +// MAIN // + +/** +* Cumulatively tests whether at least one element along one or more ndarray dimensions is truthy. +* +* @name cuany +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @param {*} [options.dtype] - output ndarray data type +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} output ndarray +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 0.0, 0.0, 4.0, 0.0, 0.0 ] ); +* +* // Define the shape of the input array: +* var sh = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); +* +* // Perform operation: +* var out = cuany( x ); +* // returns [ [ [ false, false ] ], [ [ false, true ] ], [ [ true, true ] ] ] +*/ +var cuany = factory( table, [ idtypes ], odtypes, policies, options ); + + +// EXPORTS // + +module.exports = cuany; diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/package.json b/lib/node_modules/@stdlib/blas/ext/cuany/package.json new file mode 100644 index 000000000000..58b3c0dedc31 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/cuany", + "version": "0.0.0", + "description": "Cumulatively test whether at least one element along one or more ndarray dimensions is truthy.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "cumulative", + "any", + "cuany", + "truthy", + "test", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/cuany/test/test.assign.js new file mode 100644 index 000000000000..2db514b64ea5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/test/test.assign.js @@ -0,0 +1,649 @@ +/** +* @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 isSameArray = require( '@stdlib/assert/is-same-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var emptyLike = require( '@stdlib/ndarray/empty-like' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var cuany = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuany, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var out; + var i; + + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an object', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, out, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (default)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 2, 2, 2 ], + [ 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + cuany( x, out ); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (all dimensions)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 2, 2, 2 ], + [ 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + cuany( x, out, { + 'dims': [ 0, 1 ] + }); + }; + } +}); + +tape( 'the function throws an error if provided an output array which has an invalid shape (some dimensions)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [], + [ 2, 2, 2 ], + [ 4, 4 ], + [ 4 ], + [ 1 ], + [ 1, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var out = zeros( value, { + 'dtype': 'generic' + }); + cuany( x, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out ); + expected = [ false, false, true, true ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out ); + expected = [ false, false, true, true ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [ 0, 1 ] + }); + expected = [ false, false, true, true ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [ 0, 1 ] + }); + expected = [ false, false, true, true ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [] + }); + expected = [ [ false, false ], [ true, false ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [] + }); + expected = [ [ false, true ], [ false, false ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [ 0 ] + }); + expected = [ [ false, false ], [ true, false ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [ 1 ] + }); + expected = [ [ false, false ], [ true, true ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [ 0 ] + }); + expected = [ [ false, true ], [ false, true ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cuany( x, out, { + 'dims': [ 1 ] + }); + expected = [ [ false, true ], [ false, false ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/test/test.js b/lib/node_modules/@stdlib/blas/ext/cuany/test/test.js new file mode 100644 index 000000000000..b510453710f1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/test/test.js @@ -0,0 +1,39 @@ +/** +* @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 isMethod = require( '@stdlib/assert/is-method' ); +var cuany = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuany, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( cuany, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/cuany/test/test.main.js new file mode 100644 index 000000000000..cf1ea114d300 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cuany/test/test.main.js @@ -0,0 +1,527 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var isEqualBooleanArray = require( '@stdlib/assert/is-equal-booleanarray' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var cuany = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuany, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( value ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + 'float64', + 'int32' + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cuany( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cuany( x ); + expected = [ false, false, true, true ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cuany( x ); + expected = [ false, false, true, true ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cuany( x, { + 'dims': [ 0, 1 ] + }); + expected = [ false, false, true, true ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cuany( x, { + 'dims': [ 0, 1 ] + }); + expected = [ false, false, true, true ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cuany( x, { + 'dims': [] + }); + expected = [ [ false, false ], [ true, false ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in an ndarray is truthy (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cuany( x, { + 'dims': [] + }); + expected = [ [ false, true ], [ false, false ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cuany( x, { + 'dims': [ 0 ] + }); + expected = [ [ false, false ], [ true, false ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cuany( x, { + 'dims': [ 1 ] + }); + expected = [ [ false, false ], [ true, true ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cuany( x, { + 'dims': [ 0 ] + }); + expected = [ [ false, true ], [ false, true ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cuany( x, { + 'dims': [ 1 ] + }); + expected = [ [ false, true ], [ false, false ] ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying the output array data type', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cuany( x, { + 'dtype': 'bool' + }); + expected = new BooleanArray( [ false, false, true, true ] ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'bool', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isEqualBooleanArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 0.0, 0.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cuany( x, { + 'dtype': 'bool' + }); + expected = new BooleanArray( [ false, false, true, true ] ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'bool', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isEqualBooleanArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); From 333978e64bd164e3938f10eb45e4f4fb926a8328 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:12:44 -0700 Subject: [PATCH 2/8] style: remove linebreak Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js index 3f7e15f12dba..80baf58faa71 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.js @@ -47,7 +47,6 @@ var options = { */ function createBenchmark( len ) { var x = zeros( [ len ], options ); - return benchmark; /** From 2e9bdee9e32fbe6affd8cc93a746f06490a72da6 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:13:08 -0700 Subject: [PATCH 3/8] style: remove linebreak Signed-off-by: Athan --- .../@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js index 01a7b4bad32e..e06cd802f892 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js +++ b/lib/node_modules/@stdlib/blas/ext/cuany/benchmark/benchmark.assign.js @@ -51,7 +51,6 @@ function createBenchmark( len ) { var x; x = zeros( [ len ], options ); - out = falsesLike( x, { 'dtype': 'bool' }); From b9259c311abf943e98e62f7952c5f911697d718d Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:18:48 -0700 Subject: [PATCH 4/8] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts | 4 ++-- lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts index 3ab918aa938e..025ba053dad7 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts @@ -72,7 +72,7 @@ interface Unary { * var y = cuany( x ); * // returns [ false, false, true, true ] */ - ( x: InputArray, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. + ( x: InputArray, options?: Options ): OutputArray; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`. /** * Cumulatively tests whether at least one element along one or more ndarray dimensions is truthy and assigns results to a provided output ndarray. @@ -95,7 +95,7 @@ interface Unary { * var bool = ( out === y ); * // returns true */ - assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; + assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; } /** diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts index de973e8b2825..31523a3996f4 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts @@ -32,8 +32,8 @@ import cuany = require( './index' ); 'dtype': 'float64' }); - cuany( x ); // $ExpectType OutputArray - cuany( x, {} ); // $ExpectType OutputArray + cuany( x ); // $ExpectType OutputArray + cuany( x, {} ); // $ExpectType OutputArray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... From 4ac148e4eea977dab2a7710b05fcd922bdc638e3 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:19:49 -0700 Subject: [PATCH 5/8] refactor: reduce reliance on generics Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts index 025ba053dad7..a59435de3b1a 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/index.d.ts @@ -95,7 +95,7 @@ interface Unary { * var bool = ( out === y ); * // returns true */ - assign = OutputArray>( x: InputArray, out: U, options?: BaseOptions ): U; + assign = OutputArray>( x: InputArray, out: T, options?: BaseOptions ): T; } /** From ff4bd273da96372ebd76c45658f561d99f9687b8 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:22:43 -0700 Subject: [PATCH 6/8] test: fix tests Signed-off-by: Athan --- .../@stdlib/blas/ext/cuany/docs/types/test.ts | 109 ++++++++++-------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts index 31523a3996f4..423819ce8ff6 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts @@ -20,7 +20,7 @@ /// -import zeros = require( '@stdlib/ndarray/zeros' ); +import empty = require( '@stdlib/ndarray/empty' ); import cuany = require( './index' ); @@ -28,12 +28,12 @@ import cuany = require( './index' ); // The function returns an ndarray... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - cuany( x ); // $ExpectType OutputArray - cuany( x, {} ); // $ExpectType OutputArray + cuany( x ); // $ExpectType OutputArray + cuany( x, {} ); // $ExpectType OutputArray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... @@ -59,7 +59,7 @@ import cuany = require( './index' ); // The compiler throws an error if the function is provided a second argument which is not an object... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); @@ -73,7 +73,7 @@ import cuany = require( './index' ); // The compiler throws an error if the function is provided an invalid `dtype` option... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); @@ -89,7 +89,7 @@ import cuany = require( './index' ); // The compiler throws an error if the function is provided an invalid `dims` option... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); @@ -104,7 +104,7 @@ import cuany = require( './index' ); // The compiler throws an error if the function is provided an unsupported number of arguments... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); @@ -114,42 +114,48 @@ import cuany = require( './index' ); // Attached to the function is an `assign` method which returns an ndarray... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); + const out = empty( [ 1 ], { + 'dtype': 'bool' + }); - cuany.assign( x, x ); // $ExpectType float64ndarray - cuany.assign( x, x, {} ); // $ExpectType float64ndarray + cuany.assign( x, out ); // $ExpectType boolndarray + cuany.assign( x, out, {} ); // $ExpectType boolndarray } // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); + const out = empty( [ 1 ], { + 'dtype': 'bool' + }); - cuany.assign( '5', x ); // $ExpectError - cuany.assign( 5, x ); // $ExpectError - cuany.assign( true, x ); // $ExpectError - cuany.assign( false, x ); // $ExpectError - cuany.assign( null, x ); // $ExpectError - cuany.assign( void 0, x ); // $ExpectError - cuany.assign( {}, x ); // $ExpectError - cuany.assign( ( x: number ): number => x, x ); // $ExpectError - - cuany.assign( '5', x, {} ); // $ExpectError - cuany.assign( 5, x, {} ); // $ExpectError - cuany.assign( true, x, {} ); // $ExpectError - cuany.assign( false, x, {} ); // $ExpectError - cuany.assign( null, x, {} ); // $ExpectError - cuany.assign( void 0, x, {} ); // $ExpectError - cuany.assign( {}, x, {} ); // $ExpectError - cuany.assign( ( x: number ): number => x, x, {} ); // $ExpectError + cuany.assign( '5', out ); // $ExpectError + cuany.assign( 5, out ); // $ExpectError + cuany.assign( true, out ); // $ExpectError + cuany.assign( false, out ); // $ExpectError + cuany.assign( null, out ); // $ExpectError + cuany.assign( void 0, out ); // $ExpectError + cuany.assign( {}, out ); // $ExpectError + cuany.assign( ( x: number ): number => x, out ); // $ExpectError + + cuany.assign( '5', out, {} ); // $ExpectError + cuany.assign( 5, out, {} ); // $ExpectError + cuany.assign( true, out, {} ); // $ExpectError + cuany.assign( false, out, {} ); // $ExpectError + cuany.assign( null, out, {} ); // $ExpectError + cuany.assign( void 0, out, {} ); // $ExpectError + cuany.assign( {}, out, {} ); // $ExpectError + cuany.assign( ( x: number ): number => x, out, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); @@ -172,40 +178,49 @@ import cuany = require( './index' ); // The compiler throws an error if the `assign` method is provided a third argument which is not an object... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); + const out = empty( [ 1 ], { + 'dtype': 'bool' + }); - cuany.assign( x, x, '5' ); // $ExpectError - cuany.assign( x, x, true ); // $ExpectError - cuany.assign( x, x, false ); // $ExpectError - cuany.assign( x, x, null ); // $ExpectError - cuany.assign( x, x, [] ); // $ExpectError - cuany.assign( x, x, ( x: number ): number => x ); // $ExpectError + cuany.assign( x, out, '5' ); // $ExpectError + cuany.assign( x, out, true ); // $ExpectError + cuany.assign( x, out, false ); // $ExpectError + cuany.assign( x, out, null ); // $ExpectError + cuany.assign( x, out, [] ); // $ExpectError + cuany.assign( x, out, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an invalid `dims` option... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); + const out = empty( [ 1 ], { + 'dtype': 'bool' + }); - cuany.assign( x, x, { 'dims': '5' } ); // $ExpectError - cuany.assign( x, x, { 'dims': 5 } ); // $ExpectError - cuany.assign( x, x, { 'dims': true } ); // $ExpectError - cuany.assign( x, x, { 'dims': false } ); // $ExpectError - cuany.assign( x, x, { 'dims': null } ); // $ExpectError - cuany.assign( x, x, { 'dims': {} } ); // $ExpectError - cuany.assign( x, x, { 'dims': ( x: number ): number => x } ); // $ExpectError + cuany.assign( x, out, { 'dims': '5' } ); // $ExpectError + cuany.assign( x, out, { 'dims': 5 } ); // $ExpectError + cuany.assign( x, out, { 'dims': true } ); // $ExpectError + cuany.assign( x, out, { 'dims': false } ); // $ExpectError + cuany.assign( x, out, { 'dims': null } ); // $ExpectError + cuany.assign( x, out, { 'dims': {} } ); // $ExpectError + cuany.assign( x, out, { 'dims': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an unsupported number of arguments... { - const x = zeros( [ 2, 2 ], { + const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); + const out = empty( [ 1 ], { + 'dtype': 'bool' + }); cuany.assign(); // $ExpectError cuany.assign( x ); // $ExpectError - cuany.assign( x, x, {}, {} ); // $ExpectError + cuany.assign( x, out, {}, {} ); // $ExpectError } From 8b463f4b943da9afe6ebd11a7939452db2bf4bf0 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:24:04 -0700 Subject: [PATCH 7/8] test: remove unused variable Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts index 423819ce8ff6..6abf8f839681 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts @@ -127,9 +127,6 @@ import cuany = require( './index' ); // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... { - const x = empty( [ 2, 2 ], { - 'dtype': 'float64' - }); const out = empty( [ 1 ], { 'dtype': 'bool' }); From 8c70db91786650d3935539d606e3ecf94ac28570 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 29 Aug 2026 05:26:59 -0700 Subject: [PATCH 8/8] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/cuany/docs/types/test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts index 6abf8f839681..7739a29d64a8 100644 --- a/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/cuany/docs/types/test.ts @@ -117,7 +117,7 @@ import cuany = require( './index' ); const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - const out = empty( [ 1 ], { + const out = empty( [ 2, 2 ], { 'dtype': 'bool' }); @@ -127,7 +127,7 @@ import cuany = require( './index' ); // The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... { - const out = empty( [ 1 ], { + const out = empty( [ 2, 2 ], { 'dtype': 'bool' }); @@ -178,7 +178,7 @@ import cuany = require( './index' ); const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - const out = empty( [ 1 ], { + const out = empty( [ 2, 2 ], { 'dtype': 'bool' }); @@ -195,7 +195,7 @@ import cuany = require( './index' ); const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - const out = empty( [ 1 ], { + const out = empty( [ 2, 2 ], { 'dtype': 'bool' }); @@ -213,7 +213,7 @@ import cuany = require( './index' ); const x = empty( [ 2, 2 ], { 'dtype': 'float64' }); - const out = empty( [ 1 ], { + const out = empty( [ 2, 2 ], { 'dtype': 'bool' });