Skip to content

Commit cbb24e1

Browse files
committed
fix: apply suggestions from code review
1 parent 5b5e882 commit cbb24e1

4 files changed

Lines changed: 310 additions & 84 deletions

File tree

lib/node_modules/@stdlib/ndarray/to-string/README.md

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,11 @@ var ndarray2string = require( '@stdlib/ndarray/to-string' );
4545
Serializes an [ndarray][@stdlib/ndarray/ctor] as a string.
4646

4747
```javascript
48-
var ndarray = require( '@stdlib/ndarray/ctor' );
48+
var array = require( '@stdlib/ndarray/array' );
4949

50-
var buffer = [ 1, 2, 3, 4 ];
51-
var shape = [ 2, 2 ];
52-
var order = 'row-major';
53-
var strides = [ 2, 1 ];
54-
var offset = 0;
55-
56-
var x = ndarray( 'generic', buffer, shape, strides, offset, order );
50+
var x = array( [ 1, 2, 3, 4 ], {
51+
'shape': [ 2, 2 ]
52+
});
5753
// returns <ndarray>
5854

5955
var str = ndarray2string( x );
@@ -86,43 +82,19 @@ var str = ndarray2string( x );
8682
<!-- eslint no-undef: "error" -->
8783

8884
```javascript
89-
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
90-
var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
91-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
92-
var zeroTo = require( '@stdlib/array/base/zero-to' );
93-
var ndarray = require( '@stdlib/ndarray/ctor' );
85+
var array = require( '@stdlib/ndarray/array' );
9486
var ndarray2string = require( '@stdlib/ndarray/to-string' );
9587

96-
// Create a data buffer:
97-
var buffer = zeroTo( 27 );
98-
99-
// Specify array meta data:
100-
var shape = [ 3, 3, 3 ];
101-
var order = 'column-major';
102-
var ndims = shape.length;
103-
104-
// Compute array meta data:
105-
var strides = shape2strides( shape, order );
106-
var offset = strides2offset( shape, strides );
107-
108-
// Print array information:
109-
console.log( '' );
110-
console.log( 'Dims: %s', shape.join( 'x' ) );
88+
// Create a 2x3 ndarray:
89+
var x = array( [ 1, 2, 3, 4, 5, 6 ], {
90+
'shape': [ 2, 3 ],
91+
'dtype': 'generic'
92+
});
11193

112-
// Randomly flip strides and convert an ndarray to a string...
113-
var arr;
114-
var i;
115-
for ( i = 0; i < 20; i++ ) {
116-
strides[ discreteUniform( 0, ndims-1 ) ] *= -1;
117-
offset = strides2offset( shape, strides );
118-
119-
console.log( '' );
120-
console.log( 'Strides: %s', strides.join( ',' ) );
121-
console.log( 'Offset: %d', offset );
122-
123-
arr = ndarray( 'generic', buffer, shape, strides, offset, order );
124-
console.log( ndarray2string( arr ) );
125-
}
94+
// Serialize the ndarray as a string:
95+
var str = ndarray2string( x );
96+
console.log( str );
97+
// => 'ndarray( \'generic\', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'
12698
```
12799

128100
</section>

lib/node_modules/@stdlib/ndarray/to-string/docs/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { typedndarray } from '@stdlib/types/ndarray';
23+
import { ndarray } from '@stdlib/types/ndarray';
2424

2525
/**
2626
* Serializes an ndarray as a string.
@@ -41,7 +41,7 @@ import { typedndarray } from '@stdlib/types/ndarray';
4141
* var str = ndarray2string( x );
4242
* // returns <string>
4343
*/
44-
declare function ndarray2string<T = unknown>( x: typedndarray<T> ): string;
44+
declare function ndarray2string( x: ndarray ): string;
4545

4646

4747
// EXPORTS //

lib/node_modules/@stdlib/ndarray/to-string/examples/index.js

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,16 @@
1818

1919
'use strict';
2020

21-
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
22-
var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
23-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
24-
var zeroTo = require( '@stdlib/array/base/zero-to' );
25-
var ndarray = require( '@stdlib/ndarray/ctor' );
21+
var array = require( '@stdlib/ndarray/array' );
2622
var ndarray2string = require( './../lib' );
2723

28-
// Create a data buffer:
29-
var buffer = zeroTo( 27 );
24+
// Create a 2x3 ndarray:
25+
var x = array( [ 1, 2, 3, 4, 5, 6 ], {
26+
'shape': [ 2, 3 ],
27+
'dtype': 'generic'
28+
});
3029

31-
// Specify array meta data:
32-
var shape = [ 3, 3, 3 ];
33-
var order = 'column-major';
34-
var ndims = shape.length;
35-
36-
// Compute array meta data:
37-
var strides = shape2strides( shape, order );
38-
var offset = strides2offset( shape, strides );
39-
40-
// Print array information:
41-
console.log( '' );
42-
console.log( 'Dims: %s', shape.join( 'x' ) );
43-
44-
// Randomly flip strides and convert an ndarray to a string...
45-
var arr;
46-
var i;
47-
for ( i = 0; i < 20; i++ ) {
48-
strides[ discreteUniform( 0, ndims-1 ) ] *= -1;
49-
offset = strides2offset( shape, strides );
50-
51-
console.log( '' );
52-
console.log( 'Strides: %s', strides.join( ',' ) );
53-
console.log( 'Offset: %d', offset );
54-
55-
arr = ndarray( 'generic', buffer, shape, strides, offset, order );
56-
console.log( ndarray2string( arr ) );
57-
}
30+
// Serialize the ndarray as a string:
31+
var str = ndarray2string( x );
32+
console.log( str );
33+
// => 'ndarray( \'generic\', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'

0 commit comments

Comments
 (0)