Skip to content

Commit

Permalink
refactor: update blas/ext/base/dcusumkbn to follow current project …
Browse files Browse the repository at this point in the history
…conventions

PR-URL: stdlib-js#2036
Closes: stdlib-js#1472

---------

Signed-off-by: Pranav Goswami <goswami.4@iitj.ac.in>
Signed-off-by: Athan Reines <kgryte@gmail.com>
Co-authored-by: Pranav Goswami <goswami.4@iitj.ac.in>
Co-authored-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Pranav Goswami <goswami.4@iitj.ac.in>
Reviewed-by: Athan Reines <kgryte@gmail.com> 
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent 55abd41 commit 47cc515
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 396 deletions.
33 changes: 9 additions & 24 deletions lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/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 [`Float64Array`][@stdlib/array/float64].
- **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 the strided input array,

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

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

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

var v = dcusumkbn( N, 0.0, x, 2, y, 1 );
var v = dcusumkbn( 4, 0.0, x, 2, y, 1 );
// y => <Float64Array>[ 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 Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

// Initial arrays...
var x0 = new Float64Array( [ 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 Float64Array( x0.length );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element

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

dcusumkbn( N, 0.0, x1, -2, y1, 1 );
dcusumkbn( 4, 0.0, x1, -2, y1, 1 );
// y0 => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.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`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in the strided input array starting from the second value and to store in the last `N` elements of the strided output array starting from the last element

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

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

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

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

Expand All @@ -157,20 +148,14 @@ dcusumkbn.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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Float64Array = require( '@stdlib/array/float64' );
var dcusumkbn = require( '@stdlib/blas/ext/base/dcusumkbn' );

var y;
var x;
var i;
var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) );
var y = new Float64Array( x.length );

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
// 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dcusumkbn = require( './../lib/dcusumkbn.js' );


// VARIABLES //

var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //

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

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

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -32,6 +33,7 @@ var pkg = require( './../package.json' ).name;

// VARIABLES //

var rand = uniform( -10.0, 10.0 );
var dcusumkbn = tryRequire( resolve( __dirname, './../lib/dcusumkbn.native.js' ) );
var opts = {
'skip': ( dcusumkbn instanceof Error )
Expand All @@ -48,15 +50,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

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

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
// 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dcusumkbn = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //

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

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

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -32,6 +33,7 @@ var pkg = require( './../package.json' ).name;

// VARIABLES //

var rand = uniform( -10.0, 10.0 );
var dcusumkbn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( dcusumkbn instanceof Error )
Expand All @@ -48,15 +50,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

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

function benchmark( b ) {
Expand Down
14 changes: 6 additions & 8 deletions lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the cumulative sum of double-precision floating-point strided array
elements using an improved 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.
Expand Down Expand Up @@ -47,21 +47,20 @@
// Using `N` and `stride` parameters:
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
> y = new {{alias:@stdlib/array/float64}}( 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 )
<Float64Array>[ -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, 0.0, x1, 2, y1, 1 )
> {{alias}}( 3, 0.0, x1, 2, y1, 1 )
<Float64Array>[ -2.0, 0.0, -1.0 ]
> y0
<Float64Array>[ 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 double-precision floating-point strided array
elements using an improved Kahan–Babuška algorithm and alternative indexing
Expand Down Expand Up @@ -113,8 +112,7 @@
// Advanced indexing:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
> y = new {{alias:@stdlib/array/float64}}( 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 )
<Float64Array>[ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ]

See Also
Expand Down
14 changes: 4 additions & 10 deletions lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@

'use strict';

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

var y;
var x;
var i;
var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) );
var y = new Float64Array( x.length );

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

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
* var y = new Float64Array( x.length );
* var N = x.length;
*
* var v = dcusumkbn( N, 0.0, x, 1, y, 1 );
* var v = dcusumkbn( 3, 0.0, x, 1, y, 1 );
* // returns <Float64Array>[ 1.0, -1.0, 1.0 ]
*/
function dcusumkbn( N, sum, x, strideX, y, strideY ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ var addon = require( './../src/addon.node' );
*
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
* var y = new Float64Array( x.length );
* var N = x.length;
*
* var v = dcusumkbn( N, 0.0, x, 1, y, 1 );
* var v = dcusumkbn( 3, 0.0, x, 1, y, 1 );
* // returns <Float64Array>[ 1.0, -1.0, 1.0 ]
*/
function dcusumkbn( N, sum, x, strideX, y, strideY ) {
Expand Down
7 changes: 2 additions & 5 deletions lib/node_modules/@stdlib/blas/ext/base/dcusumkbn/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@
*
* var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
* var y = new Float64Array( x.length );
* var N = x.length;
*
* dcusumkbn( N, 0.0, x, 1, y, 1 );
* dcusumkbn( 3, 0.0, x, 1, y, 1 );
* // y => <Float64Array>[ 1.0, -1.0, 1.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
* var dcusumkbn = require( '@stdlib/blas/ext/base/dcusumkbn' );
*
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
* var y = new Float64Array( x.length );
* var N = floor( x.length / 2 );
*
* dcusumkbn.ndarray( N, 0.0, x, 2, 1, y, 1, 0 );
* dcusumkbn.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 );
* // y => <Float64Array>[ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ var abs = require( '@stdlib/math/base/special/abs' );
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
*
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
* var y = new Float64Array( x.length );
* var N = floor( x.length / 2 );
*
* var v = dcusumkbn( N, 0.0, x, 2, 1, y, 1, 0 );
* var v = dcusumkbn( 4, 0.0, x, 2, 1, y, 1, 0 );
* // returns <Float64Array>[ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
*/
function dcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
Expand Down
Loading

0 comments on commit 47cc515

Please sign in to comment.