Skip to content

Commit c8985f2

Browse files
Pranavchikukgryte
andauthored
refactor: update add-on, examples, benchmarks, and docs
This commit migrates `@stdlib/blas/base/sdsdot` to use current project conventions, as discussed in #788. PR-URL: #799 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 5c4c206 commit c8985f2

22 files changed

+202
-325
lines changed

lib/node_modules/@stdlib/blas/base/sdsdot/README.md

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2020 The Stdlib Authors.
5+
Copyright (c) 2023 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -70,18 +70,15 @@ The function has the following parameters:
7070
- **y**: input [`Float32Array`][@stdlib/array/float32].
7171
- **strideY**: index increment for `y`.
7272

73-
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,
73+
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,
7474

7575
```javascript
7676
var Float32Array = require( '@stdlib/array/float32' );
77-
var floor = require( '@stdlib/math/base/special/floor' );
7877

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

82-
var N = floor( x.length / 2 );
83-
84-
var z = sdsdot( N, 0.0, x, 2, y, -1 );
81+
var z = sdsdot( 3, 0.0, x, 2, y, -1 );
8582
// returns 9.0
8683
```
8784

@@ -101,9 +98,7 @@ var y0 = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
10198
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
10299
var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
103100

104-
var N = floor( x0.length / 2 );
105-
106-
var z = sdsdot( N, 0.0, x1, -2, y1, 1 );
101+
var z = sdsdot( 3, 0.0, x1, -2, y1, 1 );
107102
// returns 128.0
108103
```
109104

@@ -126,18 +121,15 @@ The function has the following additional parameters:
126121
- **offsetX**: starting index for `x`.
127122
- **offsetY**: starting index for `y`.
128123

129-
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
124+
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
130125

131126
```javascript
132127
var Float32Array = require( '@stdlib/array/float32' );
133-
var floor = require( '@stdlib/math/base/special/floor' );
134128

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

138-
var N = floor( x.length / 2 );
139-
140-
var z = sdsdot.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
132+
var z = sdsdot.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 );
141133
// returns 128.0
142134
```
143135

@@ -163,22 +155,14 @@ var z = sdsdot.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
163155
<!-- eslint no-undef: "error" -->
164156

165157
```javascript
166-
var randu = require( '@stdlib/random/base/randu' );
167-
var round = require( '@stdlib/math/base/special/round' );
168-
var Float32Array = require( '@stdlib/array/float32' );
158+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
159+
var filledarrayBy = require( '@stdlib/array/filled-by' );
169160
var sdsdot = require( '@stdlib/blas/base/sdsdot' );
170161

171-
var x;
172-
var y;
173-
var i;
174-
175-
x = new Float32Array( 10 );
176-
y = new Float32Array( 10 );
177-
for ( i = 0; i < x.length; i++ ) {
178-
x[ i ] = round( randu() * 100.0 );
179-
y[ i ] = round( randu() * 10.0 );
180-
}
162+
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
181163
console.log( x );
164+
165+
var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) );
182166
console.log( y );
183167

184168
var z = sdsdot( x.length, 0.0, x, 1, y, -1 );

lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,14 +21,19 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
25+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float32Array = require( '@stdlib/array/float32' );
2828
var pkg = require( './../package.json' ).name;
2929
var sdsdot = require( './../lib/sdsdot.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var rand = uniform( -100.0, 100.0 );
35+
36+
3237
// FUNCTIONS //
3338

3439
/**
@@ -39,16 +44,8 @@ var sdsdot = require( './../lib/sdsdot.js' );
3944
* @returns {Function} benchmark function
4045
*/
4146
function createBenchmark( len ) {
42-
var x;
43-
var y;
44-
var i;
45-
46-
x = new Float32Array( len );
47-
y = new Float32Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20.0 ) - 10.0;
50-
y[ i ] = ( randu()*20.0 ) - 10.0;
51-
}
47+
var x = filledarrayBy( len, 'float32', rand );
48+
var y = filledarrayBy( len, 'float32', rand );
5249
return benchmark;
5350

5451
function benchmark( b ) {

lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.native.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2929
var tryRequire = require( '@stdlib/utils/try-require' );
3030
var pkg = require( './../package.json' ).name;
3131

@@ -36,6 +36,7 @@ var sdsdot = tryRequire( resolve( __dirname, './../lib/sdsdot.native.js' ) );
3636
var opts = {
3737
'skip': ( sdsdot instanceof Error )
3838
};
39+
var rand = uniform( -100.0, 100.0 );
3940

4041

4142
// FUNCTIONS //
@@ -48,16 +49,8 @@ var opts = {
4849
* @returns {Function} benchmark function
4950
*/
5051
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float32Array( len );
56-
y = new Float32Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20.0 ) - 10.0;
59-
y[ i ] = ( randu()*20.0 ) - 10.0;
60-
}
52+
var x = filledarrayBy( len, 'float32', rand );
53+
var y = filledarrayBy( len, 'float32', rand );
6154
return benchmark;
6255

6356
function benchmark( b ) {

lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,14 +21,19 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
25+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float32Array = require( '@stdlib/array/float32' );
2828
var pkg = require( './../package.json' ).name;
2929
var sdsdot = require( './../lib/ndarray.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var rand = uniform( -100.0, 100.0 );
35+
36+
3237
// FUNCTIONS //
3338

3439
/**
@@ -39,16 +44,8 @@ var sdsdot = require( './../lib/ndarray.js' );
3944
* @returns {Function} benchmark function
4045
*/
4146
function createBenchmark( len ) {
42-
var x;
43-
var y;
44-
var i;
45-
46-
x = new Float32Array( len );
47-
y = new Float32Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20.0 ) - 10.0;
50-
y[ i ] = ( randu()*20.0 ) - 10.0;
51-
}
47+
var x = filledarrayBy( len, 'float32', rand );
48+
var y = filledarrayBy( len, 'float32', rand );
5249
return benchmark;
5350

5451
function benchmark( b ) {

lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.native.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,10 +22,10 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2929
var tryRequire = require( '@stdlib/utils/try-require' );
3030
var pkg = require( './../package.json' ).name;
3131

@@ -36,6 +36,7 @@ var sdsdot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3636
var opts = {
3737
'skip': ( sdsdot instanceof Error )
3838
};
39+
var rand = uniform( -100.0, 100.0 );
3940

4041

4142
// FUNCTIONS //
@@ -48,16 +49,8 @@ var opts = {
4849
* @returns {Function} benchmark function
4950
*/
5051
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float32Array( len );
56-
y = new Float32Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20.0 ) - 10.0;
59-
y[ i ] = ( randu()*20.0 ) - 10.0;
60-
}
52+
var x = filledarrayBy( len, 'float32', rand );
53+
var y = filledarrayBy( len, 'float32', rand );
6154
return benchmark;
6255

6356
function benchmark( b ) {

lib/node_modules/@stdlib/blas/base/sdsdot/docs/repl.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Computes the dot product of two single-precision floating-point vectors with
44
extended accumulation.
55

6-
The `N`, `strideX`, and `strideY` parameters determine which elements in `x`
7-
and `y` are accessed at runtime.
6+
The `N` and stride parameters determine which elements in the strided arrays
7+
are accessed at runtime.
88

99
Indexing is relative to the first index. To introduce an offset, use a typed
1010
array view.
@@ -34,7 +34,7 @@
3434
Returns
3535
-------
3636
dot: number
37-
The dot product of `x` and `y`.
37+
The dot product.
3838

3939
Examples
4040
--------
@@ -47,19 +47,18 @@
4747
// Strides:
4848
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4949
> y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
50-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
51-
> dot = {{alias}}( N, 0.0, x, 2, y, -1 )
50+
> dot = {{alias}}( 3, 0.0, x, 2, y, -1 )
5251
9.0
5352

5453
// Using view offsets:
5554
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
5655
> y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
5756
> var x1 = new {{alias:@stdlib/array/float32}}( x.buffer, x.BYTES_PER_ELEMENT*1 );
5857
> var y1 = new {{alias:@stdlib/array/float32}}( y.buffer, y.BYTES_PER_ELEMENT*3 );
59-
> N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
60-
> dot = {{alias}}( N, 0.0, x1, -2, y1, 1 )
58+
> dot = {{alias}}( 3, 0.0, x1, -2, y1, 1 )
6159
128.0
6260

61+
6362
{{alias}}.ndarray( N, scalar, x, strideX, offsetX, y, strideY, offsetY )
6463
Computes the dot product of two single-precision floating-point vectors
6564
using alternative indexing semantics and with extended accumulation.
@@ -97,7 +96,7 @@
9796
Returns
9897
-------
9998
dot: number
100-
The dot product of `x` and `y`.
99+
The dot product.
101100

102101
Examples
103102
--------
@@ -110,15 +109,13 @@
110109
// Strides:
111110
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
112111
> y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
113-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
114-
> dot = {{alias}}.ndarray( N, 0.0, x, 2, 0, y, 2, 0 )
112+
> dot = {{alias}}.ndarray( 3, 0.0, x, 2, 0, y, 2, 0 )
115113
9.0
116114

117115
// Using offset indices:
118116
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
119117
> y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
120-
> N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
121-
> dot = {{alias}}.ndarray( N, 0.0, x, -2, x.length-1, y, 1, 3 )
118+
> dot = {{alias}}.ndarray( 3, 0.0, x, -2, x.length-1, y, 1, 3 )
122119
128.0
123120

124121
References

0 commit comments

Comments
 (0)