Skip to content

Commit

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

PR-URL: #1924
Closes: #1476 
Ref: #1152

---------

Signed-off-by: Raunak Kumar Gupta <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Pranav Goswami <[email protected]>
  • Loading branch information
raunak-dev-edu and Planeshifter authored Apr 20, 2024
1 parent 430a72b commit f0cd892
Show file tree
Hide file tree
Showing 21 changed files with 225 additions and 314 deletions.
40 changes: 15 additions & 25 deletions lib/node_modules/@stdlib/blas/ext/base/dnanasum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,14 @@ The function has the following parameters:
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **stride**: index increment for `x`.

The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of absolute values ([_L1_ norm][l1norm]) every other element in `x`,
The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values ([_L1_ norm][l1norm]) every other element in the strided array,

```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 N = floor( x.length / 2 );

var v = dnanasum( N, x, 2 );
var v = dnanasum( 4, x, 2 );
// returns 5.0
```

Expand All @@ -90,14 +88,11 @@ 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 N = floor( x0.length / 2 );

var v = dnanasum( N, x1, 2 );
var v = dnanasum( 4, x1, 2 );
// returns 9.0
```

Expand All @@ -109,26 +104,23 @@ Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision fl
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
var N = x.length;

var v = dnanasum.ndarray( N, x, 1, 0 );
var v = dnanasum.ndarray( 4, x, 1, 0 );
// returns 5.0
```

The function has the following additional parameters:

- **offset**: starting index for `x`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of absolute values ([_L1_ norm][l1norm]) every other value in `x` starting from the second value
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of absolute values ([_L1_ norm][l1norm]) every other value in the strided array starting from the second value

```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 N = floor( x.length / 2 );

var v = dnanasum.ndarray( N, x, 2, 1 );
var v = dnanasum.ndarray( 4, x, 2, 1 );
// returns 9.0
```

Expand All @@ -153,22 +145,20 @@ var v = dnanasum.ndarray( N, x, 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 dnanasum = require( '@stdlib/blas/ext/base/dnanasum' );

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 v = dnanasum( x.length, x, 1 );
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 bernoulli = require( '@stdlib/random/base/bernoulli' );
var uniform = require( '@stdlib/random/base/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' );
var pkg = require( './../package.json' ).name;
var dnanasum = require( './../lib/dnanasum.js' );

Expand All @@ -39,18 +40,15 @@ var dnanasum = require( './../lib/dnanasum.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
return benchmark;

x = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
return NaN;
}
return benchmark;

function benchmark( b ) {
var v;
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 bernoulli = require( '@stdlib/random/base/bernoulli' );
var uniform = require( '@stdlib/random/base/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' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -48,18 +49,15 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
return benchmark;

x = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
return NaN;
}
return benchmark;

function benchmark( b ) {
var v;
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 bernoulli = require( '@stdlib/random/base/bernoulli' );
var uniform = require( '@stdlib/random/base/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' );
var pkg = require( './../package.json' ).name;
var dnanasum = require( './../lib/ndarray.js' );

Expand All @@ -39,18 +40,15 @@ var dnanasum = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
return benchmark;

x = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
return NaN;
}
return benchmark;

function benchmark( b ) {
var v;
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 bernoulli = require( '@stdlib/random/base/bernoulli' );
var uniform = require( '@stdlib/random/base/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' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -48,18 +49,15 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float64', rand );
return benchmark;

x = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*20.0 ) - 10.0;
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
return NaN;
}
return benchmark;

function benchmark( b ) {
var v;
Expand Down
17 changes: 6 additions & 11 deletions lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the sum of absolute values (L1 norm) of double-precision floating-
point strided array elements, ignoring `NaN` values.

The `N` and `stride` parameters determine which elements in `x` 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 @@ -36,19 +36,16 @@

// 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 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> var stride = 2;
> {{alias}}( N, x, stride )
> {{alias}}( 4, x, 2 )
5.0

// 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 );
> stride = 2;
> {{alias}}( N, x1, stride )
> {{alias}}( 4, x1, 2 )
5.0


{{alias}}.ndarray( N, x, stride, offset )
Computes the sum of absolute values (L1 norm) of double-precision floating-
point strided array elements, ignoring `NaN` values and using alternative
Expand Down Expand Up @@ -86,10 +83,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 );
> {{alias}}.ndarray( N, x, 2, 1 )
> {{alias}}.ndarray( 4, x, 2, 1 )
5.0

See Also
--------

21 changes: 9 additions & 12 deletions lib/node_modules/@stdlib/blas/ext/base/dnanasum/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@

'use strict';

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

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 v = dnanasum( x.length, x, 1 );
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 @@ -37,9 +37,8 @@ var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
* var N = x.length;
*
* var v = dnanasum( N, x, 1 );
* var v = dnanasum( 4, x, 1 );
* // returns 5.0
*/
function dnanasum( N, x, stride ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ var addon = require( './../src/addon.node' );
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
* var N = x.length;
*
* var v = dnanasum( N, x, 1 );
* var v = dnanasum( 4, x, 1 );
* // returns 5.0
*/
function dnanasum( N, x, stride ) {
Expand Down
7 changes: 2 additions & 5 deletions lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,17 @@
* var dnanasum = require( '@stdlib/blas/ext/base/dnanasum' );
*
* var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
* var N = x.length;
*
* var v = dnanasum( N, x, 1 );
* var v = dnanasum( 4, x, 1 );
* // returns 5.0
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var floor = require( '@stdlib/math/base/special/floor' );
* var dnanasum = require( '@stdlib/blas/ext/base/dnanasum' );
*
* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
* var N = floor( x.length / 2 );
*
* var v = dnanasum.ndarray( N, x, 2, 1 );
* var v = dnanasum.ndarray( 5, x, 2, 1 );
* // returns 9.0
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' ).ndarray;
* 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 N = floor( x.length / 2 );
*
* var v = dnanasum( N, x, 2, 1 );
* var v = dnanasum( 5, x, 2, 1 );
* // returns 9.0
*/
function dnanasum( N, x, stride, offset ) {
Expand Down
Loading

1 comment on commit f0cd892

@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/dnanasum $\color{green}352/352$
$\color{green}+100.00\%$
$\color{green}13/13$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}352/352$
$\color{green}+100.00\%$

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

Please sign in to comment.