Skip to content

Commit

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

PR-URL: #2063
Closes: #1480 
Ref: #1152

---------

Signed-off-by: Philipp Burckhardt <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
vr-varad and Planeshifter authored Apr 22, 2024
1 parent 58cc765 commit 0f07a02
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 339 deletions.
35 changes: 13 additions & 22 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ The function has the following parameters:
- **out**: output [`Float64Array`][@stdlib/array/float64] whose first element is the sum and whose second element is the number of non-NaN elements.
- **strideOut**: index increment for `out`.

The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`,
The `N` and stride parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`,

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

var x = new Float64Array( [ 1.0, 2.0, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] );
var out = new Float64Array( 2 );
var N = floor( x.length / 2 );

var v = dnannsumkbn2( N, x, 2, out, 1 );
var v = dnannsumkbn2( 4, x, 2, out, 1 );
// returns <Float64Array>[ 5.0, 2 ]
```

Expand All @@ -78,17 +76,14 @@ 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' );

var x0 = new Float64Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var out0 = new Float64Array( 4 );
var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*2 ); // start at 3rd element

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

var v = dnannsumkbn2( N, x1, 2, out1, 1 );
var v = dnannsumkbn2( 4, x1, 2, out1, 1 );
// returns <Float64Array>[ 5.0, 4 ]
```

Expand All @@ -115,13 +110,11 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the

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

var x = new Float64Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var out = new Float64Array( 4 );
var N = floor( x.length / 2 );

var v = dnannsumkbn2.ndarray( N, x, 2, 1, out, 2, 1 );
var v = dnannsumkbn2.ndarray( 4, x, 2, 1, out, 2, 1 );
// returns <Float64Array>[ 0.0, 5.0, 0.0, 4 ]
```

Expand All @@ -146,22 +139,20 @@ var v = dnannsumkbn2.ndarray( N, x, 2, 1, out, 2, 1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Float64Array = require( '@stdlib/array/float64' );
var dnannsumkbn2 = require( '@stdlib/blas/ext/base/dnannsumkbn2' );

var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = round( randu()*100.0 );
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return discreteUniform( 0, 100 );
}
return NaN;
}

var x = filledarrayBy( 10, 'float64', rand );
console.log( x );

var out = new Float64Array( 2 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
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 @@ -41,16 +43,15 @@ var dnannsumkbn2 = require( './../lib/dnannsumkbn2.js' );
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
function clbk() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

x = filledarrayBy( len, 'float64', clbk );
out = new Float64Array( 2 );
return benchmark;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
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 Down Expand Up @@ -50,16 +52,15 @@ var opts = {
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
function clbk() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

x = filledarrayBy( len, 'float64', clbk );
out = new Float64Array( 2 );
return benchmark;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
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 @@ -41,16 +43,15 @@ var dnannsumkbn2 = require( './../lib/ndarray.js' );
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
function clbk() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

x = filledarrayBy( len, 'float64', clbk );
out = new Float64Array( 2 );
return benchmark;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
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 Down Expand Up @@ -50,16 +52,15 @@ var opts = {
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
function clbk() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

x = filledarrayBy( len, 'float64', clbk );
out = new Float64Array( 2 );
return benchmark;

Expand Down
18 changes: 8 additions & 10 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn2/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
ignoring `NaN` values and using a second-order iterative Kahan–Babuška
algorithm.

The `N` and `stride` parameters determine which elements are accessed at
runtime.
The `N` and stride parameters determine which elements in the strided
array are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
array view.
Expand Down Expand Up @@ -46,26 +46,25 @@
// Using `N` and `stride` parameters:
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] );
> out = new {{alias:@stdlib/array/float64}}( 2 );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, x, 2, out, 1 )
> {{alias}}( 4, x, 2, out, 1 )
<Float64Array>[ 1.0, 3 ]

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


{{alias}}.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut )
Computes the sum of double-precision floating-point strided array elements,
ignoring `NaN` values and 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 offset parameters supports indexing semantics
based on a starting index.

Parameters
----------
Expand Down Expand Up @@ -106,9 +105,8 @@

// Using offset parameter:
> var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0, NaN, NaN ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> out = new {{alias:@stdlib/array/float64}}( 2 );
> {{alias}}.ndarray( N, x, 2, 1, out, 1, 0 )
> {{alias}}.ndarray( 4, x, 2, 1, out, 1, 0 )
<Float64Array>[ 1.0, 3 ]

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@

'use strict';

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

var out;
var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = round( randu()*100.0 );
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return discreteUniform( 0, 100 );
}
return NaN;
}

var x = filledarrayBy( 10, 'float64', rand );
console.log( x );

out = new Float64Array( 2 );
var out = new Float64Array( 2 );
dnannsumkbn2( x.length, x, 1, out, 1 );
console.log( out );
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 @@ -35,15 +35,12 @@
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
* var dnannsumkbn2 = require( '@stdlib/blas/ext/base/dnannsumkbn2' );
*
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
* var out = new Float64Array( 2 );
*
* var N = floor( x.length / 2 );
*
* var v = dnannsumkbn2.ndarray( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumkbn2.ndarray( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +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, NaN, NaN ] );
* var out = new Float64Array( 2 );
*
* var N = floor( x.length / 2 );
*
* var v = dnannsumkbn2( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumkbn2( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/
function dnannsumkbn2( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

// MODULES //

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


Expand All @@ -40,27 +41,24 @@ var addon = require( './dnannsumkbn2.native.js' );
*
* @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, NaN, NaN ] );
* var out = new Float64Array( 2 );
*
* var N = floor( x.length / 2 );
*
* var v = dnannsumkbn2( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumkbn2( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/
function dnannsumkbn2( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
var viewOut;
var viewX;
if ( strideX < 0 ) {
offsetX += (N-1) * strideX;
}

offsetX = minViewBufferIndex( N, strideX, offsetX );
if ( strideOut < 0 ) {
offsetOut += strideOut;
}
viewX = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
viewOut = new Float64Array( out.buffer, out.byteOffset+(out.BYTES_PER_ELEMENT*offsetOut), out.length-offsetOut ); // eslint-disable-line max-len

viewX = offsetView( x, offsetX );
viewOut = offsetView( out, offsetOut );
addon( N, viewX, strideX, viewOut, strideOut );
return out;
}
Expand Down
Loading

1 comment on commit 0f07a02

@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/dnannsumkbn2 $\color{green}515/515$
$\color{green}+100.00\%$
$\color{green}46/46$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}515/515$
$\color{green}+100.00\%$

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

Please sign in to comment.