Skip to content

Commit fe9a802

Browse files
committed
Auto-generated commit
1 parent df39b6d commit fe9a802

File tree

17 files changed

+299
-4
lines changed

17 files changed

+299
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@
194194

195195
### Bug Fixes
196196

197+
- [`cb8907d`](https://github.com/stdlib-js/stdlib/commit/cb8907dbdb8e4670c3519555e8abc2ddddbf1d77) - preserve the sign of zero
198+
- [`8355a12`](https://github.com/stdlib-js/stdlib/commit/8355a12db3136d06875016a248eb6f8410672bd2) - preserve the sign of zero
197199
- [`43bfc6b`](https://github.com/stdlib-js/stdlib/commit/43bfc6bc1d850367f3957fdb550c40d25c6f0e62) - include value in error message
198200
- [`3b4fa18`](https://github.com/stdlib-js/stdlib/commit/3b4fa18ec5573c25c66e17441092bcbe4c63fe9f) - include value in error message
199201
- [`b6e0aca`](https://github.com/stdlib-js/stdlib/commit/b6e0aca427f23e8ec53d6c62d41e4b550bdf08c6) - add missing values in error messages in `blas/base/sgemv` [(#6722)](https://github.com/stdlib-js/stdlib/pull/6722)
@@ -393,6 +395,12 @@ A total of 17 issues were closed in this release:
393395

394396
<details>
395397

398+
- [`1a5f29d`](https://github.com/stdlib-js/stdlib/commit/1a5f29d7d9e481f34854dcbf00339d9ab8e85057) - **test:** add zeros tests _(by Athan Reines)_
399+
- [`5d0823a`](https://github.com/stdlib-js/stdlib/commit/5d0823aa846bd681e9b4ce675521be1af39e5554) - **test:** add zeros tests _(by Athan Reines)_
400+
- [`81aeefe`](https://github.com/stdlib-js/stdlib/commit/81aeefed3885d8b238875a1d656401b7d3149d10) - **test:** add zeros tests _(by Athan Reines)_
401+
- [`446ce07`](https://github.com/stdlib-js/stdlib/commit/446ce073c82847d889c7b2e43e0ce3010a0767f9) - **test:** add zeros tests _(by Athan Reines)_
402+
- [`cb8907d`](https://github.com/stdlib-js/stdlib/commit/cb8907dbdb8e4670c3519555e8abc2ddddbf1d77) - **fix:** preserve the sign of zero _(by Athan Reines)_
403+
- [`8355a12`](https://github.com/stdlib-js/stdlib/commit/8355a12db3136d06875016a248eb6f8410672bd2) - **fix:** preserve the sign of zero _(by Athan Reines)_
396404
- [`9284bd7`](https://github.com/stdlib-js/stdlib/commit/9284bd7fc74b1aea7556be0d1c98196a3eff2649) - **feat:** add `cfill` and `zfill` to namespace _(by Athan Reines)_
397405
- [`b86b7d5`](https://github.com/stdlib-js/stdlib/commit/b86b7d5988cd3f2a083355b6a91a748dca9e509b) - **feat:** add `ndarray` to namespace _(by Athan Reines)_
398406
- [`e5b3cfd`](https://github.com/stdlib-js/stdlib/commit/e5b3cfdc9a4dab44eacc47cf4e911e417ec0c8ce) - **feat:** add `blas/ext/base/ndarray` namespace _(by Athan Reines)_

ext/base/dcusumkbn/lib/ndarray.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,23 @@ function dcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
7070
ix = offsetX;
7171
iy = offsetY;
7272
s = sum;
73+
74+
// In order to preserve the sign of zero which can be lost during compensated summation below, find the first non-zero element...
75+
if ( s === 0.0 ) {
76+
for ( i = 0; i < N; i++ ) {
77+
v = x[ ix ];
78+
if ( v !== 0.0 ) {
79+
break;
80+
}
81+
y[ iy ] = s + v;
82+
ix += strideX;
83+
iy += strideY;
84+
}
85+
} else {
86+
i = 0;
87+
}
7388
c = 0.0;
74-
for ( i = 0; i < N; i++ ) {
89+
for ( ; i < N; i++ ) {
7590
v = x[ ix ];
7691
t = s + v;
7792
if ( abs( s ) >= abs( v ) ) {

ext/base/dcusumkbn/src/main.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,23 @@ void API_SUFFIX(stdlib_strided_dcusumkbn_ndarray)( const CBLAS_INT N, const doub
8080
ix = offsetX;
8181
iy = offsetY;
8282
s = sum;
83+
84+
// In order to preserve the sign of zero which can be lost during compensated summation below, find the first non-zero element...
85+
if ( s == 0.0 ) {
86+
for ( i = 0; i < N; i++ ) {
87+
v = X[ ix ];
88+
if ( v != 0.0 ) {
89+
break;
90+
}
91+
Y[ iy ] = s + v;
92+
ix += strideX;
93+
iy += strideY;
94+
}
95+
} else {
96+
i = 0;
97+
}
8398
c = 0.0;
84-
for ( i = 0; i < N; i++ ) {
99+
for ( ; i < N; i++ ) {
85100
v = X[ ix ];
86101
t = s + v;
87102
if ( stdlib_base_abs( s ) >= stdlib_base_abs( v ) ) {

ext/base/dcusumkbn/test/test.ndarray.js

Lines changed: 21 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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
2526
var Float64Array = require( '@stdlib/array/float64' );
2627
var dcusumkbn = require( './../lib/ndarray.js' );
2728

@@ -126,6 +127,26 @@ tape( 'the function calculates the cumulative sum', function test( t ) {
126127
t.end();
127128
});
128129

130+
tape( 'the function preserves the sign of zero', function test( t ) {
131+
var expected;
132+
var x;
133+
var y;
134+
135+
x = new Float64Array( [ -0.0, -0.0, -0.0, 0.0, 1.0 ] );
136+
y = new Float64Array( x.length );
137+
138+
dcusumkbn( x.length, -0.0, x, 1, 0, y, 1, 0 );
139+
expected = new Float64Array([
140+
-0.0,
141+
-0.0,
142+
-0.0,
143+
0.0,
144+
1.0
145+
]);
146+
t.strictEqual( isSameFloat64Array( y, expected ), true, 'returns expected value' );
147+
t.end();
148+
});
149+
129150
tape( 'the function returns a reference to the output array', function test( t ) {
130151
var out;
131152
var x;

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

Lines changed: 21 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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
2627
var Float64Array = require( '@stdlib/array/float64' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829

@@ -135,6 +136,26 @@ tape( 'the function calculates the cumulative sum', opts, function test( t ) {
135136
t.end();
136137
});
137138

139+
tape( 'the function preserves the sign of zero', opts, function test( t ) {
140+
var expected;
141+
var x;
142+
var y;
143+
144+
x = new Float64Array( [ -0.0, -0.0, -0.0, 0.0, 1.0 ] );
145+
y = new Float64Array( x.length );
146+
147+
dcusumkbn( x.length, -0.0, x, 1, 0, y, 1, 0 );
148+
expected = new Float64Array([
149+
-0.0,
150+
-0.0,
151+
-0.0,
152+
0.0,
153+
1.0
154+
]);
155+
t.strictEqual( isSameFloat64Array( y, expected ), true, 'returns expected value' );
156+
t.end();
157+
});
158+
138159
tape( 'the function returns a reference to the output array', opts, function test( t ) {
139160
var out;
140161
var x;

ext/base/dcusumkbn2/lib/ndarray.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,23 @@ function dcusumkbn2( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
7272
ix = offsetX;
7373
iy = offsetY;
7474

75+
// In order to preserve the sign of zero which can be lost during compensated summation below, find the first non-zero element...
76+
if ( sum === 0.0 ) {
77+
for ( i = 0; i < N; i++ ) {
78+
v = x[ ix ];
79+
if ( v !== 0.0 ) {
80+
break;
81+
}
82+
y[ iy ] = sum + v;
83+
ix += strideX;
84+
iy += strideY;
85+
}
86+
} else {
87+
i = 0;
88+
}
7589
ccs = 0.0; // second order correction term for lost low order bits
7690
cs = 0.0; // first order correction term for lost low order bits
77-
for ( i = 0; i < N; i++ ) {
91+
for ( ; i < N; i++ ) {
7892
v = x[ ix ];
7993
t = sum + v;
8094
if ( abs( sum ) >= abs( v ) ) {

ext/base/dcusumkbn2/src/main.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,24 @@ void API_SUFFIX(stdlib_strided_dcusumkbn2_ndarray)( const CBLAS_INT N, const dou
8383
ix = offsetX;
8484
iy = offsetY;
8585
s = sum;
86+
87+
// In order to preserve the sign of zero which can be lost during compensated summation below, find the first non-zero element...
88+
if ( s == 0.0 ) {
89+
for ( i = 0; i < N; i++ ) {
90+
v = X[ ix ];
91+
if ( v != 0.0 ) {
92+
break;
93+
}
94+
Y[ iy ] = s + v;
95+
ix += strideX;
96+
iy += strideY;
97+
}
98+
} else {
99+
i = 0;
100+
}
86101
ccs = 0.0; // second order correction term for lost lower order bits
87102
cs = 0.0; // first order correction term for lost low order bits
88-
for ( i = 0; i < N; i++ ) {
103+
for ( ; i < N; i++ ) {
89104
v = X[ ix ];
90105
t = s + v;
91106
if ( stdlib_base_abs( s ) >= stdlib_base_abs( v ) ) {

ext/base/dcusumkbn2/test/test.ndarray.js

Lines changed: 21 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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
2526
var Float64Array = require( '@stdlib/array/float64' );
2627
var dcusumkbn2 = require( './../lib/ndarray.js' );
2728

@@ -126,6 +127,26 @@ tape( 'the function calculates the cumulative sum', function test( t ) {
126127
t.end();
127128
});
128129

130+
tape( 'the function preserves the sign of zero', function test( t ) {
131+
var expected;
132+
var x;
133+
var y;
134+
135+
x = new Float64Array( [ -0.0, -0.0, -0.0, 0.0, 1.0 ] );
136+
y = new Float64Array( x.length );
137+
138+
dcusumkbn2( x.length, -0.0, x, 1, 0, y, 1, 0 );
139+
expected = new Float64Array([
140+
-0.0,
141+
-0.0,
142+
-0.0,
143+
0.0,
144+
1.0
145+
]);
146+
t.strictEqual( isSameFloat64Array( y, expected ), true, 'returns expected value' );
147+
t.end();
148+
});
149+
129150
tape( 'the function returns a reference to the output array', function test( t ) {
130151
var out;
131152
var x;

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

Lines changed: 21 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 isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
2627
var Float64Array = require( '@stdlib/array/float64' );
2728
var tryRequire = require( '@stdlib/utils/try-require' );
2829

@@ -135,6 +136,26 @@ tape( 'the function calculates the cumulative sum', opts, function test( t ) {
135136
t.end();
136137
});
137138

139+
tape( 'the function preserves the sign of zero', opts, function test( t ) {
140+
var expected;
141+
var x;
142+
var y;
143+
144+
x = new Float64Array( [ -0.0, -0.0, -0.0, 0.0, 1.0 ] );
145+
y = new Float64Array( x.length );
146+
147+
dcusumkbn2( x.length, -0.0, x, 1, 0, y, 1, 0 );
148+
expected = new Float64Array([
149+
-0.0,
150+
-0.0,
151+
-0.0,
152+
0.0,
153+
1.0
154+
]);
155+
t.strictEqual( isSameFloat64Array( y, expected ), true, 'returns expected value' );
156+
t.end();
157+
});
158+
138159
tape( 'the function returns a reference to the output array', opts, function test( t ) {
139160
var out;
140161
var x;

ext/base/dnansumkbn/test/test.ndarray.js

Lines changed: 18 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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
2425
var Float64Array = require( '@stdlib/array/float64' );
2526
var dnansumkbn = require( './../lib/ndarray.js' );
2627

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

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

0 commit comments

Comments
 (0)