From 94c049420b9ee17155360b121ad38fa4d56e828b Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Mon, 5 Jan 2026 10:54:41 +0530 Subject: [PATCH 1/3] test: add tests for --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/unary-accumulate/test/test.js | 722 +++++++++++++++++- 1 file changed, 721 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js index 3fea05a50627..65466eac3418 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js @@ -21,9 +21,50 @@ // MODULES // var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var accumulateUnary = require( './../lib' ); +// FUNCTIONS // + +/** +* Adds two values. +* +* @private +* @param {number} acc - accumulated value +* @param {number} x - input value +* @returns {number} sum +*/ +function add( acc, x ) { + return acc + x; +} + +/** +* Multiplies two values. +* +* @private +* @param {number} acc - accumulated value +* @param {number} x - input value +* @returns {number} product +*/ +function multiply( acc, x ) { + return acc * x; +} + +/** +* Sums the real component of a complex number. +* +* @private +* @param {number} acc - accumulated value +* @param {Complex} x - input value +* @returns {number} sum +*/ +function sumReal( acc, x ) { + return acc + x.re; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -32,4 +73,683 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -// FIXME: add tests +tape( 'the function performs a reduction over a 0-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 5.0 ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 1-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 4 ], + 'strides': [ 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 10.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 1-dimensional ndarray (negative stride)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 4 ], + 'strides': [ -1 ], + 'offset': 3, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 10.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 1-dimensional ndarray (offset)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ), + 'shape': [ 3 ], + 'strides': [ 1 ], + 'offset': 1, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 9.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 2-dimensional ndarray (row-major)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), + 'shape': [ 2, 3 ], + 'strides': [ 3, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 21.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 2-dimensional ndarray (column-major)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), + 'shape': [ 2, 3 ], + 'strides': [ 1, 2 ], + 'offset': 0, + 'order': 'column-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 21.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 3-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2, 2 ], + 'strides': [ 4, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 4-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2, 1, 2 ], + 'strides': [ 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 5-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 1, 2, 1, 2 ], + 'strides': [ 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 6-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 1, 1, 2, 1, 2 ], + 'strides': [ 4, 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 7-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 2, 1, 1, 2, 1, 2 ], + 'strides': [ 8, 4, 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 8-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 2, 1, 1, 2, 1, 2 ], + 'strides': [ 8, 8, 4, 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 9-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 2, 1, 1, 2, 1, 2 ], + 'strides': [ 8, 8, 8, 4, 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a 10-dimensional ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 2, 1, 1, 2, 1, 2 ], + 'strides': [ 8, 8, 8, 8, 4, 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over an ndarray with more than 10 dimensions', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2 ], + 'strides': [ 8, 8, 8, 8, 8, 4, 4, 4, 2, 2, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over a non-contiguous ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 3, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over an ndarray with mixed sign strides', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), + 'shape': [ 2, 3 ], + 'strides': [ -3, 1 ], + 'offset': 3, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 21.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function performs a reduction over an ndarray with only one non-singleton dimension', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 4, 1, 1 ], + 'strides': [ 1, 4, 4 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, 10.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `undefined` if provided an empty ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [] ), + 'shape': [ 0 ], + 'strides': [ 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `undefined` if provided a multi-dimensional empty ndarray', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [] ), + 'shape': [ 2, 0, 3 ], + 'strides': [ 0, 3, 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 0.0, add ); + t.strictEqual( v, void 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports different initial values', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 4 ], + 'strides': [ 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 100.0, add ); + t.strictEqual( v, 110.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports different accumulation callbacks', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 2.0, 3.0, 4.0 ] ), + 'shape': [ 3 ], + 'strides': [ 1 ], + 'offset': 0, + 'order': 'row-major' + }; + + v = accumulateUnary( [ x ], 1.0, multiply ); + t.strictEqual( v, 24.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (0d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0 ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (1d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), + 'shape': [ 3 ], + 'strides': [ 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 9.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (2d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (3d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 2, 2, 1 ], + 'strides': [ 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (4d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 2, 2, 1 ], + 'strides': [ 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (5d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (6d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (7d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (8d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 4, 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (9d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 4, 4, 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (10d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 4, 4, 4, 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (>10d)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1 ], + 'strides': [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (non-contiguous)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ), + 'shape': [ 2, 2 ], + 'strides': [ 3, 1 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 20.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (mixed sign strides)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ), + 'shape': [ 2, 3 ], + 'strides': [ -3, 1 ], + 'offset': 3, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 36.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports ndarrays with accessor protocol (only one non-singleton dimension)', function test( t ) { + var x; + var v; + + x = { + 'dtype': 'complex64', + 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), + 'shape': [ 4, 1, 1 ], + 'strides': [ 1, 4, 4 ], + 'offset': 0, + 'order': 'row-major', + 'accessorProtocol': true + }; + + v = accumulateUnary( [ x ], 0.0, sumReal ); + t.strictEqual( v, 16.0, 'returns expected value' ); + t.end(); +}); From f16b8cb344a5c80e41ee931bce9b25c991dbdaaf Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Tue, 6 Jan 2026 10:57:48 +0530 Subject: [PATCH 2/3] test: add comprehensive dimension-specific tests for `ndarray/base/unary-accumulate` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/unary-accumulate/test/test.0d.js | 111 ++ .../base/unary-accumulate/test/test.10d.js | 243 ++++ .../base/unary-accumulate/test/test.1d.js | 84 ++ .../base/unary-accumulate/test/test.2d.js | 1005 +++++++++++++++++ .../base/unary-accumulate/test/test.3d.js | 346 ++++++ .../base/unary-accumulate/test/test.4d.js | 243 ++++ .../base/unary-accumulate/test/test.5d.js | 243 ++++ .../base/unary-accumulate/test/test.6d.js | 243 ++++ .../base/unary-accumulate/test/test.7d.js | 243 ++++ .../base/unary-accumulate/test/test.8d.js | 243 ++++ .../base/unary-accumulate/test/test.9d.js | 243 ++++ .../base/unary-accumulate/test/test.js | 722 ------------ .../base/unary-accumulate/test/test.nd.js | 176 +++ 13 files changed, 3423 insertions(+), 722 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js new file mode 100644 index 000000000000..9fc8a43ca038 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 0-dimensional ndarray', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( 0.0, { + 'dtype': 'float64' + }); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 5.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 0-dimensional ndarray (accessors)', function test( t ) { + var actual; + var x; + + x = ndarray( 'generic', toAccessorArray( new Float64Array( [ 0.0 ] ) ), [], [ 0 ], 0, 'row-major' ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( 'generic', toAccessorArray( new Float64Array( [ 5.0 ] ) ), [], [ 0 ], 0, 'row-major' ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 5.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 0-dimensional ndarray (complex)', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( new Complex128( 0.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = scalar2ndarray( new Complex128( 3.0, 4.0 ), { + 'dtype': 'complex128' + }); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 7.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js new file mode 100644 index 000000000000..133912bdc536 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 10-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 10-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 10-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 1024.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 10-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 2048.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 10-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 1024.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 10-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 2048.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js new file mode 100644 index 000000000000..006eda7b622c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 ones = require( '@stdlib/array/ones' ); +var zeros = require( '@stdlib/array/zeros' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 1-dimensional ndarray', function test( t ) { + var actual; + var x; + + x = ndarray( 'float64', zeros( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( 'float64', ones( 8, 'float64' ), [ 4 ], [ 2 ], 1, 'row-major' ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 1-dimensional ndarray (accessors)', function test( t ) { + var actual; + var xbuf; + var x; + + xbuf = zeros( 6*2, 'float64' ); + x = ndarray( 'complex128', new Complex128Array( xbuf ), [ 4 ], [ 1 ], 1, 'row-major' ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( 6*2, 'float64' ); + x = ndarray( 'complex128', new Complex128Array( xbuf ), [ 4 ], [ 1 ], 1, 'row-major' ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js new file mode 100644 index 000000000000..9f58acad42ca --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js @@ -0,0 +1,1005 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, contiguous, negative strides)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, same sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, mixed sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*4, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*4, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, contiguous, negative strides, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, 2 ]; + o = strides2offset( sh, st ); + + xbuf = zeros( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2 ]; + st = [ 4, -2 ]; + o = strides2offset( sh, st ); + + xbuf = zeros( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*8, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (row-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*8, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, singleton dimensions)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, contiguous, negative strides)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, same sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, mixed sign strides)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( 8, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*4, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, large arrays)', function test( t ) { + var actual; + 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 = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*4, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, contiguous, negative strides, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, same sign strides, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ 2, 4 ]; + o = strides2offset( sh, st ); + + xbuf = zeros( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, mixed sign strides, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2 ]; + st = [ -2, 4 ]; + o = strides2offset( sh, st ); + + xbuf = zeros( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( 16, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*8, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 2-dimensional ndarray (column-major, non-contiguous, large arrays, accessors)', function test( t ) { + var actual; + var bsize; + var xbuf; + 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 = [ bsize*4, -2 ]; + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*4, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*8, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js new file mode 100644 index 000000000000..4805b17fd47c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js @@ -0,0 +1,346 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (row-major, non-contiguous, large arrays)', function test( t ) { + var actual; + 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 = [ 8, 4, 1 ]; + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh )*2, dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, bsize*4, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 16.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (column-major, singleton dimensions)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (column-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 4, 1, 1 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 3-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 16.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js new file mode 100644 index 000000000000..3258c5a73a3e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 4-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 4-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 4-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 16.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 4-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 32.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 4-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 16.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 4-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 32.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js new file mode 100644 index 000000000000..62b3eb6c1d48 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 5-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 5-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 5-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 32.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 5-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 64.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 5-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 32.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 5-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 64.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js new file mode 100644 index 000000000000..f5e091e65b48 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 6-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 6-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 6-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 64.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 6-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 128.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 6-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 64.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 6-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 128.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js new file mode 100644 index 000000000000..75f828f9a274 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 7-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 7-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 7-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 128.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 7-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 256.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 7-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 128.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 7-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 256.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js new file mode 100644 index 000000000000..b8c1aab39a26 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 8-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 8-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 8-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 256.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 8-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 512.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 8-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 256.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 8-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 512.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js new file mode 100644 index 000000000000..ecdf95691b57 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on a 9-dimensional ndarray (row-major, singleton dimensions)', function test( t ) { + var actual; + 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 ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 4.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 9-dimensional ndarray (row-major, singleton dimensions, accessors)', function test( t ) { + var actual; + var xbuf; + 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 ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 9-dimensional ndarray (row-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 512.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 9-dimensional ndarray (row-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 1024.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on a 9-dimensional ndarray (column-major, contiguous)', function test( t ) { + var actual; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 512.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on a 9-dimensional ndarray (column-major, contiguous, accessors)', function test( t ) { + var actual; + var xbuf; + var ord; + var sh; + var st; + var dt; + var o; + var x; + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 2, 2, 2, 2, 2, 2, 2, 2, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 1024.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js index 65466eac3418..1e8a7d609926 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js @@ -21,50 +21,9 @@ // MODULES // var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var Complex64Array = require( '@stdlib/array/complex64' ); var accumulateUnary = require( './../lib' ); -// FUNCTIONS // - -/** -* Adds two values. -* -* @private -* @param {number} acc - accumulated value -* @param {number} x - input value -* @returns {number} sum -*/ -function add( acc, x ) { - return acc + x; -} - -/** -* Multiplies two values. -* -* @private -* @param {number} acc - accumulated value -* @param {number} x - input value -* @returns {number} product -*/ -function multiply( acc, x ) { - return acc * x; -} - -/** -* Sums the real component of a complex number. -* -* @private -* @param {number} acc - accumulated value -* @param {Complex} x - input value -* @returns {number} sum -*/ -function sumReal( acc, x ) { - return acc + x.re; -} - - // TESTS // tape( 'main export is a function', function test( t ) { @@ -72,684 +31,3 @@ tape( 'main export is a function', function test( t ) { t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); t.end(); }); - -tape( 'the function performs a reduction over a 0-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 5.0 ] ), - 'shape': [], - 'strides': [ 0 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 5.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 1-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 4 ], - 'strides': [ 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 10.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 1-dimensional ndarray (negative stride)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 4 ], - 'strides': [ -1 ], - 'offset': 3, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 10.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 1-dimensional ndarray (offset)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ), - 'shape': [ 3 ], - 'strides': [ 1 ], - 'offset': 1, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 9.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 2-dimensional ndarray (row-major)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), - 'shape': [ 2, 3 ], - 'strides': [ 3, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 21.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 2-dimensional ndarray (column-major)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), - 'shape': [ 2, 3 ], - 'strides': [ 1, 2 ], - 'offset': 0, - 'order': 'column-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 21.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 3-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2, 2 ], - 'strides': [ 4, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 4-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2, 1, 2 ], - 'strides': [ 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 5-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 1, 2, 1, 2 ], - 'strides': [ 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 6-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 1, 1, 2, 1, 2 ], - 'strides': [ 4, 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 7-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 2, 1, 1, 2, 1, 2 ], - 'strides': [ 8, 4, 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 8-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 2, 1, 1, 2, 1, 2 ], - 'strides': [ 8, 8, 4, 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 9-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 2, 1, 1, 2, 1, 2 ], - 'strides': [ 8, 8, 8, 4, 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a 10-dimensional ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 2, 1, 1, 2, 1, 2 ], - 'strides': [ 8, 8, 8, 8, 4, 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over an ndarray with more than 10 dimensions', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2 ], - 'strides': [ 8, 8, 8, 8, 8, 4, 4, 4, 2, 2, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over a non-contiguous ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 3, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 12.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over an ndarray with mixed sign strides', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), - 'shape': [ 2, 3 ], - 'strides': [ -3, 1 ], - 'offset': 3, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 21.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a reduction over an ndarray with only one non-singleton dimension', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 4, 1, 1 ], - 'strides': [ 1, 4, 4 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, 10.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `undefined` if provided an empty ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [] ), - 'shape': [ 0 ], - 'strides': [ 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `undefined` if provided a multi-dimensional empty ndarray', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [] ), - 'shape': [ 2, 0, 3 ], - 'strides': [ 0, 3, 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 0.0, add ); - t.strictEqual( v, void 0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports different initial values', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 4 ], - 'strides': [ 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 100.0, add ); - t.strictEqual( v, 110.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports different accumulation callbacks', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 2.0, 3.0, 4.0 ] ), - 'shape': [ 3 ], - 'strides': [ 1 ], - 'offset': 0, - 'order': 'row-major' - }; - - v = accumulateUnary( [ x ], 1.0, multiply ); - t.strictEqual( v, 24.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (0d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0 ] ), - 'shape': [], - 'strides': [ 0 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 1.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (1d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ), - 'shape': [ 3 ], - 'strides': [ 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 9.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (2d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (3d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 2, 2, 1 ], - 'strides': [ 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (4d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 2, 2, 1 ], - 'strides': [ 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (5d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (6d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (7d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (8d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 4, 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (9d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 4, 4, 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (10d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 1, 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 4, 4, 4, 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (>10d)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1 ], - 'strides': [ 4, 4, 4, 4, 4, 4, 4, 4, 2, 1, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (non-contiguous)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ), - 'shape': [ 2, 2 ], - 'strides': [ 3, 1 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 20.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (mixed sign strides)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ), - 'shape': [ 2, 3 ], - 'strides': [ -3, 1 ], - 'offset': 3, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 36.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports ndarrays with accessor protocol (only one non-singleton dimension)', function test( t ) { - var x; - var v; - - x = { - 'dtype': 'complex64', - 'data': new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), - 'shape': [ 4, 1, 1 ], - 'strides': [ 1, 4, 4 ], - 'offset': 0, - 'order': 'row-major', - 'accessorProtocol': true - }; - - v = accumulateUnary( [ x ], 0.0, sumReal ); - t.strictEqual( v, 16.0, 'returns expected value' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js new file mode 100644 index 000000000000..07fecde64993 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js @@ -0,0 +1,176 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/array/zeros' ); +var ones = require( '@stdlib/array/ones' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var accumulateUnary = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof accumulateUnary, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs accumulation on an ndarray with more than 10 dimensions (row-major)', function test( t ) { + var actual; + 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, 1, 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on an ndarray with more than 10 dimensions (row-major, accessors)', function test( t ) { + var actual; + var xbuf; + 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, 1, 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 16.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); + +tape( 'the function performs accumulation on an ndarray with more than 10 dimensions (column-major)', function test( t ) { + var actual; + 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, 1, 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, zeros( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + x = ndarray( dt, ones( numel( sh ), dt ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 8.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + v; + } +}); + +tape( 'the function performs accumulation on an ndarray with more than 10 dimensions (column-major, accessors)', function test( t ) { + var actual; + var xbuf; + 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, 1, 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + xbuf = zeros( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 0.0, 'returns expected value' ); + + xbuf = ones( numel( sh )*2, 'float64' ); + x = ndarray( dt, new Complex128Array( xbuf ), sh, st, o, ord ); + + actual = accumulateUnary( [ x ], 0.0, clbk ); + t.strictEqual( actual, 16.0, 'returns expected value' ); + + t.end(); + + function clbk( acc, v ) { + return acc + real( v ) + imag( v ); + } +}); From 2677e2299e258c66f9488f365398b5a580bbd3ec Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Tue, 6 Jan 2026 11:03:47 +0530 Subject: [PATCH 3/3] test: update copyright year to 2026 in tests --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/unary-accumulate/test/test.0d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.10d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.1d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.2d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.3d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.4d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.5d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.6d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.7d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.8d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.9d.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.js | 2 +- .../@stdlib/ndarray/base/unary-accumulate/test/test.nd.js | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js index 9fc8a43ca038..d198042a8869 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js index 133912bdc536..736f3d8dc2ee 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.10d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js index 006eda7b622c..2edd1b8689cd 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.1d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js index 9f58acad42ca..4478a85701d9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.2d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js index 4805b17fd47c..32d478bb3d85 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.3d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js index 3258c5a73a3e..0c6946933c41 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.4d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js index 62b3eb6c1d48..04d7f2284d8b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.5d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js index f5e091e65b48..87afdf46a481 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.6d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js index 75f828f9a274..c29a3ba8f480 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.7d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js index b8c1aab39a26..69cb7474b8d5 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.8d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js index ecdf95691b57..dd7f8d30b1cf 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.9d.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js index 1e8a7d609926..6e1508a997db 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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. diff --git a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js index 07fecde64993..90cfecde9397 100644 --- a/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js +++ b/lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.nd.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 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.