Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Mar 23, 2024
1 parent 62c201b commit a53982a
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 327 deletions.
40 changes: 13 additions & 27 deletions ext/base/scusumkbn2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ The function has the following parameters:
- **y**: output [`Float32Array`][@stdlib/array/float32].
- **strideY**: index increment for `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum 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 sum of every other element in `x`,

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
var y = new Float32Array( x.length );

var N = floor( x.length / 2 );

var v = scusumkbn2( N, 0.0, x, 2, y, 1 );
var v = scusumkbn2( 4, 0.0, x, 2, y, 1 );
// y => <Float32Array>[ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
```

Expand All @@ -86,7 +83,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

// Initial arrays...
var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
Expand All @@ -96,9 +92,7 @@ var y0 = new Float32Array( x0.length );
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element

var N = floor( x0.length / 2 );

scusumkbn2( N, 0.0, x1, -2, y1, 1 );
scusumkbn2( 4, 0.0, x1, -2, y1, 1 );
// y0 => <Float32Array>[ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ]
```

Expand All @@ -110,9 +104,9 @@ Computes the cumulative sum of single-precision floating-point strided array ele
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
var y = new Float32Array( x.length );
var y = new Float32Array( 3 );

scusumkbn2.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 );
scusumkbn2.ndarray( 3, 0.0, x, 1, 0, y, 1, 0 );
// y => <Float32Array>[ 1.0, -1.0, 1.0 ]
```

Expand All @@ -121,18 +115,15 @@ 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 sum 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 sum 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

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var y = new Float32Array( x.length );

var N = floor( x.length / 2 );

scusumkbn2.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
scusumkbn2.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 );
// y => <Float32Array>[ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ]
```

Expand All @@ -157,21 +148,16 @@ scusumkbn2.ndarray( N, 0.0, 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 Float32Array = require( '@stdlib/array/float32' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var scusumkbn2 = require( '@stdlib/blas/ext/base/scusumkbn2' );

var y;
var x;
var i;
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );

x = new Float32Array( 10 );
y = new Float32Array( x.length );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*100.0 );
}
console.log( x );

var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) );

console.log( y );

scusumkbn2( x.length, 0.0, x, 1, y, -1 );
Expand Down
20 changes: 9 additions & 11 deletions ext/base/scusumkbn2/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var scusumkbn2 = require( './../lib/scusumkbn2.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,15 +44,8 @@ var scusumkbn2 = require( './../lib/scusumkbn2.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var y;
var x;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
16 changes: 5 additions & 11 deletions ext/base/scusumkbn2/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var scusumkbn2 = tryRequire( resolve( __dirname, './../lib/scusumkbn2.native.js'
var opts = {
'skip': ( scusumkbn2 instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,15 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
20 changes: 9 additions & 11 deletions ext/base/scusumkbn2/benchmark/benchmark.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var scusumkbn2 = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,15 +44,8 @@ var scusumkbn2 = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
16 changes: 5 additions & 11 deletions ext/base/scusumkbn2/benchmark/benchmark.ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var scusumkbn2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' )
var opts = {
'skip': ( scusumkbn2 instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,15 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
33 changes: 18 additions & 15 deletions ext/base/scusumkbn2/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

{{alias}}( N, sum, x, strideX, y, strideY )
Computes the cumulative sum of single-precision floating-point strided array
elements using a second-order iterative Kahan–Babuška algorithm.
Computes the cumulative sum of single-precision floating-point strided
array elements using a second-order iterative Kahan–Babuška algorithm.

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.
Indexing is relative to the first index. To introduce an offset, use
a typed array view.

If `N <= 0`, the function returns `y` unchanged.

Expand Down Expand Up @@ -44,11 +44,10 @@
> {{alias}}( x.length, 0.0, x, 1, y, 1 )
<Float32Array>[ 1.0, -1.0, 1.0 ]

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

// Using view offsets:
Expand All @@ -62,14 +61,16 @@
> y0
<Float32Array>[ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ]


{{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY )
Computes the cumulative sum of single-precision floating-point strided array
elements using a second-order iterative Kahan–Babuška algorithm and
Computes the cumulative sum of single-precision floating-point strided
array elements using a second-order iterative Kahan–Babuška algorithm and
alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offset` parameter supports indexing semantics based on a
starting index.
buffer, the `offsetX` and `offsetY` parameter supports indexing semantics
based on starting indices.


Parameters
----------
Expand Down Expand Up @@ -97,11 +98,13 @@
offsetY: integer
Starting index for `y`.


Returns
-------
out: Float32Array
Output array.


Examples
--------
// Standard Usage:
Expand All @@ -113,10 +116,10 @@
// Advanced indexing:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
> y = new {{alias:@stdlib/array/float32}}( x.length );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 )
> {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 )
<Float32Array>[ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ]


See Also
--------

17 changes: 5 additions & 12 deletions ext/base/scusumkbn2/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float32Array = require( '@stdlib/array/float32' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var scusumkbn2 = require( './../lib' );

var y;
var x;
var i;

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

var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) );
console.log( y );

scusumkbn2( x.length, 0.0, x, 1, y, -1 );
Expand Down
2 changes: 1 addition & 1 deletion ext/base/scusumkbn2/include.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Source files:
'src_files': [
'<(src_dir)/addon.cpp',
'<(src_dir)/addon.c',
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
],

Expand Down
Loading

0 comments on commit a53982a

Please sign in to comment.