Skip to content

Commit

Permalink
refactor: update blas/ext/base/dapx to follow current project conve…
Browse files Browse the repository at this point in the history
…ntions

PR-URL: 	#1954
Closes: #1464
Ref: #1152
Co-authored-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Athan Reines <kgryte@gmail.com> 
Signed-off-by: Athan Reines <kgryte@gmail.com>
  • Loading branch information
naveen1m and kgryte authored Mar 21, 2024
1 parent 23fba1c commit 0d2528e
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 284 deletions.
40 changes: 10 additions & 30 deletions lib/node_modules/@stdlib/blas/ext/base/dapx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var dapx = require( '@stdlib/blas/ext/base/dapx' );

#### dapx( N, alpha, x, stride )

Adds a constant `alpha` to each element in a double-precision floating-point strided array `x`.
Adds a constant `alpha` to each element in a double-precision floating-point strided array.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -50,40 +50,36 @@ The function has the following parameters:
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **stride**: index increment.

The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to add a constant to every other element
The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element

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

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

dapx( N, 5.0, x, 2 );
dapx( 4, 5.0, x, 2 );
// x => <Float64Array>[ 3.0, 1.0, 8.0, -5.0, 9.0, 0.0, 4.0, -3.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

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

// Initial array...
var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );

// Create an offset view...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var N = floor( x0.length/2 );

// Add a constant to every other element...
dapx( N, 5.0, x1, 2 );
dapx( 3, 5.0, x1, 2 );
// x0 => <Float64Array>[ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ]
```

#### dapx.ndarray( N, alpha, x, stride, offset )

Adds a constant `alpha` to each element in a double-precision floating-point strided array `x` using alternative indexing semantics.
Adds a constant `alpha` to each element in a double-precision floating-point strided array using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -98,7 +94,7 @@ The function has the following additional parameters:

- **offset**: starting index.

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 access only the last three elements of `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 access only the last three elements of the strided array

```javascript
var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -117,7 +113,7 @@ dapx.ndarray( 3, 5.0, x, 1, x.length-3 );

## Notes

- If `N <= 0`, both functions return `x` unchanged.
- If `N <= 0`, both functions return the strided array unchanged.

</section>

Expand All @@ -130,27 +126,11 @@ dapx.ndarray( 3, 5.0, x, 1, x.length-3 );
<!-- eslint no-undef: "error" -->

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

var rand;
var sign;
var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
rand = round( randu()*100.0 );
sign = randu();
if ( sign < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
x[ i ] = sign * rand;
}
var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) );
console.log( x );

dapx( x.length, 5.0, x, 1 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 dapx = require( './../lib/dapx.js' );


// VARIABLES //

var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //

/**
Expand All @@ -40,12 +45,8 @@ var dapx = require( './../lib/dapx.js' );
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
x = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 @@ -36,6 +36,7 @@ var dapx = tryRequire( resolve( __dirname, './../lib/dapx.native.js' ) );
var opts = {
'skip': ( dapx instanceof Error )
};
var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //
Expand All @@ -49,12 +50,8 @@ var opts = {
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
x = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 dapx = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //

/**
Expand All @@ -40,12 +45,8 @@ var dapx = require( './../lib/ndarray.js' );
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
x = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 @@ -36,6 +36,7 @@ var dapx = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( dapx instanceof Error )
};
var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //
Expand All @@ -49,12 +50,8 @@ var opts = {
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
}
x = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
38 changes: 14 additions & 24 deletions lib/node_modules/@stdlib/blas/ext/base/dapx/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
Adds a constant to each element in a double-precision floating-point strided
array.

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 typed
array views.

If `N <= 0`, the function returns `x` unchanged.
If `N <= 0`, the function returns the strided array unchanged.

Parameters
----------
Expand All @@ -23,40 +23,34 @@
Input array.

stride: integer
Index increment for `x`.
Index increment.

Returns
-------
x: Float64Array
Input array `x`.
Input array.

Examples
--------
// Standard Usage:
> var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
> var alpha = 5.0;
> {{alias}}( x.length, alpha, x, 1 )
> {{alias}}( x.length, 5.0, x, 1 )
<Float64Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ]

// Using `N` and `stride` parameters:
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> alpha = 5.0;
> var stride = 2;
> {{alias}}( N, alpha, x, stride )
> {{alias}}( 3, 5.0, x, 2 )
<Float64Array>[ 3.0, 1.0, 8.0, -5.0, 9.0, -1.0, -3.0 ]

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


{{alias}}.ndarray( N, alpha, x, stride, offset )
Adds a constant to each element in a double-precision floating-point strided
array using alternative indexing semantics.
Expand All @@ -77,30 +71,26 @@
Input array.

stride: integer
Index increment for `x`.
Index increment.

offset: integer
Starting index of `x`.
Starting index.

Returns
-------
x: Float64Array
Input array `x`.
Input array.

Examples
--------
// Standard Usage:
> var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
> var alpha = 5.0;
> {{alias}}.ndarray( x.length, alpha, x, 1, 0 )
> {{alias}}.ndarray( x.length, 5.0, x, 1, 0 )
<Float64Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ]

// Using an index offset:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> alpha = 5.0;
> var stride = 2;
> {{alias}}.ndarray( N, alpha, x, stride, 1 )
> {{alias}}.ndarray( 3, 5.0, x, 2, 1 )
<Float64Array>[ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ]

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface Routine {
* @param alpha - constant
* @param x - input array
* @param stride - stride length
* @returns `x`
* @returns input array
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -49,7 +49,7 @@ interface Routine {
* @param x - input array
* @param stride - stride length
* @param offset - starting index
* @returns `x`
* @returns input array
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
Expand All @@ -69,7 +69,7 @@ interface Routine {
* @param alpha - constant
* @param x - input array
* @param stride - stride length
* @returns `x`
* @returns input array
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
Expand Down
Loading

1 comment on commit 0d2528e

@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/dapx $\color{red}421/432$
$\color{green}+97.45\%$
$\color{green}40/40$
$\color{green}+100.00\%$
$\color{red}2/4$
$\color{green}+50.00\%$
$\color{red}421/432$
$\color{green}+97.45\%$

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

Please sign in to comment.