Skip to content

Commit 2306a2d

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: 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 1bbd885 commit 2306a2d

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// MODULES //
2222

23-
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
23+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
2424
var floor = require( '@stdlib/math/base/special/floor' );
2525

2626

@@ -81,9 +81,10 @@ function ssumpw( N, x, strideX, offsetX ) {
8181
}
8282
if ( N < 8 ) {
8383
// Use simple summation...
84-
s = 0.0;
85-
for ( i = 0; i < N; i++ ) {
86-
s = float64ToFloat32( s + x[ ix ] );
84+
s = x[ ix ];
85+
ix += strideX;
86+
for ( i = 1; i < N; i++ ) {
87+
s = f32( s + x[ ix ] );
8788
ix += strideX;
8889
}
8990
return s;
@@ -102,30 +103,30 @@ function ssumpw( N, x, strideX, offsetX ) {
102103

103104
M = N % 8;
104105
for ( i = 8; i < N-M; i += 8 ) {
105-
s0 = float64ToFloat32( s0 + x[ ix ] );
106-
s1 = float64ToFloat32( s1 + x[ ix+strideX ] );
107-
s2 = float64ToFloat32( s2 + x[ ix+(2*strideX) ] );
108-
s3 = float64ToFloat32( s3 + x[ ix+(3*strideX) ] );
109-
s4 = float64ToFloat32( s4 + x[ ix+(4*strideX) ] );
110-
s5 = float64ToFloat32( s5 + x[ ix+(5*strideX) ] );
111-
s6 = float64ToFloat32( s6 + x[ ix+(6*strideX) ] );
112-
s7 = float64ToFloat32( s7 + x[ ix+(7*strideX) ] );
106+
s0 = f32( s0 + x[ ix ] );
107+
s1 = f32( s1 + x[ ix+strideX ] );
108+
s2 = f32( s2 + x[ ix+(2*strideX) ] );
109+
s3 = f32( s3 + x[ ix+(3*strideX) ] );
110+
s4 = f32( s4 + x[ ix+(4*strideX) ] );
111+
s5 = f32( s5 + x[ ix+(5*strideX) ] );
112+
s6 = f32( s6 + x[ ix+(6*strideX) ] );
113+
s7 = f32( s7 + x[ ix+(7*strideX) ] );
113114
ix += 8 * strideX;
114115
}
115116
// Pairwise sum the accumulators:
116-
s = float64ToFloat32( float64ToFloat32( float64ToFloat32(s0+s1) + float64ToFloat32(s2+s3) ) + float64ToFloat32( float64ToFloat32(s4+s5) + float64ToFloat32(s6+s7) ) ); // eslint-disable-line max-len
117+
s = f32( f32( f32(s0+s1) + f32(s2+s3) ) + f32( f32(s4+s5) + f32(s6+s7) ) ); // eslint-disable-line max-len
117118

118119
// Clean-up loop...
119120
for ( i; i < N; i++ ) {
120-
s = float64ToFloat32( s + x[ ix ] );
121+
s = f32( s + x[ ix ] );
121122
ix += strideX;
122123
}
123124
return s;
124125
}
125126
// Recurse by dividing by two, but avoiding non-multiples of unroll factor...
126127
n = floor( N/2 );
127128
n -= n % 8;
128-
return float64ToFloat32( ssumpw( n, x, strideX, ix ) + ssumpw( N-n, x, strideX, ix+(n*strideX) ) ); // eslint-disable-line max-len
129+
return f32( ssumpw( n, x, strideX, ix ) + ssumpw( N-n, x, strideX, ix+(n*strideX) ) ); // eslint-disable-line max-len
129130
}
130131

131132

lib/node_modules/@stdlib/blas/ext/base/ssumpw/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 ssumpw = 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 = ssumpw( 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/ssumpw/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 = ssumpw( 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)