Skip to content

Commit b9e2010

Browse files
committed
fix: refactor drev to use arrays API pattern
1 parent 7c8432e commit b9e2010

File tree

9 files changed

+42
-60
lines changed

9 files changed

+42
-60
lines changed

lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,26 @@ Reverses the elements of a one-dimensional double-precision floating-point ndarr
4343
```javascript
4444
var Float64Array = require( '@stdlib/array/float64' );
4545
var ndarray = require( '@stdlib/ndarray/base/ctor' );
46+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
4647

4748
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] );
4849
var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
4950

50-
drev( x );
51+
drev( [ x ] );
5152
// x => <ndarray>[ 3.0, 2.0, 1.0 ]
53+
54+
var arr = ndarray2array( x );
55+
// returns [ 3.0, 2.0, 1.0 ]
5256
```
5357

5458
The function has the following parameters:
5559

56-
- **x**: input ndarray.
60+
- **arrays**: array-like object containing a single one-dimensional input ndarray.
5761

5862
</section>
5963

6064
<!-- /.usage -->
6165

62-
<section class="notes">
63-
64-
## Notes
65-
66-
- The function **mutates** the input ndarray.
67-
68-
</section>
69-
70-
<!-- /.notes -->
71-
7266
<section class="examples">
7367

7468
## Examples
@@ -87,7 +81,7 @@ var xbuf = discreteUniform( 10, -50, 50, {
8781
var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
8882
console.log( ndarray2array( x ) );
8983

90-
drev( x );
84+
drev( [ x ] );
9185
console.log( ndarray2array( x ) );
9286
```
9387

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function createBenchmark( len ) {
5858

5959
b.tic();
6060
for ( i = 0; i < b.iterations; i++ ) {
61-
drev( x );
61+
drev( [ x ] );
6262
if ( xbuf[ 0 ] !== xbuf[ 0 ] ) {
6363
b.fail( 'should not return NaN' );
6464
}

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11

2-
{{alias}}( x )
2+
{{alias}}( arrays )
33
Reverses the elements of a one-dimensional double-precision floating-point
44
ndarray in-place.
55

6-
The function mutates the input ndarray.
7-
86
Parameters
97
----------
10-
x: ndarray
11-
Input ndarray.
8+
arrays: ArrayLikeObject<ndarray>
9+
Array-like object containing a single one-dimensional input ndarray.
1210

1311
Returns
1412
-------
@@ -18,14 +16,11 @@
1816
Examples
1917
--------
2018
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0 ] );
21-
> var dt = 'float64';
22-
> var sh = [ xbuf.length ];
23-
> var sx = [ 1 ];
24-
> var ox = 0;
25-
> var ord = 'row-major';
26-
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
27-
> {{alias}}( x )
28-
<ndarray>[ 3.0, 2.0, 1.0 ]
19+
> var x = {{alias:@stdlib/ndarray/base/ctor}}( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
20+
> {{alias}}( [ x ] )
21+
<ndarray>
22+
> var data = x.data
23+
<Float64Array>[ 3.0, 2.0, 1.0 ]
2924

3025
See Also
3126
--------

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { float64ndarray } from '@stdlib/types/ndarray';
2525
/**
2626
* Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place.
2727
*
28-
* @param x - input ndarray
28+
* @param arrays - array-like object containing a single one-dimensional input ndarray
2929
* @returns input ndarray
3030
*
3131
* @example
@@ -35,10 +35,10 @@ import { float64ndarray } from '@stdlib/types/ndarray';
3535
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] );
3636
* var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
3737
*
38-
* drev( x );
38+
* drev( [ x ] );
3939
* // x => <ndarray>[ 3.0, 2.0, 1.0 ]
4040
*/
41-
declare function drev( x: float64ndarray ): float64ndarray;
41+
declare function drev( arrays: [ float64ndarray ] ): float64ndarray;
4242

4343

4444
// EXPORTS //

lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/docs/types/test.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,34 @@
1616
* limitations under the License.
1717
*/
1818

19-
/* eslint-disable space-in-parens */
20-
21-
import zeros = require( '@stdlib/ndarray/zeros' );
19+
import zeros = require( '@stdlib/ndarray/base/zeros' );
2220
import drev = require( './index' );
2321

2422

2523
// TESTS //
2624

2725
// The function returns an ndarray...
2826
{
29-
const x = zeros( [ 3 ], {
30-
'dtype': 'float64'
31-
});
32-
33-
drev( x ); // $ExpectType float64ndarray
27+
const x = zeros( 'float64', [ 3 ], 'row-major' );
28+
drev( [ x ] ); // $ExpectType float64ndarray
3429
}
3530

36-
// The compiler throws an error if the function is provided a first argument which is not an ndarray...
31+
// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarrays...
3732
{
38-
drev( '10' ); // $ExpectError
39-
drev( 10 ); // $ExpectError
33+
drev( 123 ); // $ExpectError
4034
drev( true ); // $ExpectError
4135
drev( false ); // $ExpectError
4236
drev( null ); // $ExpectError
4337
drev( undefined ); // $ExpectError
44-
drev( [] ); // $ExpectError
38+
drev( '5' ); // $ExpectError
39+
drev( [ '1', '2' ] ); // $ExpectError
4540
drev( {} ); // $ExpectError
4641
drev( ( x: number ): number => x ); // $ExpectError
4742
}
4843

4944
// The compiler throws an error if the function is provided an unsupported number of arguments...
5045
{
51-
const x = zeros( [ 3 ], {
52-
'dtype': 'float64'
53-
});
54-
46+
const x = zeros( 'float64', [ 3 ], 'row-major' );
5547
drev(); // $ExpectError
56-
drev( x, {} ); // $ExpectError
48+
drev( [ x ], 10 ); // $ExpectError
5749
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ var xbuf = discreteUniform( 10, -50, 50, {
2929
var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
3030
console.log( ndarray2array( x ) );
3131

32-
drev( x );
32+
drev( [ x ] );
3333
console.log( ndarray2array( x ) );

lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] );
3232
* var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
3333
*
34-
* drev( x );
34+
* drev( [ x ] );
3535
* // x => <ndarray>[ 3.0, 2.0, 1.0 ]
3636
*/
3737

lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/lib/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var strided = require( '@stdlib/blas/ext/base/drev' ).ndarray;
3232
/**
3333
* Reverses the elements of a one-dimensional double-precision floating-point ndarray in-place.
3434
*
35-
* @param {ndarray} x - input ndarray
35+
* @param {ArrayLikeObject<Object>} arrays - array-like object containing a single one-dimensional input ndarray
3636
* @returns {ndarray} input ndarray
3737
*
3838
* @example
@@ -42,10 +42,11 @@ var strided = require( '@stdlib/blas/ext/base/drev' ).ndarray;
4242
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] );
4343
* var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
4444
*
45-
* drev( x );
45+
* drev( [ x ] );
4646
* // x => <ndarray>[ 3.0, 2.0, 1.0 ]
4747
*/
48-
function drev( x ) {
48+
function drev( arrays ) {
49+
var x = arrays[ 0 ];
4950
strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len
5051
return x;
5152
}

lib/node_modules/@stdlib/blas/ext/base/ndarray/drev/test/test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ tape( 'the function reverses the elements of a one-dimensional ndarray in-place'
6363
x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
6464
expected = new Float64Array( [ 5.0, 4.0, 3.0, 2.0, 1.0 ] );
6565

66-
drev( vector( x, 5, 1, 0 ) );
66+
drev( [ vector( x, 5, 1, 0 ) ] );
6767
t.deepEqual( x, expected, 'returns expected value' );
6868

6969
x = new Float64Array( [ -1.0, -2.0, -3.0 ] );
7070
expected = new Float64Array( [ -3.0, -2.0, -1.0 ] );
7171

72-
drev( vector( x, 3, 1, 0 ) );
72+
drev( [ vector( x, 3, 1, 0 ) ] );
7373
t.deepEqual( x, expected, 'returns expected value' );
7474

7575
t.end();
@@ -80,7 +80,7 @@ tape( 'the function returns the input ndarray', function test( t ) {
8080
var y;
8181

8282
x = vector( new Float64Array( [ 1.0, 2.0, 3.0 ] ), 3, 1, 0 );
83-
y = drev( x );
83+
y = drev( [ x ] );
8484

8585
t.strictEqual( y, x, 'returns input ndarray' );
8686
t.end();
@@ -93,7 +93,7 @@ tape( 'if provided an empty ndarray, the function leaves the ndarray unchanged',
9393
x = new Float64Array( [] );
9494
expected = new Float64Array( [] );
9595

96-
drev( vector( x, 0, 1, 0 ) );
96+
drev( [ vector( x, 0, 1, 0 ) ] );
9797
t.deepEqual( x, expected, 'returns expected value' );
9898

9999
t.end();
@@ -106,7 +106,7 @@ tape( 'if provided an ndarray containing a single element, the function leaves t
106106
x = new Float64Array( [ 1.0 ] );
107107
expected = new Float64Array( [ 1.0 ] );
108108

109-
drev( vector( x, 1, 1, 0 ) );
109+
drev( [ vector( x, 1, 1, 0 ) ] );
110110
t.deepEqual( x, expected, 'returns expected value' );
111111

112112
t.end();
@@ -137,7 +137,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides',
137137
8.0
138138
]);
139139

140-
drev( vector( x, 4, 2, 0 ) );
140+
drev( [ vector( x, 4, 2, 0 ) ] );
141141

142142
t.deepEqual( x, expected, 'returns expected value' );
143143
t.end();
@@ -168,7 +168,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides',
168168
8.0
169169
]);
170170

171-
drev( vector( x, 4, -2, 6 ) );
171+
drev( [ vector( x, 4, -2, 6 ) ] );
172172

173173
t.deepEqual( x, expected, 'returns expected value' );
174174
t.end();
@@ -199,7 +199,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets',
199199
2.0 // reversed: 0 -> 3
200200
]);
201201

202-
drev( vector( x, 4, 2, 1 ) );
202+
drev( [ vector( x, 4, 2, 1 ) ] );
203203
t.deepEqual( x, expected, 'returns expected value' );
204204

205205
t.end();

0 commit comments

Comments
 (0)