Skip to content

Commit 0e1fdab

Browse files
add support for accessor arrays
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 92b9524 commit 0e1fdab

File tree

7 files changed

+34
-42
lines changed

7 files changed

+34
-42
lines changed

lib/node_modules/@stdlib/stats/base/cumax/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ cumax.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
122122

123123
- If `N <= 0`, both functions return `y` unchanged.
124124
- Depending on the environment, the typed versions ([`dcumax`][@stdlib/stats/strided/dcumax], [`scumax`][@stdlib/stats/base/scumax], etc.) are likely to be significantly more performant.
125+
- 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])
125126

126127
</section>
127128

@@ -181,6 +182,8 @@ console.log( y );
181182

182183
[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
183184

185+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
186+
184187
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
185188

186189
<!-- <related-links> -->

lib/node_modules/@stdlib/stats/base/cumax/docs/types/index.d.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array
2727
*/
2828
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
2929

30+
/**
31+
* Output array.
32+
*/
33+
type OutputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
34+
3035
/**
3136
* Interface describing `cumax`.
3237
*/
@@ -36,9 +41,9 @@ interface Routine {
3641
*
3742
* @param N - number of indexed elements
3843
* @param x - input array
39-
* @param strideX - `x` stride length
44+
* @param strideX - stride length for `x`
4045
* @param y - output array
41-
* @param strideY - `y` stride length
46+
* @param strideY - stride length for `y`
4247
* @returns output array
4348
*
4449
* @example
@@ -48,17 +53,17 @@ interface Routine {
4853
* cumax( x.length, x, 1, y, 1 );
4954
* // y => [ 1.0, 1.0, 2.0 ]
5055
*/
51-
<T extends InputArray>( N: number, x: T, strideX: number, y: T, strideY: number ): T;
56+
<T extends OutputArray>( N: number, x: InputArray, strideX: number, y: T, strideY: number ): T;
5257

5358
/**
5459
* Computes the cumulative maximum of a strided array using alternative indexing semantics.
5560
*
5661
* @param N - number of indexed elements
5762
* @param x - input array
58-
* @param strideX - `x` stride length
63+
* @param strideX - stride length for `x`
5964
* @param offsetX - starting index for `x`
6065
* @param y - output array
61-
* @param strideY - `y` stride length
66+
* @param strideY - stride length for `y`
6267
* @param offsetY - starting index for `y`
6368
* @returns output array
6469
*
@@ -69,17 +74,17 @@ interface Routine {
6974
* cumax.ndarray( x.length, x, 1, 0, y, 1, 0 );
7075
* // y => [ 1.0, 1.0, 2.0 ]
7176
*/
72-
ndarray<T extends InputArray>( N: number, x: T, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number ): T;
77+
ndarray<T extends OutputArray>( N: number, x: InputArray, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number ): T;
7378
}
7479

7580
/**
7681
* Computes the cumulative maximum of a strided array.
7782
*
7883
* @param N - number of indexed elements
7984
* @param x - input array
80-
* @param strideX - `x` stride length
85+
* @param strideX - stride length for `x`
8186
* @param y - output array
82-
* @param strideY - `y` stride length
87+
* @param strideY - stride length for `y`
8388
* @returns output array
8489
*
8590
* @example

lib/node_modules/@stdlib/stats/base/cumax/docs/types/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
import cumax = require( './index' );
2019
import AccessorArray = require( '@stdlib/array/base/accessor' );
20+
import cumax = require( './index' );
2121

2222

2323
// TESTS //
@@ -126,7 +126,7 @@ import AccessorArray = require( '@stdlib/array/base/accessor' );
126126
const y = new Float64Array( 10 );
127127

128128
cumax.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType NumericArray
129-
cumax( x.length, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray<number>
129+
cumax.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray<number>
130130
}
131131

132132
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
5656
function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
5757
var xbuf;
5858
var ybuf;
59-
var get;
60-
var set;
59+
var xget;
60+
var yset;
6161
var max;
6262
var ix;
6363
var iy;
@@ -69,35 +69,35 @@ function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
6969
ybuf = y.data;
7070

7171
// Cache a reference to the element accessor:
72-
get = x.accessors[ 0 ];
73-
set = y.accessors[ 1 ];
72+
xget = x.accessors[ 0 ];
73+
yset = y.accessors[ 1 ];
7474

7575
ix = offsetX;
7676
iy = offsetY;
7777

78-
max = get( xbuf, ix );
79-
set( ybuf, iy, max );
78+
max = xget( xbuf, ix );
79+
yset( ybuf, iy, max );
8080

8181
iy += strideY;
8282
i = 1;
8383
if ( isnan( max ) === false ) {
8484
for ( i; i < N; i++ ) {
8585
ix += strideX;
86-
v = get( xbuf, ix );
86+
v = xget( xbuf, ix );
8787
if ( isnan( v ) ) {
8888
max = v;
8989
break;
9090
}
9191
if ( v > max || ( v === max && isPositiveZero( v ) ) ) {
9292
max = v;
9393
}
94-
set( ybuf, iy, max );
94+
yset( ybuf, iy, max );
9595
iy += strideY;
9696
}
9797
}
9898
if ( isnan( max ) ) {
9999
for ( i; i < N; i++ ) {
100-
set( ybuf, iy, max );
100+
yset( ybuf, iy, max );
101101
iy += strideY;
102102
}
103103
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
6161
}
6262
ox = arraylike2object( x );
6363
oy = arraylike2object( y );
64-
if ( ox.accessorProtocol && oy.accessorProtocol ) {
64+
if ( ox.accessorProtocol || oy.accessorProtocol ) {
6565
accessors( N, ox, strideX, offsetX, oy, strideY, offsetY );
6666
return y;
6767
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24-
var floor = require( '@stdlib/math/base/special/floor' );
2524
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2726
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
@@ -483,7 +482,6 @@ tape( 'the function supports view offsets', function test( t ) {
483482
var y0;
484483
var x1;
485484
var y1;
486-
var N;
487485

488486
// Initial arrays...
489487
x0 = new Float64Array([
@@ -507,9 +505,7 @@ tape( 'the function supports view offsets', function test( t ) {
507505
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element
508506
y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element
509507

510-
N = floor( x0.length / 2 );
511-
512-
cumax( N, x1, -2, y1, 1 );
508+
cumax( 3, x1, -2, y1, 1 );
513509
expected = new Float64Array( [ 0.0, 0.0, 0.0, 6.0, 6.0, 6.0 ] );
514510

515511
t.deepEqual( y0, expected, 'returns expected value' );
@@ -522,7 +518,6 @@ tape( 'the function supports view offsets (accessors)', function test( t ) {
522518
var y0;
523519
var x1;
524520
var y1;
525-
var N;
526521

527522
// Initial arrays...
528523
x0 = new Float64Array([
@@ -546,9 +541,7 @@ tape( 'the function supports view offsets (accessors)', function test( t ) {
546541
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element
547542
y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element
548543

549-
N = floor( x0.length / 2 );
550-
551-
cumax( N, toAccessorArray( x1 ), -2, toAccessorArray( y1 ), 1 );
544+
cumax( 3, toAccessorArray( x1 ), -2, toAccessorArray( y1 ), 1 );
552545
expected = new Float64Array( [ 0.0, 0.0, 0.0, 6.0, 6.0, 6.0 ] );
553546

554547
t.deepEqual( y0, expected, 'returns expected value' );

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24-
var floor = require( '@stdlib/math/base/special/floor' );
2524
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2726
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
@@ -414,7 +413,6 @@ tape( 'the function supports negative strides (accessors)', function test( t ) {
414413

415414
tape( 'the function supports an `x` offset', function test( t ) {
416415
var expected;
417-
var N;
418416
var x;
419417
var y;
420418

@@ -438,9 +436,8 @@ tape( 'the function supports an `x` offset', function test( t ) {
438436
0.0,
439437
0.0
440438
];
441-
N = floor( x.length / 2 );
442439

443-
cumax( N, x, 2, 1, y, 1, 0 );
440+
cumax( 4, x, 2, 1, y, 1, 0 );
444441

445442
expected = [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];
446443
t.deepEqual( y, expected, 'returns expected value' );
@@ -450,7 +447,6 @@ tape( 'the function supports an `x` offset', function test( t ) {
450447

451448
tape( 'the function supports an `x` offset (accessors)', function test( t ) {
452449
var expected;
453-
var N;
454450
var x;
455451
var y;
456452

@@ -474,9 +470,8 @@ tape( 'the function supports an `x` offset (accessors)', function test( t ) {
474470
0.0,
475471
0.0
476472
];
477-
N = floor( x.length / 2 );
478473

479-
cumax( N, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 );
474+
cumax( 4, toAccessorArray( x ), 2, 1, toAccessorArray( y ), 1, 0 );
480475

481476
expected = [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];
482477
t.deepEqual( y, expected, 'returns expected value' );
@@ -486,7 +481,6 @@ tape( 'the function supports an `x` offset (accessors)', function test( t ) {
486481

487482
tape( 'the function supports a `y` offset', function test( t ) {
488483
var expected;
489-
var N;
490484
var x;
491485
var y;
492486

@@ -510,9 +504,8 @@ tape( 'the function supports a `y` offset', function test( t ) {
510504
0.0,
511505
0.0 // 3
512506
];
513-
N = floor( x.length / 2 );
514507

515-
cumax( N, x, 1, 0, y, 2, 1 );
508+
cumax( 4, x, 1, 0, y, 2, 1 );
516509

517510
expected = [ 0.0, 2.0, 0.0, 2.0, 0.0, 2.0, 0.0, 2.0 ];
518511
t.deepEqual( y, expected, 'returns expected value' );
@@ -522,7 +515,6 @@ tape( 'the function supports a `y` offset', function test( t ) {
522515

523516
tape( 'the function supports a `y` offset (accessors)', function test( t ) {
524517
var expected;
525-
var N;
526518
var x;
527519
var y;
528520

@@ -546,9 +538,8 @@ tape( 'the function supports a `y` offset (accessors)', function test( t ) {
546538
0.0,
547539
0.0 // 3
548540
];
549-
N = floor( x.length / 2 );
550541

551-
cumax( N, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 1 );
542+
cumax( 4, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 2, 1 );
552543

553544
expected = [ 0.0, 2.0, 0.0, 2.0, 0.0, 2.0, 0.0, 2.0 ];
554545
t.deepEqual( y, expected, 'returns expected value' );

0 commit comments

Comments
 (0)