Skip to content

Commit aeaacb5

Browse files
committed
Auto-generated commit
1 parent 1cfe845 commit aeaacb5

File tree

10 files changed

+84
-18
lines changed

10 files changed

+84
-18
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-05-19)
7+
## Unreleased (2025-05-27)
88

99
<section class="features">
1010

@@ -16,12 +16,23 @@
1616

1717
<!-- /.features -->
1818

19+
<section class="bug-fixes">
20+
21+
### Bug Fixes
22+
23+
- [`aa52ed9`](https://github.com/stdlib-js/stdlib/commit/aa52ed96730b4835b3ef403b2abbcd7910e3e483) - update implementation to preserve signed zeros
24+
25+
</section>
26+
27+
<!-- /.bug-fixes -->
28+
1929
<section class="commits">
2030

2131
### Commits
2232

2333
<details>
2434

35+
- [`aa52ed9`](https://github.com/stdlib-js/stdlib/commit/aa52ed96730b4835b3ef403b2abbcd7910e3e483) - **fix:** update implementation to preserve signed zeros _(by Athan Reines)_
2536
- [`9f85b5d`](https://github.com/stdlib-js/stdlib/commit/9f85b5d90cb6fcaf052116cd06aa4a693757f0ec) - **test:** fix description _(by Philipp Burckhardt)_
2637
- [`9367d41`](https://github.com/stdlib-js/stdlib/commit/9367d4175b33e490bdbea8da5062fe95919f5d85) - **refactor:** update paths _(by Aayush Khanna)_
2738
- [`99388d1`](https://github.com/stdlib-js/stdlib/commit/99388d1aeabe238c519707b8e08843a4bdeb04d4) - **test:** fix grammar in descriptions _(by Athan Reines)_

CONTRIBUTORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Ryan Seal <splrk@users.noreply.github.com>
146146
Rylan Yang <137365285+rylany27@users.noreply.github.com>
147147
SAHIL KUMAR <168997976+sahilk45@users.noreply.github.com>
148148
SHIVAM YADAV <120725381+Shivam-1827@users.noreply.github.com>
149+
Sachin Raj <120590207+schnrj@users.noreply.github.com>
149150
Sahil Goyal <87982509+sahil20021008@users.noreply.github.com>
150151
Sai Avinash <120403424+nasarobot@users.noreply.github.com>
151152
Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
@@ -166,10 +167,12 @@ Spandan Barve <contact@marsian.dev>
166167
Stephannie Jiménez Gacha <steff456@hotmail.com>
167168
Suhaib Ilahi <suhaib.elahi87@gmail.com>
168169
Suraj Kumar <125961509+kumarsuraj212003@users.noreply.github.com>
170+
Swapnil Hajare <69076366+Swapnil-2502@users.noreply.github.com>
169171
Tanishq Ahuja <68651083+TheGEN1U5@users.noreply.github.com>
170172
Tirtadwipa Manunggal <tirtadwipa.manunggal@gmail.com>
171173
Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com>
172174
Tufailahmed Bargir <142114244+Tufailahmed-Bargir@users.noreply.github.com>
175+
Uday Kakade <141299403+udaykakade25@users.noreply.github.com>
173176
Utkarsh <http://utkarsh11105@gmail.com>
174177
Utkarsh Raj <rajutkarsh2505@gmail.com>
175178
UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com>

dist/index.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ndarray.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,34 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
4545
function dsnansumors( N, x, strideX, offsetX ) {
4646
var sum;
4747
var ix;
48+
var v;
4849
var i;
4950

50-
sum = 0.0;
5151
if ( N <= 0 ) {
52-
return sum;
52+
return 0.0;
5353
}
5454
ix = offsetX;
5555
if ( strideX === 0 ) {
5656
if ( isnan( x[ ix ] ) ) {
57-
return sum;
57+
return 0.0;
5858
}
5959
return N * x[ ix ];
6060
}
61+
// Find the first non-NaN element...
6162
for ( i = 0; i < N; i++ ) {
63+
v = x[ ix ];
64+
if ( isnan( v ) === false ) {
65+
break;
66+
}
67+
ix += strideX;
68+
}
69+
if ( i === N ) {
70+
return 0.0;
71+
}
72+
sum = v;
73+
ix += strideX;
74+
i += 1;
75+
for ( ; i < N; i++ ) {
6276
if ( isnan( x[ ix ] ) === false ) {
6377
sum += x[ ix ];
6478
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@stdlib/array-filled-by": "^0.2.1",
6060
"@stdlib/array-float32": "^0.2.2",
6161
"@stdlib/assert-is-browser": "^0.2.2",
62+
"@stdlib/math-base-assert-is-negative-zero": "^0.2.2",
6263
"@stdlib/math-base-special-pow": "^0.3.0",
6364
"@stdlib/random-base-bernoulli": "^0.2.1",
6465
"@stdlib/random-base-discrete-uniform": "^0.2.1",

src/main.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,33 @@ double API_SUFFIX(stdlib_strided_dsnansumors_ndarray)( const CBLAS_INT N, const
4747
CBLAS_INT ix;
4848
CBLAS_INT i;
4949
double sum;
50+
double v;
5051

51-
sum = 0.0;
5252
if ( N <= 0 ) {
53-
return sum;
53+
return 0.0;
5454
}
5555
ix = offsetX;
5656
if ( strideX == 0 ) {
5757
if ( stdlib_base_is_nanf( X[ ix ] ) ) {
58-
return sum;
58+
return 0.0;
5959
}
6060
return N * X[ ix ];
6161
}
62+
// Find the first non-NaN element...
6263
for ( i = 0; i < N; i++ ) {
64+
v = X[ ix ];
65+
if ( !stdlib_base_is_nanf( v ) ) {
66+
break;
67+
}
68+
ix += strideX;
69+
}
70+
if ( i == N ) {
71+
return 0.0;
72+
}
73+
sum = (double)v;
74+
ix += strideX;
75+
i += 1;
76+
for ( ; i < N; i++ ) {
6377
if ( !stdlib_base_is_nanf( X[ ix ] ) ) {
6478
sum += (double)X[ ix ];
6579
}

test/test.ndarray.js

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

2323
var tape = require( 'tape' );
24+
var isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' );
2425
var Float32Array = require( '@stdlib/array-float32' );
2526
var dsnansumors = require( './../lib/ndarray.js' );
2627

@@ -77,6 +78,17 @@ tape( 'the function calculates the sum of strided array elements (ignoring NaN v
7778
t.end();
7879
});
7980

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

test/test.ndarray.native.js

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

2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
25+
var isNegativeZero = require( '@stdlib/math-base-assert-is-negative-zero' );
2526
var Float32Array = require( '@stdlib/array-float32' );
2627
var tryRequire = require( '@stdlib/utils-try-require' );
2728

@@ -86,6 +87,17 @@ tape( 'the function calculates the sum of strided array elements (ignoring NaN v
8687
t.end();
8788
});
8889

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

0 commit comments

Comments
 (0)