From b4ac56222cfde111a3432af6342c596c8523493f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 21 Jul 2024 18:54:14 +0000 Subject: [PATCH 1/2] test: add nullary 7d tests --- .../ndarray/base/nullary/test/test.7d.js | 1261 +++++++++++++++-- 1 file changed, 1167 insertions(+), 94 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js index 5f89606482a..6b8cc36bd99 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.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 7-di t.end(); }); +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (row-major, empty)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0, 0, 0, 0, 0 ], [ 1, 1, 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 7-dimensional ndarray (row-major, contiguous)', function test( t ) { var expected; var ord; @@ -141,6 +163,40 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di t.end(); }); +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (row-major, contiguous, negative strides)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 1, 1, 1, 2, 2, 1, 2 ]; + st = [ -8, -8, -8, -4, -2, -2, -1 ]; + 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 7-dimensional ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { var expected; var ord; @@ -225,6 +281,216 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di t.end(); }); +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ bsize*2, 1, 2, 1, 2, 1, 2 ]; + st = [ 16, -16, 8, 8, -4, 4, 2 ]; + 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[ 6 ] ); + + 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 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, bsize*2, 1, 2, 1, 1, 2 ]; + st = [ bsize*16, -8, 8, 4, -4, 4, 2 ]; + 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[ 6 ] ); + + 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 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, bsize*2, 1, 2, 1, 2 ]; + st = [ bsize*16, -bsize*16, 8, 8, -4, 4, 2 ]; + 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[ 6 ] ); + + 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 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, bsize*2, 1, 1, 2 ]; + st = [ bsize*16, -bsize*16, 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( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 6 ] ); + + 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 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, bsize*2, 1, 2 ]; + st = [ bsize*16, -bsize*16, 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( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 6 ] ); + + 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 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, 1, bsize*2, 2 ]; + st = [ bsize*16, -bsize*16, 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( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 6 ] ); + + 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 7-dimensional ndarray (row-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 = 'row-major'; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, 2, 1, bsize*2 ]; + st = [ bsize*16, -bsize*16, 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( 10.0 ) ); + + expected = new Float64Array( x.length*2 ); + dfill( x.length, 10.0, expected, st[ 6 ] ); + + 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 7-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { var expected; var ord; @@ -267,7 +533,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 7-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 7-dimensional ndarray (row-major, contiguous, accessors, negative strides)', function test( t ) { var expected; var ord; var sh; @@ -278,54 +544,54 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di dt = 'complex128'; ord = 'row-major'; - sh = [ 1, 1, 1, 2, 2, 1, 2 ]; - st = [ 16, 16, 16, 8, 4, 2, 1 ]; + sh = [ 2, 1, 2, 1, 2, 1, 2 ]; + st = [ -8, -8, -4, -4, -2, -2, -1 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + 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, - 0.0, - 0.0, - 0.0, - 0.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, + -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, 10.0, - 0.0, - 0.0, - 0.0, - 0.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 7-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 7-dimensional ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { var expected; var ord; var sh; @@ -337,7 +603,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di dt = 'complex128'; ord = 'row-major'; sh = [ 1, 1, 1, 2, 2, 1, 2 ]; - st = [ -16, 16, -16, -8, 4, -2, 1 ]; + st = [ 16, 16, 16, 8, 4, 2, 1 ]; o = strides2offset( sh, st ); x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); @@ -383,7 +649,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (column-major, singleton dimensions)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { var expected; var ord; var sh; @@ -392,10 +658,278 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di var o; var x; - dt = 'float64'; - ord = 'column-major'; - sh = [ 4, 1, 1, 1, 1, 1, 1 ]; - st = shape2strides( sh, ord ); + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 2, 2, 1, 2 ]; + st = [ -16, 16, -16, -8, 4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, 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, + 0.0, + 0.0, + 0.0, + 0.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, + 0.0, + 0.0, + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.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 7-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, 1, 2 ]; + st = [ bsize*4, -bsize*4, 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[ 6 ] ); + + 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 7-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, 1, 2 ]; + st = [ bsize*16, -8, 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[ 6 ] ); + + 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 7-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, 1, 2 ]; + st = [ bsize*16, -bsize*16, 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[ 6 ] ); + + 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 7-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, bsize*2, 1, 1, 2 ]; + st = [ bsize*16, -bsize*16, 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[ 6 ] ); + + 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 7-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, 1, 2 ]; + st = [ bsize*16, -bsize*16, 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[ 6 ] ); + + 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 7-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, 2, 1, bsize*2, 2 ]; + st = [ bsize*16, -bsize*16, bsize*16, 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[ 6 ] ); + + 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 7-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, 2, 1, bsize*2 ]; + st = [ bsize*16, -bsize*16, 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[ 6 ] ); + + 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 7-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 = [ 4, 1, 1, 1, 1, 1, 1 ]; + st = shape2strides( sh, ord ); o = strides2offset( sh, st ); x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); @@ -430,25 +964,355 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); - nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + 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 7-dimensional ndarray (column-major, empty)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0, 0, 0, 0, 0, 0 ], [ 1, 1, 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 7-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 = [ 1, 1, 1, 2, 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 7-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, 1, 2, 1, 2, 1, 2 ]; + st = [ -1, -2, -2, -4, -4, -8, -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 7-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 = [ 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 2, 4, 8, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.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 7-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 = [ 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, -1, 2, -4, 8, -8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.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 7-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, 1, 2 ]; + st = [ 2, -bsize*4, bsize*4, bsize*8, -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( 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 7-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, 2, 1, 2, 1 ]; + st = [ 2, -4, bsize*8, bsize*8, -bsize*16, bsize*16, bsize*32 ]; + 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 7-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, 1, 2 ]; + st = [ 2, -4, -4, bsize*8, 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( 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 7-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, 1, 2 ]; + st = [ 2, -4, -4, 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( 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 7-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, 1, 2 ]; + st = [ 2, -4, -4, 8, 8, bsize*16, bsize*16 ]; + 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 ] ); - 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.strictEqual( isSameFloat64Array( x.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (column-major, contiguous)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -458,31 +1322,27 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di dt = 'float64'; ord = 'column-major'; - sh = [ 1, 1, 1, 2, 2, 1, 2 ]; - st = shape2strides( sh, ord ); + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, 1, bsize*2, 2 ]; + st = [ 2, -4, -4, 8, 8, 8, bsize*16 ]; 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[ 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 7-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 7-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { var expected; + var bsize; var ord; var sh; var st; @@ -492,38 +1352,25 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di dt = 'float64'; ord = 'column-major'; - sh = [ 1, 1, 1, 2, 2, 1, 2 ]; - st = [ 1, 1, 1, 2, 4, 8, 8 ]; + + bsize = blockSize( dt ); + sh = [ 2, 1, 2, 1, 2, 1, bsize*2 ]; + st = [ 2, -4, -4, 8, 8, 16, 16 ]; o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 16, 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, - 0.0, - 10.0, - 0.0, - 10.0, - 0.0, - 10.0, - 0.0, - 10.0, - 0.0, - 10.0, - 0.0, - 10.0, - 0.0, - 10.0, - 0.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 7-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 7-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { var expected; var ord; var sh; @@ -532,40 +1379,40 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di var o; var x; - dt = 'float64'; + dt = 'complex128'; ord = 'column-major'; sh = [ 1, 1, 1, 2, 2, 1, 2 ]; - st = [ 1, 1, -1, 2, -4, 8, -8 ]; + st = shape2strides( sh, ord ); o = strides2offset( sh, st ); - x = ndarray( dt, zeros( 16, 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, - 0.0, + -10.0, 10.0, - 0.0, + -10.0, 10.0, - 0.0, + -10.0, 10.0, - 0.0, + -10.0, 10.0, - 0.0, + -10.0, 10.0, - 0.0, + -10.0, 10.0, - 0.0, + -10.0, 10.0, - 0.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 7-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (column-major, contiguous, accessors, negative strides)', function test( t ) { var expected; var ord; var sh; @@ -576,8 +1423,8 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di dt = 'complex128'; ord = 'column-major'; - sh = [ 1, 1, 1, 2, 2, 1, 2 ]; - st = shape2strides( sh, ord ); + sh = [ 2, 1, 2, 1, 2, 1, 2 ]; + st = [ -1, -2, -2, -4, -4, -8, -8 ]; o = strides2offset( sh, st ); x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); @@ -585,6 +1432,22 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di 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, 10.0, -10.0, 10.0, @@ -722,3 +1585,213 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di t.end(); }); + +tape( 'the function applies a nullary callback to each indexed element of a 7-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, 1, 2 ]; + st = [ 2, -bsize*4, -bsize*4, bsize*8, 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 7-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, 1, 1, 2, 1, 2 ]; + st = [ 2, -4, -bsize*8, bsize*8, 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 7-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, 1, 2 ]; + st = [ 2, -4, -4, bsize*8, 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 7-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, 1, 2, 2 ]; + st = [ 2, -4, -4, 4, bsize*8, bsize*8, 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 7-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, 1, 2 ]; + st = [ 2, -4, -4, 8, 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 7-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, 1, bsize*2, 2 ]; + st = [ 2, -4, -4, 8, 8, 8, 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 7-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, 2, 1, bsize*2 ]; + st = [ 2, -4, -4, 8, 8, 16, 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(); +}); From ed8d05021778d4d182a37ac9e2aa8775a9133bc5 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 22 Jul 2024 14:08:39 -0700 Subject: [PATCH 2/2] test: fix strides --- lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js index 6b8cc36bd99..198ff8a6b80 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js @@ -722,7 +722,7 @@ tape( 'the function applies a nullary callback to each indexed element of a 7-di bsize = blockSize( dt ); sh = [ bsize*2, 1, 2, 1, 2, 1, 2 ]; - st = [ bsize*4, -bsize*4, 8, 8, -4, 4, 2 ]; + st = [ 16, -16, 8, 8, -4, 4, 2 ]; o = strides2offset( sh, st ); x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord );