@stdlib/blas-ext-base-dsnansumpw 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +141 -38
- package/dist/index.js +7 -7
- package/dist/index.js.map +3 -3
- package/docs/types/index.d.ts +7 -7
- package/include/stdlib/blas/ext/base/dsnansumpw.h +8 -6
- package/lib/dsnansumpw.js +6 -36
- package/lib/dsnansumpw.native.js +4 -5
- package/lib/index.js +2 -5
- package/lib/ndarray.js +28 -30
- package/lib/ndarray.native.js +6 -13
- package/manifest.json +80 -40
- package/package.json +9 -3
- package/src/addon.c +62 -0
- package/src/{dsnansumpw.c → main.c} +58 -48
- package/src/addon.cpp +0 -117
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ npm install @stdlib/blas-ext-base-dsnansumpw
|
|
|
59
59
|
var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
#### dsnansumpw( N, x,
|
|
62
|
+
#### dsnansumpw( N, x, strideX )
|
|
63
63
|
|
|
64
64
|
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.
|
|
65
65
|
|
|
@@ -67,9 +67,8 @@ Computes the sum of single-precision floating-point strided array elements, igno
|
|
|
67
67
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
68
68
|
|
|
69
69
|
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
70
|
-
var N = x.length;
|
|
71
70
|
|
|
72
|
-
var v = dsnansumpw(
|
|
71
|
+
var v = dsnansumpw( x.length, x, 1 );
|
|
73
72
|
// returns 1.0
|
|
74
73
|
```
|
|
75
74
|
|
|
@@ -77,18 +76,16 @@ The function has the following parameters:
|
|
|
77
76
|
|
|
78
77
|
- **N**: number of indexed elements.
|
|
79
78
|
- **x**: input [`Float32Array`][@stdlib/array/float32].
|
|
80
|
-
- **stride**:
|
|
79
|
+
- **stride**: stride length for `x`.
|
|
81
80
|
|
|
82
|
-
The `N` and
|
|
81
|
+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element:
|
|
83
82
|
|
|
84
83
|
```javascript
|
|
85
84
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
86
|
-
var floor = require( '@stdlib/math-base-special-floor' );
|
|
87
85
|
|
|
88
86
|
var x = new Float32Array( [ 1.0, 2.0, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] );
|
|
89
|
-
var N = floor( x.length / 2 );
|
|
90
87
|
|
|
91
|
-
var v = dsnansumpw(
|
|
88
|
+
var v = dsnansumpw( 4, x, 2 );
|
|
92
89
|
// returns 5.0
|
|
93
90
|
```
|
|
94
91
|
|
|
@@ -98,45 +95,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
|
|
|
98
95
|
|
|
99
96
|
```javascript
|
|
100
97
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
101
|
-
var floor = require( '@stdlib/math-base-special-floor' );
|
|
102
98
|
|
|
103
99
|
var x0 = new Float32Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
|
|
104
100
|
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
|
|
105
101
|
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
var v = dsnansumpw( N, x1, 2 );
|
|
102
|
+
var v = dsnansumpw( 4, x1, 2 );
|
|
109
103
|
// returns 5.0
|
|
110
104
|
```
|
|
111
105
|
|
|
112
|
-
#### dsnansumpw.ndarray( N, x,
|
|
106
|
+
#### dsnansumpw.ndarray( N, x, strideX, offsetX )
|
|
113
107
|
|
|
114
|
-
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values
|
|
108
|
+
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
|
|
115
109
|
|
|
116
110
|
```javascript
|
|
117
111
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
118
112
|
|
|
119
113
|
var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
120
|
-
var N = x.length;
|
|
121
114
|
|
|
122
|
-
var v = dsnansumpw.ndarray(
|
|
115
|
+
var v = dsnansumpw.ndarray( x.length, x, 1, 0 );
|
|
123
116
|
// returns 1.0
|
|
124
117
|
```
|
|
125
118
|
|
|
126
119
|
The function has the following additional parameters:
|
|
127
120
|
|
|
128
|
-
- **
|
|
121
|
+
- **offsetX**: starting index for `x`.
|
|
129
122
|
|
|
130
|
-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the
|
|
123
|
+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other element starting from the second element:
|
|
131
124
|
|
|
132
125
|
```javascript
|
|
133
126
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
134
|
-
var floor = require( '@stdlib/math-base-special-floor' );
|
|
135
127
|
|
|
136
128
|
var x = new Float32Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
|
|
137
|
-
var N = floor( x.length / 2 );
|
|
138
129
|
|
|
139
|
-
var v = dsnansumpw.ndarray(
|
|
130
|
+
var v = dsnansumpw.ndarray( 4, x, 2, 1 );
|
|
140
131
|
// returns 5.0
|
|
141
132
|
```
|
|
142
133
|
|
|
@@ -162,22 +153,19 @@ var v = dsnansumpw.ndarray( N, x, 2, 1 );
|
|
|
162
153
|
<!-- eslint no-undef: "error" -->
|
|
163
154
|
|
|
164
155
|
```javascript
|
|
165
|
-
var
|
|
166
|
-
var
|
|
167
|
-
var
|
|
156
|
+
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
|
|
157
|
+
var bernoulli = require( '@stdlib/random-base-bernoulli' );
|
|
158
|
+
var filledarrayBy = require( '@stdlib/array-filled-by' );
|
|
168
159
|
var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );
|
|
169
160
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
x = new Float32Array( 10 );
|
|
174
|
-
for ( i = 0; i < x.length; i++ ) {
|
|
175
|
-
if ( randu() < 0.2 ) {
|
|
176
|
-
x[ i ] = NaN;
|
|
177
|
-
} else {
|
|
178
|
-
x[ i ] = round( randu()*100.0 );
|
|
161
|
+
function rand() {
|
|
162
|
+
if ( bernoulli( 0.8 ) > 0 ) {
|
|
163
|
+
return NaN;
|
|
179
164
|
}
|
|
165
|
+
return discreteUniform( 0, 100 );
|
|
180
166
|
}
|
|
167
|
+
|
|
168
|
+
var x = filledarrayBy( 10, 'float32', rand );
|
|
181
169
|
console.log( x );
|
|
182
170
|
|
|
183
171
|
var v = dsnansumpw( x.length, x, 1 );
|
|
@@ -188,8 +176,123 @@ console.log( v );
|
|
|
188
176
|
|
|
189
177
|
<!-- /.examples -->
|
|
190
178
|
|
|
179
|
+
<!-- C interface documentation. -->
|
|
180
|
+
|
|
191
181
|
* * *
|
|
192
182
|
|
|
183
|
+
<section class="c">
|
|
184
|
+
|
|
185
|
+
## C APIs
|
|
186
|
+
|
|
187
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
188
|
+
|
|
189
|
+
<section class="intro">
|
|
190
|
+
|
|
191
|
+
</section>
|
|
192
|
+
|
|
193
|
+
<!-- /.intro -->
|
|
194
|
+
|
|
195
|
+
<!-- C usage documentation. -->
|
|
196
|
+
|
|
197
|
+
<section class="usage">
|
|
198
|
+
|
|
199
|
+
### Usage
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
#include "stdlib/blas/ext/base/dsnansumpw.h"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### stdlib_strided_dsnansumpw( N, \*X, strideX )
|
|
206
|
+
|
|
207
|
+
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.
|
|
208
|
+
|
|
209
|
+
```c
|
|
210
|
+
const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };
|
|
211
|
+
|
|
212
|
+
double v = stdlib_strided_dsnansumpw( 4, x, 1 );
|
|
213
|
+
// returns 1.0
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The function accepts the following arguments:
|
|
217
|
+
|
|
218
|
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
|
|
219
|
+
- **X**: `[in] float*` input array.
|
|
220
|
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
|
|
221
|
+
|
|
222
|
+
```c
|
|
223
|
+
double stdlib_strided_dsnansumpw( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### stdlib_strided_dsnansumpw_ndarray( N, \*X, strideX, offsetX )
|
|
227
|
+
|
|
228
|
+
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
|
|
229
|
+
|
|
230
|
+
```c
|
|
231
|
+
const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };
|
|
232
|
+
|
|
233
|
+
double v = stdlib_strided_dsnansumpw_ndarray( 4, x, 1, 0 );
|
|
234
|
+
// returns 1.0
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The function accepts the following arguments:
|
|
238
|
+
|
|
239
|
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
|
|
240
|
+
- **X**: `[in] float*` input array.
|
|
241
|
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
|
|
242
|
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
|
|
243
|
+
|
|
244
|
+
```c
|
|
245
|
+
double stdlib_strided_dsnansumpw_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
</section>
|
|
249
|
+
|
|
250
|
+
<!-- /.usage -->
|
|
251
|
+
|
|
252
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
253
|
+
|
|
254
|
+
<section class="notes">
|
|
255
|
+
|
|
256
|
+
</section>
|
|
257
|
+
|
|
258
|
+
<!-- /.notes -->
|
|
259
|
+
|
|
260
|
+
<!-- C API usage examples. -->
|
|
261
|
+
|
|
262
|
+
<section class="examples">
|
|
263
|
+
|
|
264
|
+
### Examples
|
|
265
|
+
|
|
266
|
+
```c
|
|
267
|
+
#include "stdlib/blas/ext/base/dsnansumpw.h"
|
|
268
|
+
#include <stdio.h>
|
|
269
|
+
|
|
270
|
+
int main( void ) {
|
|
271
|
+
// Create a strided array:
|
|
272
|
+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 0.0f/0.0f, 0.0f/0.0f };
|
|
273
|
+
|
|
274
|
+
// Specify the number of elements:
|
|
275
|
+
const int N = 5;
|
|
276
|
+
|
|
277
|
+
// Specify the stride length:
|
|
278
|
+
const int strideX = 2;
|
|
279
|
+
|
|
280
|
+
// Compute the sum:
|
|
281
|
+
double v = stdlib_strided_dsnansumpw( N, x, strideX );
|
|
282
|
+
|
|
283
|
+
// Print the result:
|
|
284
|
+
printf( "sum: %lf\n", v );
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
</section>
|
|
289
|
+
|
|
290
|
+
<!-- /.examples -->
|
|
291
|
+
|
|
292
|
+
</section>
|
|
293
|
+
|
|
294
|
+
<!-- /.c -->
|
|
295
|
+
|
|
193
296
|
<section class="references">
|
|
194
297
|
|
|
195
298
|
## References
|
|
@@ -243,7 +346,7 @@ See [LICENSE][stdlib-license].
|
|
|
243
346
|
|
|
244
347
|
## Copyright
|
|
245
348
|
|
|
246
|
-
Copyright © 2016-
|
|
349
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
247
350
|
|
|
248
351
|
</section>
|
|
249
352
|
|
|
@@ -256,8 +359,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
256
359
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-dsnansumpw.svg
|
|
257
360
|
[npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-dsnansumpw
|
|
258
361
|
|
|
259
|
-
[test-image]: https://github.com/stdlib-js/blas-ext-base-dsnansumpw/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
260
|
-
[test-url]: https://github.com/stdlib-js/blas-ext-base-dsnansumpw/actions/workflows/test.yml?query=branch:v0.
|
|
362
|
+
[test-image]: https://github.com/stdlib-js/blas-ext-base-dsnansumpw/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
363
|
+
[test-url]: https://github.com/stdlib-js/blas-ext-base-dsnansumpw/actions/workflows/test.yml?query=branch:v0.3.0
|
|
261
364
|
|
|
262
365
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-dsnansumpw/main.svg
|
|
263
366
|
[coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-dsnansumpw?branch=main
|
|
@@ -269,8 +372,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
269
372
|
|
|
270
373
|
-->
|
|
271
374
|
|
|
272
|
-
[chat-image]: https://img.shields.io/
|
|
273
|
-
[chat-url]: https://
|
|
375
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
376
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
274
377
|
|
|
275
378
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
276
379
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
4
|
-
var
|
|
5
|
-
});var
|
|
6
|
-
var k=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),
|
|
7
|
-
});var A=require("path").join,D=require('@stdlib/utils-try-require/dist'),F=require('@stdlib/assert-is-error/dist'),G=
|
|
1
|
+
"use strict";var y=function(v,a){return function(){return a||v((a={exports:{}}).exports,a),a.exports}};var j=y(function(J,R){
|
|
2
|
+
var u=require('@stdlib/math-base-assert-is-nanf/dist'),S=require('@stdlib/math-base-special-floor/dist'),Z=128;function w(v,a,n,M){var r,o,i,q,p,m,c,l,t,O,f,s,e;if(v<=0)return 0;if(r=M,n===0)return u(a[r])?0:v*a[r];if(v<8){for(f=0,e=0;e<v;e++)u(a[r])===!1&&(f+=a[r]),r+=n;return f}if(v<=Z){for(o=u(a[r])?0:a[r],r+=n,i=u(a[r])?0:a[r],r+=n,q=u(a[r])?0:a[r],r+=n,p=u(a[r])?0:a[r],r+=n,m=u(a[r])?0:a[r],r+=n,c=u(a[r])?0:a[r],r+=n,l=u(a[r])?0:a[r],r+=n,t=u(a[r])?0:a[r],r+=n,O=v%8,e=8;e<v-O;e+=8)o+=u(a[r])?0:a[r],r+=n,i+=u(a[r])?0:a[r],r+=n,q+=u(a[r])?0:a[r],r+=n,p+=u(a[r])?0:a[r],r+=n,m+=u(a[r])?0:a[r],r+=n,c+=u(a[r])?0:a[r],r+=n,l+=u(a[r])?0:a[r],r+=n,t+=u(a[r])?0:a[r],r+=n;for(f=o+i+(q+p)+(m+c+(l+t)),e;e<v;e++)u(a[r])===!1&&(f+=a[r]),r+=n;return f}return s=S(v/2),s-=s%8,w(s,a,n,r)+w(v-s,a,n,r+s*n)}R.exports=w
|
|
3
|
+
});var B=y(function(P,_){
|
|
4
|
+
var b=require('@stdlib/strided-base-stride2offset/dist'),g=j();function h(v,a,n){return g(v,a,n,b(v,n))}_.exports=h
|
|
5
|
+
});var K=y(function(Q,I){
|
|
6
|
+
var k=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),C=B(),z=j();k(C,"ndarray",z);I.exports=C
|
|
7
|
+
});var A=require("path").join,D=require('@stdlib/utils-try-require/dist'),F=require('@stdlib/assert-is-error/dist'),G=K(),E,L=D(A(__dirname,"./native.js"));F(L)?E=G:E=L;module.exports=E;
|
|
8
8
|
/** @license Apache-2.0 */
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/ndarray.js", "../lib/dsnansumpw.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnanf = require( '@stdlib/math-base-assert-is-nanf' );\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\n// Blocksize for pairwise summation (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.):\nvar BLOCKSIZE = 128;\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var v = dsnansumpw( N, x, 2, 1 );\n* // returns 5.0\n*/\nfunction dsnansumpw( N, x, stride, offset ) {\n\tvar ix;\n\tvar s0;\n\tvar s1;\n\tvar s2;\n\tvar s3;\n\tvar s4;\n\tvar s5;\n\tvar s6;\n\tvar s7;\n\tvar M;\n\tvar s;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnanf( x[ offset ] ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn x[ offset ];\n\t}\n\tix = offset;\n\tif ( N < 8 ) {\n\t\t// Use simple summation...\n\t\ts = 0.0;\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tif ( isnanf( x[ ix ] ) === false ) {\n\t\t\t\ts += x[ ix ];\n\t\t\t}\n\t\t\tix += stride;\n\t\t}\n\t\treturn s;\n\t}\n\tif ( N <= BLOCKSIZE ) {\n\t\t// Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)...\n\t\ts0 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts1 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts2 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts3 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts4 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts5 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts6 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\t\ts7 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += stride;\n\n\t\tM = N % 8;\n\t\tfor ( i = 8; i < N-M; i += 8 ) {\n\t\t\ts0 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts1 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts2 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts3 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts4 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts5 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts6 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t\ts7 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += stride;\n\t\t}\n\t\t// Pairwise sum the accumulators:\n\t\ts = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7));\n\n\t\t// Clean-up loop...\n\t\tfor ( i; i < N; i++ ) {\n\t\t\tif ( isnanf( x[ ix ] ) === false ) {\n\t\t\t\ts += x[ ix ];\n\t\t\t}\n\t\t\tix += stride;\n\t\t}\n\t\treturn s;\n\t}\n\t// Recurse by dividing by two, but avoiding non-multiples of unroll factor...\n\tn = floor( N/2 );\n\tn -= n % 8;\n\treturn dsnansumpw( n, x, stride, ix ) + dsnansumpw( N-n, x, stride, ix+(n*stride) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnanf = require( '@stdlib/math-base-assert-is-nanf' );\nvar sum = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumpw( N, x, 1 );\n* // returns 1.0\n*/\nfunction dsnansumpw( N, x, stride ) {\n\tvar ix;\n\tvar s;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnanf( x[ 0 ] ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn x[ 0 ];\n\t}\n\tif ( stride < 0 ) {\n\t\tix = (1-N) * stride;\n\t} else {\n\t\tix = 0;\n\t}\n\tif ( N < 8 ) {\n\t\t// Use simple summation...\n\t\ts = 0.0;\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tif ( isnanf( x[ ix ] ) === false ) {\n\t\t\t\ts += x[ ix ];\n\t\t\t}\n\t\t\tix += stride;\n\t\t}\n\t\treturn s;\n\t}\n\treturn sum( N, x, stride, ix );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsnansumpw = require( './dsnansumpw.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsnansumpw, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.\n*\n* @module @stdlib/blas-ext-base-dsnansumpw\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumpw( N, x, 1 );\n* // returns 1.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var v = dsnansumpw.ndarray( N, x, 2, 1 );\n* // returns 5.0\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsnansumpw;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsnansumpw = main;\n} else {\n\tdsnansumpw = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n\n// exports: { \"ndarray\": \"dsnansumpw.ndarray\" }\n"],
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,kCAAmC,EACrDC,EAAQ,QAAS,iCAAkC,EAMnDC,EAAY,
|
|
6
|
-
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "isnanf", "floor", "BLOCKSIZE", "dsnansumpw", "N", "x", "
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnanf = require( '@stdlib/math-base-assert-is-nanf' );\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\n// Blocksize for pairwise summation (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.):\nvar BLOCKSIZE = 128;\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dsnansumpw( 5, x, 2, 1 );\n* // returns 5.0\n*/\nfunction dsnansumpw( N, x, strideX, offsetX ) {\n\tvar ix;\n\tvar s0;\n\tvar s1;\n\tvar s2;\n\tvar s3;\n\tvar s4;\n\tvar s5;\n\tvar s6;\n\tvar s7;\n\tvar M;\n\tvar s;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn 0.0;\n\t}\n\tix = offsetX;\n\tif ( strideX === 0 ) {\n\t\tif ( isnanf( x[ ix ] ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn N * x[ ix ];\n\t}\n\tif ( N < 8 ) {\n\t\t// Use simple summation...\n\t\ts = 0.0;\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tif ( isnanf( x[ ix ] ) === false ) {\n\t\t\t\ts += x[ ix ];\n\t\t\t}\n\t\t\tix += strideX;\n\t\t}\n\t\treturn s;\n\t}\n\tif ( N <= BLOCKSIZE ) {\n\t\t// Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)...\n\t\ts0 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts1 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts2 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts3 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts4 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts5 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts6 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\t\ts7 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\tix += strideX;\n\n\t\tM = N % 8;\n\t\tfor ( i = 8; i < N-M; i += 8 ) {\n\t\t\ts0 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts1 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts2 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts3 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts4 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts5 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts6 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t\ts7 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];\n\t\t\tix += strideX;\n\t\t}\n\t\t// Pairwise sum the accumulators:\n\t\ts = ( (s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7) );\n\n\t\t// Clean-up loop...\n\t\tfor ( i; i < N; i++ ) {\n\t\t\tif ( isnanf( x[ ix ] ) === false ) {\n\t\t\t\ts += x[ ix ];\n\t\t\t}\n\t\t\tix += strideX;\n\t\t}\n\t\treturn s;\n\t}\n\t// Recurse by dividing by two, but avoiding non-multiples of unroll factor...\n\tn = floor( N/2 );\n\tn -= n % 8;\n\treturn dsnansumpw( n, x, strideX, ix ) + dsnansumpw( N-n, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} strideX - stride length\n* @returns {number} sum\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dsnansumpw( x.length, x, 1 );\n* // returns 1.0\n*/\nfunction dsnansumpw( N, x, strideX ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar dsnansumpw = require( './dsnansumpw.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsnansumpw, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.\n*\n* @module @stdlib/blas-ext-base-dsnansumpw\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dsnansumpw( x.length, x, 1 );\n* // returns 1.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n*\n* var v = dsnansumpw.ndarray( 5, x, 2, 1 );\n* // returns 5.0\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar dsnansumpw;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsnansumpw = main;\n} else {\n\tdsnansumpw = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumpw;\n\n// exports: { \"ndarray\": \"dsnansumpw.ndarray\" }\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,kCAAmC,EACrDC,EAAQ,QAAS,iCAAkC,EAMnDC,EAAY,IA8BhB,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKhB,GAAK,EACT,MAAO,GAGR,GADAI,EAAKD,EACAD,IAAY,EAChB,OAAKN,EAAQK,EAAGG,CAAG,CAAE,EACb,EAEDJ,EAAIC,EAAGG,CAAG,EAElB,GAAKJ,EAAI,EAAI,CAGZ,IADAc,EAAI,EACEE,EAAI,EAAGA,EAAIhB,EAAGgB,IACdpB,EAAQK,EAAGG,CAAG,CAAE,IAAM,KAC1BU,GAAKb,EAAGG,CAAG,GAEZA,GAAMF,EAEP,OAAOY,CACR,CACA,GAAKd,GAAKF,EAAY,CAoBrB,IAlBAO,EAAOT,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNI,EAAOV,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNK,EAAOX,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNM,EAAOZ,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNO,EAAOb,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNQ,EAAOd,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNS,EAAOf,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EACNU,EAAOhB,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EACzCA,GAAMF,EAENW,EAAIb,EAAI,EACFgB,EAAI,EAAGA,EAAIhB,EAAEa,EAAGG,GAAK,EAC1BX,GAAQT,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNI,GAAQV,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNK,GAAQX,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNM,GAAQZ,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNO,GAAQb,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNQ,GAAQd,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNS,GAAQf,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EACNU,GAAQhB,EAAQK,EAAGG,CAAG,CAAE,EAAM,EAAMH,EAAGG,CAAG,EAC1CA,GAAMF,EAMP,IAHAY,EAAOT,EAAGC,GAAOC,EAAGC,IAASC,EAAGC,GAAOC,EAAGC,IAGpCI,EAAGA,EAAIhB,EAAGgB,IACVpB,EAAQK,EAAGG,CAAG,CAAE,IAAM,KAC1BU,GAAKb,EAAGG,CAAG,GAEZA,GAAMF,EAEP,OAAOY,CACR,CAEA,OAAAC,EAAIlB,EAAOG,EAAE,CAAE,EACfe,GAAKA,EAAI,EACFhB,EAAYgB,EAAGd,EAAGC,EAASE,CAAG,EAAIL,EAAYC,EAAEe,EAAGd,EAAGC,EAASE,EAAIW,EAAEb,CAAS,CACtF,CAKAP,EAAO,QAAUI,IC1JjB,IAAAkB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IA6Bd,SAASC,EAAYC,EAAGC,EAAGC,EAAU,CACpC,OAAOJ,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,CAAE,CAC5D,CAKAN,EAAO,QAAUG,IC3DjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAa,IACbC,EAAU,IAKdF,EAAaC,EAAY,UAAWC,CAAQ,EAK5CH,EAAO,QAAUE,ICYjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAaD,EAEbC,EAAaC,EAMd,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "isnanf", "floor", "BLOCKSIZE", "dsnansumpw", "N", "x", "strideX", "offsetX", "ix", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "M", "s", "n", "i", "require_dsnansumpw", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dsnansumpw", "N", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsnansumpw", "ndarray", "join", "tryRequire", "isError", "main", "dsnansumpw", "tmp"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ interface Routine {
|
|
|
27
27
|
*
|
|
28
28
|
* @param N - number of indexed elements
|
|
29
29
|
* @param x - input array
|
|
30
|
-
* @param
|
|
30
|
+
* @param strideX - stride length
|
|
31
31
|
* @returns sum
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
@@ -38,15 +38,15 @@ interface Routine {
|
|
|
38
38
|
* var v = dsnansumpw( x.length, x, 1 );
|
|
39
39
|
* // returns 1.0
|
|
40
40
|
*/
|
|
41
|
-
( N: number, x: Float32Array,
|
|
41
|
+
( N: number, x: Float32Array, strideX: number ): number;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values
|
|
44
|
+
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
|
|
45
45
|
*
|
|
46
46
|
* @param N - number of indexed elements
|
|
47
47
|
* @param x - input array
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
48
|
+
* @param strideX - stride length
|
|
49
|
+
* @param offsetX - starting index
|
|
50
50
|
* @returns sum
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
@@ -57,7 +57,7 @@ interface Routine {
|
|
|
57
57
|
* var v = dsnansumpw.ndarray( x.length, x, 1, 0 );
|
|
58
58
|
* // returns 1.0
|
|
59
59
|
*/
|
|
60
|
-
ndarray( N: number, x: Float32Array,
|
|
60
|
+
ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): number;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -65,7 +65,7 @@ interface Routine {
|
|
|
65
65
|
*
|
|
66
66
|
* @param N - number of indexed elements
|
|
67
67
|
* @param x - input array
|
|
68
|
-
* @param
|
|
68
|
+
* @param strideX - stride length
|
|
69
69
|
* @returns sum
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
@@ -16,13 +16,10 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Header file containing function declarations.
|
|
21
|
-
*/
|
|
22
19
|
#ifndef STDLIB_BLAS_EXT_BASE_DSNANSUMPW_H
|
|
23
20
|
#define STDLIB_BLAS_EXT_BASE_DSNANSUMPW_H
|
|
24
21
|
|
|
25
|
-
#include
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
26
23
|
|
|
27
24
|
/*
|
|
28
25
|
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
@@ -32,9 +29,14 @@ extern "C" {
|
|
|
32
29
|
#endif
|
|
33
30
|
|
|
34
31
|
/**
|
|
35
|
-
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended
|
|
32
|
+
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.
|
|
33
|
+
*/
|
|
34
|
+
double API_SUFFIX(stdlib_strided_dsnansumpw)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
|
|
36
38
|
*/
|
|
37
|
-
double
|
|
39
|
+
double API_SUFFIX(stdlib_strided_dsnansumpw_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
|
|
38
40
|
|
|
39
41
|
#ifdef __cplusplus
|
|
40
42
|
}
|
package/lib/dsnansumpw.js
CHANGED
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var
|
|
23
|
+
var stride2offset = require( '@stdlib/strided-base-stride2offset' );
|
|
24
|
+
var ndarray = require( './ndarray.js' );
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
// MAIN //
|
|
@@ -39,49 +39,19 @@ var sum = require( './ndarray.js' );
|
|
|
39
39
|
*
|
|
40
40
|
* @param {PositiveInteger} N - number of indexed elements
|
|
41
41
|
* @param {Float32Array} x - input array
|
|
42
|
-
* @param {integer}
|
|
42
|
+
* @param {integer} strideX - stride length
|
|
43
43
|
* @returns {number} sum
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
46
|
* var Float32Array = require( '@stdlib/array-float32' );
|
|
47
47
|
*
|
|
48
48
|
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
49
|
-
* var N = x.length;
|
|
50
49
|
*
|
|
51
|
-
* var v = dsnansumpw(
|
|
50
|
+
* var v = dsnansumpw( x.length, x, 1 );
|
|
52
51
|
* // returns 1.0
|
|
53
52
|
*/
|
|
54
|
-
function dsnansumpw( N, x,
|
|
55
|
-
|
|
56
|
-
var s;
|
|
57
|
-
var i;
|
|
58
|
-
|
|
59
|
-
if ( N <= 0 ) {
|
|
60
|
-
return 0.0;
|
|
61
|
-
}
|
|
62
|
-
if ( N === 1 || stride === 0 ) {
|
|
63
|
-
if ( isnanf( x[ 0 ] ) ) {
|
|
64
|
-
return 0.0;
|
|
65
|
-
}
|
|
66
|
-
return x[ 0 ];
|
|
67
|
-
}
|
|
68
|
-
if ( stride < 0 ) {
|
|
69
|
-
ix = (1-N) * stride;
|
|
70
|
-
} else {
|
|
71
|
-
ix = 0;
|
|
72
|
-
}
|
|
73
|
-
if ( N < 8 ) {
|
|
74
|
-
// Use simple summation...
|
|
75
|
-
s = 0.0;
|
|
76
|
-
for ( i = 0; i < N; i++ ) {
|
|
77
|
-
if ( isnanf( x[ ix ] ) === false ) {
|
|
78
|
-
s += x[ ix ];
|
|
79
|
-
}
|
|
80
|
-
ix += stride;
|
|
81
|
-
}
|
|
82
|
-
return s;
|
|
83
|
-
}
|
|
84
|
-
return sum( N, x, stride, ix );
|
|
53
|
+
function dsnansumpw( N, x, strideX ) {
|
|
54
|
+
return ndarray( N, x, strideX, stride2offset( N, strideX ) );
|
|
85
55
|
}
|
|
86
56
|
|
|
87
57
|
|
package/lib/dsnansumpw.native.js
CHANGED
|
@@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' );
|
|
|
30
30
|
*
|
|
31
31
|
* @param {PositiveInteger} N - number of indexed elements
|
|
32
32
|
* @param {Float32Array} x - input array
|
|
33
|
-
* @param {integer}
|
|
33
|
+
* @param {integer} strideX - stride length
|
|
34
34
|
* @returns {number} sum
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
37
37
|
* var Float32Array = require( '@stdlib/array-float32' );
|
|
38
38
|
*
|
|
39
39
|
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
40
|
-
* var N = x.length;
|
|
41
40
|
*
|
|
42
|
-
* var v = dsnansumpw(
|
|
41
|
+
* var v = dsnansumpw( x.length, x, 1 );
|
|
43
42
|
* // returns 1.0
|
|
44
43
|
*/
|
|
45
|
-
function dsnansumpw( N, x,
|
|
46
|
-
return addon( N, x,
|
|
44
|
+
function dsnansumpw( N, x, strideX ) {
|
|
45
|
+
return addon( N, x, strideX );
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
|
package/lib/index.js
CHANGED
|
@@ -28,20 +28,17 @@
|
|
|
28
28
|
* var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );
|
|
29
29
|
*
|
|
30
30
|
* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
31
|
-
* var N = x.length;
|
|
32
31
|
*
|
|
33
|
-
* var v = dsnansumpw(
|
|
32
|
+
* var v = dsnansumpw( x.length, x, 1 );
|
|
34
33
|
* // returns 1.0
|
|
35
34
|
*
|
|
36
35
|
* @example
|
|
37
36
|
* var Float32Array = require( '@stdlib/array-float32' );
|
|
38
|
-
* var floor = require( '@stdlib/math-base-special-floor' );
|
|
39
37
|
* var dsnansumpw = require( '@stdlib/blas-ext-base-dsnansumpw' );
|
|
40
38
|
*
|
|
41
39
|
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
|
|
42
|
-
* var N = floor( x.length / 2 );
|
|
43
40
|
*
|
|
44
|
-
* var v = dsnansumpw.ndarray(
|
|
41
|
+
* var v = dsnansumpw.ndarray( 5, x, 2, 1 );
|
|
45
42
|
* // returns 5.0
|
|
46
43
|
*/
|
|
47
44
|
|
package/lib/ndarray.js
CHANGED
|
@@ -45,21 +45,19 @@ var BLOCKSIZE = 128;
|
|
|
45
45
|
*
|
|
46
46
|
* @param {PositiveInteger} N - number of indexed elements
|
|
47
47
|
* @param {Float32Array} x - input array
|
|
48
|
-
* @param {integer}
|
|
49
|
-
* @param {NonNegativeInteger}
|
|
48
|
+
* @param {integer} strideX - stride length
|
|
49
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
50
50
|
* @returns {number} sum
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
53
53
|
* var Float32Array = require( '@stdlib/array-float32' );
|
|
54
|
-
* var floor = require( '@stdlib/math-base-special-floor' );
|
|
55
54
|
*
|
|
56
55
|
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
|
|
57
|
-
* var N = floor( x.length / 2 );
|
|
58
56
|
*
|
|
59
|
-
* var v = dsnansumpw(
|
|
57
|
+
* var v = dsnansumpw( 5, x, 2, 1 );
|
|
60
58
|
* // returns 5.0
|
|
61
59
|
*/
|
|
62
|
-
function dsnansumpw( N, x,
|
|
60
|
+
function dsnansumpw( N, x, strideX, offsetX ) {
|
|
63
61
|
var ix;
|
|
64
62
|
var s0;
|
|
65
63
|
var s1;
|
|
@@ -77,13 +75,13 @@ function dsnansumpw( N, x, stride, offset ) {
|
|
|
77
75
|
if ( N <= 0 ) {
|
|
78
76
|
return 0.0;
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
ix = offsetX;
|
|
79
|
+
if ( strideX === 0 ) {
|
|
80
|
+
if ( isnanf( x[ ix ] ) ) {
|
|
82
81
|
return 0.0;
|
|
83
82
|
}
|
|
84
|
-
return x[
|
|
83
|
+
return N * x[ ix ];
|
|
85
84
|
}
|
|
86
|
-
ix = offset;
|
|
87
85
|
if ( N < 8 ) {
|
|
88
86
|
// Use simple summation...
|
|
89
87
|
s = 0.0;
|
|
@@ -91,64 +89,64 @@ function dsnansumpw( N, x, stride, offset ) {
|
|
|
91
89
|
if ( isnanf( x[ ix ] ) === false ) {
|
|
92
90
|
s += x[ ix ];
|
|
93
91
|
}
|
|
94
|
-
ix +=
|
|
92
|
+
ix += strideX;
|
|
95
93
|
}
|
|
96
94
|
return s;
|
|
97
95
|
}
|
|
98
96
|
if ( N <= BLOCKSIZE ) {
|
|
99
97
|
// Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)...
|
|
100
98
|
s0 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
101
|
-
ix +=
|
|
99
|
+
ix += strideX;
|
|
102
100
|
s1 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
103
|
-
ix +=
|
|
101
|
+
ix += strideX;
|
|
104
102
|
s2 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
105
|
-
ix +=
|
|
103
|
+
ix += strideX;
|
|
106
104
|
s3 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
107
|
-
ix +=
|
|
105
|
+
ix += strideX;
|
|
108
106
|
s4 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
109
|
-
ix +=
|
|
107
|
+
ix += strideX;
|
|
110
108
|
s5 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
111
|
-
ix +=
|
|
109
|
+
ix += strideX;
|
|
112
110
|
s6 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
113
|
-
ix +=
|
|
111
|
+
ix += strideX;
|
|
114
112
|
s7 = ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
115
|
-
ix +=
|
|
113
|
+
ix += strideX;
|
|
116
114
|
|
|
117
115
|
M = N % 8;
|
|
118
116
|
for ( i = 8; i < N-M; i += 8 ) {
|
|
119
117
|
s0 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
120
|
-
ix +=
|
|
118
|
+
ix += strideX;
|
|
121
119
|
s1 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
122
|
-
ix +=
|
|
120
|
+
ix += strideX;
|
|
123
121
|
s2 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
124
|
-
ix +=
|
|
122
|
+
ix += strideX;
|
|
125
123
|
s3 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
126
|
-
ix +=
|
|
124
|
+
ix += strideX;
|
|
127
125
|
s4 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
128
|
-
ix +=
|
|
126
|
+
ix += strideX;
|
|
129
127
|
s5 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
130
|
-
ix +=
|
|
128
|
+
ix += strideX;
|
|
131
129
|
s6 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
132
|
-
ix +=
|
|
130
|
+
ix += strideX;
|
|
133
131
|
s7 += ( isnanf( x[ ix ] ) ) ? 0.0 : x[ ix ];
|
|
134
|
-
ix +=
|
|
132
|
+
ix += strideX;
|
|
135
133
|
}
|
|
136
134
|
// Pairwise sum the accumulators:
|
|
137
|
-
s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7));
|
|
135
|
+
s = ( (s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7) );
|
|
138
136
|
|
|
139
137
|
// Clean-up loop...
|
|
140
138
|
for ( i; i < N; i++ ) {
|
|
141
139
|
if ( isnanf( x[ ix ] ) === false ) {
|
|
142
140
|
s += x[ ix ];
|
|
143
141
|
}
|
|
144
|
-
ix +=
|
|
142
|
+
ix += strideX;
|
|
145
143
|
}
|
|
146
144
|
return s;
|
|
147
145
|
}
|
|
148
146
|
// Recurse by dividing by two, but avoiding non-multiples of unroll factor...
|
|
149
147
|
n = floor( N/2 );
|
|
150
148
|
n -= n % 8;
|
|
151
|
-
return dsnansumpw( n, x,
|
|
149
|
+
return dsnansumpw( n, x, strideX, ix ) + dsnansumpw( N-n, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
|
package/lib/ndarray.native.js
CHANGED
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var addon = require( './dsnansumpw.native.js' );
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
// MAIN //
|
|
@@ -31,8 +30,8 @@ var addon = require( './dsnansumpw.native.js' );
|
|
|
31
30
|
*
|
|
32
31
|
* @param {PositiveInteger} N - number of indexed elements
|
|
33
32
|
* @param {Float32Array} x - input array
|
|
34
|
-
* @param {integer}
|
|
35
|
-
* @param {NonNegativeInteger}
|
|
33
|
+
* @param {integer} strideX - stride length
|
|
34
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
36
35
|
* @returns {number} sum
|
|
37
36
|
*
|
|
38
37
|
* @example
|
|
@@ -40,18 +39,12 @@ var addon = require( './dsnansumpw.native.js' );
|
|
|
40
39
|
* var floor = require( '@stdlib/math-base-special-floor' );
|
|
41
40
|
*
|
|
42
41
|
* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
|
|
43
|
-
* var N = floor( x.length / 2 );
|
|
44
42
|
*
|
|
45
|
-
* var v = dsnansumpw(
|
|
43
|
+
* var v = dsnansumpw( 5, x, 2, 1 );
|
|
46
44
|
* // returns 5.0
|
|
47
45
|
*/
|
|
48
|
-
function dsnansumpw( N, x,
|
|
49
|
-
|
|
50
|
-
if ( stride < 0 ) {
|
|
51
|
-
offset += (N-1) * stride;
|
|
52
|
-
}
|
|
53
|
-
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
|
|
54
|
-
return addon( N, view, stride );
|
|
46
|
+
function dsnansumpw( N, x, strideX, offsetX ) {
|
|
47
|
+
return addon.ndarray( N, x, strideX, offsetX );
|
|
55
48
|
}
|
|
56
49
|
|
|
57
50
|
|
package/manifest.json
CHANGED
|
@@ -1,42 +1,82 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build"
|
|
4
|
+
},
|
|
5
|
+
"fields": [
|
|
6
|
+
{
|
|
7
|
+
"field": "src",
|
|
8
|
+
"resolve": true,
|
|
9
|
+
"relative": true
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"field": "include",
|
|
13
|
+
"resolve": true,
|
|
14
|
+
"relative": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"field": "libraries",
|
|
18
|
+
"resolve": false,
|
|
19
|
+
"relative": false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"field": "libpath",
|
|
23
|
+
"resolve": true,
|
|
24
|
+
"relative": false
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"confs": [
|
|
28
|
+
{
|
|
29
|
+
"task": "build",
|
|
30
|
+
"src": [
|
|
31
|
+
"./src/main.c"
|
|
32
|
+
],
|
|
33
|
+
"include": [
|
|
34
|
+
"./include"
|
|
35
|
+
],
|
|
36
|
+
"libraries": [],
|
|
37
|
+
"libpath": [],
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"@stdlib/napi-export",
|
|
40
|
+
"@stdlib/napi-argv",
|
|
41
|
+
"@stdlib/napi-argv-int64",
|
|
42
|
+
"@stdlib/napi-argv-strided-float32array",
|
|
43
|
+
"@stdlib/math-base-assert-is-nanf",
|
|
44
|
+
"@stdlib/napi-create-double",
|
|
45
|
+
"@stdlib/strided-base-stride2offset",
|
|
46
|
+
"@stdlib/blas-base-shared"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"task": "benchmark",
|
|
51
|
+
"src": [
|
|
52
|
+
"./src/main.c"
|
|
53
|
+
],
|
|
54
|
+
"include": [
|
|
55
|
+
"./include"
|
|
56
|
+
],
|
|
57
|
+
"libraries": [],
|
|
58
|
+
"libpath": [],
|
|
59
|
+
"dependencies": [
|
|
60
|
+
"@stdlib/math-base-assert-is-nanf",
|
|
61
|
+
"@stdlib/strided-base-stride2offset",
|
|
62
|
+
"@stdlib/blas-base-shared"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"task": "examples",
|
|
67
|
+
"src": [
|
|
68
|
+
"./src/main.c"
|
|
69
|
+
],
|
|
70
|
+
"include": [
|
|
71
|
+
"./include"
|
|
72
|
+
],
|
|
73
|
+
"libraries": [],
|
|
74
|
+
"libpath": [],
|
|
75
|
+
"dependencies": [
|
|
76
|
+
"@stdlib/math-base-assert-is-nanf",
|
|
77
|
+
"@stdlib/strided-base-stride2offset",
|
|
78
|
+
"@stdlib/blas-base-shared"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
42
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/blas-ext-base-dsnansumpw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Calculate the sum of single-precision floating-point strided array elements, ignoring NaN values, using pairwise summation with extended accumulation, and returning an extended precision result.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -35,10 +35,17 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@stdlib/assert-is-error": "^0.2.2",
|
|
38
|
+
"@stdlib/blas-base-shared": "^0.1.0",
|
|
38
39
|
"@stdlib/math-base-assert-is-nanf": "^0.2.2",
|
|
39
40
|
"@stdlib/math-base-special-floor": "^0.2.3",
|
|
41
|
+
"@stdlib/napi-argv": "^0.2.2",
|
|
42
|
+
"@stdlib/napi-argv-int64": "^0.2.2",
|
|
43
|
+
"@stdlib/napi-argv-strided-float32array": "^0.2.2",
|
|
44
|
+
"@stdlib/napi-create-double": "^0.0.2",
|
|
45
|
+
"@stdlib/napi-export": "^0.3.0",
|
|
46
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
40
47
|
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
41
|
-
"@stdlib/utils-library-manifest": "^0.2.
|
|
48
|
+
"@stdlib/utils-library-manifest": "^0.2.3",
|
|
42
49
|
"@stdlib/utils-try-require": "^0.2.2"
|
|
43
50
|
},
|
|
44
51
|
"devDependencies": {},
|
|
@@ -80,7 +87,6 @@
|
|
|
80
87
|
"float",
|
|
81
88
|
"float32array"
|
|
82
89
|
],
|
|
83
|
-
"__stdlib__": {},
|
|
84
90
|
"funding": {
|
|
85
91
|
"type": "opencollective",
|
|
86
92
|
"url": "https://opencollective.com/stdlib"
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "stdlib/blas/ext/base/dsnansumpw.h"
|
|
20
|
+
#include "stdlib/blas/base/shared.h"
|
|
21
|
+
#include "stdlib/napi/export.h"
|
|
22
|
+
#include "stdlib/napi/argv.h"
|
|
23
|
+
#include "stdlib/napi/argv_int64.h"
|
|
24
|
+
#include "stdlib/napi/argv_strided_float32array.h"
|
|
25
|
+
#include "stdlib/strided/base/stride2offset.h"
|
|
26
|
+
#include "stdlib/napi/create_double.h"
|
|
27
|
+
#include <node_api.h>
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Receives JavaScript callback invocation data.
|
|
31
|
+
*
|
|
32
|
+
* @param env environment under which the function is invoked
|
|
33
|
+
* @param info callback data
|
|
34
|
+
* @return Node-API value
|
|
35
|
+
*/
|
|
36
|
+
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
37
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
|
|
38
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
39
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
40
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
41
|
+
STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsnansumpw)( N, X, strideX ), v );
|
|
42
|
+
return v;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Receives JavaScript callback invocation data.
|
|
47
|
+
*
|
|
48
|
+
* @param env environment under which the function is invoked
|
|
49
|
+
* @param info callback data
|
|
50
|
+
* @return Node-API value
|
|
51
|
+
*/
|
|
52
|
+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
|
|
53
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
|
|
54
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
55
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
56
|
+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 );
|
|
57
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
58
|
+
STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsnansumpw_ndarray)( N, X, strideX, offsetX ), v );
|
|
59
|
+
return v;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license Apache-2.0
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2024 The Stdlib Authors.
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
|
|
19
19
|
#include "stdlib/blas/ext/base/dsnansumpw.h"
|
|
20
20
|
#include "stdlib/math/base/assert/is_nanf.h"
|
|
21
|
-
#include
|
|
21
|
+
#include "stdlib/strided/base/stride2offset.h"
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.
|
|
@@ -31,19 +32,39 @@
|
|
|
31
32
|
*
|
|
32
33
|
* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).
|
|
33
34
|
*
|
|
34
|
-
* @param N
|
|
35
|
-
* @param X
|
|
36
|
-
* @param
|
|
37
|
-
* @return
|
|
35
|
+
* @param N number of indexed elements
|
|
36
|
+
* @param X input array
|
|
37
|
+
* @param strideX stride length
|
|
38
|
+
* @return output value
|
|
38
39
|
*/
|
|
39
|
-
double stdlib_strided_dsnansumpw( const
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
double API_SUFFIX(stdlib_strided_dsnansumpw)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
|
|
41
|
+
CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
|
|
42
|
+
return API_SUFFIX( stdlib_strided_dsnansumpw_ndarray )( N, X, strideX, ox );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
|
|
47
|
+
*
|
|
48
|
+
* ## Method
|
|
49
|
+
*
|
|
50
|
+
* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.
|
|
51
|
+
*
|
|
52
|
+
* ## References
|
|
53
|
+
*
|
|
54
|
+
* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).
|
|
55
|
+
*
|
|
56
|
+
* @param N number of indexed elements
|
|
57
|
+
* @param X input array
|
|
58
|
+
* @param strideX stride length
|
|
59
|
+
* @param offsetX starting index
|
|
60
|
+
* @return output value
|
|
61
|
+
*/
|
|
62
|
+
double API_SUFFIX(stdlib_strided_dsnansumpw_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
|
|
63
|
+
CBLAS_INT ix;
|
|
64
|
+
CBLAS_INT M;
|
|
65
|
+
CBLAS_INT n;
|
|
66
|
+
CBLAS_INT i;
|
|
42
67
|
double sum;
|
|
43
|
-
int64_t ix;
|
|
44
|
-
int64_t M;
|
|
45
|
-
int64_t n;
|
|
46
|
-
int64_t i;
|
|
47
68
|
double s0;
|
|
48
69
|
double s1;
|
|
49
70
|
double s2;
|
|
@@ -56,16 +77,12 @@ double stdlib_strided_dsnansumpw( const int64_t N, const float *X, const int64_t
|
|
|
56
77
|
if ( N <= 0 ) {
|
|
57
78
|
return 0.0;
|
|
58
79
|
}
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
ix = offsetX;
|
|
81
|
+
if ( strideX == 0 ) {
|
|
82
|
+
if ( stdlib_base_is_nanf( X[ ix ] ) ) {
|
|
61
83
|
return 0.0;
|
|
62
84
|
}
|
|
63
|
-
return X[
|
|
64
|
-
}
|
|
65
|
-
if ( stride < 0 ) {
|
|
66
|
-
ix = (1-N) * stride;
|
|
67
|
-
} else {
|
|
68
|
-
ix = 0;
|
|
85
|
+
return N * X[ ix ];
|
|
69
86
|
}
|
|
70
87
|
if ( N < 8 ) {
|
|
71
88
|
// Use simple summation...
|
|
@@ -74,7 +91,7 @@ double stdlib_strided_dsnansumpw( const int64_t N, const float *X, const int64_t
|
|
|
74
91
|
if ( !stdlib_base_is_nanf( X[ ix ] ) ) {
|
|
75
92
|
sum += (double)X[ ix ];
|
|
76
93
|
}
|
|
77
|
-
ix +=
|
|
94
|
+
ix += strideX;
|
|
78
95
|
}
|
|
79
96
|
return sum;
|
|
80
97
|
}
|
|
@@ -82,62 +99,55 @@ double stdlib_strided_dsnansumpw( const int64_t N, const float *X, const int64_t
|
|
|
82
99
|
if ( N <= 128 ) {
|
|
83
100
|
// Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)...
|
|
84
101
|
s0 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
85
|
-
ix +=
|
|
102
|
+
ix += strideX;
|
|
86
103
|
s1 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
87
|
-
ix +=
|
|
104
|
+
ix += strideX;
|
|
88
105
|
s2 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
89
|
-
ix +=
|
|
106
|
+
ix += strideX;
|
|
90
107
|
s3 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
91
|
-
ix +=
|
|
108
|
+
ix += strideX;
|
|
92
109
|
s4 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
93
|
-
ix +=
|
|
110
|
+
ix += strideX;
|
|
94
111
|
s5 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
95
|
-
ix +=
|
|
112
|
+
ix += strideX;
|
|
96
113
|
s6 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
97
|
-
ix +=
|
|
114
|
+
ix += strideX;
|
|
98
115
|
s7 = ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
99
|
-
ix +=
|
|
116
|
+
ix += strideX;
|
|
100
117
|
|
|
101
118
|
M = N % 8;
|
|
102
119
|
for ( i = 8; i < N-M; i += 8 ) {
|
|
103
120
|
s0 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
104
|
-
ix +=
|
|
121
|
+
ix += strideX;
|
|
105
122
|
s1 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
106
|
-
ix +=
|
|
123
|
+
ix += strideX;
|
|
107
124
|
s2 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
108
|
-
ix +=
|
|
125
|
+
ix += strideX;
|
|
109
126
|
s3 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
110
|
-
ix +=
|
|
127
|
+
ix += strideX;
|
|
111
128
|
s4 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
112
|
-
ix +=
|
|
129
|
+
ix += strideX;
|
|
113
130
|
s5 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
114
|
-
ix +=
|
|
131
|
+
ix += strideX;
|
|
115
132
|
s6 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
116
|
-
ix +=
|
|
133
|
+
ix += strideX;
|
|
117
134
|
s7 += ( stdlib_base_is_nanf( X[ ix ] ) ) ? 0.0 : (double)X[ ix ];
|
|
118
|
-
ix +=
|
|
135
|
+
ix += strideX;
|
|
119
136
|
}
|
|
120
137
|
// Pairwise sum the accumulators:
|
|
121
|
-
sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7));
|
|
138
|
+
sum = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) );
|
|
122
139
|
|
|
123
140
|
// Clean-up loop...
|
|
124
141
|
for (; i < N; i++ ) {
|
|
125
142
|
if ( !stdlib_base_is_nanf( X[ ix ] ) ) {
|
|
126
143
|
sum += (double)X[ ix ];
|
|
127
144
|
}
|
|
128
|
-
ix +=
|
|
145
|
+
ix += strideX;
|
|
129
146
|
}
|
|
130
147
|
return sum;
|
|
131
148
|
}
|
|
132
149
|
// Recurse by dividing by two, but avoiding non-multiples of unroll factor...
|
|
133
150
|
n = N / 2;
|
|
134
151
|
n -= n % 8;
|
|
135
|
-
|
|
136
|
-
xp1 = (float *)X + ( (n-N)*stride );
|
|
137
|
-
xp2 = (float *)X;
|
|
138
|
-
} else {
|
|
139
|
-
xp1 = (float *)X;
|
|
140
|
-
xp2 = (float *)X + ( n*stride );
|
|
141
|
-
}
|
|
142
|
-
return stdlib_strided_dsnansumpw( n, xp1, stride ) + stdlib_strided_dsnansumpw( N-n, xp2, stride );
|
|
152
|
+
return API_SUFFIX(stdlib_strided_dsnansumpw_ndarray)( n, X, strideX, ix ) + API_SUFFIX(stdlib_strided_dsnansumpw_ndarray)( N-n, X, strideX, ix+(n*strideX) );
|
|
143
153
|
}
|
package/src/addon.cpp
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
#include "stdlib/blas/ext/base/dsnansumpw.h"
|
|
20
|
-
#include <node_api.h>
|
|
21
|
-
#include <stdint.h>
|
|
22
|
-
#include <stdlib.h>
|
|
23
|
-
#include <stdbool.h>
|
|
24
|
-
#include <assert.h>
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Add-on namespace.
|
|
28
|
-
*/
|
|
29
|
-
namespace stdlib_blas_ext_base_dsnansumpw {
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using pairwise summation with extended accumulation, and returning an extended precision result.
|
|
33
|
-
*
|
|
34
|
-
* ## Notes
|
|
35
|
-
*
|
|
36
|
-
* - When called from JavaScript, the function expects three arguments:
|
|
37
|
-
*
|
|
38
|
-
* - `N`: number of indexed elements
|
|
39
|
-
* - `X`: input array
|
|
40
|
-
* - `stride`: stride length
|
|
41
|
-
*/
|
|
42
|
-
napi_value node_dsnansumpw( napi_env env, napi_callback_info info ) {
|
|
43
|
-
napi_status status;
|
|
44
|
-
|
|
45
|
-
size_t argc = 3;
|
|
46
|
-
napi_value argv[ 3 ];
|
|
47
|
-
status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr );
|
|
48
|
-
assert( status == napi_ok );
|
|
49
|
-
|
|
50
|
-
if ( argc < 3 ) {
|
|
51
|
-
napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." );
|
|
52
|
-
return nullptr;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
napi_valuetype vtype0;
|
|
56
|
-
status = napi_typeof( env, argv[ 0 ], &vtype0 );
|
|
57
|
-
assert( status == napi_ok );
|
|
58
|
-
if ( vtype0 != napi_number ) {
|
|
59
|
-
napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." );
|
|
60
|
-
return nullptr;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
bool res;
|
|
64
|
-
status = napi_is_typedarray( env, argv[ 1 ], &res );
|
|
65
|
-
assert( status == napi_ok );
|
|
66
|
-
if ( res == false ) {
|
|
67
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." );
|
|
68
|
-
return nullptr;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
napi_valuetype vtype2;
|
|
72
|
-
status = napi_typeof( env, argv[ 2 ], &vtype2 );
|
|
73
|
-
assert( status == napi_ok );
|
|
74
|
-
if ( vtype2 != napi_number ) {
|
|
75
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." );
|
|
76
|
-
return nullptr;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
int64_t N;
|
|
80
|
-
status = napi_get_value_int64( env, argv[ 0 ], &N );
|
|
81
|
-
assert( status == napi_ok );
|
|
82
|
-
|
|
83
|
-
int64_t stride;
|
|
84
|
-
status = napi_get_value_int64( env, argv[ 2 ], &stride );
|
|
85
|
-
assert( status == napi_ok );
|
|
86
|
-
|
|
87
|
-
napi_typedarray_type vtype1;
|
|
88
|
-
size_t xlen;
|
|
89
|
-
void *X;
|
|
90
|
-
status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr );
|
|
91
|
-
assert( status == napi_ok );
|
|
92
|
-
if ( vtype1 != napi_float32_array ) {
|
|
93
|
-
napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." );
|
|
94
|
-
return nullptr;
|
|
95
|
-
}
|
|
96
|
-
if ( (N-1)*llabs(stride) >= (int64_t)xlen ) {
|
|
97
|
-
napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." );
|
|
98
|
-
return nullptr;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
napi_value v;
|
|
102
|
-
status = napi_create_double( env, stdlib_strided_dsnansumpw( N, (float *)X, stride ), &v );
|
|
103
|
-
assert( status == napi_ok );
|
|
104
|
-
|
|
105
|
-
return v;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
napi_value Init( napi_env env, napi_value exports ) {
|
|
109
|
-
napi_status status;
|
|
110
|
-
napi_value fcn;
|
|
111
|
-
status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsnansumpw, NULL, &fcn );
|
|
112
|
-
assert( status == napi_ok );
|
|
113
|
-
return fcn;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
NAPI_MODULE( NODE_GYP_MODULE_NAME, Init )
|
|
117
|
-
} // end namespace stdlib_blas_ext_base_dsnansumpw
|