Skip to content

Commit

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

PR-URL: #1929
Closes: #1520

---------

Signed-off-by: Pranav <85227306+Pranavchiku@users.noreply.github.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
Co-authored-by: Pranav <85227306+Pranavchiku@users.noreply.github.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Pranav Goswami <goswami.4@iitj.ac.in>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent 548f903 commit f95e706
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 320 deletions.
31 changes: 8 additions & 23 deletions lib/node_modules/@stdlib/blas/ext/base/scusumpw/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 = scusumpw( N, 0.0, x, 2, y, 1 );
var v = scusumpw( 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 );

scusumpw( N, 0.0, x1, -2, y1, 1 );
scusumpw( 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 @@ -125,14 +119,11 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the

```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 );

scusumpw.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
scusumpw.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 @@ -158,20 +149,14 @@ scusumpw.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 Float32Array = require( '@stdlib/array/float32' );
var scusumpw = require( '@stdlib/blas/ext/base/scusumpw' );

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

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 );
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 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 scusumpw = require( './../lib/scusumpw.js' );


// VARIABLES //

var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //

/**
Expand All @@ -39,15 +45,9 @@ var scusumpw = require( './../lib/scusumpw.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var y;
var x;
var i;
var y = new Float32Array( len );
var x = filledarrayBy( len, 'float32', rand );

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -36,6 +37,7 @@ var scusumpw = tryRequire( resolve( __dirname, './../lib/scusumpw.native.js' ) )
var opts = {
'skip': ( scusumpw instanceof Error )
};
var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //
Expand All @@ -48,15 +50,9 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;
var x = filledarrayBy( len, 'float32', rand );
var y = new Float32Array( len );

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
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 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 scusumpw = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //

/**
Expand All @@ -39,15 +45,9 @@ var scusumpw = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;
var x = filledarrayBy( len, 'float32', rand );
var y = new Float32Array( len );

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -36,6 +37,7 @@ var scusumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( scusumpw instanceof Error )
};
var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //
Expand All @@ -48,15 +50,9 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;
var x = filledarrayBy( len, 'float32', rand );
var y = new Float32Array( len );

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

function benchmark( b ) {
Expand Down
16 changes: 7 additions & 9 deletions lib/node_modules/@stdlib/blas/ext/base/scusumpw/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the cumulative sum of single-precision floating-point strided array
elements using pairwise summation.

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 @@ -44,24 +44,23 @@
> {{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:
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
> var y0 = new {{alias:@stdlib/array/float32}}( x0.length );
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:@stdlib/array/float32}}( 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 )
<Float32Array>[ -2.0, 0.0, -1.0 ]
> 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 pairwise summation and alternative indexing semantics.
Expand Down Expand Up @@ -112,8 +111,7 @@
// 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
Expand Down
14 changes: 4 additions & 10 deletions lib/node_modules/@stdlib/blas/ext/base/scusumpw/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 Float32Array = require( '@stdlib/array/float32' );
var scusumpw = require( './../lib' );

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

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 );
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 @@ -20,7 +20,8 @@

// MODULES //

var Float32Array = require( '@stdlib/array/float32' );
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var offsetView = require( '@stdlib/strided/base/offset-view' );
var addon = require( './scusumpw.native.js' );


Expand Down Expand Up @@ -53,14 +54,13 @@ var addon = require( './scusumpw.native.js' );
function scusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
var viewX;
var viewY;
if ( strideX < 0 ) {
offsetX += (N-1) * strideX;
}
if ( strideY < 0 ) {
offsetY += (N-1) * strideY;
}
viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len

offsetX = minViewBufferIndex( N, strideX, offsetX );
offsetY = minViewBufferIndex( N, strideY, offsetY );

viewX = offsetView( x, offsetX );
viewY = offsetView( y, offsetY );

addon( N, sum, viewX, strideX, viewY, strideY );
return y;
}
Expand Down
Loading

1 comment on commit f95e706

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/scusumpw $\color{green}450/450$
$\color{green}+100.00\%$
$\color{green}26/26$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}450/450$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.