diff --git a/lib/node_modules/@stdlib/stats/base/max/README.md b/lib/node_modules/@stdlib/stats/base/max/README.md index b40881e618d3..7faafe68c292 100644 --- a/lib/node_modules/@stdlib/stats/base/max/README.md +++ b/lib/node_modules/@stdlib/stats/base/max/README.md @@ -36,15 +36,14 @@ limitations under the License. var max = require( '@stdlib/stats/base/max' ); ``` -#### max( N, x, stride ) +#### max( N, x, strideX ) Computes the maximum value of a strided array `x`. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = max( N, x, 1 ); +var v = max( x.length, x, 1 ); // returns 2.0 ``` @@ -52,17 +51,14 @@ 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 value of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the maximum value of every other element in `x`, ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ]; -var N = floor( x.length / 2 ); -var v = max( N, x, 2 ); +var v = max( 4, x, 2 ); // returns 4.0 ``` @@ -72,42 +68,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = max( N, x1, 2 ); +var v = max( 4, x1, 2 ); // returns 4.0 ``` -#### max.ndarray( N, x, stride, offset ) +#### max.ndarray( N, x, strideX, offsetX ) Computes the maximum value of a strided array using alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = max.ndarray( N, x, 1, 0 ); +var v = max.ndarray( x.length, x, 1, 0 ); // returns 2.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 value for every other value in `x` starting from the second value +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 value for every other element in `x` starting from the second element ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -var N = floor( x.length / 2 ); -var v = max.ndarray( N, x, 2, 1 ); +var v = max.ndarray( 4, x, 2, 1 ); // returns 4.0 ``` @@ -120,6 +109,7 @@ var v = max.ndarray( N, x, 2, 1 ); ## Notes - If `N <= 0`, both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). - Depending on the environment, the typed versions ([`dmax`][@stdlib/stats/strided/dmax], [`smax`][@stdlib/stats/base/smax], etc.) are likely to be significantly more performant. @@ -133,18 +123,12 @@ var v = max.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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var max = require( '@stdlib/stats/base/max' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = max( x.length, x, 1 ); @@ -180,6 +164,8 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor + [@stdlib/stats/strided/dmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dmax diff --git a/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.js index 6960f95e53f2..db119f60bec4 100644 --- a/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.js @@ -21,11 +21,18 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; -var max = require( './../lib/max.js' ); +var max = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; // FUNCTIONS // @@ -38,13 +45,7 @@ var max = require( './../lib/max.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*20.0 ) - 10.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.ndarray.js index f3a065f0c619..2a12f69dddcf 100644 --- a/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/max/benchmark/benchmark.ndarray.js @@ -21,13 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var max = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var max = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*20.0 ) - 10.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/max/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/max/docs/repl.txt index fc48cfc149dd..168755202d83 100644 --- a/lib/node_modules/@stdlib/stats/base/max/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/max/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the maximum value of a strided array. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -18,8 +18,8 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -33,22 +33,19 @@ > {{alias}}( x.length, x, 1 ) 2.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, 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 ] ); > 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}}( 3, x1, 2 ) 2.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the maximum value of a strided array using alternative indexing semantics. @@ -64,10 +61,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -84,8 +81,7 @@ // Using offset parameter: > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) 2.0 See Also diff --git a/lib/node_modules/@stdlib/stats/base/max/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/max/docs/types/index.d.ts index 014daaefe9cb..d466bf552354 100644 --- a/lib/node_modules/@stdlib/stats/base/max/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/max/docs/types/index.d.ts @@ -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 `max`. @@ -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 value * * @example @@ -40,15 +45,15 @@ interface Routine { * var v = max( x.length, x, 1 ); * // returns 2.0 */ - ( N: number, x: NumericArray, stride: number ): number; + ( N: number, x: InputArray, strideX: number ): number; /** * Computes the maximum value of a strided array 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 value * * @example @@ -57,7 +62,7 @@ interface Routine { * var v = max.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 value * * @example diff --git a/lib/node_modules/@stdlib/stats/base/max/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/max/docs/types/test.ts index 8bff6adf9fc6..b51717abcd96 100644 --- a/lib/node_modules/@stdlib/stats/base/max/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/max/docs/types/test.ts @@ -16,6 +16,7 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import max = require( './index' ); @@ -26,6 +27,7 @@ import max = require( './index' ); const x = new Float64Array( 10 ); max( x.length, x, 1 ); // $ExpectType number + max( 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... @@ -85,6 +87,7 @@ import max = require( './index' ); const x = new Float64Array( 10 ); max.ndarray( x.length, x, 1, 0 ); // $ExpectType number + max.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/max/examples/index.js b/lib/node_modules/@stdlib/stats/base/max/examples/index.js index 78384a2e3fe1..65ba269a070b 100644 --- a/lib/node_modules/@stdlib/stats/base/max/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/max/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var max = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = max( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/max/lib/max.js b/lib/node_modules/@stdlib/stats/base/max/lib/accessors.js similarity index 54% rename from lib/node_modules/@stdlib/stats/base/max/lib/max.js rename to lib/node_modules/@stdlib/stats/base/max/lib/accessors.js index b490af748240..a5777a01f86a 100644 --- a/lib/node_modules/@stdlib/stats/base/max/lib/max.js +++ b/lib/node_modules/@stdlib/stats/base/max/lib/accessors.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. @@ -29,39 +29,46 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); /** * Computes the maximum value of a strided array. * +* @private * @param {PositiveInteger} N - number of indexed elements -* @param {NumericArray} x - input array -* @param {integer} stride - stride length -* @returns {number} maximum value +* @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} sum * * @example -* var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * -* var v = max( N, x, 1 ); -* // returns 2.0 +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +* +* var v = max( 4, arraylike2object( x ), 2, 1 ); +* // returns 4.0 */ -function max( N, x, stride ) { +function max( N, x, strideX, offsetX ) { + var xbuf; + var get; 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; + // 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 ); } - max = x[ ix ]; + ix = offsetX; + max = get( xbuf, ix ); for ( i = 1; i < N; i++ ) { - ix += stride; - v = x[ ix ]; + ix += strideX; + v = get( xbuf, ix ); if ( isnan( v ) ) { return v; } diff --git a/lib/node_modules/@stdlib/stats/base/max/lib/index.js b/lib/node_modules/@stdlib/stats/base/max/lib/index.js index a3cc94861476..13a58f2c45e4 100644 --- a/lib/node_modules/@stdlib/stats/base/max/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/max/lib/index.js @@ -45,11 +45,18 @@ // MODULES // -var max = require( './main.js' ); +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 = max; +module.exports = main; // exports: { "ndarray": "max.ndarray" } diff --git a/lib/node_modules/@stdlib/stats/base/max/lib/main.js b/lib/node_modules/@stdlib/stats/base/max/lib/main.js index 77e04be35505..159758fcaa41 100644 --- a/lib/node_modules/@stdlib/stats/base/max/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/max/lib/main.js @@ -20,14 +20,29 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var max = require( './max.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); var ndarray = require( './ndarray.js' ); // MAIN // -setReadOnly( max, 'ndarray', ndarray ); +/** +* Computes the maximum value of a strided array. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} maximum value +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = max( x.length, x, 1 ); +* // returns 2.0 +*/ +function max( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/max/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/max/lib/ndarray.js index 57f1a6de0826..64bebffc2ffb 100644 --- a/lib/node_modules/@stdlib/stats/base/max/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/max/lib/ndarray.js @@ -22,6 +22,8 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); // MAIN // @@ -31,35 +33,37 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * * @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 value * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); -* * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* var N = floor( x.length / 2 ); * -* var v = max( N, x, 2, 1 ); +* var v = max( 4, x, 2, 1 ); * // returns 4.0 */ -function max( N, x, stride, offset ) { +function max( 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 ); + } + if ( N === 1 || strideX === 0 ) { + return x[ offsetX ]; } - ix = offset; + ix = offsetX; max = x[ ix ]; for ( i = 1; i < N; i++ ) { - ix += stride; + ix += strideX; v = x[ ix ]; if ( isnan( v ) ) { return v; diff --git a/lib/node_modules/@stdlib/stats/base/max/test/test.max.js b/lib/node_modules/@stdlib/stats/base/max/test/test.main.js similarity index 69% rename from lib/node_modules/@stdlib/stats/base/max/test/test.max.js rename to lib/node_modules/@stdlib/stats/base/max/test/test.main.js index cdb4b0566a71..5ba2a7b516de 100644 --- a/lib/node_modules/@stdlib/stats/base/max/test/test.max.js +++ b/lib/node_modules/@stdlib/stats/base/max/test/test.main.js @@ -21,11 +21,11 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); 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 max = require( './../lib/max.js' ); +var max = require( './../lib/main.js' ); // TESTS // @@ -68,6 +68,33 @@ tape( 'the function calculates the maximum value of a strided array', function t t.end(); }); +tape( 'the function calculates the maximum 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 ]; + v = max( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = max( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = max( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = max( x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = max( 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; @@ -96,7 +123,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -111,15 +137,34 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = max( N, x, 2 ); + v = max( 4, x, 2 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + 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 + ]; + + v = max( 4, 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; var v; @@ -134,8 +179,28 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = max( N, x, -2 ); + v = max( 4, x, -2 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = max( 4, toAccessorArray( x ), -2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); @@ -156,7 +221,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -172,9 +236,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = max( N, x1, 2 ); + v = max( 4, x1, 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/max/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/max/test/test.ndarray.js index 719f4edc8029..c37dcb7d83f9 100644 --- a/lib/node_modules/@stdlib/stats/base/max/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/max/test/test.ndarray.js @@ -21,8 +21,8 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); 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 max = require( './../lib/ndarray.js' ); @@ -67,6 +67,33 @@ tape( 'the function calculates the maximum value of a strided array', function t t.end(); }); +tape( 'the function calculates the maximum 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 ]; + v = max( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = max( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, -4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = max( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = max( x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = max( 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; @@ -95,7 +122,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -110,15 +136,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = max( N, x, 2, 0 ); + v = max( 4, x, 2, 0 ); 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; var v; @@ -133,8 +157,28 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = max( N, x, -2, 6 ); + v = max( 4, x, -2, 6 ); + + t.strictEqual( v, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = max( 4, toAccessorArray( x ), -2, 6 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); @@ -153,7 +197,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -167,9 +210,29 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = max( N, x, 2, 1 ); + v = max( 4, x, 2, 1 ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + 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 + ]; + + v = max( 4, toAccessorArray( x ), 2, 1 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end();