Skip to content

Commit 25288d7

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 cfd1d13 commit 25288d7

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

lib/node_modules/@stdlib/blas/ext/base/gcusumpw/lib/accessors.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,19 @@ function gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
8383
xbuf = x.data;
8484
ybuf = y.data;
8585

86-
// Cache reference to the element accessors:
86+
// Cache references to the element accessors:
8787
xget = x.accessors[ 0 ];
8888
yget = y.accessors[ 0 ];
8989
yset = y.accessors[ 1 ];
9090

9191
ix = offsetX;
9292
iy = offsetY;
9393
if ( N <= BLOCKSIZE ) {
94-
s = 0.0;
95-
for ( i = 0; i < N; i++ ) {
94+
s = xget( xbuf, ix );
95+
yset( ybuf, iy, sum + s);
96+
ix += strideX;
97+
iy += strideY;
98+
for ( i = 1; i < N; i++ ) {
9699
s += xget( xbuf, ix );
97100
yset( ybuf, iy, sum + s);
98101
ix += strideX;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ function gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
8282
ix = offsetX;
8383
iy = offsetY;
8484
if ( N <= BLOCKSIZE ) {
85-
s = 0.0;
86-
for ( i = 0; i < N; i++ ) {
85+
s = x[ ix ];
86+
y[ iy ] = sum + s;
87+
ix += strideX;
88+
iy += strideY;
89+
for ( i = 1; i < N; i++ ) {
8790
s += x[ ix ];
8891
y[ iy ] = sum + s;
8992
ix += strideX;

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
* limitations under the License.
1717
*/
1818

19+
/* eslint-disable max-len */
20+
1921
'use strict';
2022

2123
// MODULES //
2224

2325
var tape = require( 'tape' );
2426
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var isSameArray = require( '@stdlib/assert/is-same-array' );
2528
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
2629
var gcusumpw = require( './../lib/ndarray.js' );
2730

@@ -213,6 +216,46 @@ tape( 'the function calculates the cumulative sum (accessors)', function test( t
213216
t.end();
214217
});
215218

219+
tape( 'the function preserves the sign of zero', function test( t ) {
220+
var expected;
221+
var x;
222+
var y;
223+
224+
x = [ -0.0, -0.0, -0.0, 0.0, 1.0 ];
225+
y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
226+
227+
gcusumpw( x.length, -0.0, x, 1, 0, y, 1, 0 );
228+
expected = [
229+
-0.0,
230+
-0.0,
231+
-0.0,
232+
0.0,
233+
1.0
234+
];
235+
t.strictEqual( isSameArray( y, expected ), true, 'returns expected value' );
236+
t.end();
237+
});
238+
239+
tape( 'the function preserves the sign of zero (accessors)', function test( t ) {
240+
var expected;
241+
var x;
242+
var y;
243+
244+
x = [ -0.0, -0.0, -0.0, 0.0, 1.0 ];
245+
y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
246+
247+
gcusumpw( x.length, -0.0, toAccessorArray( x ), 1, 0, toAccessorArray( y ), 1, 0 );
248+
expected = [
249+
-0.0,
250+
-0.0,
251+
-0.0,
252+
0.0,
253+
1.0
254+
];
255+
t.strictEqual( isSameArray( y, expected ), true, 'returns expected value' );
256+
t.end();
257+
});
258+
216259
tape( 'the function returns a reference to the output array', function test( t ) {
217260
var out;
218261
var x;

0 commit comments

Comments
 (0)