Skip to content

Commit

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

PR-URL: #2079
Closes: #1479 
Ref: #1152

---------

Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
Shubh942 and Planeshifter authored Apr 22, 2024
1 parent 0f07a02 commit be25162
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 349 deletions.
33 changes: 12 additions & 21 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ The `N` and `stride` parameters determine which elements are accessed at runtime

```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 = dnannsumkbn( N, x, 2, out, 1 );
var v = dnannsumkbn( 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 = dnannsumkbn( N, x1, 2, out1, 1 );
var v = dnannsumkbn( 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 = dnannsumkbn.ndarray( N, x, 2, 1, out, 2, 1 );
var v = dnannsumkbn.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 = dnannsumkbn.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 dnannsumkbn = require( '@stdlib/blas/ext/base/dnannsumkbn' );

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 @@ -40,19 +42,15 @@ var dnannsumkbn = require( './../lib/dnannsumkbn.js' );
*/
function createBenchmark( len ) {
var out;
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
out = new Float64Array( 2 );
return benchmark;

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 rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
}
out = new Float64Array( 2 );
return benchmark;

function benchmark( b ) {
var i;
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 All @@ -49,19 +51,16 @@ var opts = {
*/
function createBenchmark( len ) {
var out;
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
out = new Float64Array( 2 );
return benchmark;

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 rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}
out = new Float64Array( 2 );
return benchmark;

function benchmark( b ) {
var i;
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 @@ -40,19 +42,16 @@ var dnannsumkbn = require( './../lib/ndarray.js' );
*/
function createBenchmark( len ) {
var out;
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
out = new Float64Array( 2 );
return benchmark;

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 rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}
out = new Float64Array( 2 );
return benchmark;

function benchmark( b ) {
var i;
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 All @@ -49,19 +51,16 @@ var opts = {
*/
function createBenchmark( len ) {
var out;
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
out = new Float64Array( 2 );
return benchmark;

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 rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}
out = new Float64Array( 2 );
return benchmark;

function benchmark( b ) {
var i;
Expand Down
18 changes: 8 additions & 10 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the sum of double-precision floating-point strided array elements,
ignoring `NaN` values and using an improved 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 @@ -45,26 +45,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 an improved 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 a starting index.

Parameters
----------
Expand Down Expand Up @@ -105,9 +104,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 dnannsumkbn = 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 );
dnannsumkbn( 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 dnannsumkbn = require( '@stdlib/blas/ext/base/dnannsumkbn' );
*
* 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 = dnannsumkbn.ndarray( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumkbn.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 = dnannsumkbn( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumkbn( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/
function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
Expand Down
Loading

1 comment on commit be25162

@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/dnannsumkbn $\color{green}491/491$
$\color{green}+100.00\%$
$\color{green}42/42$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}491/491$
$\color{green}+100.00\%$

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

Please sign in to comment.