Skip to content

Commit 0d2528e

Browse files
naveen1mkgryte
andauthored
refactor: update blas/ext/base/dapx to follow current project conventions
PR-URL: #1954 Closes: #1464 Ref: #1152 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent 23fba1c commit 0d2528e

File tree

17 files changed

+187
-284
lines changed

17 files changed

+187
-284
lines changed

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var dapx = require( '@stdlib/blas/ext/base/dapx' );
3232

3333
#### dapx( N, alpha, x, stride )
3434

35-
Adds a constant `alpha` to each element in a double-precision floating-point strided array `x`.
35+
Adds a constant `alpha` to each element in a double-precision floating-point strided array.
3636

3737
```javascript
3838
var Float64Array = require( '@stdlib/array/float64' );
@@ -50,40 +50,36 @@ The function has the following parameters:
5050
- **x**: input [`Float64Array`][@stdlib/array/float64].
5151
- **stride**: index increment.
5252

53-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to add a constant to every other element
53+
The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element
5454

5555
```javascript
5656
var Float64Array = require( '@stdlib/array/float64' );
57-
var floor = require( '@stdlib/math/base/special/floor' );
5857

5958
var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );
60-
var N = floor( x.length / 2 );
6159

62-
dapx( N, 5.0, x, 2 );
60+
dapx( 4, 5.0, x, 2 );
6361
// x => <Float64Array>[ 3.0, 1.0, 8.0, -5.0, 9.0, 0.0, 4.0, -3.0 ]
6462
```
6563

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

6866
```javascript
6967
var Float64Array = require( '@stdlib/array/float64' );
70-
var floor = require( '@stdlib/math/base/special/floor' );
7168

7269
// Initial array...
7370
var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
7471

7572
// Create an offset view...
7673
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
77-
var N = floor( x0.length/2 );
7874

7975
// Add a constant to every other element...
80-
dapx( N, 5.0, x1, 2 );
76+
dapx( 3, 5.0, x1, 2 );
8177
// x0 => <Float64Array>[ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ]
8278
```
8379

8480
#### dapx.ndarray( N, alpha, x, stride, offset )
8581

86-
Adds a constant `alpha` to each element in a double-precision floating-point strided array `x` using alternative indexing semantics.
82+
Adds a constant `alpha` to each element in a double-precision floating-point strided array using alternative indexing semantics.
8783

8884
```javascript
8985
var Float64Array = require( '@stdlib/array/float64' );
@@ -98,7 +94,7 @@ The function has the following additional parameters:
9894

9995
- **offset**: starting index.
10096

101-
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`
97+
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 the strided array
10298

10399
```javascript
104100
var Float64Array = require( '@stdlib/array/float64' );
@@ -117,7 +113,7 @@ dapx.ndarray( 3, 5.0, x, 1, x.length-3 );
117113

118114
## Notes
119115

120-
- If `N <= 0`, both functions return `x` unchanged.
116+
- If `N <= 0`, both functions return the strided array unchanged.
121117

122118
</section>
123119

@@ -130,27 +126,11 @@ dapx.ndarray( 3, 5.0, x, 1, x.length-3 );
130126
<!-- eslint no-undef: "error" -->
131127

132128
```javascript
133-
var round = require( '@stdlib/math/base/special/round' );
134-
var randu = require( '@stdlib/random/base/randu' );
135-
var Float64Array = require( '@stdlib/array/float64' );
129+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
130+
var filledarrayBy = require( '@stdlib/array/filled-by' );
136131
var dapx = require( '@stdlib/blas/ext/base/dapx' );
137132

138-
var rand;
139-
var sign;
140-
var x;
141-
var i;
142-
143-
x = new Float64Array( 10 );
144-
for ( i = 0; i < x.length; i++ ) {
145-
rand = round( randu()*100.0 );
146-
sign = randu();
147-
if ( sign < 0.5 ) {
148-
sign = -1.0;
149-
} else {
150-
sign = 1.0;
151-
}
152-
x[ i ] = sign * rand;
153-
}
133+
var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) );
154134
console.log( x );
155135

156136
dapx( x.length, 5.0, x, 1 );

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@
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 filledarrayBy = require( '@stdlib/array/filled-by' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float64Array = require( '@stdlib/array/float64' );
2828
var pkg = require( './../package.json' ).name;
2929
var dapx = require( './../lib/dapx.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var rand = uniform( -10.0, 10.0 );
35+
36+
3237
// FUNCTIONS //
3338

3439
/**
@@ -40,12 +45,8 @@ var dapx = require( './../lib/dapx.js' );
4045
*/
4146
function createBenchmark( len ) {
4247
var x;
43-
var i;
4448

45-
x = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
x[ i ] = ( randu()*20.0 ) - 10.0;
48-
}
49+
x = filledarrayBy( len, 'float64', rand );
4950
return benchmark;
5051

5152
function benchmark( b ) {

lib/node_modules/@stdlib/blas/ext/base/dapx/benchmark/benchmark.native.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float64Array = require( '@stdlib/array/float64' );
2929
var tryRequire = require( '@stdlib/utils/try-require' );
3030
var pkg = require( './../package.json' ).name;
3131

@@ -36,6 +36,7 @@ var dapx = tryRequire( resolve( __dirname, './../lib/dapx.native.js' ) );
3636
var opts = {
3737
'skip': ( dapx instanceof Error )
3838
};
39+
var rand = uniform( -10.0, 10.0 );
3940

4041

4142
// FUNCTIONS //
@@ -49,12 +50,8 @@ var opts = {
4950
*/
5051
function createBenchmark( len ) {
5152
var x;
52-
var i;
5353

54-
x = new Float64Array( len );
55-
for ( i = 0; i < len; i++ ) {
56-
x[ i ] = ( randu()*20.0 ) - 10.0;
57-
}
54+
x = filledarrayBy( len, 'float64', rand );
5855
return benchmark;
5956

6057
function benchmark( b ) {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@
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 filledarrayBy = require( '@stdlib/array/filled-by' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float64Array = require( '@stdlib/array/float64' );
2828
var pkg = require( './../package.json' ).name;
2929
var dapx = require( './../lib/ndarray.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var rand = uniform( -10.0, 10.0 );
35+
36+
3237
// FUNCTIONS //
3338

3439
/**
@@ -40,12 +45,8 @@ var dapx = require( './../lib/ndarray.js' );
4045
*/
4146
function createBenchmark( len ) {
4247
var x;
43-
var i;
4448

45-
x = new Float64Array( len );
46-
for ( i = 0; i < len; i++ ) {
47-
x[ i ] = ( randu()*20.0 ) - 10.0;
48-
}
49+
x = filledarrayBy( len, 'float64', rand );
4950
return benchmark;
5051

5152
function benchmark( b ) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
26+
var filledarrayBy = require( '@stdlib/array/filled-by' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float64Array = require( '@stdlib/array/float64' );
2929
var tryRequire = require( '@stdlib/utils/try-require' );
3030
var pkg = require( './../package.json' ).name;
3131

@@ -36,6 +36,7 @@ var dapx = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3636
var opts = {
3737
'skip': ( dapx instanceof Error )
3838
};
39+
var rand = uniform( -10.0, 10.0 );
3940

4041

4142
// FUNCTIONS //
@@ -49,12 +50,8 @@ var opts = {
4950
*/
5051
function createBenchmark( len ) {
5152
var x;
52-
var i;
5353

54-
x = new Float64Array( len );
55-
for ( i = 0; i < len; i++ ) {
56-
x[ i ] = ( randu()*20.0 ) - 10.0;
57-
}
54+
x = filledarrayBy( len, 'float64', rand );
5855
return benchmark;
5956

6057
function benchmark( b ) {

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
Adds a constant to each element in a double-precision floating-point strided
44
array.
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 typed
1010
array views.
1111

12-
If `N <= 0`, the function returns `x` unchanged.
12+
If `N <= 0`, the function returns the strided array unchanged.
1313

1414
Parameters
1515
----------
@@ -23,40 +23,34 @@
2323
Input array.
2424

2525
stride: integer
26-
Index increment for `x`.
26+
Index increment.
2727

2828
Returns
2929
-------
3030
x: Float64Array
31-
Input array `x`.
31+
Input array.
3232

3333
Examples
3434
--------
3535
// Standard Usage:
3636
> var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
37-
> var alpha = 5.0;
38-
> {{alias}}( x.length, alpha, x, 1 )
37+
> {{alias}}( x.length, 5.0, x, 1 )
3938
<Float64Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ]
4039

4140
// Using `N` and `stride` parameters:
4241
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
43-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
44-
> alpha = 5.0;
45-
> var stride = 2;
46-
> {{alias}}( N, alpha, x, stride )
42+
> {{alias}}( 3, 5.0, x, 2 )
4743
<Float64Array>[ 3.0, 1.0, 8.0, -5.0, 9.0, -1.0, -3.0 ]
4844

4945
// Using view offsets:
5046
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
5147
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
52-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
53-
> alpha = 5.0;
54-
> stride = 2;
55-
> {{alias}}( N, alpha, x1, stride )
48+
> {{alias}}( 3, 5.0, x1, 2 )
5649
<Float64Array>[ 3.0, 3.0, 1.0, 5.0, -1.0 ]
5750
> x0
5851
<Float64Array>[ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ]
5952

53+
6054
{{alias}}.ndarray( N, alpha, x, stride, offset )
6155
Adds a constant to each element in a double-precision floating-point strided
6256
array using alternative indexing semantics.
@@ -77,30 +71,26 @@
7771
Input array.
7872

7973
stride: integer
80-
Index increment for `x`.
74+
Index increment.
8175

8276
offset: integer
83-
Starting index of `x`.
77+
Starting index.
8478

8579
Returns
8680
-------
8781
x: Float64Array
88-
Input array `x`.
82+
Input array.
8983

9084
Examples
9185
--------
9286
// Standard Usage:
9387
> var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
94-
> var alpha = 5.0;
95-
> {{alias}}.ndarray( x.length, alpha, x, 1, 0 )
88+
> {{alias}}.ndarray( x.length, 5.0, x, 1, 0 )
9689
<Float64Array>[ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ]
9790

9891
// Using an index offset:
9992
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
100-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
101-
> alpha = 5.0;
102-
> var stride = 2;
103-
> {{alias}}.ndarray( N, alpha, x, stride, 1 )
93+
> {{alias}}.ndarray( 3, 5.0, x, 2, 1 )
10494
<Float64Array>[ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ]
10595

10696
See Also

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface Routine {
2929
* @param alpha - constant
3030
* @param x - input array
3131
* @param stride - stride length
32-
* @returns `x`
32+
* @returns input array
3333
*
3434
* @example
3535
* var Float64Array = require( '@stdlib/array/float64' );
@@ -49,7 +49,7 @@ interface Routine {
4949
* @param x - input array
5050
* @param stride - stride length
5151
* @param offset - starting index
52-
* @returns `x`
52+
* @returns input array
5353
*
5454
* @example
5555
* var Float64Array = require( '@stdlib/array/float64' );
@@ -69,7 +69,7 @@ interface Routine {
6969
* @param alpha - constant
7070
* @param x - input array
7171
* @param stride - stride length
72-
* @returns `x`
72+
* @returns input array
7373
*
7474
* @example
7575
* var Float64Array = require( '@stdlib/array/float64' );

0 commit comments

Comments
 (0)