Skip to content

test: increase code coverage in blas/base/caxpy #6530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2025
Merged
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
5 changes: 1 addition & 4 deletions lib/node_modules/@stdlib/blas/base/caxpy/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ function caxpy( N, ca, cx, strideX, offsetX, cy, strideY, offsetY ) {
var iy;
var i;

if ( N <= 0 ) {
return cy;
}
if ( scabs1( ca ) === 0.0 ) {
if ( N <= 0 || scabs1( ca ) === 0.0 ) {
return cy;
}
ix = offsetX;
Expand Down
95 changes: 59 additions & 36 deletions lib/node_modules/@stdlib/blas/base/caxpy/test/test.caxpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy
var cx;
var cy;

cx = new Complex64Array( [
cx = new Complex64Array([
0.7, // 1
-0.8, // 1
-0.4, // 2
Expand All @@ -93,8 +93,8 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy
0.4,
-0.6,
0.6
] );
cy = new Complex64Array( [
]);
cy = new Complex64Array([
0.6, // 1
-0.6, // 1
-0.9, // 2
Expand All @@ -109,13 +109,13 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy
-0.3,
0.8,
-0.7
] );
]);
ca = new Complex64( 0.4, -0.7 );

caxpy( 4, ca, cx, 1, cy, 1 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [
expected = new Float32Array([
0.32, // 1
-1.41, // 1
-1.55, // 2
Expand All @@ -130,7 +130,7 @@ tape( 'the function scales elements from `cx` by `ca` and adds the result to `cy
-0.3,
0.8,
-0.7
] );
]);
isApprox( t, viewY, expected, 10.0 );
t.end();
});
Expand All @@ -142,7 +142,7 @@ tape( 'the function supports a `cx` stride', function test( t ) {
var cx;
var cy;

cx = new Complex64Array( [
cx = new Complex64Array([
0.7, // 1
-0.8, // 1
-0.4,
Expand All @@ -157,8 +157,8 @@ tape( 'the function supports a `cx` stride', function test( t ) {
0.4,
-0.6, // 4
0.6 // 4
] );
cy = new Complex64Array( [
]);
cy = new Complex64Array([
0.6, // 1
-0.6, // 1
-0.9, // 2
Expand All @@ -173,13 +173,13 @@ tape( 'the function supports a `cx` stride', function test( t ) {
-0.3,
0.8,
-0.7
] );
]);
ca = new Complex64( 0.4, -0.7 );

caxpy( 4, ca, cx, 2, cy, 1 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [
expected = new Float32Array([
0.32, // 1
-1.41, // 1
-1.57, // 2
Expand All @@ -194,7 +194,7 @@ tape( 'the function supports a `cx` stride', function test( t ) {
-0.3,
0.8,
-0.7
] );
]);
isApprox( t, viewY, expected, 10.0 );
t.end();
});
Expand All @@ -206,7 +206,7 @@ tape( 'the function supports a `cy` stride', function test( t ) {
var cx;
var cy;

cx = new Complex64Array( [
cx = new Complex64Array([
0.7, // 1
-0.8, // 1
-0.4, // 2
Expand All @@ -221,8 +221,8 @@ tape( 'the function supports a `cy` stride', function test( t ) {
0.4,
-0.6,
0.6
] );
cy = new Complex64Array( [
]);
cy = new Complex64Array([
0.6, // 1
-0.6, // 1
-0.9,
Expand All @@ -237,13 +237,13 @@ tape( 'the function supports a `cy` stride', function test( t ) {
-0.3,
0.8, // 4
-0.7 // 4
] );
]);
ca = new Complex64( 0.4, -0.7 );

caxpy( 4, ca, cx, 1, cy, 2 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [
expected = new Float32Array([
0.32, // 1
-1.41, // 1
-0.9,
Expand All @@ -258,7 +258,7 @@ tape( 'the function supports a `cy` stride', function test( t ) {
-0.3,
0.32, // 4
-1.16 // 4
] );
]);
isApprox( t, viewY, expected, 10.0 );
t.end();
});
Expand All @@ -279,6 +279,29 @@ tape( 'the function returns a reference to the output array', function test( t )
t.end();
});

tape( 'if provided `ca` parameter equal to `0`, the function returns the second input array unchanged', function test( t ) {
var expected;
var viewY;
var ca;
var cx;
var cy;

cx = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
cy = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
ca = new Complex64( 0.0, 0.0 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );

caxpy( -1, ca, cx, 1, 0, cy, 1, 0 );
t.deepEqual( viewY, expected, 'returns expected value' );

caxpy( 0, ca, cx, 1, 0, cy, 1, 0 );
t.deepEqual( viewY, expected, 'returns expected value' );

t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the second input array unchanged', function test( t ) {
var expected;
var viewY;
Expand Down Expand Up @@ -309,7 +332,7 @@ tape( 'the function supports negative `cx` strides', function test( t ) {
var cx;
var cy;

cx = new Complex64Array( [
cx = new Complex64Array([
0.7, // 4
-0.8, // 4
-0.4,
Expand All @@ -324,8 +347,8 @@ tape( 'the function supports negative `cx` strides', function test( t ) {
0.4,
-0.6, // 1
0.6 // 1
] );
cy = new Complex64Array( [
]);
cy = new Complex64Array([
0.6, // 1
-0.6, // 1
-0.9, // 2
Expand All @@ -340,13 +363,13 @@ tape( 'the function supports negative `cx` strides', function test( t ) {
-0.3,
0.8,
-0.7
] );
]);
ca = new Complex64( 0.4, -0.7 );

caxpy( 4, ca, cx, -2, cy, 1 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [
expected = new Float32Array([
0.78, // 1
0.06, // 1
-1.54, // 2
Expand All @@ -361,7 +384,7 @@ tape( 'the function supports negative `cx` strides', function test( t ) {
-0.3,
0.8,
-0.7
] );
]);
isApprox( t, viewY, expected, 10.0 );
t.end();
});
Expand All @@ -373,7 +396,7 @@ tape( 'the function supports negative `cy` strides', function test( t ) {
var cx;
var cy;

cx = new Complex64Array( [
cx = new Complex64Array([
0.7, // 1
-0.8, // 1
-0.4,
Expand All @@ -388,8 +411,8 @@ tape( 'the function supports negative `cy` strides', function test( t ) {
0.4,
-0.6, // 4
0.6 // 4
] );
cy = new Complex64Array( [
]);
cy = new Complex64Array([
0.6, // 4
-0.6, // 4
-0.9,
Expand All @@ -404,13 +427,13 @@ tape( 'the function supports negative `cy` strides', function test( t ) {
-0.3,
0.8, // 1
-0.7 // 1
] );
]);
ca = new Complex64( 0.4, -0.7 );

caxpy( 4, ca, cx, 2, cy, -2 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [
expected = new Float32Array([
0.78, // 4
0.06, // 4
-0.9,
Expand All @@ -425,7 +448,7 @@ tape( 'the function supports negative `cy` strides', function test( t ) {
-0.3,
0.52, // 1
-1.51 // 1
] );
]);
isApprox( t, viewY, expected, 10.0 );
t.end();
});
Expand All @@ -437,7 +460,7 @@ tape( 'the function supports complex access patterns', function test( t ) {
var cx;
var cy;

cx = new Complex64Array( [
cx = new Complex64Array([
0.7, // 4
-0.8, // 4
-0.4, // 3
Expand All @@ -452,8 +475,8 @@ tape( 'the function supports complex access patterns', function test( t ) {
0.4,
-0.6,
0.6
] );
cy = new Complex64Array( [
]);
cy = new Complex64Array([
0.6, // 4
-0.6, // 4
-0.9,
Expand All @@ -468,13 +491,13 @@ tape( 'the function supports complex access patterns', function test( t ) {
-0.3,
0.8, // 1
-0.7 // 1
] );
]);
ca = new Complex64( 0.4, -0.7 );

caxpy( 4, ca, cx, -1, cy, -2 );

viewY = new Float32Array( cy.buffer );
expected = new Float32Array( [
expected = new Float32Array([
0.32, // 4
-1.41, // 4
-0.9,
Expand All @@ -489,7 +512,7 @@ tape( 'the function supports complex access patterns', function test( t ) {
-0.3,
0.32, // 1
-1.16 // 1
] );
]);
isApprox( t, viewY, expected, 10.0 );
t.end();
});
Expand Down
Loading