Skip to content

Commit 432b26d

Browse files
committed
fix: address pointer increment bug
--- 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 25288d7 commit 432b26d

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,57 @@ var abs = require( '@stdlib/math/base/special/abs' );
5353
*/
5454
function dnansumkbn( N, x, strideX, offsetX ) {
5555
var sum;
56+
var flg;
5657
var ix;
5758
var v;
5859
var t;
5960
var c;
6061
var i;
6162

62-
sum = 0.0;
6363
if ( N <= 0 ) {
64-
return sum;
64+
return 0.0;
6565
}
6666
ix = offsetX;
6767
if ( strideX === 0 ) {
6868
if ( isnan( x[ ix ] ) ) {
69-
return sum;
69+
return 0.0;
7070
}
7171
return x[ ix ] * N;
7272
}
73-
c = 0.0;
73+
// Find the first non-NaN element...
7474
for ( i = 0; i < N; i++ ) {
75+
v = x[ ix ];
76+
if ( isnan( v ) === false ) {
77+
break;
78+
}
79+
ix += strideX;
80+
}
81+
if ( i === N ) {
82+
return NaN;
83+
}
84+
sum = v;
85+
ix += strideX;
86+
flg = 0;
87+
i += 1;
88+
89+
// In order to preserve the sign of zero which can be lost during compensated summation below, find the first non-zero element...
90+
if ( sum === 0.0 ) {
91+
for ( ; i < N; i++ ) {
92+
v = x[ ix ];
93+
if ( isnan( v ) === false ) {
94+
if ( v !== 0.0 ) {
95+
flg = 1;
96+
break;
97+
}
98+
sum += v;
99+
}
100+
ix += strideX;
101+
}
102+
} else {
103+
flg = 1;
104+
}
105+
c = 0.0;
106+
for ( ; i < N; i++ ) {
75107
v = x[ ix ];
76108
if ( isnan( v ) === false ) {
77109
t = sum + v;
@@ -84,7 +116,7 @@ function dnansumkbn( N, x, strideX, offsetX ) {
84116
}
85117
ix += strideX;
86118
}
87-
return sum + c;
119+
return ( flg ) ? sum+c : sum;
88120
}
89121

90122

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

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

2323
var tape = require( 'tape' );
2424
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
25+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2526
var Float64Array = require( '@stdlib/array/float64' );
2627
var dnansumkbn = require( './../lib/ndarray.js' );
2728

@@ -78,14 +79,14 @@ tape( 'the function calculates the sum of strided array elements (ignoring NaN v
7879
t.end();
7980
});
8081

81-
tape( 'the function does not preserve the sign of zero', function test( t ) {
82+
tape( 'the function preserves the sign of zero', function test( t ) {
8283
var x;
8384
var v;
8485

8586
x = new Float64Array( [ -0.0, -0.0, -0.0 ] );
8687

8788
v = dnansumkbn( x.length, x, 1, 0 );
88-
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
89+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
8990

9091
x = new Float64Array( [ 0.0, -0.0, -0.0 ] );
9192

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

Lines changed: 3 additions & 2 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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
26+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2627
var Float64Array = require( '@stdlib/array/float64' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829

@@ -87,14 +88,14 @@ tape( 'the function calculates the sum of strided array elements (ignoring NaN v
8788
t.end();
8889
});
8990

90-
tape( 'the function does not preserve the sign of zero', opts, function test( t ) {
91+
tape( 'the function preserves the sign of zero', opts, function test( t ) {
9192
var x;
9293
var v;
9394

9495
x = new Float64Array( [ -0.0, -0.0, -0.0 ] );
9596

9697
v = dnansumkbn( x.length, x, 1, 0 );
97-
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
98+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
9899

99100
x = new Float64Array( [ 0.0, -0.0, -0.0 ] );
100101

0 commit comments

Comments
 (0)