From 19e6a35236971f8982fc807c5b36c59eb2be5d60 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Wed, 22 Apr 2026 00:17:15 +0530 Subject: [PATCH 1/2] feat: add stats/strided/selmax --- .../@stdlib/stats/strided/selmax/README.md | 198 +++++++++ .../strided/selmax/benchmark/benchmark.js | 105 +++++ .../selmax/benchmark/benchmark.ndarray.js | 105 +++++ .../stats/strided/selmax/docs/repl.txt | 117 +++++ .../strided/selmax/docs/types/index.d.ts | 109 +++++ .../stats/strided/selmax/docs/types/test.ts | 250 +++++++++++ .../stats/strided/selmax/examples/index.js | 36 ++ .../stats/strided/selmax/lib/accessors.js | 112 +++++ .../@stdlib/stats/strided/selmax/lib/index.js | 59 +++ .../@stdlib/stats/strided/selmax/lib/main.js | 53 +++ .../stats/strided/selmax/lib/ndarray.js | 104 +++++ .../@stdlib/stats/strided/selmax/package.json | 73 +++ .../@stdlib/stats/strided/selmax/test/test.js | 38 ++ .../stats/strided/selmax/test/test.main.js | 420 ++++++++++++++++++ .../stats/strided/selmax/test/test.ndarray.js | 406 +++++++++++++++++ 15 files changed, 2185 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/README.md b/lib/node_modules/@stdlib/stats/strided/selmax/README.md new file mode 100644 index 000000000000..9f05760037b6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/README.md @@ -0,0 +1,198 @@ + + +# selmax + +> Calculate the maximum value of a strided array by selecting elements according to a mask. + +
+ +
+ + + +
+ +## Usage + +```javascript +var selmax = require( '@stdlib/stats/strided/selmax' ); +``` + +#### selmax( N, x, strideX, mask, strideMask ) + +Computes the maximum value of a strided array by selecting elements according to a mask. + +```javascript +var x = [ 1.0, -2.0, 4.0, 2.0 ]; +var mask = [ 1, 1, 0, 1 ]; + +var v = selmax( x.length, x, 1, mask, 1 ); +// returns 2.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. +- **strideX**: stride length for `x`. +- **mask**: mask [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. If a `mask` array element is `true`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `false`, the corresponding element in `x` is considered invalid/missing and **excluded** from computation. +- **strideMask**: stride length for `mask`. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the maximum value of every other element in `x`, + +```javascript +var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ]; +var mask = [ 1, 1, 1, 1, 1, 1, 0, 0 ]; + +var v = selmax( 4, x, 2, mask, 2 ); +// returns 4.0 +``` + +Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var BooleanArray = require( '@stdlib/array/bool' ); + +var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + +var mask0 = new BooleanArray([ + true, true, true, true, true, true, false, false +]); +var mask1 = new BooleanArray( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); + +var v = selmax( 4, x1, 2, mask1, 2 ); +// returns 4.0 +``` + +#### selmax.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ) + +Computes the maximum value of a strided array by selecting elements according to a mask and using alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 4.0, 2.0 ]; +var mask = [ 1, 1, 0, 1 ]; + +var v = selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); +// returns 2.0 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetMask**: starting index for `mask`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the maximum value for every other value in `x` starting from the second value + +```javascript +var x = [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ]; +var mask = [ 1, 1, 1, 1, 1, 1, 0, 0 ]; + +var v = selmax.ndarray( 4, x, 2, 1, mask, 2, 1 ); +// returns 4.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var selmax = require( '@stdlib/stats/strided/selmax' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +console.log( x ); + +var mask = bernoulli( x.length, 0.8, { + 'dtype': 'generic' +}); +console.log( mask ); + +var v = selmax( x.length, x, 1, mask, 1 ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js new file mode 100644 index 000000000000..623c81bd3b66 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var selmax = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask = bernoulli( len, 0.8, options ); + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = selmax( x.length, x, 1, mask, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..5cf75e8cac2a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var selmax = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var mask = bernoulli( len, 0.8, options ); + var x = uniform( len, -10.0, 10.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt new file mode 100644 index 000000000000..3a18fc5dbcef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt @@ -0,0 +1,117 @@ + +{{alias}}( N, x, strideX, mask, strideMask ) + Computes the maximum value of a strided array by selecting elements + according to a mask. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce offsets, use a typed + array views. + + If a `mask` array element is `true`, the corresponding element in `x` is + considered valid and included in computation. + + If a `mask` array element is `false`, the corresponding element in `x` is + considered invalid/missing and excluded from computation. + + If `N <= 0`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + mask: Array|TypedArray + Mask array. + + strideMask: integer + Stride length for `mask`. + + Returns + ------- + out: number + Maximum value. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 4.0, 2.0 ]; + > var mask = [ 1, 1, 0, 1 ]; + > {{alias}}( x.length, x, 1, mask, 1 ) + 2.0 + + // Using `N` and stride parameters: + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, 4.0 ]; + > mask = [ 1, 1, 1, 1, 1, 1, 0 ]; + > {{alias}}( 3, x, 2, mask, 2 ) + 2.0 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, 4.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var mask0 = new {{alias:@stdlib/array/uint8}}( [ 1, 1, 1, 1, 1, 1, 0 ] ); + > var mask1 = new {{alias:@stdlib/array/uint8}}( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, x1, 2, mask1, 2 ) + 2.0 + + +{{alias}}.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ) + Computes the maximum value of a strided array by selecting elements + according to a mask and using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + mask: Array|TypedArray + Mask array. + + strideMask: integer + Stride length for `mask`. + + offsetMask: integer + Starting index for `mask`. + + Returns + ------- + out: number + Maximum value. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0, 4.0 ]; + > var mask = [ 1, 1, 1, 0 ]; + > {{alias}}.ndarray( x.length, x, 1, 0, mask, 1, 0 ) + 2.0 + + // Using offset parameter: + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, 4.0 ]; + > mask = [ 1, 1, 1, 1, 1, 1, 0 ]; + > {{alias}}.ndarray( 3, x, 2, 1, mask, 2, 1 ) + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts new file mode 100644 index 000000000000..0aa2f986a849 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts @@ -0,0 +1,109 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 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 { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Mask array. +*/ +type MaskArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `selmax`. +*/ +interface Routine { + /** + * Computes the maximum value of a strided array by selecting elements according to a mask. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param mask - mask array + * @param strideMask - stride length for `mask` + * @returns maximum value + * + * @example + * var x = [ 1.0, -2.0, 4.0, 2.0 ]; + * var mask = [ 1, 1, 0, 1 ]; + * + * var v = selmax( x.length, x, 1, mask, 1 ); + * // returns 2.0 + */ + ( N: number, x: InputArray, strideX: number, mask: MaskArray, strideMask: number ): number; + + /** + * Computes the maximum value of a strided array by selecting elements according to a mask and using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length for `x` + * @param offsetX - `x` starting index + * @param mask - mask array + * @param strideMask - stride length for `mask` + * @param offsetMask - `mask` starting index + * @returns maximum value + * + * @example + * var x = [ 1.0, -2.0, 4.0, 2.0 ]; + * var mask = [ 1, 1, 0, 1 ]; + * + * var v = selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); + * // returns 2.0 + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, mask: MaskArray, strideMask: number, offsetMask: number ): number; +} + +/** +* Computes the maximum value of a strided array by selecting elements according to a mask. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length for `x` +* @param mask - mask array +* @param strideMask - stride length for `mask` +* @returns maximum value +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 1, 1, 0, 1 ]; +* +* var v = selmax( x.length, x, 1, mask, 1 ); +* // returns 2.0 +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 1, 1, 0, 1 ]; +* +* var v = selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); +* // returns 2.0 +*/ +declare var selmax: Routine; + + +// EXPORTS // + +export = selmax; diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts new file mode 100644 index 000000000000..d1d4c18dcc94 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts @@ -0,0 +1,250 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import selmax = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax( x.length, x, 1, mask, 1 ); // $ExpectType number + selmax( x.length, new AccessorArray( x ), 1, mask, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax( '10', x, 1, mask, 1 ); // $ExpectError + selmax( true, x, 1, mask, 1 ); // $ExpectError + selmax( false, x, 1, mask, 1 ); // $ExpectError + selmax( null, x, 1, mask, 1 ); // $ExpectError + selmax( undefined, x, 1, mask, 1 ); // $ExpectError + selmax( [], x, 1, mask, 1 ); // $ExpectError + selmax( {}, x, 1, mask, 1 ); // $ExpectError + selmax( ( x: number ): number => x, x, 1, mask, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax( x.length, 10, 1, mask, 1 ); // $ExpectError + selmax( x.length, '10', 1, mask, 1 ); // $ExpectError + selmax( x.length, true, 1, mask, 1 ); // $ExpectError + selmax( x.length, false, 1, mask, 1 ); // $ExpectError + selmax( x.length, null, 1, mask, 1 ); // $ExpectError + selmax( x.length, undefined, 1, mask, 1 ); // $ExpectError + selmax( x.length, [ '1' ], 1, mask, 1 ); // $ExpectError + selmax( x.length, {}, 1, mask, 1 ); // $ExpectError + selmax( x.length, ( x: number ): number => x, 1, mask, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax( x.length, x, '10', mask, 1 ); // $ExpectError + selmax( x.length, x, true, mask, 1 ); // $ExpectError + selmax( x.length, x, false, mask, 1 ); // $ExpectError + selmax( x.length, x, null, mask, 1 ); // $ExpectError + selmax( x.length, x, undefined, mask, 1 ); // $ExpectError + selmax( x.length, x, [], mask, 1 ); // $ExpectError + selmax( x.length, x, {}, mask, 1 ); // $ExpectError + selmax( x.length, x, ( x: number ): number => x, mask, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + selmax( x.length, x, 1, 10, 1 ); // $ExpectError + selmax( x.length, x, 1, '10', 1 ); // $ExpectError + selmax( x.length, x, 1, true, 1 ); // $ExpectError + selmax( x.length, x, 1, false, 1 ); // $ExpectError + selmax( x.length, x, 1, null, 1 ); // $ExpectError + selmax( x.length, x, 1, undefined, 1 ); // $ExpectError + selmax( x.length, x, 1, [ '1' ], 1 ); // $ExpectError + selmax( x.length, x, 1, {}, 1 ); // $ExpectError + selmax( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax( x.length, x, 1, mask, '10' ); // $ExpectError + selmax( x.length, x, 1, mask, true ); // $ExpectError + selmax( x.length, x, 1, mask, false ); // $ExpectError + selmax( x.length, x, 1, mask, null ); // $ExpectError + selmax( x.length, x, 1, mask, undefined ); // $ExpectError + selmax( x.length, x, 1, mask, [] ); // $ExpectError + selmax( x.length, x, 1, mask, {} ); // $ExpectError + selmax( x.length, x, 1, mask, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax(); // $ExpectError + selmax( x.length ); // $ExpectError + selmax( x.length, x, 1 ); // $ExpectError + selmax( x.length, x, 1, mask ); // $ExpectError + selmax( x.length, x, 1, mask, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); // $ExpectType number + selmax.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( mask ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( '10', x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( true, x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( false, x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( null, x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( undefined, x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( [], x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( {}, x, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( ( x: number ): number => x, x, 1, 0, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( x.length, 10, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, '10', 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, true, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, false, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, null, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, undefined, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, [ '1' ], 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, {}, 1, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, ( x: number ): number => x, 1, 0, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( x.length, x, '10', 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, true, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, false, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, null, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, undefined, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, [], 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, {}, 0, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, ( x: number ): number => x, 0, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( x.length, x, 1, '10', mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, true, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, false, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, null, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, undefined, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, [], mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, {}, mask, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, ( x: number ): number => x, mask, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... +{ + const x = new Float64Array( 10 ); + + selmax.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( x.length, x, 1, 0, mask, '10', 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, true, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, false, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, null, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, undefined, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, [], 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, {}, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray( x.length, x, 1, 0, mask, 1, '10' ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, true ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, false ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, null ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, undefined ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, [] ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, {} ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + selmax.ndarray(); // $ExpectError + selmax.ndarray( x.length ); // $ExpectError + selmax.ndarray( x.length, x ); // $ExpectError + selmax.ndarray( x.length, x, 1 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1 ); // $ExpectError + selmax.ndarray( x.length, x, 1, 0, mask, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js b/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js new file mode 100644 index 000000000000..fb72ae419cae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var selmax = require( './../lib' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +console.log( x ); + +var mask = bernoulli( x.length, 0.8, { + 'dtype': 'generic' +}); +console.log( mask ); + +var v = selmax( x.length, x, 1, mask, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js new file mode 100644 index 000000000000..c8218f459de0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); + + +// MAIN // + +/** +* Computes the maximum value of a strided array by selecting elements according to a mask. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Object} mask - mask array object +* @param {Collection} mask.data - mask array data +* @param {Array} mask.accessors - mask element accessors +* @param {integer} strideMask - stride length for `mask` +* @param {NonNegativeInteger} offsetMask - starting index for `mask` +* @returns {number} maximum value +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var mask = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 ]; +* +* var v = selmax( 5, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( mask ) ), 2, 1 ); +* // returns 4.0 +*/ +function selmax( N, x, strideX, offsetX, mask, strideMask, offsetMask ) { + var xbuf; + var mbuf; + var xget; + var mget; + var max; + var ix; + var im; + var v; + var i; + + // Cache references to array data: + xbuf = x.data; + mbuf = mask.data; + + // Cache references to element accessors: + xget = x.accessors[ 0 ]; + mget = mask.accessors[ 0 ]; + + ix = offsetX; + im = offsetMask; + for ( i = 0; i < N; i++ ) { + if ( mget( mbuf, im ) ) { + break; + } + ix += strideX; + im += strideMask; + } + if ( i === N ) { + return NaN; + } + max = xget( xbuf, ix ); + if ( isnan( max ) ) { + return max; + } + i += 1; + for ( i; i < N; i++ ) { + ix += strideX; + im += strideMask; + if ( !mget( mbuf, im ) ) { + continue; + } + v = xget( xbuf, ix ); + if ( isnan( v ) ) { + return v; + } + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + return max; +} + + +// EXPORTS // + +module.exports = selmax; diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js new file mode 100644 index 000000000000..9cd6b1dbef63 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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'; + +/** +* Compute the maximum value of a strided array by selecting elements according to a mask. +* +* @module @stdlib/stats/strided/selmax +* +* @example +* var selmax = require( '@stdlib/stats/strided/selmax' ); +* +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 1, 1, 0, 1 ]; +* +* var v = selmax( x.length, x, 1, mask, 1 ); +* // returns 2.0 +* +* @example +* var selmax = require( '@stdlib/stats/strided/selmax' ); +* +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var mask = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 ]; +* +* var v = selmax.ndarray( 5, x, 2, 1, mask, 2, 1 ); +* // returns 4.0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var selmax = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( selmax, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = selmax; diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js new file mode 100644 index 000000000000..3c6bbcf2de4f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the maximum value of a strided array by selecting elements according to a mask. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - `x` stride length +* @param {NumericArray} mask - mask array +* @param {integer} strideMask - `mask` stride length +* @returns {number} maximum value +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 1, 1, 0, 1 ]; +* +* var v = selmax( x.length, x, 1, mask, 1 ); +* // returns 2.0 +*/ +function selmax( N, x, strideX, mask, strideMask ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), mask, strideMask, stride2offset( N, strideMask ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = selmax; diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js new file mode 100644 index 000000000000..085b26d350be --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the maximum value of a strided array by selecting elements according to a mask. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {NumericArray} mask - mask array +* @param {integer} strideMask - stride length for `mask` +* @param {NonNegativeInteger} offsetMask - starting index for `mask` +* @returns {number} maximum value +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var mask = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 ]; +* +* var v = selmax( 5, x, 2, 1, mask, 2, 1 ); +* // returns 4.0 +*/ +function selmax( N, x, strideX, offsetX, mask, strideMask, offsetMask ) { + var max; + var ix; + var im; + var ox; + var om; + var v; + var i; + + if ( N <= 0 ) { + return NaN; + } + ox = arraylike2object( x ); + om = arraylike2object( mask ); + if ( ox.accessorProtocol || om.accessorProtocol ) { + return accessors( N, ox, strideX, offsetX, om, strideMask, offsetMask ); + } + ix = offsetX; + im = offsetMask; + for ( i = 0; i < N; i++ ) { + if ( mask[ im ] ) { + break; + } + ix += strideX; + im += strideMask; + } + if ( i === N ) { + return NaN; + } + max = x[ ix ]; + if ( isnan( max ) ) { + return max; + } + i += 1; + for ( i; i < N; i++ ) { + ix += strideX; + im += strideMask; + if ( !mask[ im ] ) { + continue; + } + v = x[ ix ]; + if ( isnan( v ) ) { + return v; + } + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + return max; +} + + +// EXPORTS // + +module.exports = selmax; diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/package.json b/lib/node_modules/@stdlib/stats/strided/selmax/package.json new file mode 100644 index 000000000000..402bdcd0165b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/strided/selmax", + "version": "0.0.0", + "description": "Calculate the maximum value of a strided array by selecting elements according to a mask.", + "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", + "statistics", + "stats", + "mathematics", + "math", + "maximum", + "max", + "range", + "extremes", + "domain", + "extent", + "strided", + "strided array", + "select", + "boolean", + "boolean array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js new file mode 100644 index 000000000000..8ca66977dc66 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 selmax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof selmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof selmax.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js new file mode 100644 index 000000000000..f74134a50039 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js @@ -0,0 +1,420 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var selmax = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof selmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( selmax.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the maximum value of a strided array by selecting elements according to a mask', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 1, 0, 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 1, 1, 0, 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 1, 1, 1, 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = selmax( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the maximum value of a strided array by selecting elements according to a mask (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 1, 0, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 1, 1, 0, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 1, 1, 1, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 1, 1 ]; + + v = selmax( 0, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = selmax( -1, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns the first element', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 1, 1 ]; + + v = selmax( 1, x, 1, mask, 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports `stride` parameters', function test( t ) { + var mask; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]; + mask = [ + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 1, + 0, // 4 + 0 + ]; + + v = selmax( 5, x, 2, mask, 2 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports `stride` parameters (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]; + mask = [ + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 1, + 0, // 4 + 0 + ]; + + v = selmax( 5, toAccessorArray( x ), 2, toAccessorArray( mask ), 2 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative `stride` parameters', function test( t ) { + var mask; + var x; + var v; + + x = [ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + mask = [ + 0, // 4 + 0, + 1, // 3 + 1, + 1, // 2 + 1, + 1, // 1 + 1, + 1, // 0 + 1 + ]; + + v = selmax( 5, x, -2, mask, -2 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative `stride` parameters (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + mask = [ + 0, // 4 + 0, + 1, // 3 + 1, + 1, // 2 + 1, + 1, // 1 + 1, + 1, // 0 + 1 + ]; + + v = selmax( 5, toAccessorArray( x ), -2, toAccessorArray( mask ), -2 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var mask0; + var mask1; + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0, + 5.0, // 4 + 6.0 + ]); + mask0 = new Uint8Array([ + 1, + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 1, + 0, // 4 + 0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = selmax( 5, x1, 2, mask1, 2 ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessor)', function test( t ) { + var mask0; + var mask1; + var x0; + var x1; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0, + 5.0, // 4 + 6.0 + ]); + mask0 = new Uint8Array([ + 1, + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 1, + 0, // 4 + 0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + v = selmax( 5, toAccessorArray( x1 ), 2, toAccessorArray( mask1 ), 2 ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js new file mode 100644 index 000000000000..5dc4ca51829e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js @@ -0,0 +1,406 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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 max-len */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var selmax = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof selmax, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( selmax.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the maximum value of a strided array by selecting elements according to a mask', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 1, 0, 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 1, 1, 0, 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 1, 1, 1, 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = selmax( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the maximum value of a strided array by selecting elements according to a mask (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 1, 0, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 1, 1, 0, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 1, 1, 1, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 1.0, 1.0 ]; + + v = selmax( 0, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = selmax( -1, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns the first element', function test( t ) { + var mask; + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 1.0, 1.0 ]; + + v = selmax( 1, x, 1, 0, mask, 1, 0 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports `stride` parameters', function test( t ) { + var mask; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]; + mask = [ + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 1, + 0, // 4 + 0 + ]; + + v = selmax( 5, x, 2, 0, mask, 2, 0 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports `stride` parameters (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + 5.0, // 4 + 6.0 + ]; + mask = [ + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 1, + 0, // 4 + 0 + ]; + + v = selmax( 5, toAccessorArray( x ), 2, 0, toAccessorArray( mask ), 2, 0 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative `stride` parameters', function test( t ) { + var mask; + var x; + var v; + + x = [ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + mask = [ + 0, // 4 + 0, + 1, // 3 + 1, + 1, // 2 + 1, + 1, // 1 + 1, + 1, // 0 + 1 + ]; + + v = selmax( 5, x, -2, 8, mask, -2, 8 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative `stride` parameters (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ + 5.0, // 4 + 6.0, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + mask = [ + 0, // 4 + 0, + 1, // 3 + 1, + 1, // 2 + 1, + 1, // 1 + 1, + 1, // 0 + 1 + ]; + + v = selmax( 5, toAccessorArray( x ), -2, 8, toAccessorArray( mask ), -2, 8 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports `offset` parameters', function test( t ) { + var mask; + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 5.0, + 6.0 // 4 + ]; + mask = [ + 1, + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 0, + 0 // 4 + ]; + + v = selmax( 5, x, 2, 1, mask, 2, 1 ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports `offset` parameters (accessor)', function test( t ) { + var mask; + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 5.0, + 6.0 // 4 + ]; + mask = [ + 1, + 1, // 0 + 1, + 1, // 1 + 1, + 1, // 2 + 1, + 1, // 3 + 0, + 0 // 4 + ]; + + v = selmax( 5, toAccessorArray( x ), 2, 1, toAccessorArray( mask ), 2, 1 ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); From 6f347cc4f2cfe18863068f63e18e51131aab7d43 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Sat, 25 Apr 2026 11:57:08 +0530 Subject: [PATCH 2/2] chore: suggested changes --- .../@stdlib/stats/strided/selmax/README.md | 35 +--- .../strided/selmax/benchmark/benchmark.js | 16 +- .../selmax/benchmark/benchmark.ndarray.js | 16 +- .../stats/strided/selmax/docs/repl.txt | 24 +-- .../strided/selmax/docs/types/index.d.ts | 12 +- .../stats/strided/selmax/docs/types/test.ts | 37 ++-- .../stats/strided/selmax/examples/index.js | 7 +- .../stats/strided/selmax/lib/accessors.js | 4 +- .../@stdlib/stats/strided/selmax/lib/index.js | 6 +- .../@stdlib/stats/strided/selmax/lib/main.js | 6 +- .../stats/strided/selmax/lib/ndarray.js | 6 +- .../@stdlib/stats/strided/selmax/test/test.js | 2 +- .../stats/strided/selmax/test/test.main.js | 180 +++++++++--------- .../stats/strided/selmax/test/test.ndarray.js | 166 ++++++++-------- 14 files changed, 246 insertions(+), 271 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/README.md b/lib/node_modules/@stdlib/stats/strided/selmax/README.md index 9f05760037b6..6f99e2153780 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/README.md +++ b/lib/node_modules/@stdlib/stats/strided/selmax/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2020 The Stdlib Authors. +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. @@ -42,7 +42,7 @@ Computes the maximum value of a strided array by selecting elements according to ```javascript var x = [ 1.0, -2.0, 4.0, 2.0 ]; -var mask = [ 1, 1, 0, 1 ]; +var mask = [ true, true, false, true ]; var v = selmax( x.length, x, 1, mask, 1 ); // returns 2.0 @@ -60,7 +60,7 @@ The `N` and stride parameters determine which elements in the strided arrays are ```javascript var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ]; -var mask = [ 1, 1, 1, 1, 1, 1, 0, 0 ]; +var mask = [ true, true, true, true, true, true, false, false ]; var v = selmax( 4, x, 2, mask, 2 ); // returns 4.0 @@ -68,7 +68,7 @@ var v = selmax( 4, x, 2, mask, 2 ); Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views. - + ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -77,9 +77,7 @@ var BooleanArray = require( '@stdlib/array/bool' ); var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); -var mask0 = new BooleanArray([ - true, true, true, true, true, true, false, false -]); +var mask0 = new BooleanArray( [ true, true, true, true, true, true, false, false ] ); var mask1 = new BooleanArray( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); var v = selmax( 4, x1, 2, mask1, 2 ); @@ -92,7 +90,7 @@ Computes the maximum value of a strided array by selecting elements according to ```javascript var x = [ 1.0, -2.0, 4.0, 2.0 ]; -var mask = [ 1, 1, 0, 1 ]; +var mask = [ true, true, false, true ]; var v = selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); // returns 2.0 @@ -107,7 +105,7 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var x = [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ]; -var mask = [ 1, 1, 1, 1, 1, 1, 0, 0 ]; +var mask = [ true, true, true, true, true, true, false, false ]; var v = selmax.ndarray( 4, x, 2, 1, mask, 2, 1 ); // returns 4.0 @@ -137,6 +135,7 @@ var v = selmax.ndarray( 4, x, 2, 1, mask, 2, 1 ); ```javascript var uniform = require( '@stdlib/random/array/uniform' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var BooleanArray = require( '@stdlib/array/bool' ); var selmax = require( '@stdlib/stats/strided/selmax' ); var x = uniform( 10, -50.0, 50.0, { @@ -144,9 +143,7 @@ var x = uniform( 10, -50.0, 50.0, { }); console.log( x ); -var mask = bernoulli( x.length, 0.8, { - 'dtype': 'generic' -}); +var mask = new BooleanArray( bernoulli( x.length, 0.8 ) ); console.log( mask ); var v = selmax( x.length, x, 1, mask, 1 ); @@ -161,14 +158,6 @@ console.log( v ); @@ -185,12 +174,6 @@ console.log( v ); -[@stdlib/stats/strided/max]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/max - -[@stdlib/stats/strided/mskmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/mskmax - -[@stdlib/stats/strided/nanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/nanmax - diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js index 623c81bd3b66..7576b39ac9fb 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -24,19 +24,13 @@ var bench = require( '@stdlib/bench' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var uniform = require( '@stdlib/random/array/uniform' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var BooleanArray = require( '@stdlib/array/bool' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var selmax = require( './../lib' ); -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - // FUNCTIONS // /** @@ -47,8 +41,10 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var mask = bernoulli( len, 0.8, options ); - var x = uniform( len, -10.0, 10.0, options ); + var mask = new BooleanArray( bernoulli( len, 0.8 ) ); + var x = uniform( len, -10.0, 10.0, { + 'dtype': 'generic' + }); return benchmark; /** diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js index 5cf75e8cac2a..52773b048785 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -24,19 +24,13 @@ var bench = require( '@stdlib/bench' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var uniform = require( '@stdlib/random/array/uniform' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var BooleanArray = require( '@stdlib/array/bool' ); var pow = require( '@stdlib/math/base/special/pow' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var selmax = require( './../lib/ndarray.js' ); -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - // FUNCTIONS // /** @@ -47,8 +41,10 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var mask = bernoulli( len, 0.8, options ); - var x = uniform( len, -10.0, 10.0, options ); + var mask = new BooleanArray( bernoulli( len, 0.8 ) ); + var x = uniform( len, -10.0, 10.0, { + 'dtype': 'generic' + }); return benchmark; /** diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt index 3a18fc5dbcef..97aa2027e6b3 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/strided/selmax/docs/repl.txt @@ -28,7 +28,7 @@ strideX: integer Stride length for `x`. - mask: Array|TypedArray + mask: Array|TypedArray Mask array. strideMask: integer @@ -43,22 +43,24 @@ -------- // Standard Usage: > var x = [ 1.0, -2.0, 4.0, 2.0 ]; - > var mask = [ 1, 1, 0, 1 ]; + > var mask = [ true, true, false, true ]; > {{alias}}( x.length, x, 1, mask, 1 ) 2.0 // Using `N` and stride parameters: > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, 4.0 ]; - > mask = [ 1, 1, 1, 1, 1, 1, 0 ]; + > mask = [ true, true, true, true, true, true, false ]; > {{alias}}( 3, x, 2, mask, 2 ) 2.0 // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, 4.0 ] ); - > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > var mask0 = new {{alias:@stdlib/array/uint8}}( [ 1, 1, 1, 1, 1, 1, 0 ] ); - > var mask1 = new {{alias:@stdlib/array/uint8}}( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, x1, 2, mask1, 2 ) + > var Float64Array = {{alias:@stdlib/array/float64}}; + > var x0 = new Float64Array( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > var BooleanArray = {{alias:@stdlib/array/bool}}; + > var m0 = new BooleanArray( [ true, true, true, true, true, false ] ); + > var m1 = new BooleanArray( m0.buffer, m0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 2, x1, 2, m1, 2 ) 2.0 @@ -84,7 +86,7 @@ offsetX: integer Starting index for `x`. - mask: Array|TypedArray + mask: Array|TypedArray Mask array. strideMask: integer @@ -102,13 +104,13 @@ -------- // Standard Usage: > var x = [ 1.0, -2.0, 2.0, 4.0 ]; - > var mask = [ 1, 1, 1, 0 ]; + > var mask = [ true, true, true, false ]; > {{alias}}.ndarray( x.length, x, 1, 0, mask, 1, 0 ) 2.0 // Using offset parameter: > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, 4.0 ]; - > mask = [ 1, 1, 1, 1, 1, 1, 0 ]; + > mask = [ true, true, true, true, true, true, false ]; > {{alias}}.ndarray( 3, x, 2, 1, mask, 2, 1 ) 2.0 diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts index 0aa2f986a849..816406d719ea 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -30,7 +30,7 @@ type InputArray = NumericArray | Collection | AccessorArrayLike; /** * Mask array. */ -type MaskArray = NumericArray | Collection | AccessorArrayLike; +type MaskArray = Collection | AccessorArrayLike; /** * Interface describing `selmax`. @@ -48,7 +48,7 @@ interface Routine { * * @example * var x = [ 1.0, -2.0, 4.0, 2.0 ]; - * var mask = [ 1, 1, 0, 1 ]; + * var mask = [ true, true, false, true ]; * * var v = selmax( x.length, x, 1, mask, 1 ); * // returns 2.0 @@ -69,7 +69,7 @@ interface Routine { * * @example * var x = [ 1.0, -2.0, 4.0, 2.0 ]; - * var mask = [ 1, 1, 0, 1 ]; + * var mask = [ true, true, false, true ]; * * var v = selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); * // returns 2.0 @@ -89,14 +89,14 @@ interface Routine { * * @example * var x = [ 1.0, -2.0, 4.0, 2.0 ]; -* var mask = [ 1, 1, 0, 1 ]; +* var mask = [ true, true, false, true ]; * * var v = selmax( x.length, x, 1, mask, 1 ); * // returns 2.0 * * @example * var x = [ 1.0, -2.0, 4.0, 2.0 ]; -* var mask = [ 1, 1, 0, 1 ]; +* var mask = [ true, true, false, true ]; * * var v = selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); * // returns 2.0 diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts index d1d4c18dcc94..6ad065682475 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/strided/selmax/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -16,6 +16,7 @@ * limitations under the License. */ +import BooleanArray = require( '@stdlib/array/bool' ); import AccessorArray = require( '@stdlib/array/base/accessor' ); import selmax = require( './index' ); @@ -25,7 +26,7 @@ import selmax = require( './index' ); // The function returns a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax( x.length, x, 1, mask, 1 ); // $ExpectType number selmax( x.length, new AccessorArray( x ), 1, mask, 1 ); // $ExpectType number @@ -34,7 +35,7 @@ import selmax = require( './index' ); // The compiler throws an error if the function is provided a first argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax( '10', x, 1, mask, 1 ); // $ExpectError selmax( true, x, 1, mask, 1 ); // $ExpectError @@ -49,7 +50,7 @@ import selmax = require( './index' ); // The compiler throws an error if the function is provided a second argument which is not a numeric array... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax( x.length, 10, 1, mask, 1 ); // $ExpectError selmax( x.length, '10', 1, mask, 1 ); // $ExpectError @@ -65,7 +66,7 @@ import selmax = require( './index' ); // The compiler throws an error if the function is provided a third argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax( x.length, x, '10', mask, 1 ); // $ExpectError selmax( x.length, x, true, mask, 1 ); // $ExpectError @@ -77,7 +78,7 @@ import selmax = require( './index' ); selmax( x.length, x, ( x: number ): number => x, mask, 1 ); // $ExpectError } -// The compiler throws an error if the function is provided a fourth argument which is not a numeric array... +// The compiler throws an error if the function is provided a fourth argument which is not an array... { const x = new Float64Array( 10 ); @@ -87,7 +88,6 @@ import selmax = require( './index' ); selmax( x.length, x, 1, false, 1 ); // $ExpectError selmax( x.length, x, 1, null, 1 ); // $ExpectError selmax( x.length, x, 1, undefined, 1 ); // $ExpectError - selmax( x.length, x, 1, [ '1' ], 1 ); // $ExpectError selmax( x.length, x, 1, {}, 1 ); // $ExpectError selmax( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError } @@ -95,7 +95,7 @@ import selmax = require( './index' ); // The compiler throws an error if the function is provided a fifth argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax( x.length, x, 1, mask, '10' ); // $ExpectError selmax( x.length, x, 1, mask, true ); // $ExpectError @@ -110,7 +110,7 @@ import selmax = require( './index' ); // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax(); // $ExpectError selmax( x.length ); // $ExpectError @@ -122,7 +122,7 @@ import selmax = require( './index' ); // Attached to main export is an `ndarray` method which returns a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( x.length, x, 1, 0, mask, 1, 0 ); // $ExpectType number selmax.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( mask ), 1, 0 ); // $ExpectType number @@ -131,7 +131,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( '10', x, 1, 0, mask, 1, 0 ); // $ExpectError selmax.ndarray( true, x, 1, 0, mask, 1, 0 ); // $ExpectError @@ -146,7 +146,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a second argument which is not a numeric array... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( x.length, 10, 1, 0, mask, 1, 0 ); // $ExpectError selmax.ndarray( x.length, '10', 1, 0, mask, 1, 0 ); // $ExpectError @@ -162,7 +162,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( x.length, x, '10', 0, mask, 1, 0 ); // $ExpectError selmax.ndarray( x.length, x, true, 0, mask, 1, 0 ); // $ExpectError @@ -177,7 +177,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( x.length, x, 1, '10', mask, 1, 0 ); // $ExpectError selmax.ndarray( x.length, x, 1, true, mask, 1, 0 ); // $ExpectError @@ -189,7 +189,7 @@ import selmax = require( './index' ); selmax.ndarray( x.length, x, 1, ( x: number ): number => x, mask, 1, 0 ); // $ExpectError } -// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a numeric array... +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not an array... { const x = new Float64Array( 10 ); @@ -199,7 +199,6 @@ import selmax = require( './index' ); selmax.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError selmax.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError selmax.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError - selmax.ndarray( x.length, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError selmax.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError selmax.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError } @@ -207,7 +206,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( x.length, x, 1, 0, mask, '10', 0 ); // $ExpectError selmax.ndarray( x.length, x, 1, 0, mask, true, 0 ); // $ExpectError @@ -222,7 +221,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray( x.length, x, 1, 0, mask, 1, '10' ); // $ExpectError selmax.ndarray( x.length, x, 1, 0, mask, 1, true ); // $ExpectError @@ -237,7 +236,7 @@ import selmax = require( './index' ); // The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... { const x = new Float64Array( 10 ); - const mask = new Uint8Array( 10 ); + const mask = new BooleanArray( 10 ); selmax.ndarray(); // $ExpectError selmax.ndarray( x.length ); // $ExpectError diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js b/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js index fb72ae419cae..8bb4c0ef3749 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -20,6 +20,7 @@ var uniform = require( '@stdlib/random/array/uniform' ); var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var BooleanArray = require( '@stdlib/array/bool' ); var selmax = require( './../lib' ); var x = uniform( 10, -50.0, 50.0, { @@ -27,9 +28,7 @@ var x = uniform( 10, -50.0, 50.0, { }); console.log( x ); -var mask = bernoulli( x.length, 0.8, { - 'dtype': 'generic' -}); +var mask = new BooleanArray( bernoulli( x.length, 0.8 ) ); console.log( mask ); var v = selmax( x.length, x, 1, mask, 1 ); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js index c8218f459de0..ed72480f3673 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/accessors.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -48,7 +48,7 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var mask = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 ]; +* var mask = [ false, true, false, true, false, true, false, true, false, false ]; * * var v = selmax( 5, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( mask ) ), 2, 1 ); * // returns 4.0 diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js index 9cd6b1dbef63..acef7bfab262 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -27,7 +27,7 @@ * var selmax = require( '@stdlib/stats/strided/selmax' ); * * var x = [ 1.0, -2.0, 4.0, 2.0 ]; -* var mask = [ 1, 1, 0, 1 ]; +* var mask = [ true, true, false, true ]; * * var v = selmax( x.length, x, 1, mask, 1 ); * // returns 2.0 @@ -36,7 +36,7 @@ * var selmax = require( '@stdlib/stats/strided/selmax' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var mask = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 ]; +* var mask = [ false, true, false, true, false, true, false, true, false, false ]; * * var v = selmax.ndarray( 5, x, 2, 1, mask, 2, 1 ); * // returns 4.0 diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js index 3c6bbcf2de4f..fd1dda0bb791 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -32,13 +32,13 @@ var ndarray = require( './ndarray.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} x - input array * @param {integer} strideX - `x` stride length -* @param {NumericArray} mask - mask array +* @param {Collection} mask - mask array * @param {integer} strideMask - `mask` stride length * @returns {number} maximum value * * @example * var x = [ 1.0, -2.0, 4.0, 2.0 ]; -* var mask = [ 1, 1, 0, 1 ]; +* var mask = [ true, true, false, true ]; * * var v = selmax( x.length, x, 1, mask, 1 ); * // returns 2.0 diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js index 085b26d350be..7fe2bc41a96e 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -35,14 +35,14 @@ var accessors = require( './accessors.js' ); * @param {NumericArray} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {NumericArray} mask - mask array +* @param {Collection} mask - mask array * @param {integer} strideMask - stride length for `mask` * @param {NonNegativeInteger} offsetMask - starting index for `mask` * @returns {number} maximum value * * @example * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; -* var mask = [ 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 ]; +* var mask = [ false, true, false, true, false, true, false, true, false, false ]; * * var v = selmax( 5, x, 2, 1, mask, 2, 1 ); * // returns 4.0 diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js index 8ca66977dc66..edb166b8ab65 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js index f74134a50039..cbd824e7bfa7 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -25,7 +25,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); -var Uint8Array = require( '@stdlib/array/uint8' ); +var BooleanArray = require( '@stdlib/array/bool' ); var selmax = require( './../lib/main.js' ); @@ -48,52 +48,52 @@ tape( 'the function calculates the maximum value of a strided array by selecting var v; x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; - mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + mask = [ true, true, true, false, true, true, true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); x = [ -4.0, NaN, -5.0 ]; - mask = [ 1, 0, 1 ]; + mask = [ true, false, true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( v, -4.0, 'returns expected value' ); x = [ -0.0, 0.0, NaN, -0.0 ]; - mask = [ 1, 1, 0, 1 ]; + mask = [ true, true, false, true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ -4.0, 0.0, NaN, 5.0 ]; - mask = [ 1, 1, 1, 1 ]; + mask = [ true, true, true, true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 1 ]; + mask = [ true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 0 ]; + mask = [ false ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 0 ]; + mask = [ false, false ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 1 ]; + mask = [ false, true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 0 ]; + mask = [ true, false ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 1 ]; + mask = [ true, true ]; v = selmax( x.length, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -106,52 +106,52 @@ tape( 'the function calculates the maximum value of a strided array by selecting var v; x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; - mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + mask = [ true, true, true, false, true, true, true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); x = [ -4.0, NaN, -5.0 ]; - mask = [ 1, 0, 1 ]; + mask = [ true, false, true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( v, -4.0, 'returns expected value' ); x = [ -0.0, 0.0, NaN, -0.0 ]; - mask = [ 1, 1, 0, 1 ]; + mask = [ true, true, false, true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ -4.0, 0.0, NaN, 5.0 ]; - mask = [ 1, 1, 1, 1 ]; + mask = [ true, true, true, true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 1 ]; + mask = [ true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 0 ]; + mask = [ false ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 0 ]; + mask = [ false, false ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 1 ]; + mask = [ false, true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 0 ]; + mask = [ true, false ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 1 ]; + mask = [ true, true ]; v = selmax( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -164,7 +164,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - mask = [ 1, 1 ]; + mask = [ true, true ]; v = selmax( 0, x, 1, mask, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -181,7 +181,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - mask = [ 1, 1 ]; + mask = [ true, true ]; v = selmax( 1, x, 1, mask, 1 ); t.strictEqual( v, 1.0, 'returns expected value' ); @@ -207,16 +207,16 @@ tape( 'the function supports `stride` parameters', function test( t ) { 6.0 ]; mask = [ - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 1, - 0, // 4 - 0 + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + true, + false, // 4 + false ]; v = selmax( 5, x, 2, mask, 2 ); @@ -243,16 +243,16 @@ tape( 'the function supports `stride` parameters (accessor)', function test( t ) 6.0 ]; mask = [ - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 1, - 0, // 4 - 0 + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + true, + false, // 4 + false ]; v = selmax( 5, toAccessorArray( x ), 2, toAccessorArray( mask ), 2 ); @@ -279,16 +279,16 @@ tape( 'the function supports negative `stride` parameters', function test( t ) { 2.0 ]; mask = [ - 0, // 4 - 0, - 1, // 3 - 1, - 1, // 2 - 1, - 1, // 1 - 1, - 1, // 0 - 1 + false, // 4 + false, + true, // 3 + true, + true, // 2 + true, + true, // 1 + true, + true, // 0 + true ]; v = selmax( 5, x, -2, mask, -2 ); @@ -315,16 +315,16 @@ tape( 'the function supports negative `stride` parameters (accessor)', function 2.0 ]; mask = [ - 0, // 4 - 0, - 1, // 3 - 1, - 1, // 2 - 1, - 1, // 1 - 1, - 1, // 0 - 1 + false, // 4 + false, + true, // 3 + true, + true, // 2 + true, + true, // 1 + true, + true, // 0 + true ]; v = selmax( 5, toAccessorArray( x ), -2, toAccessorArray( mask ), -2 ); @@ -353,22 +353,22 @@ tape( 'the function supports view offsets', function test( t ) { 5.0, // 4 6.0 ]); - mask0 = new Uint8Array([ - 1, - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 1, - 0, // 4 - 0 + mask0 = new BooleanArray([ + true, + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + true, + false, // 4 + false ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + mask1 = new BooleanArray( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element v = selmax( 5, x1, 2, mask1, 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); @@ -396,22 +396,22 @@ tape( 'the function supports view offsets (accessor)', function test( t ) { 5.0, // 4 6.0 ]); - mask0 = new Uint8Array([ - 1, - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 1, - 0, // 4 - 0 + mask0 = new BooleanArray([ + true, + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + true, + false, // 4 + false ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + mask1 = new BooleanArray( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element v = selmax( 5, toAccessorArray( x1 ), 2, toAccessorArray( mask1 ), 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js index 5dc4ca51829e..8e07a802919d 100644 --- a/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/selmax/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -48,52 +48,52 @@ tape( 'the function calculates the maximum value of a strided array by selecting var v; x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; - mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + mask = [ true, true, true, false, true, true, true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); x = [ -4.0, NaN, -5.0 ]; - mask = [ 1, 0, 1 ]; + mask = [ true, false, true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( v, -4.0, 'returns expected value' ); x = [ -0.0, 0.0, NaN, -0.0 ]; - mask = [ 1, 1, 0, 1 ]; + mask = [ true, true, false, true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ -4.0, 0.0, NaN, 5.0 ]; - mask = [ 1, 1, 1, 1 ]; + mask = [ true, true, true, true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 1 ]; + mask = [ true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 0 ]; + mask = [ false ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 0 ]; + mask = [ false, false ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 1 ]; + mask = [ false, true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 0 ]; + mask = [ true, false ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 1 ]; + mask = [ true, true ]; v = selmax( x.length, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -106,52 +106,52 @@ tape( 'the function calculates the maximum value of a strided array by selecting var v; x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; - mask = [ 1, 1, 1, 0, 1, 1, 1 ]; + mask = [ true, true, true, false, true, true, true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); x = [ -4.0, NaN, -5.0 ]; - mask = [ 1, 0, 1 ]; + mask = [ true, false, true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( v, -4.0, 'returns expected value' ); x = [ -0.0, 0.0, NaN, -0.0 ]; - mask = [ 1, 1, 0, 1 ]; + mask = [ true, true, false, true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ -4.0, 0.0, NaN, 5.0 ]; - mask = [ 1, 1, 1, 1 ]; + mask = [ true, true, true, true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 1 ]; + mask = [ true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN ]; - mask = [ 0 ]; + mask = [ false ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 0 ]; + mask = [ false, false ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 0, 1 ]; + mask = [ false, true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 0 ]; + mask = [ true, false ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - mask = [ 1, 1 ]; + mask = [ true, true ]; v = selmax( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -164,7 +164,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - mask = [ 1.0, 1.0 ]; + mask = [ true, true ]; v = selmax( 0, x, 1, 0, mask, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -181,7 +181,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - mask = [ 1.0, 1.0 ]; + mask = [ true, true ]; v = selmax( 1, x, 1, 0, mask, 1, 0 ); t.strictEqual( v, 1.0, 'returns expected value' ); @@ -207,16 +207,16 @@ tape( 'the function supports `stride` parameters', function test( t ) { 6.0 ]; mask = [ - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 1, - 0, // 4 - 0 + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + true, + false, // 4 + false ]; v = selmax( 5, x, 2, 0, mask, 2, 0 ); @@ -243,16 +243,16 @@ tape( 'the function supports `stride` parameters (accessor)', function test( t ) 6.0 ]; mask = [ - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 1, - 0, // 4 - 0 + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + true, + false, // 4 + false ]; v = selmax( 5, toAccessorArray( x ), 2, 0, toAccessorArray( mask ), 2, 0 ); @@ -279,16 +279,16 @@ tape( 'the function supports negative `stride` parameters', function test( t ) { 2.0 ]; mask = [ - 0, // 4 - 0, - 1, // 3 - 1, - 1, // 2 - 1, - 1, // 1 - 1, - 1, // 0 - 1 + false, // 4 + false, + true, // 3 + true, + true, // 2 + true, + true, // 1 + true, + true, // 0 + true ]; v = selmax( 5, x, -2, 8, mask, -2, 8 ); @@ -315,16 +315,16 @@ tape( 'the function supports negative `stride` parameters (accessor)', function 2.0 ]; mask = [ - 0, // 4 - 0, - 1, // 3 - 1, - 1, // 2 - 1, - 1, // 1 - 1, - 1, // 0 - 1 + false, // 4 + false, + true, // 3 + true, + true, // 2 + true, + true, // 1 + true, + true, // 0 + true ]; v = selmax( 5, toAccessorArray( x ), -2, 8, toAccessorArray( mask ), -2, 8 ); @@ -351,16 +351,16 @@ tape( 'the function supports `offset` parameters', function test( t ) { 6.0 // 4 ]; mask = [ - 1, - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 0, - 0 // 4 + true, + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + false, + false // 4 ]; v = selmax( 5, x, 2, 1, mask, 2, 1 ); @@ -387,16 +387,16 @@ tape( 'the function supports `offset` parameters (accessor)', function test( t ) 6.0 // 4 ]; mask = [ - 1, - 1, // 0 - 1, - 1, // 1 - 1, - 1, // 2 - 1, - 1, // 3 - 0, - 0 // 4 + true, + true, // 0 + true, + true, // 1 + true, + true, // 2 + true, + true, // 3 + false, + false // 4 ]; v = selmax( 5, toAccessorArray( x ), 2, 1, toAccessorArray( mask ), 2, 1 );