Skip to content

Commit

Permalink
Refactor and clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Dec 31, 2022
1 parent ee0cdc9 commit d66d80c
Show file tree
Hide file tree
Showing 25 changed files with 229 additions and 371 deletions.
35 changes: 10 additions & 25 deletions lib/node_modules/@stdlib/blas/base/saxpy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,17 @@ The function has the following parameters:
- **y**: input [`Float32Array`][mdn-float32array].
- **strideY**: index increment for `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to multiply every other value in `x` by `alpha` and add the result to the first `N` elements of `y` in reverse order,
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to multiply every other value in `x` by `alpha` and add the result to the first `N` elements of `y` in reverse order,

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

var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );

var alpha = 5.0;
var N = floor( x.length / 2 );

saxpy( N, alpha, x, 2, y, -1 );
saxpy( 3, alpha, x, 2, y, -1 );
// y => <Float32Array>[ 26.0, 16.0, 6.0, 1.0, 1.0, 1.0 ]
```

Expand All @@ -76,7 +74,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [

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

// Initial arrays...
var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
Expand All @@ -86,9 +83,7 @@ var y0 = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element

var N = floor( x0.length / 2 );

saxpy( N, 5.0, x1, -2, y1, 1 );
saxpy( 3, 5.0, x1, -2, y1, 1 );
// y0 => <Float32Array>[ 7.0, 8.0, 9.0, 40.0, 31.0, 22.0 ]
```

Expand All @@ -112,19 +107,17 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to multiply every other value in `x` by a constant `alpha` starting from the second value and add to the last `N` elements in `y` where `x[i] -> y[n]`, `x[i+2] -> y[n-1]`,...,
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameters support indexing semantics based on starting indices. For example, to multiply every other value in `x` by a constant `alpha` starting from the second value and add to the last `N` elements in `y` where `x[i] -> y[n]`, `x[i+2] -> y[n-1]`,...,

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

var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );

var alpha = 5.0;
var N = floor( x.length / 2 );

saxpy.ndarray( N, alpha, x, 2, 1, y, -1, y.length-1 );
saxpy.ndarray( 3, alpha, x, 2, 1, y, -1, y.length-1 );
// y => <Float32Array>[ 7.0, 8.0, 9.0, 40.0, 31.0, 22.0 ]
```

Expand All @@ -150,22 +143,14 @@ saxpy.ndarray( N, alpha, x, 2, 1, y, -1, y.length-1 );
<!-- eslint no-undef: "error" -->

```javascript
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' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var saxpy = require( '@stdlib/blas/base/saxpy' );

var x;
var y;
var i;

x = new Float32Array( 10 );
y = new Float32Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*100.0 );
y[ i ] = round( randu()*10.0 );
}
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
console.log( x );

var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) );
console.log( y );

saxpy.ndarray( x.length, 5.0, x, 1, 0, y, -1, y.length-1 );
Expand Down
21 changes: 9 additions & 12 deletions lib/node_modules/@stdlib/blas/base/saxpy/benchmark/benchmark.js
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 Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var saxpy = require( './../lib/saxpy.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,16 +44,8 @@ var saxpy = require( './../lib/saxpy.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*200.0 ) - 100.0;
y[ i ] = ( randu()*200.0 ) - 100.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

/**
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 Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var saxpy = tryRequire( resolve( __dirname, './../lib/saxpy.native.js' ) );
var opts = {
'skip': ( saxpy instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,16 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*200.0 ) - 100.0;
y[ i ] = ( randu()*200.0 ) - 100.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

/**
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 Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var saxpy = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,16 +44,8 @@ var saxpy = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*200.0 ) - 100.0;
y[ i ] = ( randu()*200.0 ) - 100.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

/**
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 Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var saxpy = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( saxpy instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,16 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*200.0 ) - 100.0;
y[ i ] = ( randu()*200.0 ) - 100.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

/**
Expand Down
27 changes: 12 additions & 15 deletions lib/node_modules/@stdlib/blas/base/saxpy/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{alias}}( N, alpha, x, strideX, y, strideY )
Multiplies a vector `x` by a constant `alpha` and adds the result to `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are
accessed at runtime.
The `N` and stride parameters determine which elements in the strided arrays
are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use typed
array views.
Expand All @@ -25,15 +25,15 @@
Index increment for `x`.

y: Float32Array
Destination array.
Output array.

strideY: integer
Index increment for `y`.

Returns
-------
y: Float32Array
Input array `y`.
Output array.

Examples
--------
Expand All @@ -44,20 +44,18 @@
> {{alias}}( x.length, alpha, x, 1, y, 1 )
<Float32Array>[ 6.0, 11.0, 16.0, 21.0, 26.0 ]

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, alpha, x, 2, y, -1 )
> {{alias}}( 3, alpha, x, 2, y, -1 )
<Float32Array>[ 26.0, 16.0, 6.0, 1.0, 1.0, 1.0 ]

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> var y0 = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> {{alias}}( N, 5.0, x1, -2, y1, 1 )
> {{alias}}( 3, 5.0, x1, -2, y1, 1 )
<Float32Array>[ 40.0, 31.0, 22.0 ]
> y0
<Float32Array>[ 7.0, 8.0, 9.0, 40.0, 31.0, 22.0 ]
Expand All @@ -68,8 +66,8 @@
using alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offsetX` and `offsetY` parameters support indexing semantics
based on starting indices.
buffer, the offset parameters support indexing semantics based on starting
indices.

Parameters
----------
Expand All @@ -89,7 +87,7 @@
Starting index for `x`.

y: Float32Array
Destination array.
Output array.

strideY: integer
Index increment for `y`.
Expand All @@ -100,7 +98,7 @@
Returns
-------
y: Float32Array
Input array `y`.
Output array.

Examples
--------
Expand All @@ -114,8 +112,7 @@
// Advanced indexing:
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, alpha, x, 2, 1, y, -1, y.length-1 )
> {{alias}}.ndarray( 3, alpha, x, 2, 1, y, -1, y.length-1 )
<Float32Array>[ 7.0, 8.0, 9.0, 40.0, 31.0, 22.0 ]

See Also
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/blas/base/saxpy/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ interface Routine {
* @param alpha - constant
* @param x - input array
* @param strideX - `x` stride length
* @param y - destination array
* @param y - output array
* @param strideY - `y` stride length
* @returns `y`
* @returns output array
*
* @example
* var Float32Array = require( `@stdlib/array/float32` );
Expand All @@ -52,10 +52,10 @@ interface Routine {
* @param x - input array
* @param strideX - `x` stride length
* @param offsetX - starting index for `x`
* @param y - destination array
* @param y - output array
* @param strideY - `y` stride length
* @param offsetY - starting index for `y`
* @returns `y`
* @returns output array
*
* @example
* var Float32Array = require( `@stdlib/array/float32` );
Expand All @@ -76,9 +76,9 @@ interface Routine {
* @param alpha - constant
* @param x - input array
* @param strideX - `x` stride length
* @param y - destination array
* @param y - output array
* @param strideY - `y` stride length
* @returns `y`
* @returns output array
*
* @example
* var Float32Array = require( `@stdlib/array/float32` );
Expand Down
Loading

0 comments on commit d66d80c

Please sign in to comment.