diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/README.md b/lib/node_modules/@stdlib/stats/base/nanmaxabs/README.md
index b3499b7733da..3a61a42d1c17 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/README.md
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/README.md
@@ -2,7 +2,7 @@
@license Apache-2.0
-Copyright (c) 2020 The Stdlib Authors.
+Copyright (c) 2025 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.
@@ -36,7 +36,7 @@ limitations under the License.
var nanmaxabs = require( '@stdlib/stats/base/nanmaxabs' );
```
-#### nanmaxabs( N, x, stride )
+#### nanmaxabs( N, x, strideX )
Computes the maximum absolute value of a strided array `x`, ignoring `NaN` values.
@@ -52,7 +52,7 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
-- **stride**: index increment for `x`.
+- **strideX**: stride length for `x`.
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the maximum absolute value of every other element in `x`,
@@ -83,7 +83,7 @@ var v = nanmaxabs( N, x1, 2 );
// returns 4.0
```
-#### nanmaxabs.ndarray( N, x, stride, offset )
+#### nanmaxabs.ndarray( N, x, strideX, offsetX )
Computes the maximum absolute value of a strided array, ignoring `NaN` values and using alternative indexing semantics.
@@ -97,7 +97,7 @@ var v = nanmaxabs.ndarray( N, x, 1, 0 );
The function has the following additional parameters:
-- **offset**: starting index for `x`.
+- **offsetX**: starting index for `x`.
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the maximum absolute value for every other value in `x` starting from the second value
@@ -120,7 +120,7 @@ var v = nanmaxabs.ndarray( N, x, 2, 1 );
## Notes
- If `N <= 0`, both functions return `NaN`.
-- Depending on the environment, the typed versions ([`dnanmaxabs`][@stdlib/stats/strided/dnanmaxabs], [`snanmaxabs`][@stdlib/stats/base/snanmaxabs], etc.) are likely to be significantly more performant.
+- Depending on the environment, the typed versions ([`dnanmaxabs`][@stdlib/stats/strided/dnanmaxabs], [`snanmaxabs`][@stdlib/stats/strided/snanmaxabs], etc.) are likely to be significantly more performant.
@@ -133,22 +133,19 @@ var v = nanmaxabs.ndarray( N, x, 2, 1 );
```javascript
-var randu = require( '@stdlib/random/base/randu' );
-var round = require( '@stdlib/math/base/special/round' );
-var Float64Array = require( '@stdlib/array/float64' );
+var uniform = require( '@stdlib/random/base/uniform' );
+var filledarrayBy = require( '@stdlib/array/filled-by' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
var nanmaxabs = require( '@stdlib/stats/base/nanmaxabs' );
-var x;
-var i;
-
-x = new Float64Array( 10 );
-for ( i = 0; i < x.length; i++ ) {
- if ( randu() < 0.2 ) {
- x[ i ] = NaN;
- } else {
- x[ i ] = round( (randu()*100.0) - 50.0 );
+function rand() {
+ if ( bernoulli( 0.8 ) < 1 ) {
+ return NaN;
}
+ return uniform( -50.0, 50.0 );
}
+
+var x = filledarrayBy( 10, 'float64', rand );
console.log( x );
var v = nanmaxabs( x.length, x, 1 );
@@ -171,7 +168,7 @@ console.log( v );
- [`@stdlib/stats/base/maxabs`][@stdlib/stats/base/maxabs]: calculate the maximum absolute value of a strided array.
- [`@stdlib/stats/base/nanmax`][@stdlib/stats/base/nanmax]: calculate the maximum value of a strided array, ignoring NaN values.
- [`@stdlib/stats/base/nanminabs`][@stdlib/stats/base/nanminabs]: calculate the minimum absolute value of a strided array, ignoring NaN values.
-- [`@stdlib/stats/base/snanmaxabs`][@stdlib/stats/base/snanmaxabs]: calculate the maximum absolute value of a single-precision floating-point strided array, ignoring NaN values.
+- [`@stdlib/stats/strided/snanmaxabs`][@stdlib/stats/strided/snanmaxabs]: calculate the maximum absolute value of a single-precision floating-point strided array, ignoring NaN values.
@@ -182,7 +179,7 @@ console.log( v );
[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
-
+[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
@@ -195,7 +192,7 @@ console.log( v );
[@stdlib/stats/base/nanminabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/nanminabs
-[@stdlib/stats/base/snanmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/snanmaxabs
+[@stdlib/stats/strided/snanmaxabs]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/snanmaxabs
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.js
index 68077cc5f91b..e8195ccf19d7 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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.
@@ -21,7 +21,9 @@
// MODULES //
var bench = require( '@stdlib/bench' );
-var randu = require( '@stdlib/random/base/randu' );
+var uniform = require( '@stdlib/random/base/uniform' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
+var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
@@ -30,6 +32,19 @@ var nanmaxabs = require( './../lib/nanmaxabs.js' );
// FUNCTIONS //
+/**
+* Returns a random value or `NaN`.
+*
+* @private
+* @returns {number} random number or `NaN`
+*/
+function rand() {
+ if ( bernoulli( 0.8 ) < 1 ) {
+ return NaN;
+ }
+ return uniform( -10.0, 10.0 );
+}
+
/**
* Creates a benchmark function.
*
@@ -38,17 +53,7 @@ var nanmaxabs = require( './../lib/nanmaxabs.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x;
- var i;
-
- x = [];
- for ( i = 0; i < len; i++ ) {
- if ( randu() < 0.2 ) {
- x.push( NaN );
- } else {
- x.push( ( randu()*20.0 ) - 10.0 );
- }
- }
+ var x = filledarrayBy( len, 'float64', rand );
return benchmark;
function benchmark( b ) {
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.ndarray.js
index 3927f9a2e182..68dd2463e02c 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.ndarray.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/benchmark/benchmark.ndarray.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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.
@@ -21,7 +21,9 @@
// MODULES //
var bench = require( '@stdlib/bench' );
-var randu = require( '@stdlib/random/base/randu' );
+var uniform = require( '@stdlib/random/base/uniform' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
+var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
@@ -30,6 +32,19 @@ var nanmaxabs = require( './../lib/ndarray.js' );
// FUNCTIONS //
+/**
+* Returns a random value or `NaN`.
+*
+* @private
+* @returns {number} random number or `NaN`
+*/
+function rand() {
+ if ( bernoulli( 0.8 ) < 1 ) {
+ return NaN;
+ }
+ return uniform( -10.0, 10.0 );
+}
+
/**
* Creates a benchmark function.
*
@@ -38,17 +53,7 @@ var nanmaxabs = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x;
- var i;
-
- x = [];
- for ( i = 0; i < len; i++ ) {
- if ( randu() < 0.2 ) {
- x.push( NaN );
- } else {
- x.push( ( randu()*20.0 ) - 10.0 );
- }
- }
+ var x = filledarrayBy( len, 'float64', rand );
return benchmark;
function benchmark( b ) {
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/repl.txt
index f605750df30e..f0c7875cbc68 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/repl.txt
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/repl.txt
@@ -1,13 +1,13 @@
-{{alias}}( N, x, stride )
- Computes the maximum absolute value of a strided array, ignoring `NaN`
- values.
+{{alias}}( N, x, strideX )
+ Computes the maximum absolute value of a strided array, ignoring
+ `NaN` values.
- The `N` and `stride` parameters determine which elements in `x` are accessed
- at runtime.
+ The `N` and stride parameters determine which elements in the
+ stridedarray are accessed at runtime.
- Indexing is relative to the first index. To introduce an offset, use a typed
- array view.
+ Indexing is relative to the first index. To introduce an offset,
+ use a typed array view.
If `N <= 0`, the function returns `NaN`.
@@ -19,8 +19,8 @@
x: Array|TypedArray
Input array.
- stride: integer
- Index increment.
+ strideX: integer
+ Stride length.
Returns
-------
@@ -36,20 +36,17 @@
// Using `N` and `stride` parameters:
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ];
- > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
- > var stride = 2;
- > {{alias}}( N, x, stride )
+ > {{alias}}( 4, x, 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, NaN, NaN ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
- > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
- > stride = 2;
- > {{alias}}( N, x1, stride )
+ > {{alias}}( 4, x1, 2 )
2.0
-{{alias}}.ndarray( N, x, stride, offset )
+
+{{alias}}.ndarray( N, x, strideX, offsetX )
Computes the maximum absolute value of a strided array, ignoring `NaN`
values and using alternative indexing semantics.
@@ -65,10 +62,10 @@
x: Array|TypedArray
Input array.
- stride: integer
- Index increment.
+ strideX: integer
+ Stride length.
- offset: integer
+ offsetX: integer
Starting index.
Returns
@@ -85,10 +82,8 @@
// Using offset parameter:
> var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ];
- > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
- > {{alias}}.ndarray( N, x, 2, 1 )
+ > {{alias}}.ndarray( 4, x, 2, 1 )
2.0
See Also
--------
-
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/index.d.ts
index 33687f14025b..06957504671a 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/index.d.ts
@@ -1,7 +1,7 @@
/*
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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,7 +20,12 @@
///
-import { NumericArray } from '@stdlib/types/array';
+
+import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
+/**
+* Input array.
+*/
+type InputArray = NumericArray | Collection | AccessorArrayLike;
/**
* Interface describing `nanmaxabs`.
@@ -31,7 +36,7 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
- * @param stride - stride length
+ * @param strideX - stride length
* @returns maximum absolute value
*
* @example
@@ -40,15 +45,15 @@ interface Routine {
* var v = nanmaxabs( x.length, x, 1 );
* // returns 2.0
*/
- ( N: number, x: NumericArray, stride: number ): number;
+ ( N: number, x: InputArray, strideX: number ): number;
/**
* Computes the maximum absolute value of a strided array, ignoring `NaN` values and using alternative indexing semantics.
*
* @param N - number of indexed elements
* @param x - input array
- * @param stride - stride length
- * @param offset - starting index
+ * @param strideX - stride length
+ * @param offsetX - starting index
* @returns maximum absolute value
*
* @example
@@ -57,7 +62,7 @@ interface Routine {
* var v = nanmaxabs.ndarray( x.length, x, 1, 0 );
* // returns 2.0
*/
- ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
+ ndarray( N: number, x: InputArray, strideX: number, offsetX: number ): number;
}
/**
@@ -65,7 +70,7 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
-* @param stride - stride length
+* @param strideX - stride length
* @returns maximum absolute value
*
* @example
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/test.ts
index bf70b119e0f9..6b7a55fdd832 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/test.ts
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/docs/types/test.ts
@@ -1,7 +1,7 @@
/*
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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.
@@ -17,7 +17,7 @@
*/
import nanmaxabs = require( './index' );
-
+import AccessorArray = require( '@stdlib/array/base/accessor' );
// TESTS //
@@ -25,7 +25,7 @@ import nanmaxabs = require( './index' );
{
const x = new Float64Array( 10 );
- nanmaxabs( x.length, x, 1 ); // $ExpectType number
+ nanmaxabs( x.length, new AccessorArray( x ), 1 ); // $ExpectType number
}
// The compiler throws an error if the function is provided a first argument which is not a number...
@@ -84,7 +84,7 @@ import nanmaxabs = require( './index' );
{
const x = new Float64Array( 10 );
- nanmaxabs.ndarray( x.length, x, 1, 0 ); // $ExpectType number
+ nanmaxabs.ndarray( x.length, new AccessorArray( x ), 1, 0 ); // $ExpectType number
}
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/examples/index.js
index 803a2025e406..cb75e42f70a6 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/examples/index.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/examples/index.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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.
@@ -18,22 +18,19 @@
'use strict';
-var randu = require( '@stdlib/random/base/randu' );
-var round = require( '@stdlib/math/base/special/round' );
-var Float64Array = require( '@stdlib/array/float64' );
+var uniform = require( '@stdlib/random/base/uniform' );
+var filledarrayBy = require( '@stdlib/array/filled-by' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
var nanmaxabs = require( './../lib' );
-var x;
-var i;
-
-x = new Float64Array( 10 );
-for ( i = 0; i < x.length; i++ ) {
- if ( randu() < 0.2 ) {
- x[ i ] = NaN;
- } else {
- x[ i ] = round( (randu()*100.0) - 50.0 );
+function rand() {
+ if ( bernoulli( 0.8 ) < 1 ) {
+ return NaN;
}
+ return uniform( -50.0, 50.0 );
}
+
+var x = filledarrayBy( 10, 'float64', rand );
console.log( x );
var v = nanmaxabs( x.length, x, 1 );
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/accessors.js
new file mode 100644
index 000000000000..f747150fc213
--- /dev/null
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/accessors.js
@@ -0,0 +1,96 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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 abs = require( '@stdlib/math/base/special/abs' );
+
+
+// MAIN //
+
+/**
+* Computes the maximum absolute value of a strided array, ignoring `NaN` values.
+*
+* @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
+* @param {NonNegativeInteger} offsetX - starting index
+* @returns {number} maximum value
+*
+* @example
+* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
+* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
+*
+* var x = toAccessorArray( [ 1.0, -2.0, NaN, 2.0 ] );
+*
+* var v = nanmaxabs( 4, arraylike2object( x ), 1, 0 );
+* // returns 2.0
+*/
+function nanmaxabs( N, x, strideX, offsetX ) {
+ var xbuf;
+ var get;
+ var max;
+ var ix;
+ var v;
+ var i;
+
+ // Cache reference to array data:
+ xbuf = x.data;
+
+ // Cache a reference to the element accessor:
+ get = x.accessors[0];
+
+ if ( N === 1 || strideX === 0 ) {
+ return get( xbuf, offsetX );
+ }
+ ix = offsetX;
+ for ( i = 0; i < N; i++ ) {
+ v = get( xbuf, ix );
+ if ( !isnan( v ) ) {
+ max = abs( v );
+ break;
+ }
+ ix += strideX;
+ }
+ if ( i === N ) {
+ return NaN;
+ }
+ i += 1;
+ for ( i; i < N; i++ ) {
+ ix += strideX;
+ v = get( xbuf, ix );
+ if ( isnan( v ) ) {
+ continue;
+ }
+ v = abs( v );
+ if ( v > max) {
+ max = abs( v );
+ }
+ }
+ return max;
+}
+
+
+// EXPORTS //
+
+module.exports = nanmaxabs;
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/nanmaxabs.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/nanmaxabs.js
index b3fddc634530..bd43c168bcb8 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/nanmaxabs.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/nanmaxabs.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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,8 +20,8 @@
// MODULES //
-var isnan = require( '@stdlib/math/base/assert/is-nan' );
-var abs = require( '@stdlib/math/base/special/abs' );
+var stride2offset = require( '@stdlib/strided/base/stride2offset' );
+var ndarray = require( './ndarray.js' );
// MAIN //
@@ -31,7 +31,7 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {NumericArray} x - input array
-* @param {integer} stride - stride length
+* @param {integer} strideX - stride length
* @returns {number} maximum absolute value
*
* @example
@@ -41,46 +41,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
* var v = nanmaxabs( N, x, 1 );
* // returns 2.0
*/
-function nanmaxabs( N, x, stride ) {
- var max;
- var ix;
- var v;
- var i;
-
- if ( N <= 0 ) {
- return NaN;
- }
- if ( N === 1 || stride === 0 ) {
- return x[ 0 ];
- }
- if ( stride < 0 ) {
- ix = (1-N) * stride;
- } else {
- ix = 0;
- }
- for ( i = 0; i < N; i++ ) {
- v = x[ ix ];
- if ( v === v ) {
- break;
- }
- ix += stride;
- }
- if ( i === N ) {
- return NaN;
- }
- max = abs( v );
- i += 1;
- for ( i; i < N; i++ ) {
- ix += stride;
- v = abs( x[ ix ] );
- if ( isnan( v ) ) {
- continue;
- }
- if ( v > max ) {
- max = v;
- }
- }
- return max;
+function nanmaxabs( N, x, strideX ) {
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
}
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/ndarray.js
index cc144dd7f0f8..7066d37d5d47 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/lib/ndarray.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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.
@@ -22,6 +22,8 @@
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
+var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
+var accessors = require( './accessors.js' );
// MAIN //
@@ -31,8 +33,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {NumericArray} x - input array
-* @param {integer} stride - stride length
-* @param {NonNegativeInteger} offset - starting index
+* @param {integer} strideX - stride length
+* @param {NonNegativeInteger} offsetX - starting index
* @returns {number} maximum absolute value
*
* @example
@@ -44,25 +46,30 @@ var abs = require( '@stdlib/math/base/special/abs' );
* var v = nanmaxabs( N, x, 2, 1 );
* // returns 4.0
*/
-function nanmaxabs( N, x, stride, offset ) {
+function nanmaxabs( N, x, strideX, offsetX ) {
var max;
var ix;
+ var o;
var v;
var i;
if ( N <= 0 ) {
return NaN;
}
- if ( N === 1 || stride === 0 ) {
- return x[ offset ];
+ o = arraylike2object( x );
+ if ( o.accessorProtocol ) {
+ return accessors( N, o, strideX, offsetX );
}
- ix = offset;
+ if ( N === 1 || strideX === 0 ) {
+ return x[ offsetX ];
+ }
+ ix = offsetX;
for ( i = 0; i < N; i++ ) {
v = x[ ix ];
if ( v === v ) {
break;
}
- ix += stride;
+ ix += strideX;
}
if ( i === N ) {
return NaN;
@@ -70,7 +77,7 @@ function nanmaxabs( N, x, stride, offset ) {
max = abs( v );
i += 1;
for ( i; i < N; i++ ) {
- ix += stride;
+ ix += strideX;
v = abs( x[ ix ] );
if ( isnan( v ) ) {
continue;
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.nanmaxabs.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.nanmaxabs.js
index 6b01fb9969a5..32e8bbc534d0 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.nanmaxabs.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.nanmaxabs.js
@@ -22,6 +22,7 @@
var tape = require( 'tape' );
var floor = require( '@stdlib/math/base/special/floor' );
+var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var Float64Array = require( '@stdlib/array/float64' );
@@ -68,6 +69,33 @@ tape( 'the function calculates the maximum absolute value of a strided array', f
t.end();
});
+tape( 'the function calculates the maximum absolute value of a strided array (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0, NaN, NaN ];
+ v = nanmaxabs( x.length, toAccessorArray(x), 1 );
+ t.strictEqual( v, 5.0, 'returns expected value' );
+
+ x = [ -4.0, NaN, -5.0 ];
+ v = nanmaxabs( x.length, toAccessorArray(x), 1 );
+ t.strictEqual( v, 5.0, 'returns expected value' );
+
+ x = [ -0.0, NaN, 0.0, -0.0 ];
+ v = nanmaxabs( x.length, toAccessorArray(x), 1 );
+ t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
+
+ x = [ NaN ];
+ v = nanmaxabs( x.length, toAccessorArray(x), 1 );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = [ NaN, NaN ];
+ v = nanmaxabs( x.length, toAccessorArray(x), 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 x;
var v;
@@ -83,13 +111,13 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
t.end();
});
-tape( 'if provided an `N` parameter equal to `1`, the function returns the first element', function test( t ) {
+tape( 'if provided an `N` parameter equal to `1`, the function returns the first element (accessors)', function test( t ) {
var x;
var v;
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
- v = nanmaxabs( 1, x, 1 );
+ v = nanmaxabs( 1, toAccessorArray(x), 1 );
t.strictEqual( v, 1.0, 'returns expected value' );
t.end();
@@ -120,6 +148,31 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
t.end();
});
+tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
+ var N;
+ 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,
+ NaN, // 4
+ NaN
+ ];
+
+ N = floor( x.length / 2 );
+ v = nanmaxabs( N, toAccessorArray(x), 2 );
+
+ t.strictEqual( v, 4.0, 'returns expected value' );
+ t.end();
+});
+
tape( 'the function supports a negative `stride` parameter', function test( t ) {
var N;
var x;
@@ -145,6 +198,31 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
t.end();
});
+tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
+ var N;
+ var x;
+ var v;
+
+ x = [
+ NaN, // 4
+ NaN,
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ N = floor( x.length / 2 );
+ v = nanmaxabs( N, toAccessorArray(x), -2 );
+
+ t.strictEqual( v, 4.0, 'returns expected value' );
+ t.end();
+});
+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) {
var x;
var v;
@@ -157,6 +235,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f
t.end();
});
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxabs( x.length, toAccessorArray(x), 0 );
+ t.strictEqual( v, 1.0, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports view offsets', function test( t ) {
var x0;
var x1;
@@ -185,3 +275,32 @@ tape( 'the function supports view offsets', function test( t ) {
t.end();
});
+
+tape( 'the function supports view offsets (accessors)', function test( t ) {
+ var x0;
+ var x1;
+ var N;
+ 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,
+ NaN, // 4
+ NaN
+ ]);
+
+ x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
+ N = floor(x1.length / 2);
+
+ v = nanmaxabs( N, toAccessorArray(x1), 2 );
+ t.strictEqual( v, 4.0, 'returns expected value' );
+
+ t.end();
+});
diff --git a/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.ndarray.js
index 97b50d1c6c2b..e05691afdf8e 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.ndarray.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmaxabs/test/test.ndarray.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 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.
@@ -22,6 +22,7 @@
var tape = require( 'tape' );
var floor = require( '@stdlib/math/base/special/floor' );
+var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var nanmaxabs = require( './../lib/ndarray.js' );
@@ -52,7 +53,7 @@ tape( 'the function calculates the maximum absolute value of a strided array', f
v = nanmaxabs( x.length, x, 1, 0 );
t.strictEqual( v, 5.0, 'returns expected value' );
- x = [ -0.0, 0.0, NaN, -0.0 ];
+ x = [ 0.0, -0.0, NaN, 0.0 ];
v = nanmaxabs( x.length, x, 1, 0 );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
@@ -67,6 +68,33 @@ tape( 'the function calculates the maximum absolute value of a strided array', f
t.end();
});
+tape( 'the function calculates the maximum absolute value of a strided array (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ];
+ v = nanmaxabs( x.length, toAccessorArray( x ), 1, 0 );
+ t.strictEqual( v, 5.0, 'returns expected value' );
+
+ x = [ -4.0, NaN, -5.0 ];
+ v = nanmaxabs( x.length, toAccessorArray( x ), 1, 0 );
+ t.strictEqual( v, 5.0, 'returns expected value' );
+
+ x = [ 0.0, -0.0, NaN, 0.0 ];
+ v = nanmaxabs( x.length, toAccessorArray( x ), 1, 0 );
+ t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
+
+ x = [ NaN ];
+ v = nanmaxabs( x.length, toAccessorArray( x ), 1, 0 );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = [ NaN, NaN ];
+ v = nanmaxabs( x.length, toAccessorArray( x ), 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 x;
var v;
@@ -144,6 +172,31 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
t.end();
});
+tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
+ var N;
+ var x;
+ var v;
+
+ x = [
+ NaN, // 4
+ NaN,
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ N = floor( x.length / 2 );
+ v = nanmaxabs( N, toAccessorArray( x ), -2, 8 );
+
+ t.strictEqual( v, 4.0, 'returns expected value' );
+ t.end();
+});
+
tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) {
var x;
var v;
@@ -180,3 +233,28 @@ tape( 'the function supports an `offset` parameter', function test( t ) {
t.end();
});
+
+tape( 'the function supports an `offset` parameter (accessors)', function test( t ) {
+ var N;
+ 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
+ NaN,
+ NaN // 4
+ ];
+ N = floor( x.length / 2 );
+
+ v = nanmaxabs( N, toAccessorArray( x ), 2, 1 );
+ t.strictEqual( v, 4.0, 'returns expected value' );
+
+ t.end();
+});