From dedba403fed1905619a3e04f4e8547459d5cc489 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 21 Jul 2024 06:10:10 +0500 Subject: [PATCH] test: add tests to `ndarray/base/nullary` PR-URL: https://github.com/stdlib-js/stdlib/pull/2634 Ref: https://github.com/stdlib-js/stdlib/issues/2229 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../ndarray/base/nullary/test/test.5d.js | 1127 ++++++++++++++--- 1 file changed, 968 insertions(+), 159 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.5d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.5d.js index 4bafca3b2da..44a2f4bb8bc 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.5d.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.5d.js @@ -32,6 +32,9 @@ var ndarray = require( '@stdlib/ndarray/ctor' ); var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); var numel = require( '@stdlib/ndarray/base/numel' ); +var dfill = require( '@stdlib/blas/ext/base/dfill' ); +var gfill = require( '@stdlib/blas/ext/base/gfill' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); var nullary = require( './../lib' ); @@ -107,6 +110,25 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di t.end(); }); +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, empty)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0, 0, 0 ], [ 1, 1, 1, 1, 1 ], 0, 'row-major' ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, contiguous)', function test( t ) { var expected; var ord; @@ -141,7 +163,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, contiguous, negative strides)', function test( t ) { var expected; var ord; var sh; @@ -152,11 +174,11 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di dt = 'float64'; ord = 'row-major'; - sh = [ 2, 1, 2, 1, 2 ]; - st = [ 8, 4, 2, 2, 1 ]; + sh = [ 2, 2, 1, 2, 2 ]; + st = [ -8, -4, -4, -2, -1 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); nullary( [ x ], constantFunction( 10.0 ) ); @@ -165,10 +187,14 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di 10.0, 10.0, 10.0, - 0.0, - 0.0, - 0.0, - 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, 10.0, 10.0, 10.0, @@ -179,7 +205,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { var expected; var ord; var sh; @@ -191,7 +217,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di dt = 'float64'; ord = 'row-major'; sh = [ 2, 1, 2, 1, 2 ]; - st = [ 8, 4, -2, -2, 1 ]; + st = [ 8, 4, 2, 2, 1 ]; o = strides2offset( sh, st ); x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); @@ -217,7 +243,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { var expected; var ord; var sh; @@ -226,41 +252,38 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var o; var x; - dt = 'complex128'; + dt = 'float64'; ord = 'row-major'; sh = [ 2, 1, 2, 1, 2 ]; - st = shape2strides( sh, ord ); + st = [ 8, 4, -2, -2, 1 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( new Complex128( 10.0, -10.0 ) ) ); + nullary( [ x ], constantFunction( 10.0 ) ); - expected = new Complex128Array([ - 10.0, - -10.0, + expected = new Float64Array([ 10.0, - -10.0, 10.0, - -10.0, 10.0, - -10.0, 10.0, - -10.0, + 0.0, + 0.0, + 0.0, + 0.0, 10.0, - -10.0, 10.0, - -10.0, 10.0, - -10.0 + 10.0 ]); - t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -268,49 +291,29 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var o; var x; - dt = 'complex128'; + dt = 'float64'; ord = 'row-major'; - sh = [ 2, 1, 2, 1, 2 ]; - st = [ 8, 4, 2, 2, 1 ]; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2, 1, 2 ]; + st = [ 8, -8, -4, 4, 2 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + nullary( [ x ], constantFunction( 10.0 ) ); - expected = new Complex128Array([ - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0 - ]); - t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 4 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -318,49 +321,29 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var o; var x; - dt = 'complex128'; + dt = 'float64'; ord = 'row-major'; - sh = [ 2, 1, 2, 1, 2 ]; - st = [ 8, 4, -2, -2, -1 ]; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1, 1, 2 ]; + st = [ bsize*8, -4, 4, -4, -2 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + nullary( [ x ], constantFunction( 10.0 ) ); - expected = new Complex128Array([ - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0 - ]); - t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 4 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, singleton dimensions)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -369,28 +352,28 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var x; dt = 'float64'; - ord = 'column-major'; - sh = [ 1, 1, 1, 1, 4 ]; - st = shape2strides( sh, ord ); + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2, 1, 2 ]; + st = [ bsize*8, bsize*8, -4, -4, 2 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); nullary( [ x ], constantFunction( 10.0 ) ); - expected = new Float64Array([ - 10.0, - 10.0, - 10.0, - 10.0 - ]); + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 4 ] ); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, singleton dimensions, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -398,33 +381,29 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var o; var x; - dt = 'complex128'; - ord = 'column-major'; - sh = [ 1, 1, 1, 1, 4 ]; - st = shape2strides( sh, ord ); + dt = 'float64'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, bsize*2, 1 ]; + st = [ bsize*8, -bsize*8, -bsize*4, -2, 2 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + nullary( [ x ], constantFunction( 10.0 ) ); - expected = new Complex128Array([ - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0 - ]); - t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 4 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, contiguous)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -433,31 +412,26 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var x; dt = 'float64'; - ord = 'column-major'; - sh = [ 2, 1, 2, 1, 2 ]; - st = shape2strides( sh, ord ); + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, bsize*2 ]; + st = [ bsize*8, -bsize*8, -bsize*4, -bsize*4, 2 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); nullary( [ x ], constantFunction( 10.0 ) ); - expected = new Float64Array([ - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0, - 10.0 - ]); + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 4 ] ); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { var expected; var ord; var sh; @@ -467,7 +441,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var x; dt = 'complex128'; - ord = 'column-major'; + ord = 'row-major'; sh = [ 2, 1, 2, 1, 2 ]; st = shape2strides( sh, ord ); o = strides2offset( sh, st ); @@ -499,7 +473,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, contiguous, negative strides, accessors)', function test( t ) { var expected; var ord; var sh; @@ -508,36 +482,40 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var o; var x; - dt = 'float64'; - ord = 'column-major'; + dt = 'complex128'; + ord = 'row-major'; sh = [ 2, 1, 2, 1, 2 ]; - st = [ 1, 2, 2, 4, 8 ]; + st = [ -4, -4, -2, -2, -1 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( 10.0 ) ); + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); - expected = new Float64Array([ + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, 10.0, 10.0, 10.0, 10.0, - 0.0, - 0.0, - 0.0, - 0.0, 10.0, 10.0, 10.0, 10.0 ]); - t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { var expected; var ord; var sh; @@ -546,36 +524,48 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var o; var x; - dt = 'float64'; - ord = 'column-major'; + dt = 'complex128'; + ord = 'row-major'; sh = [ 2, 1, 2, 1, 2 ]; - st = [ 1, 2, -2, -4, 8 ]; + st = [ 8, 4, 2, 2, 1 ]; o = strides2offset( sh, st ); x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( 10.0 ) ); + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); - expected = new Float64Array([ + expected = new Complex128Array([ + 10.0, 10.0, 10.0, 10.0, 10.0, + 10.0, + 10.0, + 10.0, + 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, 10.0, 10.0, 10.0, 10.0 ]); - t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { var expected; var ord; var sh; @@ -585,7 +575,676 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di var x; dt = 'complex128'; - ord = 'column-major'; + ord = 'row-major'; + sh = [ 2, 1, 2, 1, 2 ]; + st = [ 8, 4, -2, -2, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2, 1, 2 ]; + st = [ 8, -8, -4, 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 4 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1, 1, 2 ]; + st = [ bsize*8, -4, 4, -4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 4 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2, 1, 2 ]; + st = [ bsize*8, bsize*8, -4, -4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 4 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 1, bsize*2, 2 ]; + st = [ bsize*8, -bsize*8, -bsize*8, -4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 4 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, bsize*2 ]; + st = [ bsize*8, -bsize*8, -bsize*4, -bsize*4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 4 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 1, 1, 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 1, 1, 1, 1, 4 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, empty)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0, 0, 0 ], [ 1, 1, 1, 1, 1 ], 0, 'column-major' ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 1, 2, 2 ]; + st = [ -1, -2, -4, -4, -8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2, 1, 2 ]; + st = [ 1, 2, 2, 4, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2, 1, 2 ]; + st = [ 1, 2, -2, -4, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 12, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2, 1, 2 ]; + st = [ -2, bsize*4, -bsize*4, bsize*8, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1, 1, 2 ]; + st = [ -2, 4, -bsize*8, bsize*8, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2, 1, 2 ]; + st = [ -2, 4, -4, bsize*8, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 1, bsize*2, 2 ]; + st = [ -2, 4, -4, 4, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, bsize*2 ]; + st = [ -2, 4, -4, 8, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 0 ] ); + + t.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, -10.0 ) ) ); + + expected = new Complex128Array([ + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0, + 10.0, + -10.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, contiguous, negative strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 1, 2, 1, 2 ]; + st = [ -1, -2, -2, -4, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; sh = [ 2, 1, 2, 1, 2 ]; st = [ 1, 2, 2, 4, 8 ]; o = strides2offset( sh, st ); @@ -674,3 +1333,153 @@ tape( 'the function applies a nullary callback to each indexed element of a 5-di t.end(); }); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2, 1, 2 ]; + st = [ -2, bsize*4, -bsize*4, bsize*8, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 2, 1, 1 ]; + st = [ -2, 4, -bsize*8, bsize*16, bsize*16 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2, 1, 2 ]; + st = [ -2, 4, -4, bsize*8, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 1, bsize*2, 2 ]; + st = [ -2, -4, -4, 4, bsize*8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var expected; + var bsize; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, bsize*2 ]; + st = [ 2, 4, -4, 8, -8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( x.length*2 ); + gfill( x.length, new Complex128( 10.0, 10.0 ), expected, st[ 0 ] ); + + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +});