Skip to content

Commit

Permalink
refactor: update add-on, examples, benchmarks, and docs
Browse files Browse the repository at this point in the history
This commit migrates `@stdlib/blas/base/sdsdot` to use current project conventions, as discussed in #788.

PR-URL: #799
Co-authored-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Athan Reines <kgryte@gmail.com>
  • Loading branch information
Pranavchiku and kgryte authored Mar 2, 2023
1 parent 5c4c206 commit c8985f2
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 325 deletions.
38 changes: 11 additions & 27 deletions lib/node_modules/@stdlib/blas/base/sdsdot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@license Apache-2.0
Copyright (c) 2020 The Stdlib Authors.
Copyright (c) 2023 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,18 +70,15 @@ The function has the following parameters:
- **y**: input [`Float32Array`][@stdlib/array/float32].
- **strideY**: index increment for `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to calculate the dot product of every other value in `x` and 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 calculate the dot product of every other value in `x` and 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 N = floor( x.length / 2 );

var z = sdsdot( N, 0.0, x, 2, y, -1 );
var z = sdsdot( 3, 0.0, x, 2, y, -1 );
// returns 9.0
```

Expand All @@ -101,9 +98,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 );

var z = sdsdot( N, 0.0, x1, -2, y1, 1 );
var z = sdsdot( 3, 0.0, x1, -2, y1, 1 );
// returns 128.0
```

Expand All @@ -126,18 +121,15 @@ 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 calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order
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 calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `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( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );

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

var z = sdsdot.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
var z = sdsdot.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 );
// returns 128.0
```

Expand All @@ -163,22 +155,14 @@ var z = sdsdot.ndarray( N, 0.0, 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 sdsdot = require( '@stdlib/blas/base/sdsdot' );

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 );

var z = sdsdot( x.length, 0.0, x, 1, y, -1 );
Expand Down
23 changes: 10 additions & 13 deletions lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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 sdsdot = require( './../lib/sdsdot.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,16 +44,8 @@ var sdsdot = require( './../lib/sdsdot.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()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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 sdsdot = tryRequire( resolve( __dirname, './../lib/sdsdot.native.js' ) );
var opts = {
'skip': ( sdsdot 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()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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 sdsdot = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,16 +44,8 @@ var sdsdot = 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()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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 sdsdot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( sdsdot 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()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float32', rand );
var y = filledarrayBy( len, 'float32', rand );
return benchmark;

function benchmark( b ) {
Expand Down
21 changes: 9 additions & 12 deletions lib/node_modules/@stdlib/blas/base/sdsdot/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the dot product of two single-precision floating-point vectors with
extended accumulation.

The `N`, `strideX`, and `strideY` 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 a typed
array view.
Expand Down Expand Up @@ -34,7 +34,7 @@
Returns
-------
dot: number
The dot product of `x` and `y`.
The dot product.

Examples
--------
Expand All @@ -47,19 +47,18 @@
// Strides:
> 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 );
> dot = {{alias}}( N, 0.0, x, 2, y, -1 )
> dot = {{alias}}( 3, 0.0, x, 2, y, -1 )
9.0

// Using view offsets:
> 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 x1 = new {{alias:@stdlib/array/float32}}( x.buffer, x.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:@stdlib/array/float32}}( y.buffer, y.BYTES_PER_ELEMENT*3 );
> N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> dot = {{alias}}( N, 0.0, x1, -2, y1, 1 )
> dot = {{alias}}( 3, 0.0, x1, -2, y1, 1 )
128.0


{{alias}}.ndarray( N, scalar, x, strideX, offsetX, y, strideY, offsetY )
Computes the dot product of two single-precision floating-point vectors
using alternative indexing semantics and with extended accumulation.
Expand Down Expand Up @@ -97,7 +96,7 @@
Returns
-------
dot: number
The dot product of `x` and `y`.
The dot product.

Examples
--------
Expand All @@ -110,15 +109,13 @@
// Strides:
> 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 );
> dot = {{alias}}.ndarray( N, 0.0, x, 2, 0, y, 2, 0 )
> dot = {{alias}}.ndarray( 3, 0.0, x, 2, 0, y, 2, 0 )
9.0

// Using offset indices:
> 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 ] );
> N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> dot = {{alias}}.ndarray( N, 0.0, x, -2, x.length-1, y, 1, 3 )
> dot = {{alias}}.ndarray( 3, 0.0, x, -2, x.length-1, y, 1, 3 )
128.0

References
Expand Down
Loading

0 comments on commit c8985f2

Please sign in to comment.