Skip to content

Commit 176a1bb

Browse files
committed
Auto-generated commit
1 parent a1ad58d commit 176a1bb

File tree

14 files changed

+55
-125
lines changed

14 files changed

+55
-125
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,9 @@ A total of 45 issues were closed in this release:
820820

821821
<details>
822822

823+
- [`1a45821`](https://github.com/stdlib-js/stdlib/commit/1a458218a5e319ee00c0d3ddb4e065ad64edef4c) - **docs:** update examples to use accessor functions _(by Athan Reines)_
824+
- [`e835a44`](https://github.com/stdlib-js/stdlib/commit/e835a4459def3255aa112790371508f6d9b7d16b) - **docs:** update examples to use accessor functions _(by Athan Reines)_
825+
- [`887f9ca`](https://github.com/stdlib-js/stdlib/commit/887f9caca4ebe0bca507718b2f0ac26f063298c3) - **docs:** update examples and benchmarks _(by Athan Reines)_
823826
- [`c13dd70`](https://github.com/stdlib-js/stdlib/commit/c13dd703daff4a5893dac860a78fe6e0631e68ec) - **refactor:** normalize dtypes to enums to reduce memory consumption and speed-up comparisons _(by Athan Reines)_
824827
- [`2041e12`](https://github.com/stdlib-js/stdlib/commit/2041e12c968c4bd6f4a4f051271aacaa65727a6d) - **docs:** ensure support for dtype instances and update examples _(by Athan Reines)_
825828
- [`88a7c4d`](https://github.com/stdlib-js/stdlib/commit/88a7c4de78c60740018a7038279248e48a2019cc) - **refactor:** add support for ancillary ndarray arguments having trailing dimensions _(by Athan Reines)_

base/to-array/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,11 @@ var arr = ndarray2array( buffer, shape, strides, offset, order );
105105
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
106106
var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
107107
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
108+
var zeroTo = require( '@stdlib/array/base/zero-to' );
108109
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
109110

110111
// Create a data buffer:
111-
var buffer = [];
112-
var i;
113-
for ( i = 0; i < 27; i++ ) {
114-
buffer.push( i );
115-
}
112+
var buffer = zeroTo( 27 );
116113

117114
// Specify array meta data:
118115
var shape = [ 3, 3, 3 ];
@@ -129,6 +126,7 @@ console.log( 'Dims: %s', shape.join( 'x' ) );
129126

130127
// Randomly flip strides and convert an ndarray to a nested array...
131128
var arr;
129+
var i;
132130
var j;
133131
for ( i = 0; i < 20; i++ ) {
134132
j = discreteUniform( 0, ndims-1 );

base/to-array/benchmark/benchmark.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
2524
var isArrayArray = require( '@stdlib/assert/is-array-array' );
2625
var shape2strides = require( './../../../base/shape2strides' );
2726
var strides2offset = require( './../../../base/strides2offset' );
2827
var numel = require( './../../../base/numel' );
28+
var zeroTo = require( '@stdlib/array/base/zero-to' );
2929
var pkg = require( './../package.json' ).name;
3030
var ndarray2array = require( './../lib' );
3131

@@ -47,15 +47,11 @@ bench( pkg+':order=row-major', function benchmark( b ) {
4747
len = numel( shape );
4848
strides = shape2strides( shape, order );
4949
offset = strides2offset( shape, strides );
50-
51-
buffer = [];
52-
for ( i = 0; i < len; i++ ) {
53-
buffer.push( i );
54-
}
50+
buffer = zeroTo( len );
5551

5652
b.tic();
5753
for ( i = 0; i < b.iterations; i++ ) {
58-
strides[ 1 ] *= ( randu() < 0.5 ) ? -1 : 1;
54+
strides[ 1 ] *= ( i%2 === 0 ) ? -1 : 1;
5955
out = ndarray2array( buffer, shape, strides, offset, order );
6056
if ( out.length !== shape[ 0 ] ) {
6157
b.fail( 'should have expected length' );
@@ -87,15 +83,11 @@ bench( pkg+':order=column-major', function benchmark( b ) {
8783
len = numel( shape );
8884
strides = shape2strides( shape, order );
8985
offset = strides2offset( shape, strides );
90-
91-
buffer = [];
92-
for ( i = 0; i < len; i++ ) {
93-
buffer.push( i );
94-
}
86+
buffer = zeroTo( len );
9587

9688
b.tic();
9789
for ( i = 0; i < b.iterations; i++ ) {
98-
strides[ 1 ] *= ( randu() < 0.5 ) ? -1 : 1;
90+
strides[ 1 ] *= ( i%2 === 0 ) ? -1 : 1;
9991
out = ndarray2array( buffer, shape, strides, offset, order );
10092
if ( out.length !== shape[ 0 ] ) {
10193
b.fail( 'should have expected length' );

base/to-array/examples/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
var shape2strides = require( './../../../base/shape2strides' );
2222
var strides2offset = require( './../../../base/strides2offset' );
2323
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
24+
var zeroTo = require( '@stdlib/array/base/zero-to' );
2425
var ndarray2array = require( './../lib' );
2526

2627
// Create a data buffer:
27-
var buffer = [];
28-
var i;
29-
for ( i = 0; i < 27; i++ ) {
30-
buffer.push( i );
31-
}
28+
var buffer = zeroTo( 27 );
3229

3330
// Specify array meta data:
3431
var shape = [ 3, 3, 3 ];
@@ -45,6 +42,7 @@ console.log( 'Dims: %s', shape.join( 'x' ) );
4542

4643
// Randomly flip strides and convert an ndarray to a nested array...
4744
var arr;
45+
var i;
4846
var j;
4947
for ( i = 0; i < 20; i++ ) {
5048
j = discreteUniform( 0, ndims-1 );

base/to-flippedlr/README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,24 @@ Returns a new ndarray where the order of elements along the last dimension of an
4646

4747
```javascript
4848
var ndarray = require( '@stdlib/ndarray/ctor' );
49-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
49+
var getShape = require( '@stdlib/ndarray/shape' );
5050

5151
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
5252
var shape = [ 3, 2 ];
5353
var strides = [ 2, 1 ];
5454
var offset = 0;
5555

5656
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
57-
// returns <ndarray>
57+
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
5858

59-
var sh = x.shape;
59+
var sh = getShape( x );
6060
// returns [ 3, 2 ]
6161

62-
var arr = ndarray2array( x );
63-
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
64-
6562
var y = toFlippedlr( x );
66-
// returns <ndarray>
63+
// returns <ndarray>[ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
6764

68-
sh = y.shape;
65+
sh = getShape( y );
6966
// returns [ 3, 2 ]
70-
71-
arr = ndarray2array( y );
72-
// returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
7367
```
7468

7569
The function accepts the following arguments:

base/to-flippedlr/docs/repl.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616
Examples
1717
--------
1818
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] )
19-
<ndarray>
20-
> x.shape
21-
[ 2, 2 ]
19+
<ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
2220
> var y = {{alias}}( x )
23-
<ndarray>
24-
> y.shape
25-
[ 2, 2 ]
26-
> {{alias:@stdlib/ndarray/to-array}}( y )
27-
[ [ 2, 1 ], [ 4, 3 ] ]
21+
<ndarray>[ [ 2, 1 ], [ 4, 3 ] ]
2822

2923
See Also
3024
--------

base/to-flippedlr/docs/types/index.d.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,25 @@ import { ndarray } from '@stdlib/types/ndarray';
3030
*
3131
* @example
3232
* var typedarray = require( '@stdlib/array/typed' );
33+
* var getShape = require( '@stdlib/ndarray/shape' );
3334
* var ndarray = require( '@stdlib/ndarray/ctor' );
34-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
3535
*
3636
* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' );
3737
* var shape = [ 3, 2 ];
3838
* var strides = [ 2, 1 ];
3939
* var offset = 0;
4040
*
4141
* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
42-
* // returns <ndarray>
42+
* // returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
4343
*
44-
* var sh = x.shape;
44+
* var sh = getShape( x );
4545
* // returns [ 3, 2 ]
4646
*
47-
* var arr = ndarray2array( x );
48-
* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
49-
*
5047
* var y = toFlippedlr( x );
51-
* // returns <ndarray>
48+
* // returns <ndarray>[ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
5249
*
53-
* sh = y.shape;
50+
* sh = getShape( y );
5451
* // returns [ 3, 2 ]
55-
*
56-
* arr = ndarray2array( y );
57-
* // returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
5852
*/
5953
declare function toFlippedlr<T extends ndarray>( x: T ): T;
6054

base/to-flippedlr/lib/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @example
2727
* var ndarray = require( '@stdlib/ndarray/ctor' );
28-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
28+
* var getShape = require( '@stdlib/ndarray/shape' );
2929
* var toFlippedlr = require( '@stdlib/ndarray/base/to-flippedlr' );
3030
*
3131
* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
@@ -34,22 +34,16 @@
3434
* var offset = 0;
3535
*
3636
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
37-
* // returns <ndarray>
37+
* // returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
3838
*
39-
* var sh = x.shape;
39+
* var sh = getShape( x );
4040
* // returns [ 3, 2 ]
4141
*
42-
* var arr = ndarray2array( x );
43-
* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
44-
*
4542
* var y = toFlippedlr( x );
46-
* // returns <ndarray>
43+
* // returns <ndarray>[ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
4744
*
48-
* sh = y.shape;
45+
* sh = getShape( y );
4946
* // returns [ 3, 2 ]
50-
*
51-
* arr = ndarray2array( y );
52-
* // returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
5347
*/
5448

5549
// MODULES //

base/to-flippedlr/lib/main.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,24 @@ var assign = require( './../../../base/assign' );
3636
*
3737
* @example
3838
* var ndarray = require( '@stdlib/ndarray/ctor' );
39-
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
39+
* var getShape = require( '@stdlib/ndarray/shape' );
4040
*
4141
* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
4242
* var shape = [ 3, 2 ];
4343
* var strides = [ 2, 1 ];
4444
* var offset = 0;
4545
*
4646
* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
47-
* // returns <ndarray>
47+
* // returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
4848
*
49-
* var sh = x.shape;
49+
* var sh = getShape( x );
5050
* // returns [ 3, 2 ]
5151
*
52-
* var arr = ndarray2array( x );
53-
* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
54-
*
5552
* var y = toFlippedlr( x );
56-
* // returns <ndarray>
53+
* // returns <ndarray>[ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
5754
*
58-
* sh = y.shape;
55+
* sh = getShape( y );
5956
* // returns [ 3, 2 ]
60-
*
61-
* arr = ndarray2array( y );
62-
* // returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]
6357
*/
6458
function toFlippedlr( x ) {
6559
var out;

base/to-flippedud/README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,24 @@ Returns a new ndarray where the order of elements along the second-to-last dimen
4646

4747
```javascript
4848
var ndarray = require( '@stdlib/ndarray/ctor' );
49-
var ndarray2array = require( '@stdlib/ndarray/to-array' );
49+
var getShape = require( '@stdlib/ndarray/shape' );
5050

5151
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
5252
var shape = [ 3, 2 ];
5353
var strides = [ 2, 1 ];
5454
var offset = 0;
5555

5656
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
57-
// returns <ndarray>
57+
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
5858

59-
var sh = x.shape;
59+
var sh = getShape( x );
6060
// returns [ 3, 2 ]
6161

62-
var arr = ndarray2array( x );
63-
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
64-
6562
var y = toFlippedud( x );
66-
// returns <ndarray>
63+
// returns <ndarray>[ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]
6764

68-
sh = y.shape;
65+
sh = getShape( y );
6966
// returns [ 3, 2 ]
70-
71-
arr = ndarray2array( y );
72-
// returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]
7367
```
7468

7569
The function accepts the following arguments:

0 commit comments

Comments
 (0)