Skip to content
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3c9b304
refactor(stats/base/cuminabs): add accessor protocol support
jsndz Mar 15, 2025
7e7602e
fixup! refactor(stats/base/cuminabs): Fixed README example
jsndz Mar 15, 2025
044a99c
fixup! refactor(stats/base/cuminabs): Fixed lint error
jsndz Mar 15, 2025
f385c11
fixup! refactor(stats/base/cuminabs): Fixed lint error 2
jsndz Mar 15, 2025
931d23b
fixup! refactor(stats/base/cuminabs): Fixed lint error 3
jsndz Mar 15, 2025
f16941b
fixup! refactor(stats/base/cuminabs): Fixed lint error 4
jsndz Mar 15, 2025
98c9d12
fixup! refactor(stats/base/cuminabs): Fixed lint error 5
jsndz Mar 15, 2025
c89beec
fixup! refactor(stats/base/cuminabs): Fixed lint error 6
jsndz Mar 16, 2025
78ad06a
fixup! refactor(stats/base/cuminabs): Fixed lint error 6
jsndz Mar 16, 2025
a6e8902
fixup! refactor(stats/base/cuminabs): Fixed lint error 7
jsndz Mar 16, 2025
8b0cfd5
fixup! refactor(stats/base/cuminabs): Fixed lint error 7
jsndz Mar 16, 2025
8874c14
fixup! refactor(stats/base/cuminabs): Fixed lint error 8
jsndz Mar 16, 2025
55c692e
fixup! refactor(stats/base/cuminabs): Fixed lint error 8
jsndz Mar 16, 2025
bf990ad
fixup! refactor(stats/base/cuminabs): Fixed lint error 8
jsndz Mar 16, 2025
91eed3d
fixup! refactor(stats/base/cuminabs): Fixed lint error 9
jsndz Mar 16, 2025
29d0213
fixup! refactor(stats/base/cuminabs): Fixed lint error 10
jsndz Mar 16, 2025
6d26282
Update lib/node_modules/@stdlib/stats/base/cuminabs/README.md
jsndz Mar 16, 2025
594cc53
Update lib/node_modules/@stdlib/stats/base/cuminabs/lib/accessors.js
jsndz Mar 16, 2025
ab41736
Update lib/node_modules/@stdlib/stats/base/cuminabs/lib/accessors.js
jsndz Mar 16, 2025
5c8b1b4
Apply suggestions from code review
kgryte Mar 19, 2025
ffbd6e7
Apply suggestions from code review
kgryte Mar 19, 2025
a7c4a54
docs: update example
kgryte Mar 19, 2025
b1829ab
docs: remove unused import
kgryte Mar 19, 2025
f326581
style: add missing space
kgryte Mar 19, 2025
4f719b1
Update lib/node_modules/@stdlib/stats/base/cuminabs/test/test.cuminab…
jsndz Mar 19, 2025
5df0d99
Update lib/node_modules/@stdlib/stats/base/cuminabs/test/test.ndarray.js
jsndz Mar 19, 2025
4913bd7
Update lib/node_modules/@stdlib/stats/base/cuminabs/test/test.ndarray.js
jsndz Mar 19, 2025
3f25ab5
fixup! refactor(stats/base/cuminabs): Update test.ndarray.js
jsndz Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions lib/node_modules/@stdlib/stats/base/cuminabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideX**: index increment for `x`.
- **strideX**: stride length for `x`.
- **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideY**: index increment for `y`.
- **strideY**: stride length for `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative minimum absolute value of every other element in `x`,
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative minimum absolute value of every other element in `x`,

```javascript
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
Expand Down Expand Up @@ -102,7 +102,7 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum absolute value of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum absolute value of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element

```javascript
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
Expand All @@ -122,6 +122,7 @@ cuminabs.ndarray( 4, x, 2, 1, y, -1, y.length-1 );

- If `N <= 0`, both functions return `y` unchanged.
- Depending on the environment, the typed versions ([`dcuminabs`][@stdlib/stats/strided/dcuminabs], [`scuminabs`][@stdlib/stats/base/scuminabs], 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]).

</section>

Expand All @@ -134,21 +135,16 @@ cuminabs.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
<!-- eslint no-undef: "error" -->

```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 cuminabs = require( '@stdlib/stats/base/cuminabs' );
var Float64Array = require( '@stdlib/array/float64' );

var y;
var x;
var i;

x = new Float64Array( 10 );
y = new Float64Array( x.length );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*100.0 );
}
var x = discreteUniform( 10, 0, 100, {
'dtype': 'float64'
});
console.log( x );

var y = new Float64Array( x.length );
console.log( y );

cuminabs( x.length, x, 1, y, -1 );
Expand Down Expand Up @@ -188,6 +184,8 @@ console.log( y );

[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

<!-- <related-links> -->
Expand Down
31 changes: 15 additions & 16 deletions lib/node_modules/@stdlib/stats/base/cuminabs/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var zeros = require( '@stdlib/array/zeros' );
var gfill = require( '@stdlib/blas/ext/base/gfill' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var cuminabs = require( './../lib/cuminabs.js' );


// VARIABLES //

var options = {
'dtype': 'generic'
};


// FUNCTIONS //

/**
Expand All @@ -38,35 +47,25 @@ var cuminabs = require( './../lib/cuminabs.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var y;
var x;
var i;

x = [];
y = [];
for ( i = 0; i < len; i++ ) {
x.push( ( randu()*20.0 ) - 10.0 );
y.push( 0.0 );
}
var x = uniform( len, -10, 10, options );
var y = zeros( len, options.dtype );
return benchmark;

function benchmark( b ) {
var v;
var i;

for ( i = 0; i < len; i++ ) {
y[ i ] = 0.0;
}
gfill( len, 0.0, y, 1 );
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x[ 0 ] += 1.0;
v = cuminabs( x.length, x, 1, y, 1 );
if ( isnan( v[ i%len ] ) ) {
if ( isnan( v[ i % len ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( v[ i%len ] ) ) {
if ( isnan( v[ i % len ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@
// 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 zeros = require( '@stdlib/array/zeros' );
var gfill = require( '@stdlib/blas/ext/base/gfill' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var cuminabs = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
'dtype': 'generic'
};


// FUNCTIONS //

/**
Expand All @@ -38,35 +47,25 @@ var cuminabs = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = [];
y = [];
for ( i = 0; i < len; i++ ) {
x.push( ( randu()*20.0 ) - 10.0 );
y.push( 0.0 );
}
var x = uniform( len, -10, 10, options );
var y = zeros( len, options.dtype );
return benchmark;

function benchmark( b ) {
var v;
var i;

for ( i = 0; i < len; i++ ) {
y[ i ] = 0.0;
}
gfill( len, 0.0, y, 1 );
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x[ 0 ] += 1.0;
v = cuminabs( x.length, x, 1, 0, y, 1, 0 );
if ( isnan( v[ i%len ] ) ) {
if ( isnan( v[ i % len ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( v[ i%len ] ) ) {
if ( isnan( v[ i % len ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
24 changes: 11 additions & 13 deletions lib/node_modules/@stdlib/stats/base/cuminabs/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{alias}}( N, x, strideX, y, strideY )
Computes the cumulative minimum absolute value of a strided array.

The `N` and `stride` parameters determine which elements in `x` and `y` are
accessed at runtime.
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 an offset, use a typed
array view.
Expand All @@ -19,13 +19,13 @@
Input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

y: Array<number>|TypedArray
Output array.

strideY: integer
Index increment for `y`.
Stride length for `y`.

Returns
-------
Expand All @@ -40,24 +40,23 @@
> {{alias}}( x.length, x, 1, y, 1 )
[ 1.0, 1.0, 1.0 ]

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ];
> y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, x, 2, y, 2 )
> {{alias}}( 3, x, 2, y, 2 )
[ 2.0, 0.0, 1.0, 0.0, 1.0, 0.0 ]

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
> var y0 = new {{alias:@stdlib/array/float64}}( x0.length );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> {{alias}}( N, x1, 2, y1, 1 )
> {{alias}}( 3, x1, 2, y1, 1 )
<Float64Array>[ 2.0, 2.0, 1.0 ]
> y0
<Float64Array>[ 0.0, 0.0, 0.0, 2.0, 2.0, 1.0 ]


{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
Computes the cumulative minimum absolute value of a strided array using
alternative indexing semantics.
Expand All @@ -75,7 +74,7 @@
Input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

offsetX: integer
Starting index for `x`.
Expand All @@ -84,7 +83,7 @@
Output array.

strideY: integer
Index increment for `y`.
Stride length for `y`.

offsetY: integer
Starting index for `y`.
Expand All @@ -105,8 +104,7 @@
// Advanced indexing:
> x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ];
> y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, x, 2, 1, y, -1, y.length-1 )
> {{alias}}.ndarray( 3, x, 2, 1, y, -1, y.length-1 )
[ 0.0, 0.0, 0.0, 1.0, 2.0, 2.0 ]

See Also
Expand Down
28 changes: 19 additions & 9 deletions lib/node_modules/@stdlib/stats/base/cuminabs/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@

/// <reference types="@stdlib/types"/>

import { NumericArray } from '@stdlib/types/array';
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';

/**
* Input array.
*/
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;

/**
* Output array.
*/
type OutputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;

/**
* Interface describing `cuminabs`.
Expand All @@ -31,9 +41,9 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param strideX - `x` stride length
* @param strideX - stride length for `x`
* @param y - output array
* @param strideY - `y` stride length
* @param strideY - stride length for `y`
* @returns output array
*
* @example
Expand All @@ -43,17 +53,17 @@ interface Routine {
* cuminabs( x.length, x, 1, y, 1 );
* // y => [ 1.0, 1.0, 1.0 ]
*/
( N: number, x: NumericArray, strideX: number, y: NumericArray, strideY: number ): NumericArray;
<T extends OutputArray>( N: number, x: InputArray, strideX: number, y: T, strideY: number ): T;

/**
* Computes the cumulative minimum absolute value of a strided array using alternative indexing semantics.
*
* @param N - number of indexed elements
* @param x - input array
* @param strideX - `x` stride length
* @param strideX - stride length for `x`
* @param offsetX - starting index for `x`
* @param y - output array
* @param strideY - `y` stride length
* @param strideY - stride length for `y`
* @param offsetY - starting index for `y`
* @returns output array
*
Expand All @@ -64,17 +74,17 @@ interface Routine {
* cuminabs.ndarray( x.length, x, 1, 0, y, 1, 0 );
* // y => [ 1.0, 1.0, 1.0 ]
*/
ndarray( N: number, x: NumericArray, strideX: number, offsetX: number, y: NumericArray, strideY: number, offsetY: number ): NumericArray;
ndarray<T extends OutputArray>( N: number, x: InputArray, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number ): T;
}

/**
* Computes the cumulative minimum absolute value of a strided array.
*
* @param N - number of indexed elements
* @param x - input array
* @param strideX - `x` stride length
* @param strideX - stride length for `x`
* @param y - output array
* @param strideY - `y` stride length
* @param strideY - stride length for `y`
* @returns output array
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import AccessorArray = require( '@stdlib/array/base/accessor' );
import cuminabs = require( './index' );


Expand All @@ -27,6 +28,7 @@ import cuminabs = require( './index' );
const y = new Float64Array( 10 );

cuminabs( x.length, x, 1, y, 1 ); // $ExpectType NumericArray
cuminabs( x.length, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray<number>
}

// The compiler throws an error if the function is provided a first argument which is not a number...
Expand Down Expand Up @@ -124,6 +126,8 @@ import cuminabs = require( './index' );
const y = new Float64Array( 10 );

cuminabs.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType NumericArray
cuminabs.ndarray( x.length, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray<number>

}

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