Skip to content

Commit dbeb62d

Browse files
committed
Auto-generated commit
1 parent 505ff4e commit dbeb62d

File tree

7 files changed

+82
-12
lines changed

7 files changed

+82
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224

225225
### Bug Fixes
226226

227+
- [`151f3e5`](https://github.com/stdlib-js/stdlib/commit/151f3e5714bf1b13e00b72ee0c98fb65ee095ba8) - update implementation to preserve signed zeros
227228
- [`71cafe3`](https://github.com/stdlib-js/stdlib/commit/71cafe3750d452180ec33524aa0d2fb19322b743) - add support for complex64 and complex128
228229
- [`3014ce9`](https://github.com/stdlib-js/stdlib/commit/3014ce93b3fd6a8d7d26b7951d762f5100faffdf) - update return type
229230
- [`2acc7f0`](https://github.com/stdlib-js/stdlib/commit/2acc7f03aa6e89410deb74d99f466cc1cd400384) - update return type
@@ -477,6 +478,8 @@ A total of 22 issues were closed in this release:
477478

478479
<details>
479480

481+
- [`151f3e5`](https://github.com/stdlib-js/stdlib/commit/151f3e5714bf1b13e00b72ee0c98fb65ee095ba8) - **fix:** update implementation to preserve signed zeros _(by Athan Reines)_
482+
- [`9bfb869`](https://github.com/stdlib-js/stdlib/commit/9bfb8691fc945a8e38c592d0e387c84aa31d8585) - **test:** add signed zero tests _(by Athan Reines)_
480483
- [`f20c234`](https://github.com/stdlib-js/stdlib/commit/f20c234a4112d25281d202e8a0cf9ba223becb4c) - **docs:** update namespace table of contents [(#7092)](https://github.com/stdlib-js/stdlib/pull/7092) _(by stdlib-bot)_
481484
- [`71cafe3`](https://github.com/stdlib-js/stdlib/commit/71cafe3750d452180ec33524aa0d2fb19322b743) - **fix:** add support for complex64 and complex128 _(by Athan Reines)_
482485
- [`3014ce9`](https://github.com/stdlib-js/stdlib/commit/3014ce93b3fd6a8d7d26b7951d762f5100faffdf) - **fix:** update return type _(by Athan Reines)_

ext/base/dssumors/lib/ndarray.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ function dssumors( N, x, strideX, offsetX ) {
4848
var m;
4949
var i;
5050

51-
sum = 0.0;
5251
if ( N <= 0 ) {
53-
return sum;
52+
return 0.0;
5453
}
5554
ix = offsetX;
5655
if ( strideX === 0 ) {
5756
return N * x[ ix ];
5857
}
58+
sum = x[ ix ];
59+
ix += strideX;
5960

6061
// If the stride is equal to `1`, use unrolled loops...
6162
if ( strideX === 1 ) {
62-
m = N % M;
63+
m = (N-1) % M;
6364

6465
// If we have a remainder, run a clean-up loop...
6566
if ( m > 0 ) {
@@ -71,13 +72,13 @@ function dssumors( N, x, strideX, offsetX ) {
7172
if ( N < M ) {
7273
return sum;
7374
}
74-
for ( i = m; i < N; i += M ) {
75+
for ( i = m; i < N-1; i += M ) {
7576
sum += x[ix] + x[ix+1] + x[ix+2] + x[ix+3] + x[ix+4] + x[ix+5];
7677
ix += M;
7778
}
7879
return sum;
7980
}
80-
for ( i = 0; i < N; i++ ) {
81+
for ( i = 1; i < N; i++ ) {
8182
sum += x[ ix ];
8283
ix += strideX;
8384
}

ext/base/dssumors/src/main.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,38 @@ double API_SUFFIX(stdlib_strided_dssumors_ndarray)( const CBLAS_INT N, const flo
4848
CBLAS_INT i;
4949
double sum;
5050

51-
sum = 0.0;
5251
if ( N <= 0 ) {
53-
return sum;
52+
return 0.0;
5453
}
5554
ix = offsetX;
5655
if ( strideX == 0 ) {
5756
return N * X[ ix ];
5857
}
58+
sum = X[ ix ];
59+
ix += strideX;
60+
5961
// If the stride is equal to `1`, use unrolled loops...
6062
if ( strideX == 1 ) {
61-
m = N % 6;
63+
m = (N-1) % 6;
6264

6365
// If we have a remainder, run a clean-up loop...
6466
if ( m > 0 ) {
6567
for ( i = 0; i < m; i++ ) {
66-
sum += (double)X[ i ];
68+
sum += (double)X[ ix ];
69+
ix += strideX;
6770
}
6871
}
6972
if ( N < 6 ) {
7073
return sum;
7174
}
72-
for ( i = m; i < N; i += 6 ) {
73-
sum += (double)X[i] + (double)X[i+1] + (double)X[i+2] + (double)X[i+3] + (double)X[i+4] + (double)X[i+5];
75+
for ( i = m; i < N-1; i += 6 ) {
76+
sum += (double)X[ix] + (double)X[ix+1] + (double)X[ix+2] + (double)X[ix+3] + (double)X[ix+4] + (double)X[ix+5];
77+
ix += 6;
7478
}
7579
return sum;
7680
}
7781

78-
for ( i = 0; i < N; i++ ) {
82+
for ( i = 1; i < N; i++ ) {
7983
sum += (double)X[ ix ];
8084
ix += strideX;
8185
}

ext/base/dssumors/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 dssumors = 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 = dssumors( 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;

ext/base/dssumors/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 = dssumors( 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;

ext/base/dsum/test/test.ndarray.js

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

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
26+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2527
var Float64Array = require( '@stdlib/array/float64' );
2628
var dsum = require( './../lib/ndarray.js' );
2729

@@ -66,6 +68,23 @@ tape( 'the function calculates the sum of all strided array elements', function
6668
t.end();
6769
});
6870

71+
tape( 'the function preserves the sign of zero', function test( t ) {
72+
var x;
73+
var v;
74+
75+
x = new Float64Array( [ -0.0, -0.0, -0.0 ] );
76+
77+
v = dsum( x.length, x, 1, 0 );
78+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
79+
80+
x = new Float64Array( [ 0.0, -0.0, -0.0 ] );
81+
82+
v = dsum( x.length, x, 1, 0 );
83+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
84+
85+
t.end();
86+
});
87+
6988
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test( t ) {
7089
var x;
7190
var v;

ext/base/dsum/test/test.ndarray.native.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
27+
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2628
var Float64Array = require( '@stdlib/array/float64' );
2729
var tryRequire = require( '@stdlib/utils/try-require' );
2830

@@ -75,6 +77,23 @@ tape( 'the function calculates the sum of all strided array elements', opts, fun
7577
t.end();
7678
});
7779

80+
tape( 'the function preserves the sign of zero', opts, function test( t ) {
81+
var x;
82+
var v;
83+
84+
x = new Float64Array( [ -0.0, -0.0, -0.0 ] );
85+
86+
v = dsum( x.length, x, 1, 0 );
87+
t.strictEqual( isNegativeZero( v ), true, 'returns expected value' );
88+
89+
x = new Float64Array( [ 0.0, -0.0, -0.0 ] );
90+
91+
v = dsum( x.length, x, 1, 0 );
92+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
93+
94+
t.end();
95+
});
96+
7897
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', opts, function test( t ) {
7998
var x;
8099
var v;

0 commit comments

Comments
 (0)