Skip to content

Commit c217016

Browse files
headlessNodekgryte
andauthored
refactor: update blas/ext/base/gfill-by to follow current project conventions
PR-URL: #4553 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent b5162a4 commit c217016

File tree

7 files changed

+64
-117
lines changed

7 files changed

+64
-117
lines changed

lib/node_modules/@stdlib/blas/ext/base/gfill-by/README.md

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ limitations under the License.
3030
var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' );
3131
```
3232

33-
#### gfillBy( N, x, stride, clbk\[, thisArg] )
33+
#### gfillBy( N, x, strideX, clbk\[, thisArg] )
3434

35-
Fills a strided array `x` according to a provided callback function.
35+
Fills a strided array according to a provided callback function.
3636

3737
```javascript
3838
function fill( v, i ) {
@@ -48,17 +48,17 @@ gfillBy( x.length, x, 1, fill );
4848
The function has the following parameters:
4949

5050
- **N**: number of indexed elements.
51-
- **x**: input array.
52-
- **stride**: index increment.
51+
- **x**: input array.
52+
- **strideX**: stride length.
5353
- **clbk**: callback function.
5454
- **thisArg**: execution context (_optional_).
5555

56-
The invoked callback is provided four arguments:
56+
The callback function is provided the following arguments:
5757

58-
- **value**: array element.
58+
- **value**: current array element.
5959
- **aidx**: array index.
6060
- **sidx**: strided index (`offset + aidx*stride`).
61-
- **array**: input array/collection.
61+
- **array**: the input array.
6262

6363
To set the callback execution context, provide a `thisArg`.
6464

@@ -81,27 +81,23 @@ var cnt = context.count;
8181
// returns 8
8282
```
8383

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

8686
```javascript
87-
var floor = require( '@stdlib/math/base/special/floor' );
88-
8987
function fill( v, i ) {
9088
return v * i;
9189
}
9290

9391
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
94-
var N = floor( x.length / 2 );
9592

96-
gfillBy( N, x, 2, fill );
93+
gfillBy( 4, x, 2, fill );
9794
// x => [ 0.0, 1.0, 3.0, -5.0, 8.0, 0.0, -3.0, -3.0 ]
9895
```
9996

10097
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
10198

10299
```javascript
103100
var Float64Array = require( '@stdlib/array/float64' );
104-
var floor = require( '@stdlib/math/base/special/floor' );
105101

106102
function fill( v, i ) {
107103
return v * i;
@@ -112,16 +108,15 @@ var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
112108

113109
// Create an offset view...
114110
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
115-
var N = floor( x0.length/2 );
116111

117112
// Fill every other element...
118-
gfillBy( N, x1, 2, fill );
113+
gfillBy( 3, x1, 2, fill );
119114
// x0 => <Float64Array>[ 1.0, 0.0, 3.0, -4.0, 5.0, -12.0 ]
120115
```
121116

122-
#### gfillBy.ndarray( N, x, stride, offset, clbk\[, thisArg] )
117+
#### gfillBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] )
123118

124-
Fills a strided array `x` according to a provided callback function and using alternative indexing semantics.
119+
Fills a strided array according to a provided callback function and using alternative indexing semantics.
125120

126121
```javascript
127122
function fill( v, i ) {
@@ -136,9 +131,9 @@ gfillBy.ndarray( x.length, x, 1, 0, fill );
136131

137132
The function has the following additional parameters:
138133

139-
- **offset**: starting index.
134+
- **offsetX**: starting index.
140135

141-
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 only the last three elements of `x`
136+
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 only the last three elements:
142137

143138
```javascript
144139
function fill( v, i ) {
@@ -174,26 +169,14 @@ gfillBy.ndarray( 3, x, 1, x.length-3, fill );
174169
<!-- eslint no-undef: "error" -->
175170

176171
```javascript
177-
var round = require( '@stdlib/math/base/special/round' );
178-
var randu = require( '@stdlib/random/base/randu' );
172+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
179173
var Float64Array = require( '@stdlib/array/float64' );
180174
var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' );
181175

182-
function fill() {
183-
var rand = round( randu()*100.0 );
184-
var sign = randu();
185-
if ( sign < 0.5 ) {
186-
sign = -1.0;
187-
} else {
188-
sign = 1.0;
189-
}
190-
return sign * rand;
191-
}
192-
193176
var x = new Float64Array( 10 );
194177
console.log( x );
195178

196-
gfillBy( x.length, x, 1, fill );
179+
gfillBy( x.length, x, 1, discreteUniform( -100, 100 ) );
197180
console.log( x );
198181
```
199182

lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/repl.txt

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
{{alias}}( N, x, stride, clbk[, thisArg] )
2+
{{alias}}( N, x, strideX, clbk[, thisArg] )
33
Fills a strided array according to a provided callback function.
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

88
Indexing is relative to the first index. To introduce an offset, use typed
99
array views.
@@ -12,7 +12,7 @@
1212

1313
The callback function is provided four arguments:
1414

15-
- value: array element.
15+
- value: current array element.
1616
- aidx: array index.
1717
- sidx: strided index (offset + aidx*stride).
1818
- array: the input array.
@@ -28,8 +28,8 @@
2828
x: ArrayLikeObject
2929
Input array.
3030

31-
stride: integer
32-
Index increment for `x`.
31+
strideX: integer
32+
Stride length.
3333

3434
clbk: Function
3535
Callback function.
@@ -40,7 +40,7 @@
4040
Returns
4141
-------
4242
x: ArrayLikeObject
43-
Input array `x`.
43+
Input array.
4444

4545
Examples
4646
--------
@@ -50,28 +50,26 @@
5050
> {{alias}}( x.length, x, 1, fill )
5151
[ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]
5252

53-
// Using `N` and `stride` parameters:
53+
// Using `N` and stride parameters:
5454
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ];
55-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
56-
> {{alias}}( N, x, 2, fill )
55+
> {{alias}}( 3, x, 2, fill )
5756
[ 5.0, 1.0, 5.0, -5.0, 5.0, -1.0, -3.0 ]
5857

5958
// Using view offsets:
6059
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
6160
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
62-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
63-
> {{alias}}( N, x1, 2, fill )
61+
> {{alias}}( 3, x1, 2, fill )
6462
<Float64Array>[ 5.0, 3.0, 5.0, 5.0, 5.0 ]
6563
> x0
6664
<Float64Array>[ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ]
6765

6866

69-
{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] )
67+
{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] )
7068
Fills a strided array according to a provided callback function and using
7169
alternative indexing semantics.
7270

7371
While typed array views mandate a view offset based on the underlying
74-
buffer, the `offset` parameter supports indexing semantics based on a
72+
buffer, the offset parameter supports indexing semantics based on a
7573
starting index.
7674

7775
Parameters
@@ -82,11 +80,11 @@
8280
x: ArrayLikeObject
8381
Input array.
8482

85-
stride: integer
86-
Index increment for `x`.
83+
strideX: integer
84+
Stride length.
8785

88-
offset: integer
89-
Starting index of `x`.
86+
offsetX: integer
87+
Starting index.
9088

9189
clbk: Function
9290
Callback function.
@@ -97,7 +95,7 @@
9795
Returns
9896
-------
9997
x: ArrayLikeObject
100-
Input array `x`.
98+
Input array.
10199

102100
Examples
103101
--------
@@ -109,8 +107,7 @@
109107

110108
// Using an index offset:
111109
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
112-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
113-
> {{alias}}.ndarray( N, x, 2, 1, fill )
110+
> {{alias}}.ndarray( 3, x, 2, 1, fill )
114111
[ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ]
115112

116113
See Also

lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/types/index.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ interface Routine {
9898
*
9999
* @param N - number of indexed elements
100100
* @param x - input array
101-
* @param stride - stride length
102-
* @param clbk - callback
101+
* @param strideX - stride length
102+
* @param clbk - callback function
103103
* @param thisArg - execution context
104104
* @returns `x`
105105
*
@@ -113,7 +113,7 @@ interface Routine {
113113
* gfillBy( x.length, x, 1, fill );
114114
* // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ]
115115
*/
116-
<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, stride: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
116+
<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, strideX: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
117117

118118
/**
119119
* Fills a strided array according to a provided callback function and using alternative indexing semantics.
@@ -131,9 +131,9 @@ interface Routine {
131131
*
132132
* @param N - number of indexed elements
133133
* @param x - input array
134-
* @param stride - stride length
135-
* @param offset - starting index
136-
* @param clbk - callback
134+
* @param strideX - stride length
135+
* @param offsetX - starting index
136+
* @param clbk - callback function
137137
* @param thisArg - execution context
138138
* @returns `x`
139139
*
@@ -147,7 +147,7 @@ interface Routine {
147147
* gfillBy.ndarray( x.length, x, 1, 0, fill );
148148
* // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ]
149149
*/
150-
ndarray<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, stride: number, offset: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
150+
ndarray<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, strideX: number, offsetX: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
151151
}
152152

153153
/**
@@ -166,8 +166,8 @@ interface Routine {
166166
*
167167
* @param N - number of indexed elements
168168
* @param x - input array
169-
* @param stride - stride length
170-
* @param clbk - callback
169+
* @param strideX - stride length
170+
* @param clbk - callback function
171171
* @param thisArg - execution context
172172
* @returns `x`
173173
*

lib/node_modules/@stdlib/blas/ext/base/gfill-by/examples/index.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,12 @@
1818

1919
'use strict';
2020

21-
var round = require( '@stdlib/math/base/special/round' );
22-
var randu = require( '@stdlib/random/base/randu' );
21+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
2322
var Float64Array = require( '@stdlib/array/float64' );
2423
var gfillBy = require( './../lib' );
2524

26-
function fill() {
27-
var rand = round( randu()*100.0 );
28-
var sign = randu();
29-
if ( sign < 0.5 ) {
30-
sign = -1.0;
31-
} else {
32-
sign = 1.0;
33-
}
34-
return sign * rand;
35-
}
36-
3725
var x = new Float64Array( 10 );
3826
console.log( x );
3927

40-
gfillBy( x.length, x, 1, fill );
28+
gfillBy( x.length, x, 1, discreteUniform( -100, 100 ) );
4129
console.log( x );

lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/accessors.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
* @param {Object} x - input array object
2929
* @param {Collection} x.data - input array data
3030
* @param {Array<Function>} x.accessors - array element accessors
31-
* @param {integer} stride - index increment
32-
* @param {NonNegativeInteger} offset - starting index
33-
* @param {Callback} clbk - callback
31+
* @param {integer} strideX - stride length
32+
* @param {NonNegativeInteger} offsetX - starting index
33+
* @param {Callback} clbk - callback function
3434
* @param {*} thisArg - execution context
3535
* @returns {Object} input array object
3636
*
@@ -63,7 +63,7 @@
6363
* var view = reinterpret64( x.data, 0 );
6464
* // view => <Float32Array>[ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]
6565
*/
66-
function gfillBy( N, x, stride, offset, clbk, thisArg ) {
66+
function gfillBy( N, x, strideX, offsetX, clbk, thisArg ) {
6767
var xbuf;
6868
var set;
6969
var get;
@@ -77,10 +77,10 @@ function gfillBy( N, x, stride, offset, clbk, thisArg ) {
7777
get = x.accessors[ 0 ];
7878
set = x.accessors[ 1 ];
7979

80-
ix = offset;
80+
ix = offsetX;
8181
for ( i = 0; i < N; i++ ) {
8282
set( xbuf, ix, clbk.call( thisArg, get( xbuf, ix ), i, ix, x ) );
83-
ix += stride;
83+
ix += strideX;
8484
}
8585
return x;
8686
}

0 commit comments

Comments
 (0)