2121// MODULES //
2222
2323var tape = require ( 'tape' ) ;
24- var isndarrayLike = require ( '@stdlib/assert/is-ndarray-like' ) ;
2524var isEqualDataType = require ( '@stdlib/ndarray/base/assert/is-equal-data-type' ) ;
26- var zeroTo = require ( '@stdlib/array/zero-to' ) ;
27- var ndarray = require ( '@stdlib/ndarray/ctor' ) ;
28- var array = require ( '@stdlib/ndarray/array' ) ;
25+ var zeroTo = require ( '@stdlib/blas/ext/zero-to' ) ;
2926var getShape = require ( '@stdlib/ndarray/shape' ) ;
3027var getDType = require ( '@stdlib/ndarray/dtype' ) ;
3128var getData = require ( '@stdlib/ndarray/data-buffer' ) ;
@@ -72,10 +69,14 @@ tape( 'the function throws an error if provided a first argument which is not an
7269
7370tape ( 'the function throws an error if provided a second argument which is not an integer' , function test ( t ) {
7471 var values ;
72+ var opts ;
7573 var x ;
7674 var i ;
7775
78- x = new ndarray ( 'float64' , [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
76+ opts = {
77+ 'dtype' : 'float64'
78+ } ;
79+ x = zeroTo ( [ 6 ] , opts ) ;
7980
8081 values = [
8182 '5' ,
@@ -104,10 +105,14 @@ tape( 'the function throws an error if provided a second argument which is not a
104105
105106tape ( 'the function throws an error if provided a third argument which is not an array of nonnegative integers' , function test ( t ) {
106107 var values ;
108+ var opts ;
107109 var x ;
108110 var i ;
109111
110- x = new ndarray ( 'float64' , [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
112+ opts = {
113+ 'dtype' : 'float64'
114+ } ;
115+ x = zeroTo ( [ 6 ] , opts ) ;
111116
112117 values = [
113118 '5' ,
@@ -137,41 +142,70 @@ tape( 'the function throws an error if provided a third argument which is not an
137142} ) ;
138143
139144tape ( 'the function throws an error if provided an invalid dimension index' , function test ( t ) {
145+ var values ;
146+ var opts ;
147+ var i ;
140148 var x ;
141149
142- x = new ndarray ( 'float64' , [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
143-
144- t . throws ( function badValue ( ) {
145- toUnflattened ( x , 5 , [ 2 , 3 ] ) ;
146- } , RangeError , 'throws an error when dimension index is out-of-bounds (positive)' ) ;
150+ opts = {
151+ 'dtype' : 'float64'
152+ } ;
153+ x = zeroTo ( [ 6 ] , opts ) ;
147154
148- t . throws ( function badValue ( ) {
149- toUnflattened ( x , - 3 , [ 2 , 3 ] ) ;
150- } , RangeError , 'throws an error when dimension index is out-of-bounds (negative)' ) ;
155+ values = [
156+ 5 ,
157+ - 3
158+ ] ;
151159
160+ for ( i = 0 ; i < values . length ; i ++ ) {
161+ t . throws ( badValue ( values [ i ] ) , RangeError , 'throws an error when provided ' + values [ i ] ) ;
162+ }
152163 t . end ( ) ;
164+
165+ function badValue ( dim ) {
166+ return function test ( ) {
167+ toUnflattened ( x , dim , [ 2 , 3 ] ) ;
168+ } ;
169+ }
153170} ) ;
154171
155172tape ( 'the function throws an error if the product of `sizes` does not match the dimension size' , function test ( t ) {
173+ var values ;
174+ var opts ;
175+ var i ;
156176 var x ;
157177
158- x = new ndarray ( 'float64' , [ 1 , 2 , 3 , 4 , 5 , 6 ] , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
178+ opts = {
179+ 'dtype' : 'float64'
180+ } ;
181+ x = zeroTo ( [ 6 ] , opts ) ;
159182
160- t . throws ( function badValue ( ) {
161- toUnflattened ( x , 0 , [ 2 , 4 ] ) ;
162- } , RangeError , 'throws an error when product of sizes does not match dimension size' ) ;
183+ values = [
184+ [ 2 , 4 ]
185+ ] ;
163186
187+ for ( i = 0 ; i < values . length ; i ++ ) {
188+ t . throws ( badValue ( values [ i ] ) , RangeError , 'throws an error when product of sizes does not match dimension size' ) ;
189+ }
164190 t . end ( ) ;
191+
192+ function badValue ( sizes ) {
193+ return function test ( ) {
194+ toUnflattened ( x , 0 , sizes ) ;
195+ } ;
196+ }
165197} ) ;
166198
167199tape ( 'the function returns a new ndarray with the unflattened dimension (1D input)' , function test ( t ) {
168200 var expected ;
169- var buf ;
201+ var opts ;
170202 var x ;
171203 var y ;
172204
173- buf = zeroTo ( 6 ) ;
174- x = ndarray ( 'generic' , buf , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
205+ opts = {
206+ 'dtype' : 'generic'
207+ } ;
208+ x = zeroTo ( [ 6 ] , opts ) ;
175209
176210 expected = [
177211 [ 0 , 1 , 2 ] ,
@@ -189,12 +223,14 @@ tape( 'the function returns a new ndarray with the unflattened dimension (1D inp
189223
190224tape ( 'the function returns a new ndarray with the unflattened dimension (1D input, unflattened to 3D)' , function test ( t ) {
191225 var expected ;
192- var buf ;
226+ var opts ;
193227 var x ;
194228 var y ;
195229
196- buf = zeroTo ( 12 ) ;
197- x = ndarray ( 'generic' , buf , [ 12 ] , [ 1 ] , 0 , 'row-major' ) ;
230+ opts = {
231+ 'dtype' : 'generic'
232+ } ;
233+ x = zeroTo ( [ 12 ] , opts ) ;
198234
199235 expected = [
200236 [ [ 0 , 1 , 2 ] , [ 3 , 4 , 5 ] ] ,
@@ -212,12 +248,14 @@ tape( 'the function returns a new ndarray with the unflattened dimension (1D inp
212248
213249tape ( 'the function supports negative dimension indices' , function test ( t ) {
214250 var expected ;
215- var buf ;
251+ var opts ;
216252 var x ;
217253 var y ;
218254
219- buf = zeroTo ( 6 ) ;
220- x = ndarray ( 'generic' , buf , [ 6 ] , [ 1 ] , 0 , 'row-major' ) ;
255+ opts = {
256+ 'dtype' : 'generic'
257+ } ;
258+ x = zeroTo ( [ 6 ] , opts ) ;
221259
222260 expected = [
223261 [ 0 , 1 , 2 ] ,
@@ -233,31 +271,17 @@ tape( 'the function supports negative dimension indices', function test( t ) {
233271 t . end ( ) ;
234272} ) ;
235273
236- tape ( 'the function returns a new ndarray that is ndarray-like' , function test ( t ) {
237- var x ;
238- var y ;
239-
240- x = array ( zeroTo ( 6 ) , {
241- 'shape' : [ 6 ] ,
242- 'dtype' : 'float64'
243- } ) ;
244-
245- y = toUnflattened ( x , 0 , [ 2 , 3 ] ) ;
246- t . strictEqual ( isndarrayLike ( y ) , true , 'returns ndarray-like object' ) ;
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' ) ;
249-
250- t . end ( ) ;
251- } ) ;
252-
253274tape ( 'the function supports column-major order' , function test ( t ) {
254275 var expected ;
255- var buf ;
276+ var opts ;
256277 var x ;
257278 var y ;
258279
259- buf = zeroTo ( 6 ) ;
260- x = ndarray ( 'generic' , buf , [ 6 ] , [ 1 ] , 0 , 'column-major' ) ;
280+ opts = {
281+ 'dtype' : 'generic' ,
282+ 'order' : 'column-major'
283+ } ;
284+ x = zeroTo ( [ 6 ] , opts ) ;
261285
262286 expected = [
263287 [ 0 , 2 , 4 ] ,
@@ -275,12 +299,15 @@ tape( 'the function supports column-major order', function test( t ) {
275299
276300tape ( 'the function unflattens a middle dimension in a multidimensional input' , function test ( t ) {
277301 var expected ;
278- var buf ;
302+ var opts ;
279303 var x ;
280304 var y ;
281305
282- buf = zeroTo ( 12 ) ;
283- x = ndarray ( 'generic' , buf , [ 3 , 4 ] , [ 4 , 1 ] , 0 , 'row-major' ) ;
306+ opts = {
307+ 'dtype' : 'generic' ,
308+ 'dims' : [ 0 , 1 ]
309+ } ;
310+ x = zeroTo ( [ 3 , 4 ] , opts ) ;
284311
285312 expected = [
286313 [ [ 0 , 1 ] , [ 2 , 3 ] ] ,
0 commit comments