Skip to content

Commit db2bafa

Browse files
committed
refactor: apply suggestions from code review
1 parent 06d51ee commit db2bafa

2 files changed

Lines changed: 23 additions & 29 deletions

File tree

lib/node_modules/@stdlib/ndarray/to-unflattened/benchmark/benchmark.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ bench( format( '%s:ctor=base,ndims=1', pkg ), function benchmark( b ) {
3737
var buffer;
3838
var offset;
3939
var dtype;
40-
var shape;
4140
var order;
41+
var shape;
4242
var sizes;
4343
var out;
4444
var i;
@@ -71,11 +71,11 @@ bench( format( '%s:ctor=base,ndims=1', pkg ), function benchmark( b ) {
7171

7272
bench( format( '%s:ctor=ndarray,ndims=1', pkg ), function benchmark( b ) {
7373
var strides;
74-
var offset;
7574
var buffer;
75+
var offset;
7676
var dtype;
77-
var shape;
7877
var order;
78+
var shape;
7979
var sizes;
8080
var out;
8181
var i;
@@ -108,11 +108,11 @@ bench( format( '%s:ctor=ndarray,ndims=1', pkg ), function benchmark( b ) {
108108

109109
bench( format( '%s:ctor=base,ndims=2', pkg ), function benchmark( b ) {
110110
var strides;
111-
var offset;
112111
var buffer;
112+
var offset;
113113
var dtype;
114-
var shape;
115114
var order;
115+
var shape;
116116
var sizes;
117117
var out;
118118
var i;
@@ -145,11 +145,11 @@ bench( format( '%s:ctor=base,ndims=2', pkg ), function benchmark( b ) {
145145

146146
bench( format( '%s:ctor=ndarray,ndims=2', pkg ), function benchmark( b ) {
147147
var strides;
148-
var offset;
149148
var buffer;
149+
var offset;
150150
var dtype;
151-
var shape;
152151
var order;
152+
var shape;
153153
var sizes;
154154
var out;
155155
var i;

lib/node_modules/@stdlib/ndarray/to-unflattened/test/test.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
var tape = require( 'tape' );
2424
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
25+
var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' );
2526
var zeroTo = require( '@stdlib/array/zero-to' );
2627
var ndarray = require( '@stdlib/ndarray/ctor' );
2728
var array = require( '@stdlib/ndarray/array' );
2829
var getShape = require( '@stdlib/ndarray/shape' );
2930
var getDType = require( '@stdlib/ndarray/dtype' );
31+
var getData = require( '@stdlib/ndarray/data-buffer' );
3032
var ndarray2array = require( '@stdlib/ndarray/to-array' );
3133
var toUnflattened = require( './../lib' );
3234

@@ -100,7 +102,7 @@ tape( 'the function throws an error if provided a second argument which is not a
100102
}
101103
});
102104

103-
tape( 'the function throws an error if provided a third argument which is not a collection of numbers', function test( t ) {
105+
tape( 'the function throws an error if provided a third argument which is not an array of nonnegative integers', function test( t ) {
104106
var values;
105107
var x;
106108
var i;
@@ -117,6 +119,7 @@ tape( 'the function throws an error if provided a third argument which is not a
117119
void 0,
118120
[ '1', '2' ],
119121
[ 1.5, 2.5 ],
122+
[ -1, 6 ],
120123
{},
121124
function noop() {}
122125
];
@@ -177,7 +180,8 @@ tape( 'the function returns a new ndarray with the unflattened dimension (1D inp
177180

178181
y = toUnflattened( x, 0, [ 2, 3 ] );
179182
t.deepEqual( getShape( y ), [ 2, 3 ], 'returns expected shape' );
180-
t.strictEqual( String( getDType( y ) ), String( getDType( x ) ), 'returns expected dtype' );
183+
t.strictEqual( isEqualDataType( getDType( y ), getDType( x ) ), true, 'returns expected dtype' );
184+
t.notEqual( getData( y ), getData( x ), 'does not share the same data buffer' );
181185
t.deepEqual( ndarray2array( y ), expected, 'returns expected value' );
182186

183187
t.end();
@@ -199,7 +203,8 @@ tape( 'the function returns a new ndarray with the unflattened dimension (1D inp
199203

200204
y = toUnflattened( x, 0, [ 2, 2, 3 ] );
201205
t.deepEqual( getShape( y ), [ 2, 2, 3 ], 'returns expected shape' );
202-
t.strictEqual( String( getDType( y ) ), String( getDType( x ) ), 'returns expected dtype' );
206+
t.strictEqual( isEqualDataType( getDType( y ), getDType( x ) ), true, 'returns expected dtype' );
207+
t.notEqual( getData( y ), getData( x ), 'does not share the same data buffer' );
203208
t.deepEqual( ndarray2array( y ), expected, 'returns expected value' );
204209

205210
t.end();
@@ -221,6 +226,8 @@ tape( 'the function supports negative dimension indices', function test( t ) {
221226

222227
y = toUnflattened( x, -1, [ 2, 3 ] );
223228
t.deepEqual( getShape( y ), [ 2, 3 ], 'returns expected shape' );
229+
t.strictEqual( isEqualDataType( getDType( y ), getDType( x ) ), true, 'returns expected dtype' );
230+
t.notEqual( getData( y ), getData( x ), 'does not share the same data buffer' );
224231
t.deepEqual( ndarray2array( y ), expected, 'returns expected value' );
225232

226233
t.end();
@@ -237,25 +244,8 @@ tape( 'the function returns a new ndarray that is ndarray-like', function test(
237244

238245
y = toUnflattened( x, 0, [ 2, 3 ] );
239246
t.strictEqual( isndarrayLike( y ), true, 'returns ndarray-like object' );
240-
241-
t.end();
242-
});
243-
244-
tape( 'the function returns a new ndarray with the same dtype', function test( t ) {
245-
var dtypes;
246-
var buf;
247-
var x;
248-
var y;
249-
var i;
250-
251-
dtypes = [ 'float32', 'float64', 'int32', 'uint8' ];
252-
253-
for ( i = 0; i < dtypes.length; i++ ) {
254-
buf = zeroTo( 6 );
255-
x = ndarray( dtypes[ i ], buf, [ 6 ], [ 1 ], 0, 'row-major' );
256-
y = toUnflattened( x, 0, [ 2, 3 ] );
257-
t.strictEqual( String( getDType( y ) ), dtypes[ i ], 'returns expected dtype for ' + dtypes[ i ] );
258-
}
247+
t.strictEqual( isEqualDataType( getDType( y ), getDType( x ) ), true, 'returns expected dtype' );
248+
t.notEqual( getData( y ), getData( x ), 'does not share the same data buffer' );
259249

260250
t.end();
261251
});
@@ -276,6 +266,8 @@ tape( 'the function supports column-major order', function test( t ) {
276266

277267
y = toUnflattened( x, 0, [ 2, 3 ] );
278268
t.deepEqual( getShape( y ), [ 2, 3 ], 'returns expected shape' );
269+
t.strictEqual( isEqualDataType( getDType( y ), getDType( x ) ), true, 'returns expected dtype' );
270+
t.notEqual( getData( y ), getData( x ), 'does not share the same data buffer' );
279271
t.deepEqual( ndarray2array( y ), expected, 'returns expected value' );
280272

281273
t.end();
@@ -298,6 +290,8 @@ tape( 'the function unflattens a middle dimension in a multidimensional input',
298290

299291
y = toUnflattened( x, 1, [ 2, 2 ] );
300292
t.deepEqual( getShape( y ), [ 3, 2, 2 ], 'returns expected shape' );
293+
t.strictEqual( isEqualDataType( getDType( y ), getDType( x ) ), true, 'returns expected dtype' );
294+
t.notEqual( getData( y ), getData( x ), 'does not share the same data buffer' );
301295
t.deepEqual( ndarray2array( y ), expected, 'returns expected value' );
302296

303297
t.end();

0 commit comments

Comments
 (0)