Skip to content

Commit

Permalink
refactor: update blas/ext/base/dsnannsumors
Browse files Browse the repository at this point in the history
PR-URL: #2804
Closes:  #1491 
Ref: #1152

---------

Signed-off-by: Philipp Burckhardt <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
GittyHarsha and Planeshifter authored Sep 2, 2024
1 parent d125530 commit 7cc8bb9
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 363 deletions.
35 changes: 14 additions & 21 deletions lib/node_modules/@stdlib/blas/ext/base/dsnannsumors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,16 @@ 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 Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float32Array( [ 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 = dsnannsumors( N, x, 2, out, 1 );
var v = dsnannsumors( 4, x, 2, out, 1 );
// returns <Float64Array>[ 5.0, 2 ]
```

Expand All @@ -81,17 +79,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [
```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

var x0 = new Float32Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var x1 = new Float32Array( 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 = dsnannsumors( N, x1, 2, out1, 1 );
var v = dsnannsumors( 4, x1, 2, out1, 1 );
// returns <Float64Array>[ 5.0, 4 ]
```

Expand Down Expand Up @@ -120,13 +115,11 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float32Array( [ 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 = dsnannsumors.ndarray( N, x, 2, 1, out, 2, 1 );
var v = dsnannsumors.ndarray( 4, x, 2, 1, out, 2, 1 );
// returns <Float64Array>[ 0.0, 5.0, 0.0, 4 ]
```

Expand All @@ -152,23 +145,23 @@ var v = dsnannsumors.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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var dsnannsumors = require( '@stdlib/blas/ext/base/dsnannsumors' );

var x;

This comment has been minimized.

Copy link
@kgryte

kgryte Sep 17, 2024

Member

@Planeshifter This declaration should be moved down to L164.

This comment has been minimized.

Copy link
@Planeshifter

Planeshifter Sep 20, 2024

Author Member

Done.

var i;

x = new Float32Array( 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.5 ) < 0.2 ) {

This comment has been minimized.

Copy link
@kgryte

kgryte Sep 17, 2024

Member

@Planeshifter I don't think this condition makes sense. I think you either want if ( bernoulli( 0.2 ) ) {...} or use randu(). This applies here and in the benchmarks.

This comment has been minimized.

Copy link
@Planeshifter

Planeshifter Sep 20, 2024

Author Member

Addressed.

return NaN;
}
return discreteUniform( 0, 100 );
}

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

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

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
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 Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dsnannsumors = require( './../lib/dsnannsumors.js' );
Expand All @@ -42,19 +43,18 @@ var dsnannsumors = require( './../lib/dsnannsumors.js' );
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
x = filledarrayBy( len, 'float32', rand );
out = new Float64Array( 2 );
return benchmark;

function rand() {
if ( bernoulli( 0.5 ) < 0.2 ) {
return NaN;
}
return uniform( -10.0, 10.0 );
}

function benchmark( b ) {
var i;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
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 Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -51,19 +52,18 @@ var opts = {
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
x = filledarrayBy( len, 'float32', rand );
out = new Float64Array( 2 );
return benchmark;

function rand() {
if ( bernoulli( 0.5 ) < 0.2 ) {
return NaN;
}
return uniform( -10.0, 10.0 );
}

function benchmark( b ) {
var i;

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

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
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 Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var dsnannsumors = require( './../lib/ndarray.js' );
Expand All @@ -42,19 +43,18 @@ var dsnannsumors = require( './../lib/ndarray.js' );
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
x = filledarrayBy( len, 'float32', rand );
out = new Float64Array( 2 );
return benchmark;

function rand() {
if ( bernoulli( 0.5 ) < 0.2 ) {
return NaN;
}
return uniform( -10.0, 10.0 );
}

function benchmark( b ) {
var i;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
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 Float32Array = require( '@stdlib/array/float32' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -51,19 +52,18 @@ var opts = {
function createBenchmark( len ) {
var out;
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
x = filledarrayBy( len, 'float32', rand );
out = new Float64Array( 2 );
return benchmark;

function rand() {
if ( bernoulli( 0.5 ) < 0.2 ) {
return NaN;
}
return uniform( -10.0, 10.0 );
}

function benchmark( b ) {
var i;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ignoring `NaN` values, using ordinary recursive summation with extended
accumulation, and returning an extended precision result.

The `N` and `stride` parameters determine which elements are accessed at
The `N` and stride parameters determine which elements are accessed at
runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
Expand Down Expand Up @@ -43,11 +43,10 @@
> {{alias}}( x.length, x, 1, out, 1 )
<Float64Array>[ 1.0, 3 ]

// 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, 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:
Expand All @@ -58,13 +57,14 @@
> {{alias}}( N, x1, 2, out, 1 )
<Float64Array>[ 1.0, 3 ]


{{alias}}.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut )
Computes the sum of single-precision floating-point strided array elements,
ignoring `NaN` values and using ordinary recursive summation with extended
accumulation 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
buffer, the offset parameter supports indexing semantics based on a
starting index.

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

// Using offset parameter:
> var x = new {{alias:@stdlib/array/float32}}( [ 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,24 +18,23 @@

'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' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Float64Array = require( '@stdlib/array/float64' );
var dsnannsumors = require( './../lib' );

var out;

This comment has been minimized.

Copy link
@kgryte

kgryte Sep 17, 2024

Member

@Planeshifter These declarations can be moved to L37 and L40.

This comment has been minimized.

Copy link
@Planeshifter

Planeshifter Sep 20, 2024

Author Member

Done.

var x;
var i;

x = new Float32Array( 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.5 ) < 0.2 ) {
return NaN;
}
return discreteUniform( 0, 100 );
}

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

out = new Float64Array( 2 );
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 @@ -31,21 +31,18 @@
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
* var out = new Float64Array( 2 );
*
* var v = dsnannsumors( x.length, x, 1, out, 1 );
* var v = dsnannsumors( 4, x, 1, out, 1 );
* // returns <Float64Array>[ 1.0, 3 ]
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
* var dsnannsumors = require( '@stdlib/blas/ext/base/dsnannsumors' );
*
* var x = new Float32Array( [ 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 = dsnannsumors.ndarray( N, x, 2, 1, out, 1, 0 );
* var v = dsnannsumors.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 @@ -40,14 +40,11 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
* @example
* var Float32Array = require( '@stdlib/array/float32' );
* var Float64Array = require( '@stdlib/array/float64' );
* 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, NaN, NaN ] );
* var out = new Float64Array( 2 );
*
* var N = floor( x.length / 2 );
*
* var v = dsnannsumors( N, x, 2, 1, out, 1, 0 );
* var v = dsnannsumors( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/
function dsnannsumors( N, x, strideX, offsetX, out, strideOut, offsetOut ) {
Expand Down
Loading

1 comment on commit 7cc8bb9

@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/dsnannsumors $\color{green}454/454$
$\color{green}+100.00\%$
$\color{green}37/37$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}454/454$
$\color{green}+100.00\%$

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

Please sign in to comment.