Skip to content

Commit 92b9524

Browse files
add support for accessor arrays
1 parent 55c0a81 commit 92b9524

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

lib/node_modules/@stdlib/stats/base/cumax/lib/accessors.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3131
*
3232
* @private
3333
* @param {PositiveInteger} N - number of indexed elements
34-
* @param {NumericArray} x - input array
35-
* @param {integer} strideX - `x` stride length
34+
* @param {Object} x - input array object
35+
* @param {Collection} x.data - input array data
36+
* @param {Array<Function>} x.accessors - array element accessors
37+
* @param {integer} strideX - stride length for `x`
3638
* @param {NonNegativeInteger} offsetX - starting index for `x`
37-
* @param {NumericArray} y - output array
38-
* @param {integer} strideY - `y` stride length
39+
* @param {Object} y - output array object
40+
* @param {Collection} y.data - output array data
41+
* @param {Array<Function>} y.accessors - array element accessors
42+
* @param {integer} strideY - stride length for `y`
3943
* @param {NonNegativeInteger} offsetY - starting index for `y`
40-
* @returns {NumericArray} output array
44+
* @returns {Object} output array object
4145
*
4246
* @example
4347
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
48+
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
4449
*
4550
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
4651
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
4752
*
48-
* cumax( 4, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 );
53+
* cumax( 4, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );
4954
* // y => [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];
5055
*/
5156
function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
@@ -59,16 +64,12 @@ function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
5964
var v;
6065
var i;
6166

62-
// Cache reference to input array data:
67+
// Cache reference to array data:
6368
xbuf = x.data;
64-
65-
// Cache reference to output array data:
6669
ybuf = y.data;
6770

6871
// Cache a reference to the element accessor:
6972
get = x.accessors[ 0 ];
70-
71-
// Cache a reference to the element accessor:
7273
set = y.accessors[ 1 ];
7374

7475
ix = offsetX;

lib/node_modules/@stdlib/stats/base/cumax/lib/ndarray.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,18 @@ var accessors = require( './accessors.js' );
3333
*
3434
* @param {PositiveInteger} N - number of indexed elements
3535
* @param {NumericArray} x - input array
36-
* @param {integer} strideX - `x` stride length
36+
* @param {integer} strideX - stride length for `x`
3737
* @param {NonNegativeInteger} offsetX - starting index for `x`
3838
* @param {NumericArray} y - output array
39-
* @param {integer} strideY - `y` stride length
39+
* @param {integer} strideY - stride length for `y`
4040
* @param {NonNegativeInteger} offsetY - starting index for `y`
4141
* @returns {NumericArray} output array
4242
*
4343
* @example
44-
* var floor = require( '@stdlib/math/base/special/floor' );
45-
*
4644
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
4745
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
48-
* var N = floor( x.length / 2 );
4946
*
50-
* var v = cumax( N, x, 2, 1, y, 1, 0 );
47+
* var v = cumax( 4, x, 2, 1, y, 1, 0 );
5148
* // returns [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
5249
*/
5350
function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {

lib/node_modules/@stdlib/stats/base/cumax/test/test.cumax.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ tape( 'the function returns a reference to the output array', function test( t )
200200
t.end();
201201
});
202202

203+
tape( 'the function returns a reference to the output array (accessors)', function test( t ) {
204+
var out;
205+
var x;
206+
var y;
207+
208+
x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
209+
y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
210+
211+
out = cumax( x.length, x, 1, y, 1 );
212+
213+
t.strictEqual( out, y, 'same reference' );
214+
t.end();
215+
});
216+
203217
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) {
204218
var expected;
205219
var x;

0 commit comments

Comments
 (0)