Skip to content

Commit 678f294

Browse files
headlessNodekgryte
andauthored
refactor: update blas/ext/base/gapxsum to follow current project conventions
PR-URL: #4348 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 8e4ef81 commit 678f294

File tree

10 files changed

+91
-122
lines changed

10 files changed

+91
-122
lines changed

lib/node_modules/@stdlib/blas/ext/base/gapxsum/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
# gapxsum
2222

23-
> Add a constant to each strided array element and compute the sum.
23+
> Add a scalar constant to each strided array element and compute the sum.
2424
2525
<section class="intro">
2626

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

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

41-
Adds a constant to each strided array element and computes the sum.
41+
Adds a scalar constant to each strided array element and computes the sum.
4242

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

47-
var v = gapxsum( N, 5.0, x, 1 );
46+
var v = gapxsum( 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 = gapxsum( N, 5.0, x, 2 );
61+
var v = gapxsum( 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 = gapxsum( N, 5.0, x1, 2 );
75+
var v = gapxsum( 4, 5.0, x1, 2 );
8376
// returns 25.0
8477
```
8578

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

88-
Adds a constant to each strided array element and computes the sum using alternative indexing semantics.
81+
Adds a scalar constant to each strided array element and computes the sum using alternative indexing semantics.
8982

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

94-
var v = gapxsum.ndarray( N, 5.0, x, 1, 0 );
86+
var v = gapxsum.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 = gapxsum.ndarray( N, 5.0, x, 2, 1 );
99+
var v = gapxsum.ndarray( 4, 5.0, x, 2, 1 );
111100
// returns 25.0
112101
```
113102

@@ -133,18 +122,12 @@ var v = gapxsum.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 gapxsum = require( '@stdlib/blas/ext/base/gapxsum' );
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 = gapxsum( x.length, 5.0, x, 1 );

lib/node_modules/@stdlib/blas/ext/base/gapxsum/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 gapxsum = 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 gapxsum = 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/gapxsum/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 gapxsum = 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 gapxsum = 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/gapxsum/docs/repl.txt

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

2-
{{alias}}( N, alpha, x, stride )
3-
Adds a constant to each strided array element and computes the sum.
2+
{{alias}}( N, alpha, x, strideX )
3+
Adds a scalar constant to each strided array element and computes the sum.
44

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

8-
Indexing is relative to the first index. To introduce an offset, use a typed
9-
array view.
8+
Indexing is relative to the first index. To introduce an offset, use typed
9+
array views.
1010

1111
If `N <= 0`, the function returns `0.0`.
1212

@@ -16,13 +16,13 @@
1616
Number of indexed elements.
1717

1818
alpha: number
19-
Constant.
19+
Scalar constant.
2020

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

24-
stride: integer
25-
Index increment.
24+
strideX: integer
25+
Stride length.
2626

2727
Returns
2828
-------
@@ -36,27 +36,24 @@
3636
> {{alias}}( x.length, 5.0, x, 1 )
3737
16.0
3838

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

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

54-
{{alias}}.ndarray( N, alpha, x, stride, offset )
55-
Adds a constant to each strided array element and computes the sum using
56-
alternative indexing semantics.
50+
51+
{{alias}}.ndarray( N, alpha, x, strideX, offsetX )
52+
Adds a scalar constant to each strided array element and computes the sum
53+
using alternative indexing semantics.
5754

5855
While typed array views mandate a view offset based on the underlying
59-
buffer, the `offset` parameter supports indexing semantics based on a
56+
buffer, the offset parameter supports indexing semantics based on a
6057
starting index.
6158

6259
Parameters
@@ -65,15 +62,15 @@
6562
Number of indexed elements.
6663

6764
alpha: number
68-
Constant.
65+
Scalar constant.
6966

7067
x: Array<number>|TypedArray
7168
Input array.
7269

73-
stride: integer
74-
Index increment.
70+
strideX: integer
71+
Stride length.
7572

76-
offset: integer
73+
offsetX: integer
7774
Starting index.
7875

7976
Returns
@@ -90,8 +87,7 @@
9087

9188
// Using offset parameter:
9289
> var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ];
93-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
94-
> {{alias}}.ndarray( N, 5.0, x, 2, 1 )
90+
> {{alias}}.ndarray( 3, 5.0, x, 2, 1 )
9591
14.0
9692

9793
See Also

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

Lines changed: 10 additions & 10 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.
30+
* Adds a scalar constant to each strided array element and computes the sum.
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 = gapxsum( 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 alternative indexing semantics.
47+
* Adds a scalar constant to each strided array element and computes the sum using alternative indexing semantics.
4848
*
4949
* @param N - number of indexed elements
5050
* @param alpha - 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 = gapxsum.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.
66+
* Adds a scalar constant to each strided array element and computes the sum.
6767
*
6868
* @param N - number of indexed elements
6969
* @param alpha - 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/gapxsum/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 gapxsum = 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 = gapxsum( x.length, 5.0, x, 1 );

0 commit comments

Comments
 (0)