Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/unary-accumulate/test/test.0d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @license Apache-2.0
*
* 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.
* 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 );
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/**
* @license Apache-2.0
*
* 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.
* 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 );
}
});
Loading