Skip to content

Commit 3d2831c

Browse files
headlessNodekgryte
authored andcommitted
refactor: update blas/ext/base/gapxsumkbn to follow current project conventions
PR-URL: stdlib-js#4358 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 0a2fa41 commit 3d2831c

File tree

12 files changed

+100
-161
lines changed

12 files changed

+100
-161
lines changed

lib/node_modules/@stdlib/blas/ext/base/gapxsumkbn/README.md

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# gapxsumkbn
2222

23-
> Add a constant to each strided array element and compute the sum using an improved Kahan–Babuška algorithm.
23+
> Add a scalar constant to each strided array element and compute the sum using an improved Kahan–Babuška algorithm.
2424
2525
<section class="intro">
2626

@@ -36,33 +36,29 @@ limitations under the License.
3636
var gapxsumkbn = require( '@stdlib/blas/ext/base/gapxsumkbn' );
3737
```
3838

39-
#### gapxsumkbn( N, alpha, x, stride )
39+
#### gapxsumkbn( N, alpha, x, strideX )
4040

41-
Adds a constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm.
41+
Adds a scalar constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm.
4242

4343
```javascript
4444
var x = [ 1.0, -2.0, 2.0 ];
45-
var N = x.length;
4645

47-
var v = gapxsumkbn( N, 5.0, x, 1 );
46+
var v = gapxsumkbn( x.length, 5.0, x, 1 );
4847
// returns 16.0
4948
```
5049

5150
The function has the following parameters:
5251

5352
- **N**: number of indexed elements.
5453
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
55-
- **stride**: index increment for `x`.
54+
- **strideX**: stride length.
5655

57-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element in `x`,
56+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element:
5857

5958
```javascript
60-
var floor = require( '@stdlib/math/base/special/floor' );
61-
6259
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
63-
var N = floor( x.length / 2 );
6460

65-
var v = gapxsumkbn( N, 5.0, x, 2 );
61+
var v = gapxsumkbn( 4, 5.0, x, 2 );
6662
// returns 25.0
6763
```
6864

@@ -72,42 +68,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [
7268

7369
```javascript
7470
var Float64Array = require( '@stdlib/array/float64' );
75-
var floor = require( '@stdlib/math/base/special/floor' );
7671

7772
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
7873
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
7974

80-
var N = floor( x0.length / 2 );
81-
82-
var v = gapxsumkbn( N, 5.0, x1, 2 );
75+
var v = gapxsumkbn( 4, 5.0, x1, 2 );
8376
// returns 25.0
8477
```
8578

86-
#### gapxsumkbn.ndarray( N, alpha, x, stride, offset )
79+
#### gapxsumkbn.ndarray( N, alpha, x, strideX, offsetX )
8780

88-
Adds a constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm and alternative indexing semantics.
81+
Adds a scalar constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm and alternative indexing semantics.
8982

9083
```javascript
9184
var x = [ 1.0, -2.0, 2.0 ];
92-
var N = x.length;
9385

94-
var v = gapxsumkbn.ndarray( N, 5.0, x, 1, 0 );
86+
var v = gapxsumkbn.ndarray( x.length, 5.0, x, 1, 0 );
9587
// returns 16.0
9688
```
9789

9890
The function has the following additional parameters:
9991

100-
- **offset**: starting index for `x`.
92+
- **offsetX**: starting index.
10193

102-
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 every other value in `x` starting from the second value
94+
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 every other element starting from the second element:
10395

10496
```javascript
105-
var floor = require( '@stdlib/math/base/special/floor' );
106-
10797
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
108-
var N = floor( x.length / 2 );
10998

110-
var v = gapxsumkbn.ndarray( N, 5.0, x, 2, 1 );
99+
var v = gapxsumkbn.ndarray( 4, 5.0, x, 2, 1 );
111100
// returns 25.0
112101
```
113102

@@ -133,18 +122,12 @@ var v = gapxsumkbn.ndarray( N, 5.0, x, 2, 1 );
133122
<!-- eslint no-undef: "error" -->
134123

135124
```javascript
136-
var randu = require( '@stdlib/random/base/randu' );
137-
var round = require( '@stdlib/math/base/special/round' );
138-
var Float64Array = require( '@stdlib/array/float64' );
125+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
139126
var gapxsumkbn = require( '@stdlib/blas/ext/base/gapxsumkbn' );
140127

141-
var x;
142-
var i;
143-
144-
x = new Float64Array( 10 );
145-
for ( i = 0; i < x.length; i++ ) {
146-
x[ i ] = round( randu()*100.0 );
147-
}
128+
var x = discreteUniform( 10, -100, 100, {
129+
'dtype': 'float64'
130+
});
148131
console.log( x );
149132

150133
var v = gapxsumkbn( x.length, 5.0, x, 1 );

lib/node_modules/@stdlib/blas/ext/base/gapxsumkbn/benchmark/benchmark.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var pkg = require( './../package.json' ).name;
2828
var gapxsumkbn = require( './../lib/main.js' );
2929

3030

31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'generic'
35+
};
36+
37+
3138
// FUNCTIONS //
3239

3340
/**
@@ -38,13 +45,7 @@ var gapxsumkbn = require( './../lib/main.js' );
3845
* @returns {Function} benchmark function
3946
*/
4047
function createBenchmark( len ) {
41-
var x;
42-
var i;
43-
44-
x = [];
45-
for ( i = 0; i < len; i++ ) {
46-
x.push( ( randu()*20.0 ) - 10.0 );
47-
}
48+
var x = uniform( len, -100, 100, options );
4849
return benchmark;
4950

5051
function benchmark( b ) {

lib/node_modules/@stdlib/blas/ext/base/gapxsumkbn/benchmark/benchmark.ndarray.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var pkg = require( './../package.json' ).name;
2828
var gapxsumkbn = require( './../lib/ndarray.js' );
2929

3030

31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'generic'
35+
};
36+
37+
3138
// FUNCTIONS //
3239

3340
/**
@@ -38,13 +45,7 @@ var gapxsumkbn = require( './../lib/ndarray.js' );
3845
* @returns {Function} benchmark function
3946
*/
4047
function createBenchmark( len ) {
41-
var x;
42-
var i;
43-
44-
x = [];
45-
for ( i = 0; i < len; i++ ) {
46-
x.push( ( randu()*20.0 ) - 10.0 );
47-
}
48+
var x = uniform( len, -100, 100, options );
4849
return benchmark;
4950

5051
function benchmark( b ) {

lib/node_modules/@stdlib/blas/ext/base/gapxsumkbn/docs/repl.txt

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
{{alias}}( N, alpha, x, stride )
3-
Adds a constant to each strided array element and computes the sum using an
4-
improved Kahan–Babuška algorithm.
2+
{{alias}}( N, alpha, x, strideX )
3+
Adds a scalar constant to each strided array element and computes the sum
4+
using an improved Kahan–Babuška algorithm.
55

6-
The `N` and `stride` parameters determine which elements in `x` are accessed
7-
at runtime.
6+
The `N` and stride parameters determine which elements in the strided array
7+
are accessed at runtime.
88

99
Indexing is relative to the first index. To introduce an offset, use a typed
1010
array view.
@@ -17,13 +17,13 @@
1717
Number of indexed elements.
1818

1919
alpha: number
20-
Constant.
20+
Scalar constant.
2121

2222
x: Array<number>|TypedArray
2323
Input array.
2424

25-
stride: integer
26-
Index increment.
25+
strideX: integer
26+
Stride length.
2727

2828
Returns
2929
-------
@@ -37,27 +37,25 @@
3737
> {{alias}}( x.length, 5.0, x, 1 )
3838
16.0
3939

40-
// Using `N` and `stride` parameters:
40+
// Using `N` and stride parameters:
4141
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ];
42-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
43-
> var stride = 2;
44-
> {{alias}}( N, 5.0, x, stride )
42+
> {{alias}}( 3, 5.0, x, 2 )
4543
16.0
4644

4745
// Using view offsets:
4846
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
4947
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
50-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
51-
> stride = 2;
52-
> {{alias}}( N, 5.0, x1, stride )
48+
> {{alias}}( 3, 5.0, x1, 2 )
5349
14.0
5450

55-
{{alias}}.ndarray( N, alpha, x, stride, offset )
56-
Adds a constant to each strided array element and computes the sum using an
57-
improved Kahan–Babuška algorithm and alternative indexing semantics.
51+
52+
{{alias}}.ndarray( N, alpha, x, strideX, offsetX )
53+
Adds a scalar constant to each strided array element and computes the sum
54+
using an improved Kahan–Babuška algorithm and alternative indexing
55+
semantics.
5856

5957
While typed array views mandate a view offset based on the underlying
60-
buffer, the `offset` parameter supports indexing semantics based on a
58+
buffer, the offset parameter supports indexing semantics based on a
6159
starting index.
6260

6361
Parameters
@@ -66,15 +64,15 @@
6664
Number of indexed elements.
6765

6866
alpha: number
69-
Constant.
67+
Scalar constant.
7068

7169
x: Array<number>|TypedArray
7270
Input array.
7371

74-
stride: integer
75-
Index increment.
72+
strideX: integer
73+
Stride length.
7674

77-
offset: integer
75+
offsetX: integer
7876
Starting index.
7977

8078
Returns
@@ -91,8 +89,7 @@
9189

9290
// Using offset parameter:
9391
> var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ];
94-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
95-
> {{alias}}.ndarray( N, 5.0, x, 2, 1 )
92+
> {{alias}}.ndarray( 3, 5.0, x, 2, 1 )
9693
14.0
9794

9895
See Also

lib/node_modules/@stdlib/blas/ext/base/gapxsumkbn/docs/types/index.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import { NumericArray } from '@stdlib/types/array';
2727
*/
2828
interface Routine {
2929
/**
30-
* Adds a constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm.
30+
* Adds a scalar constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm.
3131
*
3232
* @param N - number of indexed elements
33-
* @param alpha - constant
33+
* @param alpha - scalar constant
3434
* @param x - input array
35-
* @param stride - stride length
35+
* @param strideX - stride length
3636
* @returns sum
3737
*
3838
* @example
@@ -41,16 +41,16 @@ interface Routine {
4141
* var v = gapxsumkbn( x.length, 5.0, x, 1 );
4242
* // returns 16.0
4343
*/
44-
( N: number, alpha: number, x: NumericArray, stride: number ): number;
44+
( N: number, alpha: number, x: NumericArray, strideX: number ): number;
4545

4646
/**
47-
* Adds a constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm and alternative indexing semantics.
47+
* Adds a scalar constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm and alternative indexing semantics.
4848
*
4949
* @param N - number of indexed elements
50-
* @param alpha - constant
50+
* @param alpha - scalar constant
5151
* @param x - input array
52-
* @param stride - stride length
53-
* @param offset - starting index
52+
* @param strideX - stride length
53+
* @param offsetX - starting index
5454
* @returns sum
5555
*
5656
* @example
@@ -59,16 +59,16 @@ interface Routine {
5959
* var v = gapxsumkbn.ndarray( x.length, 5.0, x, 1, 0 );
6060
* // returns 16.0
6161
*/
62-
ndarray( N: number, alpha: number, x: NumericArray, stride: number, offset: number ): number;
62+
ndarray( N: number, alpha: number, x: NumericArray, strideX: number, offsetX: number ): number;
6363
}
6464

6565
/**
66-
* Adds a constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm.
66+
* Adds a scalar constant to each strided array element and computes the sum using an improved Kahan–Babuška algorithm.
6767
*
6868
* @param N - number of indexed elements
69-
* @param alpha - constant
69+
* @param alpha - scalar constant
7070
* @param x - input array
71-
* @param stride - stride length
71+
* @param strideX - stride length
7272
* @returns sum
7373
*
7474
* @example

lib/node_modules/@stdlib/blas/ext/base/gapxsumkbn/examples/index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
22-
var round = require( '@stdlib/math/base/special/round' );
23-
var Float64Array = require( '@stdlib/array/float64' );
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2422
var gapxsumkbn = require( './../lib' );
2523

26-
var x;
27-
var i;
28-
29-
x = new Float64Array( 10 );
30-
for ( i = 0; i < x.length; i++ ) {
31-
x[ i ] = round( randu()*100.0 );
32-
}
24+
var x = discreteUniform( 10, -100, 100, {
25+
'dtype': 'float64'
26+
});
3327
console.log( x );
3428

3529
var v = gapxsumkbn( x.length, 5.0, x, 1 );

0 commit comments

Comments
 (0)