@@ -64,7 +64,30 @@ tape( 'the function throws an error if provided an invalid second argument', fun
6464 }
6565} ) ;
6666
67- tape ( 'the function prepends singleton dimensions' , function test ( t ) {
67+ tape ( 'the function prepends singleton dimensions (1d)' , function test ( t ) {
68+ var x ;
69+ var y ;
70+
71+ x = array ( [ 1 , 2 , 3 , 4 ] ) ;
72+
73+ y = expandDimensions ( x , 0 , false ) ;
74+
75+ t . notEqual ( y , x , 'returns expected value' ) ;
76+ t . deepEqual ( getShape ( y ) , [ 1 , 4 ] , 'returns expected value' ) ;
77+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
78+ t . strictEqual ( isReadOnly ( y ) , true , 'returns expected value' ) ;
79+
80+ y = expandDimensions ( x , 0 , true ) ;
81+
82+ t . notEqual ( y , x , 'returns expected value' ) ;
83+ t . deepEqual ( getShape ( y ) , [ 1 , 4 ] , 'returns expected value' ) ;
84+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
85+ t . strictEqual ( isReadOnly ( y ) , false , 'returns expected value' ) ;
86+
87+ t . end ( ) ;
88+ } ) ;
89+
90+ tape ( 'the function prepends singleton dimensions (2d)' , function test ( t ) {
6891 var x ;
6992 var y ;
7093
@@ -110,7 +133,30 @@ tape( 'the function prepends singleton dimensions (negative index)', function te
110133 t . end ( ) ;
111134} ) ;
112135
113- tape ( 'the function appends singleton dimensions' , function test ( t ) {
136+ tape ( 'the function appends singleton dimensions (1d)' , function test ( t ) {
137+ var x ;
138+ var y ;
139+
140+ x = array ( [ 1 , 2 , 3 , 4 ] ) ;
141+
142+ y = expandDimensions ( x , ndims ( x ) , false ) ;
143+
144+ t . notEqual ( y , x , 'returns expected value' ) ;
145+ t . deepEqual ( getShape ( y ) , [ 4 , 1 ] , 'returns expected value' ) ;
146+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
147+ t . strictEqual ( isReadOnly ( y ) , true , 'returns expected value' ) ;
148+
149+ y = expandDimensions ( x , ndims ( x ) , true ) ;
150+
151+ t . notEqual ( y , x , 'returns expected value' ) ;
152+ t . deepEqual ( getShape ( y ) , [ 4 , 1 ] , 'returns expected value' ) ;
153+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
154+ t . strictEqual ( isReadOnly ( y ) , false , 'returns expected value' ) ;
155+
156+ t . end ( ) ;
157+ } ) ;
158+
159+ tape ( 'the function appends singleton dimensions (2d)' , function test ( t ) {
114160 var x ;
115161 var y ;
116162
@@ -214,6 +260,15 @@ tape( 'the function prepends singleton dimensions (base; row-major)', function t
214260 t . deepEqual ( getStrides ( y ) , [ 4 , 2 , 1 ] , 'returns expected value' ) ;
215261 t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
216262
263+ // Transposed:
264+ x = ndarray ( 'generic' , [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] , [ 1 , 2 ] , 0 , 'row-major' ) ;
265+ y = expandDimensions ( x , 0 , false ) ;
266+
267+ t . notEqual ( y , x , 'returns expected value' ) ;
268+ t . deepEqual ( getShape ( y ) , [ 1 , 2 , 2 ] , 'returns expected value' ) ;
269+ t . deepEqual ( getStrides ( y ) , [ 1 , 1 , 2 ] , 'returns expected value' ) ;
270+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
271+
217272 t . end ( ) ;
218273} ) ;
219274
@@ -244,6 +299,15 @@ tape( 'the function prepends singleton dimensions (base; column-major)', functio
244299 t . deepEqual ( getStrides ( y ) , [ 1 , 1 , 2 ] , 'returns expected value' ) ;
245300 t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
246301
302+ // Transposed:
303+ x = ndarray ( 'generic' , [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] , [ 2 , 1 ] , 0 , 'column-major' ) ;
304+ y = expandDimensions ( x , 0 , false ) ;
305+
306+ t . notEqual ( y , x , 'returns expected value' ) ;
307+ t . deepEqual ( getShape ( y ) , [ 1 , 2 , 2 ] , 'returns expected value' ) ;
308+ t . deepEqual ( getStrides ( y ) , [ 4 , 2 , 1 ] , 'returns expected value' ) ;
309+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
310+
247311 t . end ( ) ;
248312} ) ;
249313
@@ -274,6 +338,15 @@ tape( 'the function appends singleton dimensions (base; row-major)', function te
274338 t . deepEqual ( getStrides ( y ) , [ 2 , 1 , 1 ] , 'returns expected value' ) ;
275339 t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
276340
341+ // Transposed:
342+ x = ndarray ( 'generic' , [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] , [ 1 , 2 ] , 0 , 'row-major' ) ;
343+ y = expandDimensions ( x , ndims ( x ) , false ) ;
344+
345+ t . notEqual ( y , x , 'returns expected value' ) ;
346+ t . deepEqual ( getShape ( y ) , [ 2 , 2 , 1 ] , 'returns expected value' ) ;
347+ t . deepEqual ( getStrides ( y ) , [ 1 , 2 , 4 ] , 'returns expected value' ) ;
348+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
349+
277350 t . end ( ) ;
278351} ) ;
279352
@@ -304,6 +377,15 @@ tape( 'the function appends singleton dimensions (base; column-major)', function
304377 t . deepEqual ( getStrides ( y ) , [ 1 , 2 , 4 ] , 'returns expected value' ) ;
305378 t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
306379
380+ // Transposed:
381+ x = ndarray ( 'generic' , [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] , [ 2 , 1 ] , 0 , 'column-major' ) ;
382+ y = expandDimensions ( x , ndims ( x ) , false ) ;
383+
384+ t . notEqual ( y , x , 'returns expected value' ) ;
385+ t . deepEqual ( getShape ( y ) , [ 2 , 2 , 1 ] , 'returns expected value' ) ;
386+ t . deepEqual ( getStrides ( y ) , [ 2 , 1 , 1 ] , 'returns expected value' ) ;
387+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
388+
307389 t . end ( ) ;
308390} ) ;
309391
@@ -334,6 +416,15 @@ tape( 'the function inserts singleton dimensions (base; row-major)', function te
334416 t . deepEqual ( getStrides ( y ) , [ 2 , 2 , 1 ] , 'returns expected value' ) ;
335417 t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
336418
419+ // Transposed:
420+ x = ndarray ( 'generic' , [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] , [ 1 , 2 ] , 0 , 'row-major' ) ;
421+ y = expandDimensions ( x , 1 , false ) ;
422+
423+ t . notEqual ( y , x , 'returns expected value' ) ;
424+ t . deepEqual ( getShape ( y ) , [ 2 , 1 , 2 ] , 'returns expected value' ) ;
425+ t . deepEqual ( getStrides ( y ) , [ 1 , 2 , 2 ] , 'returns expected value' ) ;
426+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
427+
337428 t . end ( ) ;
338429} ) ;
339430
@@ -364,6 +455,15 @@ tape( 'the function inserts singleton dimensions (base; column-major)', function
364455 t . deepEqual ( getStrides ( y ) , [ 1 , 2 , 2 ] , 'returns expected value' ) ;
365456 t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
366457
458+ // Transposed:
459+ x = ndarray ( 'generic' , [ 1 , 2 , 3 , 4 ] , [ 2 , 2 ] , [ 2 , 1 ] , 0 , 'column-major' ) ;
460+ y = expandDimensions ( x , 1 , false ) ;
461+
462+ t . notEqual ( y , x , 'returns expected value' ) ;
463+ t . deepEqual ( getShape ( y ) , [ 2 , 1 , 2 ] , 'returns expected value' ) ;
464+ t . deepEqual ( getStrides ( y ) , [ 2 , 2 , 1 ] , 'returns expected value' ) ;
465+ t . strictEqual ( getData ( y ) , getData ( x ) , 'returns expected value' ) ;
466+
367467 t . end ( ) ;
368468} ) ;
369469
0 commit comments