Skip to content

Commit ffdc1d2

Browse files
Pranavchikukgryte
andauthored
Refactor @stdlib/blas/base/dcopy (#792)
* cleanup readme.md * rename addon.cpp to addon.c * refactor dcopy.c, dcopy_cblas.c and dcopy_f.c * refactor dcopy, dcopy.native, ndarray, ndarray.native in lib/ * refactor index.js * refactor various js benchmarks * refactor manifest and package.json * change addon.c in include.gypi * Refactor addon.c * refactor tests * refactor repl.txt * refactor index.d.ts * Fix typo and remove unused dep Co-authored-by: Athan <kgryte@gmail.com>
1 parent 0550658 commit ffdc1d2

24 files changed

+242
-364
lines changed

lib/node_modules/@stdlib/blas/base/dcopy/README.md

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2018 The Stdlib Authors.
5+
Copyright (c) 2023 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -52,18 +52,15 @@ The function has the following parameters:
5252
- **y**: destination [`Float64Array`][mdn-float64array].
5353
- **strideY**: index increment for `y`.
5454

55-
The `N` and `stride` parameters determine how values from `x` are copied into `y`. For example, to copy in reverse order every other value in `x` into the first `N` elements of `y`,
55+
The `N` and stride parameters determine how values from `x` are copied into `y`. For example, to copy in reverse order every other value in `x` into the first `N` elements of `y`,
5656

5757
```javascript
5858
var Float64Array = require( '@stdlib/array/float64' );
59-
var floor = require( '@stdlib/math/base/special/floor' );
6059

6160
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
6261
var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
6362

64-
var N = floor( x.length / 2 );
65-
66-
dcopy( N, x, -2, y, 1 );
63+
dcopy( 3, x, -2, y, 1 );
6764
// y => <Float64Array>[ 5.0, 3.0, 1.0, 10.0, 11.0, 12.0 ]
6865
```
6966

@@ -73,7 +70,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [
7370

7471
```javascript
7572
var Float64Array = require( '@stdlib/array/float64' );
76-
var floor = require( '@stdlib/math/base/special/floor' );
7773

7874
// Initial arrays...
7975
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
@@ -83,10 +79,8 @@ var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
8379
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
8480
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
8581

86-
var N = floor( x0.length / 2 );
87-
8882
// Copy in reverse order every other value from `x1` into `y1`...
89-
dcopy( N, x1, -2, y1, 1 );
83+
dcopy( 3, x1, -2, y1, 1 );
9084
// y0 => <Float64Array>[ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ]
9185
```
9286

@@ -109,18 +103,15 @@ The function has the following additional parameters:
109103
- **offsetX**: starting index for `x`.
110104
- **offsetY**: starting index for `y`.
111105

112-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to copy every other value in `x` starting from the second value into the last `N` elements in `y` where `x[i] = y[n]`, `x[i+2] = y[n-1]`,...,
106+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameters support indexing semantics based on starting indices. For example, to copy every other value in `x` starting from the second value into the last `N` elements in `y` where `x[i] = y[n]`, `x[i+2] = y[n-1]`,...,
113107

114108
```javascript
115109
var Float64Array = require( '@stdlib/array/float64' );
116-
var floor = require( '@stdlib/math/base/special/floor' );
117110

118111
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
119112
var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
120113

121-
var N = floor( x.length / 2 );
122-
123-
dcopy.ndarray( N, x, 2, 1, y, -1, y.length-1 );
114+
dcopy.ndarray( 3, x, 2, 1, y, -1, y.length-1 );
124115
// y => <Float64Array>[ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ]
125116
```
126117

@@ -146,22 +137,14 @@ dcopy.ndarray( N, x, 2, 1, y, -1, y.length-1 );
146137
<!-- eslint no-undef: "error" -->
147138

148139
```javascript
149-
var randu = require( '@stdlib/random/base/randu' );
150-
var round = require( '@stdlib/math/base/special/round' );
151-
var Float64Array = require( '@stdlib/array/float64' );
140+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
141+
var filledarrayBy = require( '@stdlib/array/filled-by' );
152142
var dcopy = require( '@stdlib/blas/base/dcopy' );
153143

154-
var x;
155-
var y;
156-
var i;
157-
158-
x = new Float64Array( 10 );
159-
y = new Float64Array( 10 );
160-
for ( i = 0; i < x.length; i++ ) {
161-
x[ i ] = round( randu()*500.0 );
162-
y[ i ] = round( randu()*255.0 );
163-
}
144+
var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 500 ) );
164145
console.log( x );
146+
147+
var y = filledarrayBy( x.length, 'float64', discreteUniform( 0, 255 ) );
165148
console.log( y );
166149

167150
// Copy elements from `x` into `y` starting from the end of `y`:

lib/node_modules/@stdlib/blas/base/dcopy/benchmark/benchmark.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -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 dcopy = require( './../lib/dcopy.js' );
3030

3131

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

3439
/**
@@ -39,15 +44,8 @@ var dcopy = require( './../lib/dcopy.js' );
3944
* @returns {Function} benchmark function
4045
*/
4146
function createBenchmark( len ) {
42-
var x;
43-
var y;
44-
var i;
45-
46-
x = new Float64Array( len );
47-
y = new Float64Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20000.0 ) - 10000.0;
50-
}
47+
var x = filledarrayBy( len, 'float64', rand );
48+
var y = filledarrayBy( len, 'float64', rand );
5149
return benchmark;
5250

5351
/**

lib/node_modules/@stdlib/blas/base/dcopy/benchmark/benchmark.native.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -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 dcopy = tryRequire( resolve( __dirname, './../lib/native.js' ) );
3636
var opts = {
3737
'skip': ( dcopy instanceof Error )
3838
};
39+
var rand = uniform( -10000.0, 10000.0 );
3940

4041

4142
// FUNCTIONS //
@@ -48,15 +49,8 @@ var opts = {
4849
* @returns {Function} benchmark function
4950
*/
5051
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float64Array( len );
56-
y = new Float64Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20000.0 ) - 10000.0;
59-
}
52+
var x = filledarrayBy( len, 'float64', rand );
53+
var y = filledarrayBy( len, 'float64', rand );
6054
return benchmark;
6155

6256
/**

lib/node_modules/@stdlib/blas/base/dcopy/benchmark/benchmark.ndarray.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -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 dcopy = require( './../lib/ndarray.js' );
3030

3131

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

3439
/**
@@ -39,15 +44,8 @@ var dcopy = require( './../lib/ndarray.js' );
3944
* @returns {Function} benchmark function
4045
*/
4146
function createBenchmark( len ) {
42-
var x;
43-
var y;
44-
var i;
45-
46-
x = new Float64Array( len );
47-
y = new Float64Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20000.0 ) - 10000.0;
50-
}
47+
var x = filledarrayBy( len, 'float64', rand );
48+
var y = filledarrayBy( len, 'float64', rand );
5149
return benchmark;
5250

5351
/**

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

Lines changed: 5 additions & 11 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 dcopy = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3636
var opts = {
3737
'skip': ( dcopy instanceof Error )
3838
};
39+
var rand = uniform( -10000.0, 10000.0 );
3940

4041

4142
// FUNCTIONS //
@@ -48,15 +49,8 @@ var opts = {
4849
* @returns {Function} benchmark function
4950
*/
5051
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float64Array( len );
56-
y = new Float64Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20000.0 ) - 10000.0;
59-
}
52+
var x = filledarrayBy( len, 'float64', rand );
53+
var y = filledarrayBy( len, 'float64', rand );
6054
return benchmark;
6155

6256
/**

lib/node_modules/@stdlib/blas/base/dcopy/docs/repl.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{alias}}( N, x, strideX, y, strideY )
33
Copies values from `x` into `y`.
44

5-
The `N` and `stride` parameters determine how values from `x` are copied
5+
The `N` and stride parameters determine how values from `x` are copied
66
into `y`.
77

88
Indexing is relative to the first index. To introduce an offset, use typed
@@ -13,7 +13,7 @@
1313
Parameters
1414
----------
1515
N: integer
16-
Number of values to copy.
16+
Number of values.
1717

1818
x: Float64Array
1919
Input array.
@@ -22,15 +22,15 @@
2222
Index increment for `x`.
2323

2424
y: Float64Array
25-
Destination array.
25+
Output array.
2626

2727
strideY: integer
2828
Index increment for `y`.
2929

3030
Returns
3131
-------
3232
y: Float64Array
33-
Input array `y`.
33+
Output array.
3434

3535
Examples
3636
--------
@@ -43,17 +43,15 @@
4343
// Advanced indexing:
4444
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
4545
> y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
46-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
47-
> {{alias}}( N, x, -2, y, 1 )
46+
> {{alias}}( 3, x, -2, y, 1 )
4847
<Float64Array>[ 5.0, 3.0, 1.0, 10.0, 11.0, 12.0 ]
4948

5049
// Using typed array views:
5150
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
5251
> var y0 = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
5352
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
5453
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 );
55-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
56-
> {{alias}}( N, x1, -2, y1, 1 )
54+
> {{alias}}( 3, x1, -2, y1, 1 )
5755
<Float64Array>[ 6.0, 4.0, 2.0 ]
5856
> y0
5957
<Float64Array>[ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ]
@@ -63,13 +61,13 @@
6361
Copies values from `x` into `y` using alternative indexing semantics.
6462

6563
While typed array views mandate a view offset based on the underlying
66-
buffer, the `offset` parameters support indexing semantics based on starting
64+
buffer, the offset parameters support indexing semantics based on starting
6765
indices.
6866

6967
Parameters
7068
----------
7169
N: integer
72-
Number of values to copy.
70+
Number of values.
7371

7472
x: Float64Array
7573
Input array.
@@ -81,7 +79,7 @@
8179
Starting index for `x`.
8280

8381
y: Float64Array
84-
Destination array.
82+
Output array.
8583

8684
strideY: integer
8785
Index increment for `y`.
@@ -92,7 +90,7 @@
9290
Returns
9391
-------
9492
y: Float64Array
95-
Input array `y`.
93+
Output array.
9694

9795
Examples
9896
--------
@@ -105,8 +103,7 @@
105103
// Advanced indexing:
106104
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
107105
> y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
108-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
109-
> {{alias}}.ndarray( N, x, 2, 1, y, -1, y.length-1 )
106+
> {{alias}}.ndarray( 3, x, 2, 1, y, -1, y.length-1 )
110107
<Float64Array>[ 7.0, 8.0, 9.0, 6.0, 4.0, 2.0 ]
111108

112109
See Also

0 commit comments

Comments
 (0)