Skip to content

Commit ea9e425

Browse files
authored
refactor: update blas/ext/base/grev to follow current project conventions
PR-URL: #4659 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 53c0427 commit ea9e425

File tree

8 files changed

+63
-155
lines changed

8 files changed

+63
-155
lines changed

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

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

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

35-
Reverses a strided array `x` in-place.
35+
Reverses a strided array in-place.
3636

3737
```javascript
3838
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
@@ -45,41 +45,36 @@ The function has the following parameters:
4545

4646
- **N**: number of indexed elements.
4747
- **x**: input array.
48-
- **stride**: index increment.
48+
- **strideX**: stride length.
4949

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

5252
```javascript
53-
var floor = require( '@stdlib/math/base/special/floor' );
54-
5553
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
56-
var N = floor( x.length / 2 );
5754

58-
grev( N, x, 2 );
55+
grev( 4, x, 2 );
5956
// x => [ -1.0, 1.0, 4.0, -5.0, 3.0, 0.0, -2.0, -3.0 ]
6057
```
6158

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

6461
```javascript
6562
var Float64Array = require( '@stdlib/array/float64' );
66-
var floor = require( '@stdlib/math/base/special/floor' );
6763

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

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

7570
// Reverse every other element...
76-
grev( N, x1, 2 );
71+
grev( 3, x1, 2 );
7772
// x0 => <Float64Array>[ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ]
7873
```
7974

80-
#### grev.ndarray( N, x, stride, offset )
75+
#### grev.ndarray( N, x, strideX, offsetX )
8176

82-
Reverses a strided array `x` in-place using alternative indexing semantics.
77+
Reverses a strided array in-place using alternative indexing semantics.
8378

8479
```javascript
8580
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
@@ -90,9 +85,9 @@ grev.ndarray( x.length, x, 1, 0 );
9085

9186
The function has the following additional parameters:
9287

93-
- **offset**: starting index.
88+
- **offsetX**: starting index.
9489

95-
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`
90+
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:
9691

9792
```javascript
9893
var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
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 zeros = require( '@stdlib/array/base/zeros' );
26+
var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
@@ -38,13 +40,7 @@ var grev = require( './../lib/main.js' );
3840
* @returns {Function} benchmark function
3941
*/
4042
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-
}
43+
var x = gfillBy( len, zeros( len ), 1, uniform( -100, 100 ) );
4844
return benchmark;
4945

5046
function benchmark( b ) {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
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 zeros = require( '@stdlib/array/base/zeros' );
26+
var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
28-
var grev = require( './../lib/main.js' ).ndarray;
30+
var grev = require( './../lib/ndarray.js' );
2931

3032

3133
// FUNCTIONS //
@@ -38,13 +40,7 @@ var grev = require( './../lib/main.js' ).ndarray;
3840
* @returns {Function} benchmark function
3941
*/
4042
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-
}
43+
var x = gfillBy( len, zeros( len ), 1, uniform( -100, 100 ) );
4844
return benchmark;
4945

5046
function benchmark( b ) {

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

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

2-
{{alias}}( N, x, stride )
2+
{{alias}}( N, x, strideX )
33
Reverses a strided array in-place.
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.
@@ -18,8 +18,8 @@
1818
x: ArrayLikeObject
1919
Input array.
2020

21-
stride: integer
22-
Index increment for `x`.
21+
strideX: integer
22+
Stride length.
2323

2424
Returns
2525
-------
@@ -33,27 +33,25 @@
3333
> {{alias}}( x.length, x, 1 )
3434
[ -3.0, -1.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
3535

36-
// Using `N` and `stride` parameters:
36+
// Using `N` and stride parameters:
3737
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ];
38-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
39-
> {{alias}}( N, x, 2 )
38+
> {{alias}}( 3, x, 2 )
4039
[ 4.0, 1.0, 3.0, -5.0, -2.0, -1.0, -3.0 ]
4140

4241
// Using view offsets:
4342
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
4443
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
45-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
46-
> {{alias}}( N, x1, 2 )
44+
> {{alias}}( 3, x1, 2 )
4745
<Float64Array>[ -6.0, 3.0, -4.0, 5.0, -2.0 ]
4846
> x0
4947
<Float64Array>[ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ]
5048

5149

52-
{{alias}}.ndarray( N, x, stride, offset )
50+
{{alias}}.ndarray( N, x, strideX, offsetX )
5351
Reverses a strided array in-place using alternative indexing semantics.
5452

5553
While typed array views mandate a view offset based on the underlying
56-
buffer, the `offset` parameter supports indexing semantics based on a
54+
buffer, the offset parameter supports indexing semantics based on a
5755
starting index.
5856

5957
Parameters
@@ -64,11 +62,11 @@
6462
x: ArrayLikeObject
6563
Input array.
6664

67-
stride: integer
68-
Index increment for `x`.
65+
strideX: integer
66+
Stride length.
6967

70-
offset: integer
71-
Starting index of `x`.
68+
offsetX: integer
69+
Starting index.
7270

7371
Returns
7472
-------
@@ -84,8 +82,7 @@
8482

8583
// Using an index offset:
8684
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
87-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
88-
> {{alias}}.ndarray( N, x, 2, 1 )
85+
> {{alias}}.ndarray( 3, x, 2, 1 )
8986
[ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ]
9087

9188
See Also

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface Routine {
3131
*
3232
* @param N - number of indexed elements
3333
* @param x - input array
34-
* @param stride - stride length
34+
* @param strideX - stride length
3535
* @returns `x`
3636
*
3737
* @example
@@ -40,15 +40,15 @@ interface Routine {
4040
* grev( x.length, x, 1 );
4141
* // x => [ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
4242
*/
43-
<T = unknown>( N: number, x: Collection<T>, stride: number ): Collection<T>;
43+
<T = unknown>( N: number, x: Collection<T>, strideX: number ): Collection<T>;
4444

4545
/**
4646
* Reverses a strided array in-place. using alternative indexing semantics.
4747
*
4848
* @param N - number of indexed elements
4949
* @param x - input array
50-
* @param stride - stride length
51-
* @param offset - starting index
50+
* @param strideX - stride length
51+
* @param offsetX - starting index
5252
* @returns `x`
5353
*
5454
* @example
@@ -57,15 +57,15 @@ interface Routine {
5757
* grev.ndarray( x.length, x, 1, 0 );
5858
* // x => [ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
5959
*/
60-
ndarray<T = unknown>( N: number, x: Collection<T>, stride: number, offset: number ): Collection<T>;
60+
ndarray<T = unknown>( N: number, x: Collection<T>, strideX: number, offsetX: number ): Collection<T>;
6161
}
6262

6363
/**
6464
* Reverses a strided array in-place.
6565
*
6666
* @param N - number of indexed elements
6767
* @param x - input array
68-
* @param stride - stride length
68+
* @param strideX - stride length
6969
* @returns `x`
7070
*
7171
* @example

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ var floor = require( '@stdlib/math/base/special/floor' );
3434
* @param {Object} x - input array object
3535
* @param {Collection} x.data - input array data
3636
* @param {Array<Function>} x.accessors - array element accessors
37-
* @param {integer} stride - index increment
38-
* @param {NonNegativeInteger} offset - starting index
37+
* @param {integer} strideX - stride length
38+
* @param {NonNegativeInteger} offsetX - starting index
3939
* @returns {Object} input array object
4040
*
4141
* @example
@@ -63,7 +63,7 @@ var floor = require( '@stdlib/math/base/special/floor' );
6363
* var view = reinterpret64( x.data, 0 );
6464
* // view => <Float32Array>[ -1.0, -3.0, 4.0, 0.0, 3.0, -5.0, -2.0, 1.0 ]
6565
*/
66-
function grev( N, x, stride, offset ) {
66+
function grev( N, x, strideX, offsetX ) {
6767
var xbuf;
6868
var set;
6969
var get;
@@ -81,14 +81,14 @@ function grev( N, x, stride, offset ) {
8181
set = x.accessors[ 1 ];
8282

8383
n = floor( N/2 );
84-
ix = offset;
85-
iy = ix + ((N-1)*stride);
84+
ix = offsetX;
85+
iy = ix + ( ( N - 1 ) * strideX );
8686
for ( i = 0; i < n; i++ ) {
8787
tmp = get( xbuf, ix );
8888
set( xbuf, ix, get( xbuf, iy ) );
8989
set( xbuf, iy, tmp );
90-
ix += stride;
91-
iy -= stride;
90+
ix += strideX;
91+
iy -= strideX;
9292
}
9393
return x;
9494
}

0 commit comments

Comments
 (0)