From 903c51c7d0a06d9186a6f2be1b01fa25f770a3eb Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 14 Jul 2024 11:39:57 +0500 Subject: [PATCH] test: add tests to `@stdlib/ndarray/base/nullary` PR-URL: https://github.com/stdlib-js/stdlib/pull/2350 Ref: https://github.com/stdlib-js/stdlib/issues/2229 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../ndarray/base/nullary/test/test.0d.js | 72 ++ .../ndarray/base/nullary/test/test.10d.js | 724 ++++++++++++ .../ndarray/base/nullary/test/test.1d.js | 114 ++ .../ndarray/base/nullary/test/test.2d.js | 1013 +++++++++++++++++ .../ndarray/base/nullary/test/test.3d.js | 580 ++++++++++ .../ndarray/base/nullary/test/test.4d.js | 604 ++++++++++ .../ndarray/base/nullary/test/test.5d.js | 676 +++++++++++ .../ndarray/base/nullary/test/test.6d.js | 700 ++++++++++++ .../ndarray/base/nullary/test/test.7d.js | 724 ++++++++++++ .../ndarray/base/nullary/test/test.8d.js | 724 ++++++++++++ .../ndarray/base/nullary/test/test.9d.js | 724 ++++++++++++ .../@stdlib/ndarray/base/nullary/test/test.js | 2 - .../ndarray/base/nullary/test/test.nd.js | 724 ++++++++++++ 13 files changed, 7379 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary/test/test.nd.js diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.0d.js new file mode 100644 index 00000000000..1e9a9701a5b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.0d.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 0-dimensional ndarray', function test( t ) { + var expected; + var x; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array( [ 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 0-dimensional ndarray (accessors)', function test( t ) { + var expected; + var x; + + x = scalar2ndarray( new Complex128( 0.0, 0.0 ), { + 'dtype': 'complex128' + }); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array( [ 10.0, 10.0 ] ); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.10d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.10d.js new file mode 100644 index 00000000000..3ddf3244050 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.10d.js @@ -0,0 +1,724 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 10-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 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 ); + + 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 10-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 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 ); + + 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 10-dimensional ndarray (row-major, contiguous)', 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, 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 10-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 16, 8, 4, 2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 10-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 16, -8, -4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 10-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 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( 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 10-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 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 10-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 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 10-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, 1, 1, 1 ]; + 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 10-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 = [ 4, 1, 1, 1, 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 ); + + 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 10-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, 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 an 10-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, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 1, 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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an 10-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, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, -1, -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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 10-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 = [ 1, 1, 1, 1, 1, 2, 2, 1, 2, 1 ]; + 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 10-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 = [ 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 1, 4, 8, 8 ]; + 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 10-dimensional ndarray (column-major, non-contiguous, mixed 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 = [ 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, -1, 1, -1, 1, 1, -4, -8, 8 ]; + 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(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.1d.js new file mode 100644 index 00000000000..340538dea5e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.1d.js @@ -0,0 +1,114 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 1-dimensional ndarray', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 0.0, + 10.0, + 0.0, + 10.0, + 0.0, + 10.0, + 0.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 1-dimensional ndarray (empty array)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 8, 'float64' ), [ 0 ], [ 1 ], 0, 'row-major' ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 0.0, + 0.0, + 0.0, + 0.0, + 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 1-dimensional ndarray (accessors)', function test( t ) { + var expected; + var x; + + x = ndarray( 'complex128', zeros( 6, 'complex128' ), [ 4 ], [ 1 ], 1, 'row-major' ); + + nullary( [ x ], constantFunction( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array([ + 0.0, + 0.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.2d.js new file mode 100644 index 00000000000..16fcde9f669 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.2d.js @@ -0,0 +1,1013 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 2-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1 ]; + 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 2-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1 ]; + 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 2-dimensional ndarray (row-major, empty)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 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 2-dimensional ndarray (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 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 + ]); + 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 2-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 = [ 2, 2 ]; + st = [ -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 + ]); + 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 2-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 2-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 2-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, 2 ]; + st = [ -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[ 1 ] ); + + 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 2-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 ]; + st = [ 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[ 1 ] ); + + 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 2-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 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 + ]); + 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 2-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 2 ]; + st = [ -2, -1 ]; + 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 2-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 2-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 2-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, 2 ]; + st = [ -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[ 1 ] ); + + 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 2-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 ]; + st = [ 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[ 1 ] ); + + 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 2-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, 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 2-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 = [ 4, 1 ]; + 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 2-dimensional ndarray (column-major, empty)', function test( t ) { + var expected; + var x; + + x = ndarray( 'float64', zeros( 4, 'float64' ), [ 0, 0 ], [ 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 2-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, 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 + ]); + 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 2-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 ]; + st = [ -1, -2 ]; + 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 2-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, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 2-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, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 2-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, 2 ]; + st = [ 2, -bsize*4 ]; + 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 2-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 ]; + st = [ -2, 4 ]; + 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 2-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, 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 + ]); + 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 2-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, 2 ]; + st = [ -1, -2 ]; + 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 2-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, 2 ]; + st = [ 1, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 2-dimensional ndarray (column-major, non-contiguous, mixed 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, 2 ]; + st = [ 1, -4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 2-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, 2 ]; + st = [ 2, -bsize*4 ]; + 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 2-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 ]; + st = [ -2, 4 ]; + 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(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.3d.js new file mode 100644 index 00000000000..224ccb4711b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.3d.js @@ -0,0 +1,580 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 3-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + 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 3-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1 ]; + 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 3-dimensional ndarray (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 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 + ]); + 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 3-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 3, 2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.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 3-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -3, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.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 3-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 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 + ]); + 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 3-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ 3, 2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, 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, + 10.0, + 10.0, + 10.0, + 10.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 3-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = [ -3, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, 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, + 10.0, + 10.0, + 10.0, + 10.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 3-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, 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 3-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, 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 3-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 ]; + 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 3-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 ]; + st = [ 1, 2, 3 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.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 3-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 ]; + st = [ -1, -2, 3 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 10.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 3-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 ]; + 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 3-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 ]; + st = [ 1, 2, 3 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, 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, + 10.0, + 10.0, + 10.0, + 10.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 3-dimensional ndarray (column-major, non-contiguous, mixed 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 ]; + st = [ -1, -2, 3 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 6, 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, + 10.0, + 10.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.4d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.4d.js new file mode 100644 index 00000000000..1efe0eb18e1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.4d.js @@ -0,0 +1,604 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 4-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1 ]; + 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 4-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1 ]; + 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 4-dimensional ndarray (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2, 1 ]; + 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 4-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 1, 2, 1 ]; + st = [ 4, 2, 1, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 4-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 1, 2, 1 ]; + st = [ 4, -2, -1, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 4-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2, 1 ]; + 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 4-dimensional ndarray (row-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 = 'row-major'; + sh = [ 2, 1, 2, 1 ]; + st = [ 4, 2, 1, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 4-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 1, 2, 1 ]; + st = [ 4, -2, -1, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 4-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, 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 4-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, 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 4-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 ]; + 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 4-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 ]; + 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 4-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 ]; + st = [ 1, 2, 4, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 4-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 ]; + st = [ 1, -2, -4, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 4-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 ]; + st = [ 1, 2, 4, 8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + 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 4-dimensional ndarray (column-major, non-contiguous, mixed 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 ]; + st = [ 1, 2, -4, -8 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, 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 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); 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 new file mode 100644 index 00000000000..4bafca3b2da --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.5d.js @@ -0,0 +1,676 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 5-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 1 ]; + 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 (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 1 ]; + 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 (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-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 (row-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 = '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( 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 (row-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 = '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( 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 (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-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 (row-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 = '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, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + 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 (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, 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, 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, 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, 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 ); + + 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 (column-major, non-contiguous, mixed 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 ); + + 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(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.6d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.6d.js new file mode 100644 index 00000000000..3238e38622c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.6d.js @@ -0,0 +1,700 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 6-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 1, 1 ]; + 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 6-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 1, 1 ]; + 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 6-dimensional ndarray (row-major, contiguous)', 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, 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 6-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 8, 4, 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 6-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 2, 2, 1, 2 ]; + st = [ 16, -16, 8, -4, 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 6-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 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( 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 6-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 8, 4, 4, 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 6-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 8, -4, -4, -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 6-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 ); + + 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 6-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 = [ 4, 1, 1, 1, 1, 1 ]; + 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 6-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, 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 6-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, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 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 6-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, 2, 2, 1, 2 ]; + st = [ 1, -1, 1, -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 6-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 = [ 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( 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 6-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 = [ 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 2, 4, 8 ]; + 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 6-dimensional ndarray (column-major, non-contiguous, mixed 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 = [ 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, -2, -4, -8 ]; + 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(); +}); 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 new file mode 100644 index 00000000000..5f89606482a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.7d.js @@ -0,0 +1,724 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 7-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-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 ); + + 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 7-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-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 ); + + 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 (row-major, contiguous)', 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 = 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 (row-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 = '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( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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, 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 = '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( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-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( 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 7-dimensional ndarray (row-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 = '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, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + 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 (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 ); + + 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 7-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 = [ 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 ); + + 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, 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, 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, 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 = [ 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( 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 7-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 = [ 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( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 (column-major, non-contiguous, mixed 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 = [ 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( new Complex128( 10.0, 10.0 ) ) ); + + expected = new Complex128Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0 + ]); + t.strictEqual( isSameComplex128Array( x.data, expected ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.8d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.8d.js new file mode 100644 index 00000000000..0f51650441d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.8d.js @@ -0,0 +1,724 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of an 8-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 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 ); + + 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 an 8-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 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 ); + + 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 an 8-dimensional ndarray (row-major, contiguous)', 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, 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 an 8-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 8, 4, 2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an 8-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, -8, -4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an 8-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 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( 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 an 8-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 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 an 8-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 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 an 8-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, 1 ]; + 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 an 8-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 = [ 4, 1, 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 ); + + 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 an 8-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, 1 ]; + 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 an 8-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, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an 8-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, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, -1, -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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an 8-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 = [ 1, 1, 1, 2, 2, 1, 2, 1 ]; + 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 an 8-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 = [ 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 4, 8, 8 ]; + 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 an 8-dimensional ndarray (column-major, non-contiguous, mixed 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 = [ 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ -1, 1, -1, 1, 1, -4, -8, 8 ]; + 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(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.9d.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.9d.js new file mode 100644 index 00000000000..3abc38954bb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.9d.js @@ -0,0 +1,724 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of a 9-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1, 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 ); + + 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 9-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1, 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 ); + + 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 9-dimensional ndarray (row-major, contiguous)', 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, 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 9-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 8, 4, 2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 9-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, -8, -4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 9-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 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( 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 9-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 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 9-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 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 9-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, 1, 1 ]; + 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 9-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 = [ 4, 1, 1, 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 ); + + 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 9-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, 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 an 9-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, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an 9-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, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, -1, -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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 9-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 = [ 1, 1, 1, 1, 2, 2, 1, 2, 1 ]; + 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 9-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 = [ 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 4, 8, 8 ]; + 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 9-dimensional ndarray (column-major, non-contiguous, mixed 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 = [ 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, -1, 1, -1, 1, 1, -4, -8, 8 ]; + 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(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.js index dbf444497d0..854cefca7c8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.js @@ -31,5 +31,3 @@ tape( 'main export is a function', function test( t ) { t.strictEqual( typeof nullary, 'function', 'main export is a function' ); t.end(); }); - -// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.nd.js b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.nd.js new file mode 100644 index 00000000000..19d92cc925c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary/test/test.nd.js @@ -0,0 +1,724 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var zeros = require( '@stdlib/array/zeros' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var constantFunction = require( '@stdlib/utils/constant-function' ); +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 nullary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nullary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function applies a nullary callback to each indexed element of an n-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 1, 1, 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 ); + + 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 an n-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 4, 1, 1, 1, 1, 1, 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 ); + + 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 an n-dimensional ndarray (row-major, contiguous)', 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, 1, 1, 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 an n-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 16, 16, 16, 8, 4, 2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an n-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 16, 16, 16, -8, -4, -2, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 16, dt ), sh, st, o, ord ); + + nullary( [ x ], constantFunction( 10.0 ) ); + + expected = new Float64Array([ + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an n-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 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( 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 an n-dimensional ndarray (row-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 = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 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 an n-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 16, 16, 16, 16, 16, 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 an n-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, 1, 1, 1, 1, 1 ]; + 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 an n-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 = [ 4, 1, 1, 1, 1, 1, 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 ); + + 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 an n-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, 1, 1, 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 an n-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, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an n-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, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 1, 1, -1, -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, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.0, + 0.0, + 0.0, + 10.0, + 10.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 an n-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 = [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1 ]; + 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 an n-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 = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 8, 8 ]; + 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 an n-dimensional ndarray (column-major, non-contiguous, mixed 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 = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2 ]; + st = [ 1, 1, 1, 1, -1, 1, -1, 1, 1, -4, -8, 8 ]; + 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(); +});