Skip to content

Commit

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

PR-URL: #2082
Closes: #1481
Ref: #1152

---------

Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
Shubh942 and Planeshifter authored Apr 17, 2024
1 parent 326479a commit 118791f
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 343 deletions.
34 changes: 13 additions & 21 deletions lib/node_modules/@stdlib/blas/ext/base/dnannsumors/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 = dnannsumors( N, x, 2, out, 1 );
var v = dnannsumors( 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 = dnannsumors( N, x1, 2, out1, 1 );
var v = dnannsumors( 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 = dnannsumors.ndarray( N, x, 2, 1, out, 2, 1 );
var v = dnannsumors.ndarray( 4, x, 2, 1, out, 2, 1 );
// returns <Float64Array>[ 0.0, 5.0, 0.0, 4 ]
```

Expand All @@ -147,22 +140,21 @@ var v = dnannsumors.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 Float64Array = require( '@stdlib/array/float64' );
var dnannsumors = require( '@stdlib/blas/ext/base/dnannsumors' );

var x;
var i;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var dnannsumors = require( '@stdlib/blas/ext/base/dnannsumors' );

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,10 +21,12 @@
// 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 Float64Array = require( '@stdlib/array/float64' );
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 dnannsumors = require( './../lib/dnannsumors.js' );

Expand All @@ -40,19 +42,16 @@ var dnannsumors = require( './../lib/dnannsumors.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.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
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,10 +22,12 @@

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 Float64Array = require( '@stdlib/array/float64' );
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 @@ -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.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
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,10 +21,12 @@
// 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 Float64Array = require( '@stdlib/array/float64' );
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 dnannsumors = require( './../lib/ndarray.js' );

Expand All @@ -40,19 +42,16 @@ var dnannsumors = 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.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
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,10 +22,12 @@

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 Float64Array = require( '@stdlib/array/float64' );
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 @@ -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.8 ) > 0 ) {
return uniform( -10.0, 10.0 );
}
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 @@ -18,25 +18,23 @@

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

var out;
var x;
var i;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var dnannsumors = require( './../lib' );

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 );
dnannsumors( 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 dnannsumors = require( '@stdlib/blas/ext/base/dnannsumors' );
*
* 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 = dnannsumors.ndarray( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumors.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 @@ -39,14 +39,11 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' );
*
* @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 = dnannsumors( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumors( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/
function dnannsumors( 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( './dnannsumors.native.js' );


Expand All @@ -40,27 +41,23 @@ var addon = require( './dnannsumors.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 = dnannsumors( N, x, 2, 1, out, 1, 0 );
* var v = dnannsumors( 5, x, 2, 1, out, 1, 0 );
* // returns <Float64Array>[ 5.0, 4 ]
*/
function dnannsumors( 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 118791f

@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/dnannsumors $\color{green}450/450$
$\color{green}+100.00\%$
$\color{green}38/38$
$\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.