Skip to content

Commit b5162a4

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

File tree

9 files changed

+92
-161
lines changed

9 files changed

+92
-161
lines changed

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

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

33-
#### gfill( N, alpha, x, stride )
33+
#### gfill( N, alpha, x, strideX )
3434

35-
Fills a strided array `x` with a specified scalar constant `alpha`.
35+
Fills a strided array with a specified scalar constant.
3636

3737
```javascript
3838
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
@@ -46,41 +46,36 @@ The function has the following parameters:
4646
- **N**: number of indexed elements.
4747
- **alpha**: scalar constant.
4848
- **x**: input array.
49-
- **stride**: index increment.
49+
- **strideX**: stride length.
5050

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

5353
```javascript
54-
var floor = require( '@stdlib/math/base/special/floor' );
55-
5654
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
57-
var N = floor( x.length / 2 );
5855

59-
gfill( N, 5.0, x, 2 );
56+
gfill( 4, 5.0, x, 2 );
6057
// x => [ 5.0, 1.0, 5.0, -5.0, 5.0, 0.0, 5.0, -3.0 ]
6158
```
6259

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

6562
```javascript
6663
var Float64Array = require( '@stdlib/array/float64' );
67-
var floor = require( '@stdlib/math/base/special/floor' );
6864

6965
// Initial array...
7066
var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
7167

7268
// Create an offset view...
7369
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
74-
var N = floor( x0.length/2 );
7570

7671
// Fill every other element...
77-
gfill( N, 5.0, x1, 2 );
72+
gfill( 3, 5.0, x1, 2 );
7873
// x0 => <Float64Array>[ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ]
7974
```
8075

81-
#### gfill.ndarray( N, alpha, x, stride, offset )
76+
#### gfill.ndarray( N, alpha, x, strideX, offsetX )
8277

83-
Fills a strided array `x` with a specified scalar constant `alpha` using alternative indexing semantics.
78+
Fills a strided array with a specified scalar constant using alternative indexing semantics.
8479

8580
```javascript
8681
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
@@ -91,9 +86,9 @@ gfill.ndarray( x.length, 5.0, x, 1, 0 );
9186

9287
The function has the following additional parameters:
9388

94-
- **offset**: starting index.
89+
- **offsetX**: starting index.
9590

96-
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`
91+
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:
9792

9893
```javascript
9994
var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
@@ -125,15 +120,12 @@ gfill.ndarray( 3, 5.0, x, 1, x.length-3 );
125120
<!-- eslint no-undef: "error" -->
126121

127122
```javascript
128-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
129-
var Float64Array = require( '@stdlib/array/float64' );
123+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
130124
var gfill = require( '@stdlib/blas/ext/base/gfill' );
131125

132-
var x = new Float64Array( 10 );
133-
var i;
134-
for ( i = 0; i < x.length; i++ ) {
135-
x[ i ] = discreteUniform( -100, 100 );
136-
}
126+
var x = discreteUniform( 10, -100, 100, {
127+
'dtype': 'float64'
128+
});
137129
console.log( x );
138130

139131
gfill( x.length, 5.0, x, 1 );

lib/node_modules/@stdlib/blas/ext/base/gfill/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 gfill = 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 gfill = 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/gfill/benchmark/benchmark.ndarray.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,18 @@
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;
28-
var gfill = require( './../lib/main.js' ).ndarray;
28+
var gfill = require( './../lib/ndarray.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'generic'
35+
};
2936

3037

3138
// FUNCTIONS //
@@ -38,13 +45,7 @@ var gfill = require( './../lib/main.js' ).ndarray;
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/gfill/docs/repl.txt

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

2-
{{alias}}( N, alpha, x, stride )
3-
Fills a strided array with a specified scalar value.
2+
{{alias}}( N, alpha, x, strideX )
3+
Fills a strided array with a specified scalar constant.
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.
@@ -16,18 +16,18 @@
1616
Number of indexed elements.
1717

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

2121
x: ArrayLikeObject
2222
Input array.
2323

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

2727
Returns
2828
-------
2929
x: ArrayLikeObject
30-
Input array `x`.
30+
Input array.
3131

3232
Examples
3333
--------
@@ -36,51 +36,49 @@
3636
> {{alias}}( x.length, 5.0, x, 1 )
3737
[ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]
3838

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

4544
// Using view offsets:
4645
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
4746
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
48-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
49-
> {{alias}}( N, 5.0, x1, 2 )
47+
> {{alias}}( 3, 5.0, x1, 2 )
5048
<Float64Array>[ 5.0, 3.0, 5.0, 5.0, 5.0 ]
5149
> x0
5250
<Float64Array>[ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ]
5351

5452

55-
{{alias}}.ndarray( N, alpha, x, stride, offset )
56-
Fills a strided array with a specified scalar value using alternative
53+
{{alias}}.ndarray( N, alpha, x, strideX, offsetX )
54+
Fills a strided array with a specified scalar constant using alternative
5755
indexing 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
61-
starting index.
58+
buffer, the offset parameter supports indexing semantics based on a starting
59+
index.
6260

6361
Parameters
6462
----------
6563
N: integer
6664
Number of indexed elements.
6765

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

7169
x: ArrayLikeObject
7270
Input array.
7371

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

77-
offset: integer
78-
Starting index of `x`.
75+
offsetX: integer
76+
Starting index.
7977

8078
Returns
8179
-------
8280
x: ArrayLikeObject
83-
Input array `x`.
81+
Input array.
8482

8583
Examples
8684
--------
@@ -91,8 +89,7 @@
9189

9290
// Using an index offset:
9391
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.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
[ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ]
9794

9895
See Also

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import { Collection } from '@stdlib/types/array';
2727
*/
2828
interface Routine {
2929
/**
30-
* Fills a strided array with a specified scalar value.
30+
* Fills a strided array with a specified scalar constant.
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 `x`
3737
*
3838
* @example
@@ -41,16 +41,16 @@ interface Routine {
4141
* gfill( x.length, 5.0, x, 1 );
4242
* // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ]
4343
*/
44-
<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, stride: number ): Collection<T | U>;
44+
<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, strideX: number ): Collection<T | U>;
4545

4646
/**
47-
* Fills a strided array with a specified scalar value using alternative indexing semantics.
47+
* Fills a strided array with a specified scalar constant using 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 `x`
5555
*
5656
* @example
@@ -59,16 +59,16 @@ interface Routine {
5959
* gfill.ndarray( x.length, 5.0, x, 1, 0 );
6060
* // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ]
6161
*/
62-
ndarray<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, stride: number, offset: number ): Collection<T | U>;
62+
ndarray<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, strideX: number, offsetX: number ): Collection<T | U>;
6363
}
6464

6565
/**
66-
* Fills a strided array with a specified scalar value.
66+
* Fills a strided array with a specified scalar constant.
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 `x`
7373
*
7474
* @example

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

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

1919
'use strict';
2020

21-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
22-
var Float64Array = require( '@stdlib/array/float64' );
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2322
var gfill = require( './../lib' );
2423

25-
var x = new Float64Array( 10 );
26-
var i;
27-
for ( i = 0; i < x.length; i++ ) {
28-
x[ i ] = discreteUniform( -100, 100 );
29-
}
24+
var x = discreteUniform( 10, -100, 100, {
25+
'dtype': 'float64'
26+
});
3027
console.log( x );
3128

3229
gfill( x.length, 5.0, x, 1 );

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
*
2626
* @private
2727
* @param {PositiveInteger} N - number of indexed elements
28-
* @param {*} alpha - scalar
28+
* @param {*} alpha - scalar constant
2929
* @param {Object} x - input array object
3030
* @param {Collection} x.data - input array data
3131
* @param {Array<Function>} x.accessors - array element accessors
32-
* @param {integer} stride - index increment
33-
* @param {NonNegativeInteger} offset - starting index
32+
* @param {integer} strideX - stride length
33+
* @param {NonNegativeInteger} offsetX - starting index
3434
* @returns {Object} input array object
3535
*
3636
* @example
@@ -56,7 +56,7 @@
5656
* var view = reinterpret64( x.data, 0 );
5757
* // view => <Float32Array>[ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]
5858
*/
59-
function gfill( N, alpha, x, stride, offset ) {
59+
function gfill( N, alpha, x, strideX, offsetX ) {
6060
var xbuf;
6161
var set;
6262
var ix;
@@ -68,10 +68,10 @@ function gfill( N, alpha, x, stride, offset ) {
6868
// Cache a reference to the element accessor:
6969
set = x.accessors[ 1 ];
7070

71-
ix = offset;
71+
ix = offsetX;
7272
for ( i = 0; i < N; i++ ) {
7373
set( xbuf, ix, alpha );
74-
ix += stride;
74+
ix += strideX;
7575
}
7676
return x;
7777
}

0 commit comments

Comments
 (0)