From e7d1ce9506b99a967ba7246aefbc13360468f745 Mon Sep 17 00:00:00 2001 From: orthodox-64 Date: Sun, 11 Jan 2026 20:37:11 +0530 Subject: [PATCH 1/2] feat: add stats/strided/mskmaxabs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/strided/mskmaxabs/README.md | 207 +++++++++ .../strided/mskmaxabs/benchmark/benchmark.js | 105 +++++ .../mskmaxabs/benchmark/benchmark.ndarray.js | 105 +++++ .../stats/strided/mskmaxabs/docs/repl.txt | 116 +++++ .../strided/mskmaxabs/docs/types/index.d.ts | 104 +++++ .../strided/mskmaxabs/docs/types/test.ts | 250 +++++++++++ .../stats/strided/mskmaxabs/examples/index.js | 36 ++ .../stats/strided/mskmaxabs/lib/accessors.js | 116 +++++ .../stats/strided/mskmaxabs/lib/index.js | 61 +++ .../stats/strided/mskmaxabs/lib/main.js | 53 +++ .../stats/strided/mskmaxabs/lib/ndarray.js | 105 +++++ .../stats/strided/mskmaxabs/package.json | 76 ++++ .../stats/strided/mskmaxabs/test/test.js | 38 ++ .../stats/strided/mskmaxabs/test/test.main.js | 420 ++++++++++++++++++ .../strided/mskmaxabs/test/test.ndarray.js | 406 +++++++++++++++++ 15 files changed, 2198 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/README.md b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/README.md new file mode 100644 index 000000000000..c139b578c0a4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/README.md @@ -0,0 +1,207 @@ + + +# mskmaxabs + +> Calculate the maximum absolute value of a strided array according to a mask. + +
+ +
+ + + +
+ +## Usage + +```javascript +var mskmaxabs = require( '@stdlib/stats/strided/mskmaxabs' ); +``` + +#### mskmaxabs( N, x, strideX, mask, strideMask ) + +Computes the maximum absolute value of a strided array according to a mask. + +```javascript +var x = [ 1.0, -2.0, 4.0, 2.0 ]; +var mask = [ 0, 0, 1, 0 ]; + +var v = mskmaxabs( 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 `0`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `1`, 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 absolute 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 = [ 0, 0, 0, 0, 0, 0, 1, 1 ]; + +var v = mskmaxabs( 4, x, 2, mask, 2 ); +// returns 7.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 Uint8Array = require( '@stdlib/array/uint8' ); + +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 ); // start at 2nd element + +var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1 ] ); +var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = mskmaxabs( 4, x1, 2, mask1, 2 ); +// returns 4.0 +``` + +#### mskmaxabs.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask ) + +Computes the maximum absolute value of a strided array according to a `mask` and using alternative indexing semantics. + +```javascript +var x = [ 1.0, -2.0, 4.0, 2.0 ]; +var mask = [ 0, 0, 1, 0 ]; + +var v = mskmaxabs.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 absolute 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 = [ 0, 0, 0, 0, 0, 0, 1, 1 ]; + +var v = mskmaxabs.ndarray( 4, x, 2, 1, mask, 2, 1 ); +// returns 4.0 +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `NaN`. +- Depending on the environment, the typed versions ([`dmskmaxabs`][@stdlib/stats/strided/dmskmaxabs], [`smskmaxabs`][@stdlib/stats/strided/smskmaxabs], etc.) are likely to be significantly more performant. +- 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 mskmaxabs = require( '@stdlib/stats/strided/mskmaxabs' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +console.log( x ); + +var mask = bernoulli( x.length, 0.2, { + 'dtype': 'uint8' +}); +console.log( mask ); + +var v = mskmaxabs( x.length, x, 1, mask, 1 ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.js new file mode 100644 index 000000000000..066f5e8890db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var 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 mskmaxabs = 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.2, 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 = mskmaxabs( 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/mskmaxabs/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..e29a536f98bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/benchmark/benchmark.ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var 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 mskmaxabs = 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.2, 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 = mskmaxabs( 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/mskmaxabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/repl.txt new file mode 100644 index 000000000000..6b010957b922 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/repl.txt @@ -0,0 +1,116 @@ + +{{alias}}( N, x, strideX, mask, strideMask ) + Computes the maximum absolute value of a strided array 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 `0`, the corresponding element in `x` is + considered valid and included in computation. + + If a `mask` array element is `1`, 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 absolute value. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 4.0, 2.0 ]; + > var mask = [ 0, 0, 1, 0 ]; + > {{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 = [ 0, 0, 0, 0, 0, 0, 1 ]; + > {{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}}( [ 0, 0, 0, 0, 0, 0, 1 ] ); + > 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 absolute value of a strided array according to a mask + and using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the `offset` parameter supports indexing semantics based on a + starting index. + + 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 absolute value. + + Examples + -------- + // Standard Usage: + > var x = [ 1.0, -2.0, 2.0, 4.0 ]; + > var mask = [ 0, 0, 0, 1 ]; + > {{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 = [ 0, 0, 0, 0, 0, 0, 1 ]; + > {{alias}}.ndarray( 3, x, 2, 1, mask, 2, 1 ) + 2.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/index.d.ts new file mode 100644 index 000000000000..fea0034139b8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/index.d.ts @@ -0,0 +1,104 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + +/** +* Interface describing `mskmaxabs`. +*/ +interface Routine { + /** + * Computes the maximum absolute value of a strided array 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 absolute value + * + * @example + * var x = [ 1.0, -2.0, 4.0, 2.0 ]; + * var mask = [ 0, 0, 1, 0 ]; + * + * var v = mskmaxabs( x.length, x, 1, mask, 1 ); + * // returns 2.0 + */ + ( N: number, x: InputArray, strideX: number, mask: InputArray, strideMask: number ): number; + + /** + * Computes the maximum absolute value of a strided array 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 absolute value + * + * @example + * var x = [ 1.0, -2.0, 4.0, 2.0 ]; + * var mask = [ 0, 0, 1, 0 ]; + * + * var v = mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, 0 ); + * // returns 2.0 + */ + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, mask: InputArray, strideMask: number, offsetMask: number ): number; +} + +/** +* Computes the maximum absolute value of a strided array 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 absolute value +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskmaxabs( x.length, x, 1, mask, 1 ); +* // returns 2.0 +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, 0 ); +* // returns 2.0 +*/ +declare var mskmaxabs: Routine; + + +// EXPORTS // + +export = mskmaxabs; diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts new file mode 100644 index 000000000000..2f22a463c241 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts @@ -0,0 +1,250 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import mskmaxabs = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + const mask = new Uint8Array( 10 ); + + mskmaxabs( x.length, x, 1, mask, 1 ); // $ExpectType number + mskmaxabs( 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 ); + + mskmaxabs( '10', x, 1, mask, 1 ); // $ExpectError + mskmaxabs( true, x, 1, mask, 1 ); // $ExpectError + mskmaxabs( false, x, 1, mask, 1 ); // $ExpectError + mskmaxabs( null, x, 1, mask, 1 ); // $ExpectError + mskmaxabs( undefined, x, 1, mask, 1 ); // $ExpectError + mskmaxabs( [], x, 1, mask, 1 ); // $ExpectError + mskmaxabs( {}, x, 1, mask, 1 ); // $ExpectError + mskmaxabs( ( 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 ); + + mskmaxabs( x.length, 10, 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, '10', 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, true, 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, false, 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, null, 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, undefined, 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, [ '1' ], 1, mask, 1 ); // $ExpectError + mskmaxabs( x.length, {}, 1, mask, 1 ); // $ExpectError + mskmaxabs( 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 ); + + mskmaxabs( x.length, x, '10', mask, 1 ); // $ExpectError + mskmaxabs( x.length, x, true, mask, 1 ); // $ExpectError + mskmaxabs( x.length, x, false, mask, 1 ); // $ExpectError + mskmaxabs( x.length, x, null, mask, 1 ); // $ExpectError + mskmaxabs( x.length, x, undefined, mask, 1 ); // $ExpectError + mskmaxabs( x.length, x, [], mask, 1 ); // $ExpectError + mskmaxabs( x.length, x, {}, mask, 1 ); // $ExpectError + mskmaxabs( 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 ); + + mskmaxabs( x.length, x, 1, 10, 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, '10', 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, true, 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, false, 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, null, 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, undefined, 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, [ '1' ], 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, {}, 1 ); // $ExpectError + mskmaxabs( 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 ); + + mskmaxabs( x.length, x, 1, mask, '10' ); // $ExpectError + mskmaxabs( x.length, x, 1, mask, true ); // $ExpectError + mskmaxabs( x.length, x, 1, mask, false ); // $ExpectError + mskmaxabs( x.length, x, 1, mask, null ); // $ExpectError + mskmaxabs( x.length, x, 1, mask, undefined ); // $ExpectError + mskmaxabs( x.length, x, 1, mask, [] ); // $ExpectError + mskmaxabs( x.length, x, 1, mask, {} ); // $ExpectError + mskmaxabs( 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 ); + + mskmaxabs(); // $ExpectError + mskmaxabs( x.length ); // $ExpectError + mskmaxabs( x.length, x, 1 ); // $ExpectError + mskmaxabs( x.length, x, 1, mask ); // $ExpectError + mskmaxabs( 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 ); + + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, 0 ); // $ExpectType number + mskmaxabs.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 ); + + mskmaxabs.ndarray( '10', x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( true, x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( false, x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( null, x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( undefined, x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( [], x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( {}, x, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.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 ); + + mskmaxabs.ndarray( x.length, 10, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, '10', 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, true, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, false, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, null, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, undefined, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, [ '1' ], 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, {}, 1, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.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 ); + + mskmaxabs.ndarray( x.length, x, '10', 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, true, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, false, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, null, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, undefined, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, [], 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, {}, 0, mask, 1, 0 ); // $ExpectError + mskmaxabs.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 ); + + mskmaxabs.ndarray( x.length, x, 1, '10', mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, true, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, false, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, null, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, undefined, mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, [], mask, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, {}, mask, 1, 0 ); // $ExpectError + mskmaxabs.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 ); + + mskmaxabs.ndarray( x.length, 1, 0, 10, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, '10', 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, true, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, false, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, null, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, undefined, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 1, 0, {}, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, 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 ); + + mskmaxabs.ndarray( x.length, x, 1, 0, mask, '10', 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, true, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, false, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, null, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, undefined, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, [], 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, {}, 0 ); // $ExpectError + mskmaxabs.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 ); + + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, '10' ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, true ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, false ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, null ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, undefined ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, [] ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, {} ); // $ExpectError + mskmaxabs.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 ); + + mskmaxabs.ndarray(); // $ExpectError + mskmaxabs.ndarray( x.length ); // $ExpectError + mskmaxabs.ndarray( x.length, x ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, mask, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/examples/index.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/examples/index.js new file mode 100644 index 000000000000..c1f00f058fc9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var mskmaxabs = require( './../lib' ); + +var x = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); +console.log( x ); + +var mask = bernoulli( x.length, 0.2, { + 'dtype': 'uint8' +}); +console.log( mask ); + +var v = mskmaxabs( x.length, x, 1, mask, 1 ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js new file mode 100644 index 000000000000..efe2c873a5d8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var abs = require( '@stdlib/math/base/special/abs' ); + + +// MAIN // + +/** +* Computes the maximum absolute value of a strided array 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 {Object} output 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, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]; +* +* var v = mskmaxabs( 5, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( mask ) ), 2, 1 ); +* // returns 4.0 +*/ +function mskmaxabs( 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 ]; + + if ( N <= 0 ) { + return NaN; + } + ix = offsetX; + im = offsetMask; + for ( i = 0; i < N; i++ ) { + if ( mget( mbuf, im ) === 0 ) { + break; + } + ix += strideX; + im += strideMask; + } + if ( i === N ) { + return NaN; + } + max = abs( 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 = abs( xget( xbuf, ix ) ); + if ( isnan( v ) ) { + return v; + } + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + return max; +} + + +// EXPORTS // + +module.exports = mskmaxabs; diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/index.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/index.js new file mode 100644 index 000000000000..f6dba9ea6ad8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/index.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the maximum absolute value of a strided array according to a mask. +* +* @module @stdlib/stats/strided/mskmaxabs +* +* @example +* var mskmaxabs = require( '@stdlib/stats/strided/mskmaxabs' ); +* +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskmaxabs( x.length, x, 1, mask, 1 ); +* // returns 2.0 +* +* @example +* var mskmaxabs = require( '@stdlib/stats/strided/mskmaxabs' ); +* +* 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, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]; +* +* var v = mskmaxabs.ndarray( 5, x, 2, 1, mask, 2, 1 ); +* // returns 4.0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "ndarray": "main.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/main.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/main.js new file mode 100644 index 000000000000..ab854190403e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/main.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the maximum absolute value of a strided array 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 absolute value +* +* @example +* var x = [ 1.0, -2.0, 4.0, 2.0 ]; +* var mask = [ 0, 0, 1, 0 ]; +* +* var v = mskmaxabs( x.length, x, 1, mask, 1 ); +* // returns 2.0 +*/ +function mskmaxabs( 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 = mskmaxabs; diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/ndarray.js new file mode 100644 index 000000000000..9bfb7e1ea008 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/ndarray.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Computes the maximum absolute value of a strided array 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 absolute 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, 0, 0, 0, 0, 0, 0, 0, 1, 1 ]; +* +* var v = mskmaxabs( 5, x, 2, 1, mask, 2, 1 ); +* // returns 4.0 +*/ +function mskmaxabs( 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 ] === 0 ) { + break; + } + ix += strideX; + im += strideMask; + } + if ( i === N ) { + return NaN; + } + max = abs( x[ ix ] ); + if ( isnan( max ) ) { + return max; + } + i += 1; + for ( i; i < N; i++ ) { + ix += strideX; + im += strideMask; + if ( mask[ im ] ) { + continue; + } + v = abs( x[ ix ] ); + if ( isnan( v ) ) { + return v; + } + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + return max; +} + + +// EXPORTS // + +module.exports = mskmaxabs; diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/package.json b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/package.json new file mode 100644 index 000000000000..aecc1486a224 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats/strided/mskmaxabs", + "version": "0.0.0", + "description": "Calculate the maximum absolute value of a strided array 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", + "browser": "./lib/main.js", + "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", + "absolute", + "abs", + "range", + "extremes", + "domain", + "extent", + "strided", + "strided array", + "masked", + "mask", + "masked array", + "typed", + "array" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.js new file mode 100644 index 000000000000..9ad054374823 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var mskmaxabs = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmaxabs, '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 mskmaxabs.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.main.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.main.js new file mode 100644 index 000000000000..0515b517c4c2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.main.js @@ -0,0 +1,420 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var 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 mskmaxabs = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmaxabs, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( mskmaxabs.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the maximum absolute value of a strided array 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 = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 0, 1, 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ -4.0, 0.0, NaN, 5.0 ]; + mask = [ 0, 0, 0, 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = mskmaxabs( x.length, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the maximum absolute value of a strided array 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 = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 0, 1, 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskmaxabs( 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 = [ 0, 0, 0, 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, toAccessorArray( mask ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = mskmaxabs( 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 = [ 0, 0 ]; + + v = mskmaxabs( 0, x, 1, mask, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = mskmaxabs( -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 absolute value', function test( t ) { + var mask; + var x; + var v; + + x = [ -1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 0, 0 ]; + + v = mskmaxabs( 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 = [ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]; + + v = mskmaxabs( 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 = [ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]; + + v = mskmaxabs( 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 = [ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]; + + v = mskmaxabs( 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 = [ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]; + + v = mskmaxabs( 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([ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]); + + 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 = mskmaxabs( 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([ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]); + + 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 = mskmaxabs( 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/mskmaxabs/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.ndarray.js new file mode 100644 index 000000000000..f31152f96734 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/test/test.ndarray.js @@ -0,0 +1,406 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable 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 mskmaxabs = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mskmaxabs, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( mskmaxabs.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the maximum absolute value of a strided array 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 = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + mask = [ 0, 1, 0 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskmaxabs( 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 = [ 0, 0, 0, 0 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 1 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 1, 0 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 1 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + mask = [ 0, 0 ]; + v = mskmaxabs( x.length, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the maximum absolute value of a strided array 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 = [ 0, 0, 0, 1, 0, 0, 0 ]; + v = mskmaxabs( 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 = [ 0, 1, 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + mask = [ 0, 0, 1, 0 ]; + v = mskmaxabs( 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 = [ 0, 0, 0, 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 0 ]; + v = mskmaxabs( x.length, toAccessorArray( x ), 1, 0, toAccessorArray( mask ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + mask = [ 1 ]; + v = mskmaxabs( 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 = mskmaxabs( 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 = mskmaxabs( 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 = mskmaxabs( 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 = mskmaxabs( 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 = [ 0.0, 0.0 ]; + + v = mskmaxabs( 0, x, 1, 0, mask, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = mskmaxabs( -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 absolute value', function test( t ) { + var mask; + var x; + var v; + + x = [ -1.0, -2.0, -4.0, 5.0, 3.0 ]; + mask = [ 0.0, 0.0 ]; + + v = mskmaxabs( 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 = [ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]; + + v = mskmaxabs( 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 = [ + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 0, + 1, // 4 + 1 + ]; + + v = mskmaxabs( 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 = [ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]; + + v = mskmaxabs( 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 = [ + 1, // 4 + 1, + 0, // 3 + 0, + 0, // 2 + 0, + 0, // 1 + 0, + 0, // 0 + 0 + ]; + + v = mskmaxabs( 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 = [ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 1, + 1 // 4 + ]; + + v = mskmaxabs( 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 = [ + 0, + 0, // 0 + 0, + 0, // 1 + 0, + 0, // 2 + 0, + 0, // 3 + 1, + 1 // 4 + ]; + + v = mskmaxabs( 5, toAccessorArray( x ), 2, 1, toAccessorArray( mask ), 2, 1 ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); From 8d2f1f2824e3614729e60f507414f32ca905481a Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 11 Jan 2026 23:50:02 -0600 Subject: [PATCH 2/2] chore: minor clean-up Signed-off-by: Philipp Burckhardt --- .../stats/strided/mskmaxabs/docs/types/test.ts | 18 +++++++++--------- .../stats/strided/mskmaxabs/lib/accessors.js | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts index 2f22a463c241..4b4b529d1e59 100644 --- a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/docs/types/test.ts @@ -193,15 +193,15 @@ import mskmaxabs = require( './index' ); { const x = new Float64Array( 10 ); - mskmaxabs.ndarray( x.length, 1, 0, 10, 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, '10', 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, true, 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, false, 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, null, 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, undefined, 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, [ '1' ], 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, {}, 1, 0 ); // $ExpectError - mskmaxabs.ndarray( x.length, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, [ '1' ], 1, 0 ); // $ExpectError + mskmaxabs.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + mskmaxabs.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... diff --git a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js index efe2c873a5d8..de1729ee4a7a 100644 --- a/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/strided/mskmaxabs/lib/accessors.js @@ -42,7 +42,7 @@ var abs = require( '@stdlib/math/base/special/abs' ); * @param {Array} mask.accessors - mask element accessors * @param {integer} strideMask - stride length for `mask` * @param {NonNegativeInteger} offsetMask - starting index for `mask` -* @returns {Object} output maximum value +* @returns {number} output maximum value * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );