diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/README.md b/lib/node_modules/@stdlib/blas/ext/cusome/README.md new file mode 100644 index 000000000000..310989a611cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/README.md @@ -0,0 +1,202 @@ + + +# cusome + +> Cumulatively test whether at least `k` elements along one or more [ndarray][@stdlib/ndarray/ctor] dimensions are truthy. + +
+ +## Usage + +```javascript +var cusome = require( '@stdlib/blas/ext/cusome' ); +``` + +#### cusome( x, k\[, options] ) + +Cumulatively tests whether at least `k` elements along one or more [ndarray][@stdlib/ndarray/ctor] dimensions are truthy. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 0.0, 1.0, 1.0, 0.0 ] ); + +var y = cusome( x, 2 ); +// returns [ false, false, true, true ] +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **k**: minimum number of truthy elements. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] value must be a zero-dimensional [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( [ 1.0, 1.0, 0.0, 1.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); + +var y = cusome( x, 2, { + 'dims': [ 0 ] +}); +// returns [ [ false, false ], [ false, true ] ] + +y = cusome( x, 2, { + 'dims': [ 1 ] +}); +// returns [ [ false, true ], [ false, false ] ] + +y = cusome( x, 2, { + 'dims': [ 0, 1 ] +}); +// returns [ [ false, true ], [ 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, 1.0, 1.0, 0.0 ] ); + +var y = cusome( x, 2, { + 'dtype': 'generic' +}); +// returns + +var dt = String( getDType( y ) ); +// returns 'generic' +``` + +#### cusome.assign( x, k, out\[, options] ) + +Cumulatively tests whether at least `k` elements along one or more [ndarray][@stdlib/ndarray/ctor] dimensions are 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, 1.0, 1.0, 0.0 ] ); +var y = falses( [ 4 ] ); + +var out = cusome.assign( x, 2, y ); +// returns [ false, false, true, true ] + +var bool = ( out === y ); +// returns true +``` + +The method has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **k**: minimum number of truthy elements. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] value must be a zero-dimensional [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 cusome = require( '@stdlib/blas/ext/cusome' ); + +// Generate an ndarray of random numbers: +var x = bernoulli( [ 5, 5 ], 0.3, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +var y = cusome( x, 2, { + '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/cusome/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/blas/ext/cusome/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..79d54eadcf26 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/benchmark/benchmark.assign.js @@ -0,0 +1,111 @@ +/** +* @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 cusome = 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 = cusome.assign( x, 2, 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/cusome/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/cusome/benchmark/benchmark.js new file mode 100644 index 000000000000..10cd0bdbc9d9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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 cusome = 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 = cusome( x, 2 ); + 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/cusome/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/cusome/docs/repl.txt new file mode 100644 index 000000000000..775b2b5122bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/docs/repl.txt @@ -0,0 +1,92 @@ + +{{alias}}( x, k[, options] ) + Cumulatively tests whether at least `k` elements along one or more ndarray + dimensions are truthy. + + Parameters + ---------- + x: ndarray + Input array. + + k: ndarray|integer + Minimum number of truthy elements. May be either a scalar value or an + ndarray having an integer index or "generic" data type. If provided an + ndarray, the value must have a shape which is broadcast compatible with + the complement of the shape defined by `options.dims`. For example, + given the input shape [2, 3, 4] and `options.dims=[0]`, an ndarray + value must have a shape which is broadcast compatible with the shape + [3, 4]. Similarly, when performing the operation over all elements in + a provided input ndarray, an ndarray value must be a zero-dimensional + ndarray. + + 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, 1.0, 1.0, 0.0 ] ); + > var y = {{alias}}( x, 2 ) + [ false, false, true, true ] + + +{{alias}}.assign( x, k, out[, options] ) + Cumulatively tests whether at least `k` elements along one or more ndarray + dimensions are truthy and assigns results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + k: ndarray|integer + Minimum number of truthy elements. May be either a scalar value or an + ndarray having an integer index or "generic" data type. If provided an + ndarray, the value must have a shape which is broadcast compatible with + the complement of the shape defined by `options.dims`. For example, + given the input shape [2, 3, 4] and `options.dims=[0]`, an ndarray + value must have a shape which is broadcast compatible with the shape + [3, 4]. Similarly, when performing the operation over all elements in + a provided input ndarray, an ndarray value must be a zero-dimensional + ndarray. + + 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, 1.0, 1.0, 0.0 ] ); + > var out = {{alias:@stdlib/ndarray/falses}}( [ 4 ] ); + > var y = {{alias}}.assign( x, 2, out ) + [ false, false, true, true ] + > var bool = ( out === y ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/cusome/docs/types/index.d.ts new file mode 100644 index 000000000000..c2090c7d0933 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/docs/types/index.d.ts @@ -0,0 +1,142 @@ +/* +* @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; + +/** +* Minimum number of truthy elements. +*/ +type K = typedndarray | number; + +/** +* 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 `k` elements along one or more ndarray dimensions are truthy. + * + * @param x - input ndarray + * @param k - minimum number of truthy elements + * @param options - function options + * @returns output ndarray + * + * @example + * var array = require( '@stdlib/ndarray/array' ); + * + * var x = array( [ 0.0, 1.0, 1.0, 0.0 ] ); + * + * var y = cusome( x, 2 ); + * // returns [ false, false, true, true ] + */ + ( x: InputArray, k: K, 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 `k` elements along one or more ndarray dimensions are truthy and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param k - minimum number of truthy elements + * @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, 1.0, 1.0, 0.0 ] ); + * var y = falses( [ 4 ] ); + * + * var out = cusome.assign( x, 2, y ); + * // returns [ false, false, true, true ] + * + * var bool = ( out === y ); + * // returns true + */ + assign = OutputArray>( x: InputArray, k: K, out: T, options?: BaseOptions ): T; +} + +/** +* Cumulatively tests whether at least `k` elements along one or more ndarray dimensions are truthy. +* +* @param x - input ndarray +* @param k - minimum number of truthy elements +* @param options - function options +* @returns output ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 1.0, 1.0, 0.0 ] ); +* +* var y = cusome( x, 2 ); +* // returns [ false, false, true, true ] +* +* @example +* var falses = require( '@stdlib/ndarray/falses' ); +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 0.0, 1.0, 1.0, 0.0 ] ); +* var y = falses( [ 4 ] ); +* +* var out = cusome.assign( x, 2, y ); +* // returns [ false, false, true, true ] +* +* var bool = ( out === y ); +* // returns true +*/ +declare const cusome: Unary; + + +// EXPORTS // + +export = cusome; diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/cusome/docs/types/test.ts new file mode 100644 index 000000000000..add44c6dd8d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/docs/types/test.ts @@ -0,0 +1,286 @@ +/* +* @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 empty = require( '@stdlib/ndarray/empty' ); +import cusome = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + const k = empty( [], { + 'dtype': 'int32' + }); + + cusome( x, 2 ); // $ExpectType OutputArray + cusome( x, 2, {} ); // $ExpectType OutputArray + + cusome( x, k ); // $ExpectType OutputArray + cusome( x, k, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + cusome( '5', 2 ); // $ExpectError + cusome( 5, 2 ); // $ExpectError + cusome( true, 2 ); // $ExpectError + cusome( false, 2 ); // $ExpectError + cusome( null, 2 ); // $ExpectError + cusome( void 0, 2 ); // $ExpectError + cusome( {}, 2 ); // $ExpectError + cusome( ( x: number ): number => x, 2 ); // $ExpectError + + cusome( '5', 2, {} ); // $ExpectError + cusome( 5, 2, {} ); // $ExpectError + cusome( true, 2, {} ); // $ExpectError + cusome( false, 2, {} ); // $ExpectError + cusome( null, 2, {} ); // $ExpectError + cusome( void 0, 2, {} ); // $ExpectError + cusome( {}, 2, {} ); // $ExpectError + cusome( ( x: number ): number => x, 2, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an ndarray or number... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cusome( x, '5' ); // $ExpectError + cusome( x, true ); // $ExpectError + cusome( x, false ); // $ExpectError + cusome( x, null ); // $ExpectError + cusome( x, void 0 ); // $ExpectError + cusome( x, [] ); // $ExpectError + cusome( x, ( x: number ): number => x ); // $ExpectError + + cusome( x, '5', {} ); // $ExpectError + cusome( x, true, {} ); // $ExpectError + cusome( x, false, {} ); // $ExpectError + cusome( x, null, {} ); // $ExpectError + cusome( x, void 0, {} ); // $ExpectError + cusome( x, [], {} ); // $ExpectError + cusome( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not an object... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cusome( x, 2, '5' ); // $ExpectError + cusome( x, 2, true ); // $ExpectError + cusome( x, 2, false ); // $ExpectError + cusome( x, 2, null ); // $ExpectError + cusome( x, 2, [] ); // $ExpectError + cusome( x, 2, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dtype` option... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cusome( x, 2, { 'dtype': '5' } ); // $ExpectError + cusome( x, 2, { 'dtype': 5 } ); // $ExpectError + cusome( x, 2, { 'dtype': true } ); // $ExpectError + cusome( x, 2, { 'dtype': false } ); // $ExpectError + cusome( x, 2, { 'dtype': null } ); // $ExpectError + cusome( x, 2, { 'dtype': [] } ); // $ExpectError + cusome( x, 2, { 'dtype': {} } ); // $ExpectError + cusome( x, 2, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cusome( x, 2, { 'dims': '5' } ); // $ExpectError + cusome( x, 2, { 'dims': 5 } ); // $ExpectError + cusome( x, 2, { 'dims': true } ); // $ExpectError + cusome( x, 2, { 'dims': false } ); // $ExpectError + cusome( x, 2, { 'dims': null } ); // $ExpectError + cusome( x, 2, { 'dims': {} } ); // $ExpectError + cusome( x, 2, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cusome(); // $ExpectError + cusome( x ); // $ExpectError + cusome( x, 2, {}, {} ); // $ExpectError +} + +// Attached to the function is an `assign` method which returns an ndarray... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + const k = empty( [], { + 'dtype': 'int32' + }); + const out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + cusome.assign( x, 2, out ); // $ExpectType boolndarray + cusome.assign( x, 2, out, {} ); // $ExpectType boolndarray + + cusome.assign( x, k, out ); // $ExpectType boolndarray + cusome.assign( x, k, out, {} ); // $ExpectType boolndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + cusome.assign( '5', 2, out ); // $ExpectError + cusome.assign( 5, 2, out ); // $ExpectError + cusome.assign( true, 2, out ); // $ExpectError + cusome.assign( false, 2, out ); // $ExpectError + cusome.assign( null, 2, out ); // $ExpectError + cusome.assign( void 0, 2, out ); // $ExpectError + cusome.assign( {}, 2, out ); // $ExpectError + cusome.assign( ( x: number ): number => x, 2, out ); // $ExpectError + + cusome.assign( '5', 2, out, {} ); // $ExpectError + cusome.assign( 5, 2, out, {} ); // $ExpectError + cusome.assign( true, 2, out, {} ); // $ExpectError + cusome.assign( false, 2, out, {} ); // $ExpectError + cusome.assign( null, 2, out, {} ); // $ExpectError + cusome.assign( void 0, 2, out, {} ); // $ExpectError + cusome.assign( {}, 2, out, {} ); // $ExpectError + cusome.assign( ( x: number ): number => x, 2, out, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray or number... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + cusome.assign( x, '5', out ); // $ExpectError + cusome.assign( x, true, out ); // $ExpectError + cusome.assign( x, false, out ); // $ExpectError + cusome.assign( x, null, out ); // $ExpectError + cusome.assign( x, void 0, out ); // $ExpectError + cusome.assign( x, [], out ); // $ExpectError + cusome.assign( x, ( x: number ): number => x, out ); // $ExpectError + + cusome.assign( x, '5', out, {} ); // $ExpectError + cusome.assign( x, true, out, {} ); // $ExpectError + cusome.assign( x, false, out, {} ); // $ExpectError + cusome.assign( x, null, out, {} ); // $ExpectError + cusome.assign( x, void 0, out, {} ); // $ExpectError + cusome.assign( x, [], out, {} ); // $ExpectError + cusome.assign( x, ( x: number ): number => x, out, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an ndarray... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + cusome.assign( x, 2, '5' ); // $ExpectError + cusome.assign( x, 2, 5 ); // $ExpectError + cusome.assign( x, 2, true ); // $ExpectError + cusome.assign( x, 2, false ); // $ExpectError + cusome.assign( x, 2, null ); // $ExpectError + cusome.assign( x, 2, void 0 ); // $ExpectError + cusome.assign( x, 2, ( x: number ): number => x ); // $ExpectError + + cusome.assign( x, 2, '5', {} ); // $ExpectError + cusome.assign( x, 2, 5, {} ); // $ExpectError + cusome.assign( x, 2, true, {} ); // $ExpectError + cusome.assign( x, 2, false, {} ); // $ExpectError + cusome.assign( x, 2, null, {} ); // $ExpectError + cusome.assign( x, 2, void 0, {} ); // $ExpectError + cusome.assign( x, 2, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not an object... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + cusome.assign( x, 2, out, '5' ); // $ExpectError + cusome.assign( x, 2, out, true ); // $ExpectError + cusome.assign( x, 2, out, false ); // $ExpectError + cusome.assign( x, 2, out, null ); // $ExpectError + cusome.assign( x, 2, out, [] ); // $ExpectError + cusome.assign( x, 2, out, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + cusome.assign( x, 2, out, { 'dims': '5' } ); // $ExpectError + cusome.assign( x, 2, out, { 'dims': 5 } ); // $ExpectError + cusome.assign( x, 2, out, { 'dims': true } ); // $ExpectError + cusome.assign( x, 2, out, { 'dims': false } ); // $ExpectError + cusome.assign( x, 2, out, { 'dims': null } ); // $ExpectError + cusome.assign( x, 2, out, { 'dims': {} } ); // $ExpectError + cusome.assign( x, 2, 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 = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + const out = empty( [ 2, 2 ], { + 'dtype': 'bool' + }); + + cusome.assign(); // $ExpectError + cusome.assign( x ); // $ExpectError + cusome.assign( x, 2 ); // $ExpectError + cusome.assign( x, 2, out, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/examples/index.js b/lib/node_modules/@stdlib/blas/ext/cusome/examples/index.js new file mode 100644 index 000000000000..cb80c2bb053d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/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 cusome = 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 = cusome( x, 2, { + '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/cusome/lib/assign.js b/lib/node_modules/@stdlib/blas/ext/cusome/lib/assign.js new file mode 100644 index 000000000000..5b71732bada4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/lib/assign.js @@ -0,0 +1,159 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var base = require( './base.js' ).assign; + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least `k` elements along one or more ndarray dimensions are truthy and assigns the results to a provided output ndarray. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} k - minimum number of truthy elements +* @param {ndarrayLike} out - output ndarray +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object or an integer +* @throws {TypeError} third 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 BooleanArray = require( '@stdlib/array/bool' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 0.0, 1.0, 0.0, 4.0, 3.0, 0.0 ] ); +* var ybuf = new BooleanArray( 6 ); +* +* // Define the shape of the input array: +* var shape = [ 3, 1, 2 ]; +* +* // Define the array strides: +* var strides = [ 2, 2, 1 ]; +* +* // Define the index offset: +* var offset = 0; +* +* // Create an input ndarray: +* var x = new ndarray( 'float64', xbuf, shape, strides, offset, 'row-major' ); +* +* // Create an output ndarray: +* var y = new ndarray( 'bool', ybuf, shape, strides, offset, 'row-major' ); +* +* // Perform operation: +* var out = assign( x, 2, y ); +* // returns [ [ [ false, false ] ], [ [ false, true ] ], [ [ true, true ] ] ] +* +* var bool = ( out === y ); +* // returns true +*/ +function assign( x, k, out ) { + var options; + var nargs; + var opts; + var iflg; + var ord; + var sh; + var v; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = {}; + + // Initialize a flag indicating whether the `k` argument is a scalar: + iflg = true; + + // Case: assign( x, k_ndarray, out, ... ) + if ( isndarrayLike( k ) ) { + iflg = false; + } + // Case: assign( x, ???, out, ... ) + else if ( !isInteger( k ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) ); + } + if ( !isndarrayLike( out ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an ndarray. Value: `%s`.', out ) ); + } + // Case: assign( x, k, out, options ) + if ( nargs > 3 ) { + options = arguments[ 3 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dims' ) ) { + opts.dims = options.dims; + } + } + // Resolve the shape of the non-core dimensions, noting that, when not provided `dims`, the operation is performed across all dimensions: + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + // Broadcast `k` to match the shape of the non-core dimensions, noting that, when not provided `dims`, `k` must be a zero-dimensional ndarray, as the operation is performed across all dimensions... + if ( iflg ) { + v = broadcastScalar( k, DEFAULT_DTYPE, sh, ord ); + } else if ( hasOwnProp( opts, 'dims' ) ) { + v = maybeBroadcastArray( k, sh ); + } else if ( ndims( k ) === 0 ) { + v = k; + } else { + throw new TypeError( 'invalid argument. Second argument must be a zero-dimensional ndarray.' ); + } + return base( x, v, out, opts ); +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/lib/base.js b/lib/node_modules/@stdlib/blas/ext/cusome/lib/base.js new file mode 100644 index 000000000000..f205d1e11a41 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/lib/base.js @@ -0,0 +1,116 @@ +/** +* @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 gcusome = require( '@stdlib/blas/ext/base/ndarray/gcusome' ); +var dcusome = require( '@stdlib/blas/ext/base/ndarray/dcusome' ); +var scusome = require( '@stdlib/blas/ext/base/ndarray/scusome' ); +var factory = require( '@stdlib/ndarray/base/unary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'all' ); // input ndarray +var idtypes1 = dtypes( 'integer_index_and_generic' ); // minimum number of truthy elements ndarray +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 `ccusome` and `zcusome` once the corresponding packages are implemented + ], + 'fcns': [ + dcusome, + scusome + ], + 'default': gcusome +}; +var options = { + 'strictTraversalOrder': true +}; + + +// MAIN // + +/** +* Cumulatively tests whether at least `k` elements along one or more ndarray dimensions are truthy. +* +* @private +* @name cusome +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} k - ndarray containing the minimum number of truthy elements +* @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} second 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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 1.0, 0.0, 4.0, 3.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' ); +* +* // Create an ndarray containing the minimum number of truthy elements: +* var k = scalar2ndarray( 2, { +* 'dtype': 'int32' +* }); +* +* // Perform operation: +* var out = cusome( x, k ); +* // returns [ [ [ false, false ] ], [ [ false, true ] ], [ [ true, true ] ] ] +*/ +var cusome = factory( table, [ idtypes0, idtypes1 ], odtypes, policies, options ); // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = cusome; + +// exports: { "assign": "cusome.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/lib/index.js b/lib/node_modules/@stdlib/blas/ext/cusome/lib/index.js new file mode 100644 index 000000000000..828b35cbb89d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/lib/index.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Cumulatively test whether at least `k` elements along one or more ndarray dimensions are truthy. +* +* @module @stdlib/blas/ext/cusome +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var cusome = require( '@stdlib/blas/ext/cusome' ); +* +* // Create a data buffer: +* var xbuf = new Float64Array( [ 0.0, 1.0, 0.0, 4.0, 3.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 = cusome( x, 2 ); +* // returns [ [ [ false, false ] ], [ [ false, true ] ], [ [ true, true ] ] ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/lib/main.js b/lib/node_modules/@stdlib/blas/ext/cusome/lib/main.js new file mode 100644 index 000000000000..0838e6f456c7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/lib/main.js @@ -0,0 +1,150 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); +var format = require( '@stdlib/string/format' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var base = require( './base.js' ); + + +// VARIABLES // + +var DEFAULT_DTYPE = defaults.get( 'dtypes.integer_index' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least `k` elements along one or more ndarray dimensions are truthy. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|integer)} k - minimum number of truthy elements +* @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} second argument must be either an ndarray-like object or an integer +* @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, 1.0, 0.0, 4.0, 3.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 = cusome( x, 2 ); +* // returns [ [ [ false, false ] ], [ [ false, true ] ], [ [ true, true ] ] ] +*/ +function cusome( x, k ) { + var options; + var nargs; + var opts; + var iflg; + var ord; + var sh; + var v; + + nargs = arguments.length; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + // Resolve input ndarray meta data: + ord = getOrder( x ); + + // Initialize an options object: + opts = {}; + + // Initialize a flag indicating whether the `k` argument is a scalar: + iflg = true; + + // Case: cusome( x, k_ndarray, ... ) + if ( isndarrayLike( k ) ) { + iflg = false; + } + // Case: cusome( x, ???, ... ) + else if ( !isInteger( k ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) ); + } + // Case: cusome( x, k, options ) + if ( nargs > 2 ) { + options = arguments[ 2 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + // Resolve provided options... + if ( hasOwnProp( options, 'dims' ) ) { + opts.dims = options.dims; + } + if ( hasOwnProp( options, 'dtype' ) ) { + opts.dtype = options.dtype; + } + } + // Resolve the shape of the non-core dimensions, noting that, when not provided `dims`, the operation is performed across all dimensions: + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + // Broadcast `k` to match the shape of the non-core dimensions, noting that, when not provided `dims`, `k` must be a zero-dimensional ndarray, as the operation is performed across all dimensions... + if ( iflg ) { + v = broadcastScalar( k, DEFAULT_DTYPE, sh, ord ); + } else if ( hasOwnProp( opts, 'dims' ) ) { + v = maybeBroadcastArray( k, sh ); + } else if ( ndims( k ) === 0 ) { + v = k; + } else { + throw new TypeError( 'invalid argument. Second argument must be a zero-dimensional ndarray.' ); + } + return base( x, v, opts ); +} + + +// EXPORTS // + +module.exports = cusome; diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/package.json b/lib/node_modules/@stdlib/blas/ext/cusome/package.json new file mode 100644 index 000000000000..92e6d2551283 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/cusome", + "version": "0.0.0", + "description": "Cumulatively test whether at least `k` elements along one or more ndarray dimensions are truthy.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "cumulative", + "some", + "cusome", + "truthy", + "test", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/test/test.assign.js b/lib/node_modules/@stdlib/blas/ext/cusome/test/test.assign.js new file mode 100644 index 000000000000..9898ddb9f970 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/test/test.assign.js @@ -0,0 +1,1203 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +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 cusome = require( './../lib' ).assign; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, '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() { + cusome( value, 2, 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() { + cusome( value, 2, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( value, k, out ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (k ndarray, 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( value, k, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third 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() { + cusome( x, 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third 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() { + cusome( x, 2, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an ndarray-like object (k ndarray, 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth 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() { + cusome( x, 2, out, value ); + }; + } +}); + +tape( 'the function throws an error if provided a fourth argument which is not an object (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, out, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or an integer', 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', + 3.14, + 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() { + cusome( x, value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or an integer (options)', 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', + 3.14, + 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() { + cusome( x, value, out, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not broadcast-compatible', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 3 ], { + 'dtype': 'int32' + }), + zeros( [ 2, 2 ], { + 'dtype': 'int32' + }) + ]; + 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() { + cusome( x, value, out ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var out; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + out = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 3 ], { + 'dtype': 'int32' + }), + zeros( [ 2, 2 ], { + 'dtype': 'int32' + }) + ]; + 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() { + cusome( x, value, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +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() { + cusome( x, 2, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, 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() { + cusome( x, 2, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, 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() { + cusome( x, 2, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, 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() { + cusome( x, 2, out, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, 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' + }); + cusome( x, 2, 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' + }); + cusome( x, 2, 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' + }); + cusome( x, 2, out, { + 'dims': [ 0 ] + }); + }; + } +}); + +tape( 'the function cumulatively tests whether at least `k` elements in an ndarray are truthy (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, 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 `k` elements in an ndarray are truthy (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, 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 `k` elements in an ndarray are truthy (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, 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 `k` elements in an ndarray are truthy (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, 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 `k` elements in an ndarray are truthy (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 1, out, { + 'dims': [] + }); + expected = [ [ false, true ], [ 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 `k` elements in an ndarray are truthy (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 1, out, { + 'dims': [] + }); + expected = [ [ false, true ], [ true, 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 = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, out, { + 'dims': [ 0 ] + }); + expected = [ [ false, false ], [ false, true ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, 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(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, out, { + 'dims': [ 0 ] + }); + expected = [ [ false, false ], [ true, false ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + out = emptyLike( x ); + + actual = cusome( x, 2, out, { + 'dims': [ 1 ] + }); + expected = [ [ false, false ], [ false, true ] ]; + + t.strictEqual( actual, out, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a minimum number of truthy elements (0d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var k; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + + actual = cusome( x, k, 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 supports specifying a minimum number of truthy elements (0d ndarray, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var out; + var x; + var k; + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + + actual = cusome( x, k, 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(); +}); + +tape( 'the function supports specifying a minimum number of truthy elements (1d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var kbuf; + var out; + var x; + var k; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + out = emptyLike( x ); + + kbuf = [ 1, 2 ]; + k = new ndarray( 'generic', kbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = cusome( x, k, 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/cusome/test/test.js b/lib/node_modules/@stdlib/blas/ext/cusome/test/test.js new file mode 100644 index 000000000000..8660523e9d5f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/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 cusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( cusome, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/cusome/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/cusome/test/test.main.js new file mode 100644 index 000000000000..1382b7977c61 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/cusome/test/test.main.js @@ -0,0 +1,998 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +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 cusome = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusome, '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() { + cusome( value, 2 ); + }; + } +}); + +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() { + cusome( value, 2, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( value, k ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (k ndarray, 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( value, k, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a third 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() { + cusome( x, 2, value ); + }; + } +}); + +tape( 'the function throws an error if provided a third argument which is not an object (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or an integer', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + 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() { + cusome( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not an ndarray-like object or an integer (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 3.14, + 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() { + cusome( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not broadcast-compatible', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 3 ], { + 'dtype': 'int32' + }), + zeros( [ 2, 2 ], { + 'dtype': 'int32' + }) + ]; + 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() { + cusome( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 3 ], { + 'dtype': 'int32' + }), + zeros( [ 2, 2 ], { + 'dtype': 'int32' + }) + ]; + 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() { + cusome( x, value, { + 'dims': [ 0 ] + }); + }; + } +}); + +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() { + cusome( x, 2, { + 'dtype': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dtype` option which is not a supported data type (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, { + '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() { + cusome( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, { + '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() { + cusome( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, { + '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() { + cusome( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, { + '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() { + cusome( x, 2, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (k ndarray)', 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() { + var k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + cusome( x, k, { + 'dims': value + }); + }; + } +}); + +tape( 'the function cumulatively tests whether at least `k` elements in an ndarray are truthy (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cusome( x, 2 ); + 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 `k` elements in an ndarray are truthy (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cusome( x, 2 ); + 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 `k` elements in an ndarray are truthy (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cusome( x, 2, { + '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 `k` elements in an ndarray are truthy (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cusome( x, 2, { + '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 `k` elements in an ndarray are truthy (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cusome( x, 1, { + 'dims': [] + }); + expected = [ [ false, true ], [ 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 `k` elements in an ndarray are truthy (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cusome( x, 1, { + 'dims': [] + }); + expected = [ [ false, true ], [ 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 supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cusome( x, 2, { + 'dims': [ 0 ] + }); + expected = [ [ false, false ], [ 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 = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cusome( x, 2, { + '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 operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cusome( x, 2, { + '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 = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cusome( x, 2, { + 'dims': [ 1 ] + }); + expected = [ [ false, false ], [ 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' ); + + 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, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = cusome( x, 2, { + '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, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = cusome( x, 2, { + '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(); +}); + +tape( 'the function supports specifying a minimum number of truthy elements (0d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var k; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + + actual = cusome( x, k ); + 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 supports specifying a minimum number of truthy elements (0d ndarray, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + var k; + + xbuf = [ 1.0, 1.0, 0.0, 1.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + k = scalar2ndarray( 2, { + 'dtype': 'int32' + }); + + actual = cusome( x, k, { + '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 a minimum number of truthy elements (1d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var kbuf; + var x; + var k; + + xbuf = [ 0.0, 1.0, 1.0, 0.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + kbuf = [ 1, 2 ]; + k = new ndarray( 'generic', kbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = cusome( x, k, { + '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(); +});