Skip to content

Commit b0eea3a

Browse files
committed
fix: update implementation to preserve signed zeros
--- 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: passed - 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: passed - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 34f6c88 commit b0eea3a

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

lib/node_modules/@stdlib/blas/ext/base/dssumpw/lib/ndarray.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ function dssumpw( N, x, strideX, offsetX ) {
7878
if ( strideX === 0 ) {
7979
return N * x[ ix ];
8080
}
81-
8281
if ( N < 8 ) {
8382
// Use simple summation...
84-
s = 0.0;
85-
for ( i = 0; i < N; i++ ) {
83+
s = x[ ix ];
84+
ix += strideX;
85+
for ( i = 1; i < N; i++ ) {
8686
s += x[ ix ];
8787
ix += strideX;
8888
}
@@ -116,7 +116,7 @@ function dssumpw( N, x, strideX, offsetX ) {
116116
s = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) );
117117

118118
// Clean-up loop...
119-
for ( i; i < N; i++ ) {
119+
for ( ; i < N; i++ ) {
120120
s += x[ ix ];
121121
ix += strideX;
122122
}

lib/node_modules/@stdlib/blas/ext/base/dssumpw/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ double API_SUFFIX(stdlib_strided_dssumpw_ndarray)( const CBLAS_INT N, const floa
8080
if ( strideX == 0 ) {
8181
return N * X[ 0 ];
8282
}
83-
8483
if ( N < 8 ) {
8584
// Use simple summation...
86-
sum = 0.0;
87-
for ( i = 0; i < N; i++ ) {
85+
sum = (double)X[ ix ];
86+
ix += strideX;
87+
for ( i = 1; i < N; i++ ) {
8888
sum += (double)X[ ix ];
8989
ix += strideX;
9090
}

lib/node_modules/@stdlib/blas/ext/base/dssumpw/test/test.ndarray.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2526
var Float32Array = require( '@stdlib/array/float32' );
2627
var dssumpw = require( './../lib/ndarray.js' );
2728

@@ -74,6 +75,17 @@ tape( 'the function calculates the sum of all strided array elements', function
7475
t.end();
7576
});
7677

78+
tape( 'the function preserves the sign of zero', function test( t ) {
79+
var x;
80+
var v;
81+
82+
x = new Float32Array( [ -0.0, -0.0, -0.0, -0.0, -0.0 ] );
83+
v = dssumpw( x.length, x, 1, 0 );
84+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
85+
86+
t.end();
87+
});
88+
7789
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test( t ) {
7890
var x;
7991
var v;

lib/node_modules/@stdlib/blas/ext/base/dssumpw/test/test.ndarray.native.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2627
var Float32Array = require( '@stdlib/array/float32' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829

@@ -83,6 +84,17 @@ tape( 'the function calculates the sum of all strided array elements', opts, fun
8384
t.end();
8485
});
8586

87+
tape( 'the function preserves the sign of zero', opts, function test( t ) {
88+
var x;
89+
var v;
90+
91+
x = new Float32Array( [ -0.0, -0.0, -0.0, -0.0, -0.0 ] );
92+
v = dssumpw( x.length, x, 1, 0 );
93+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
94+
95+
t.end();
96+
});
97+
8698
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', opts, function test( t ) {
8799
var x;
88100
var v;

0 commit comments

Comments
 (0)