@stdlib/blas-ext-base-dsnansumors 0.2.1 → 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -59,7 +59,7 @@ npm install @stdlib/blas-ext-base-dsnansumors
59
59
  var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );
60
60
  ```
61
61
 
62
- #### dsnansumors( N, x, stride )
62
+ #### dsnansumors( N, x, strideX )
63
63
 
64
64
  Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive 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 = dsnansumors( N, x, 1 );
71
+ var v = dsnansumors( 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**: index increment for `x`.
79
+ - **stride**: stride length for `x`.
81
80
 
82
- The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the sum of every other element in `x`,
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 = dsnansumors( N, x, 2 );
88
+ var v = dsnansumors( 4, x, 2 );
92
89
  // returns 5.0
93
90
  ```
94
91
 
@@ -98,18 +95,15 @@ 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 N = floor( x0.length / 2 );
107
-
108
- var v = dsnansumors( N, x1, 2 );
102
+ var v = dsnansumors( 4, x1, 2 );
109
103
  // returns 5.0
110
104
  ```
111
105
 
112
- #### dsnansumors.ndarray( N, x, stride, offset )
106
+ #### dsnansumors.ndarray( N, x, strideX, offsetX )
113
107
 
114
108
  Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics.
115
109
 
@@ -117,26 +111,23 @@ Computes the sum of single-precision floating-point strided array elements, igno
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 = dsnansumors.ndarray( N, x, 1, 0 );
115
+ var v = dsnansumors.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
- - **offset**: starting index for `x`.
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 `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value
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 = dsnansumors.ndarray( N, x, 2, 1 );
130
+ var v = dsnansumors.ndarray( 4, x, 2, 1 );
140
131
  // returns 5.0
141
132
  ```
142
133
 
@@ -162,22 +153,19 @@ var v = dsnansumors.ndarray( N, x, 2, 1 );
162
153
  <!-- eslint no-undef: "error" -->
163
154
 
164
155
  ```javascript
165
- var randu = require( '@stdlib/random-base-randu' );
166
- var round = require( '@stdlib/math-base-special-round' );
167
- var Float32Array = require( '@stdlib/array-float32' );
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 dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );
169
160
 
170
- var x;
171
- var i;
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 = dsnansumors( x.length, x, 1 );
@@ -188,6 +176,124 @@ console.log( v );
188
176
 
189
177
  <!-- /.examples -->
190
178
 
179
+ <!-- C interface documentation. -->
180
+
181
+ * * *
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/dsnansumors.h"
203
+ ```
204
+
205
+ #### stdlib_strided_dsnansumors( N, \*X, strideX )
206
+
207
+ Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive 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_dsnansumors( 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_dsnansumors( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
224
+ ```
225
+
226
+ #### stdlib_strided_dsnansumors_ndarray( N, \*X, strideX, offsetX )
227
+
228
+ Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive 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_dsnansumors_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_dsnansumors_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/dsnansumors.h"
268
+ #include "stdlib/blas/base/shared.h"
269
+ #include <stdio.h>
270
+
271
+ int main( void ) {
272
+ // Create a strided array:
273
+ 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 };
274
+
275
+ // Specify the number of elements:
276
+ const int N = 5;
277
+
278
+ // Specify the stride length:
279
+ const int strideX = 2;
280
+
281
+ // Compute the sum:
282
+ double v = stdlib_strided_dsnansumors( N, x, strideX );
283
+
284
+ // Print the result:
285
+ printf( "sum: %lf\n", v );
286
+ }
287
+ ```
288
+
289
+ </section>
290
+
291
+ <!-- /.examples -->
292
+
293
+ </section>
294
+
295
+ <!-- /.c -->
296
+
191
297
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
192
298
 
193
299
  <section class="related">
@@ -196,7 +302,7 @@ console.log( v );
196
302
 
197
303
  ## See Also
198
304
 
199
- - <span class="package-name">[`@stdlib/stats-base/dsnanmeanors`][@stdlib/stats/base/dsnanmeanors]</span><span class="delimiter">: </span><span class="description">calculate the arithmetic mean of a single-precision floating-point strided array, ignoring NaN values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.</span>
305
+ - <span class="package-name">[`@stdlib/stats-strided/dsnanmeanors`][@stdlib/stats/strided/dsnanmeanors]</span><span class="delimiter">: </span><span class="description">calculate the arithmetic mean of a single-precision floating-point strided array, ignoring NaN values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.</span>
200
306
  - <span class="package-name">[`@stdlib/blas-ext/base/dssum`][@stdlib/blas/ext/base/dssum]</span><span class="delimiter">: </span><span class="description">calculate the sum of single-precision floating-point strided array elements using extended accumulation and returning an extended precision result.</span>
201
307
  - <span class="package-name">[`@stdlib/blas-ext/base/dssumors`][@stdlib/blas/ext/base/dssumors]</span><span class="delimiter">: </span><span class="description">calculate the sum of single-precision floating-point strided array elements using ordinary recursive summation with extended accumulation and returning an extended precision result.</span>
202
308
  - <span class="package-name">[`@stdlib/blas-ext/base/snansumors`][@stdlib/blas/ext/base/snansumors]</span><span class="delimiter">: </span><span class="description">calculate the sum of single-precision floating-point strided array elements, ignoring NaN values and using ordinary recursive summation.</span>
@@ -231,7 +337,7 @@ See [LICENSE][stdlib-license].
231
337
 
232
338
  ## Copyright
233
339
 
234
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
340
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
235
341
 
236
342
  </section>
237
343
 
@@ -244,8 +350,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
244
350
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-dsnansumors.svg
245
351
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-dsnansumors
246
352
 
247
- [test-image]: https://github.com/stdlib-js/blas-ext-base-dsnansumors/actions/workflows/test.yml/badge.svg?branch=v0.2.1
248
- [test-url]: https://github.com/stdlib-js/blas-ext-base-dsnansumors/actions/workflows/test.yml?query=branch:v0.2.1
353
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-dsnansumors/actions/workflows/test.yml/badge.svg?branch=v0.3.0
354
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-dsnansumors/actions/workflows/test.yml?query=branch:v0.3.0
249
355
 
250
356
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-dsnansumors/main.svg
251
357
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-dsnansumors?branch=main
@@ -257,8 +363,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
257
363
 
258
364
  -->
259
365
 
260
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
261
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
366
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
367
+ [chat-url]: https://stdlib.zulipchat.com
262
368
 
263
369
  [stdlib]: https://github.com/stdlib-js/stdlib
264
370
 
@@ -283,7 +389,7 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
283
389
 
284
390
  <!-- <related-links> -->
285
391
 
286
- [@stdlib/stats/base/dsnanmeanors]: https://www.npmjs.com/package/@stdlib/stats-base-dsnanmeanors
392
+ [@stdlib/stats/strided/dsnanmeanors]: https://www.npmjs.com/package/@stdlib/stats-strided-dsnanmeanors
287
393
 
288
394
  [@stdlib/blas/ext/base/dssum]: https://www.npmjs.com/package/@stdlib/blas-ext-base-dssum
289
395
 
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var t=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var q=t(function(x,f){
2
- var o=require('@stdlib/math-base-assert-is-nan/dist');function R(i,r,u){var a,e,n;if(a=0,i<=0)return a;if(i===1||u===0)return o(r[0])?a:r[0];for(u<0?e=(1-i)*u:e=0,n=0;n<i;n++)o(r[e])===!1&&(a+=r[e]),e+=u;return a}f.exports=R
3
- });var l=t(function(z,c){
4
- var m=require('@stdlib/math-base-assert-is-nan/dist');function _(i,r,u,a){var e,n,s;if(e=0,i<=0)return e;if(i===1||u===0)return m(r[a])?e:r[a];for(n=a,s=0;s<i;s++)m(r[n])===!1&&(e+=r[n]),n+=u;return e}c.exports=_
5
- });var y=t(function(A,d){
6
- var E=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=q(),O=l();E(p,"ndarray",O);d.exports=p
7
- });var b=require("path").join,g=require('@stdlib/utils-try-require/dist'),h=require('@stdlib/assert-is-error/dist'),k=y(),v,j=g(b(__dirname,"./native.js"));h(j)?v=k:v=j;module.exports=v;
1
+ "use strict";var t=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var o=t(function(A,q){
2
+ var v=require('@stdlib/math-base-assert-is-nan/dist');function R(e,r,i,j){var n,a,u,s;if(e<=0)return 0;if(a=j,i===0)return v(r[a])?0:e*r[a];for(s=0;s<e&&(u=r[a],v(u)!==!1);s++)a+=i;if(s===e)return 0;for(n=u,a+=i,s+=1;s<e;s++)v(r[a])===!1&&(n+=r[a]),a+=i;return n}q.exports=R
3
+ });var c=t(function(B,m){
4
+ var _=require('@stdlib/strided-base-stride2offset/dist'),b=o();function k(e,r,i){return b(e,r,i,_(e,i))}m.exports=k
5
+ });var y=t(function(C,p){
6
+ var x=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),d=c(),E=o();x(d,"ndarray",E);p.exports=d
7
+ });var O=require("path").join,g=require('@stdlib/utils-try-require/dist'),h=require('@stdlib/assert-is-error/dist'),w=y(),f,l=g(O(__dirname,"./native.js"));h(l)?f=w:f=l;module.exports=f;
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
- "sources": ["../lib/dsnansumors.js", "../lib/ndarray.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 isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\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 = dsnansumors( N, x, 1 );\n* // returns 1.0\n*/\nfunction dsnansumors( N, x, stride ) {\n\tvar sum;\n\tvar ix;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn sum;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ 0 ] ) ) {\n\t\t\treturn sum;\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\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\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 isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\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 = dsnansumors( N, x, 2, 1 );\n* // returns 5.0\n*/\nfunction dsnansumors( N, x, stride, offset ) {\n\tvar sum;\n\tvar ix;\n\tvar i;\n\n\tsum = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn sum;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ offset ] ) ) {\n\t\t\treturn sum;\n\t\t}\n\t\treturn x[ offset ];\n\t}\n\tix = offset;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\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 dsnansumors = require( './dsnansumors.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsnansumors, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\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 ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @module @stdlib/blas-ext-base-dsnansumors\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = dsnansumors( 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 dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\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 = dsnansumors.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 dsnansumors;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsnansumors = main;\n} else {\n\tdsnansumors = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n\n// exports: { \"ndarray\": \"dsnansumors.ndarray\" }\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAsBvD,SAASC,EAAaC,EAAGC,EAAGC,EAAS,CACpC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAM,EACDH,GAAK,EACT,OAAOG,EAER,GAAKH,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAG,CAAE,CAAE,EACXE,EAEDF,EAAG,CAAE,EAOb,IALKC,EAAS,EACbE,GAAM,EAAEJ,GAAKE,EAEbE,EAAK,EAEAC,EAAI,EAAGA,EAAIL,EAAGK,IACdP,EAAOG,EAAGG,CAAG,CAAE,IAAM,KACzBD,GAAOF,EAAGG,CAAG,GAEdA,GAAMF,EAEP,OAAOC,CACR,CAKAN,EAAO,QAAUE,IC5EjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAwBvD,SAASC,EAAaC,EAAGC,EAAGC,EAAQC,EAAS,CAC5C,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAM,EACDJ,GAAK,EACT,OAAOI,EAER,GAAKJ,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAGE,CAAO,CAAE,EAChBC,EAEDH,EAAGE,CAAO,EAGlB,IADAE,EAAKF,EACCG,EAAI,EAAGA,EAAIN,EAAGM,IACdR,EAAOG,EAAGI,CAAG,CAAE,IAAM,KACzBD,GAAOH,EAAGI,CAAG,GAEdA,GAAMH,EAEP,OAAOE,CACR,CAKAP,EAAO,QAAUE,IC1EjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7CH,EAAO,QAAUE,ICejB,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,EAAcD,EAEdC,EAAcC,EAMf,OAAO,QAAUD",
6
- "names": ["require_dsnansumors", "__commonJSMin", "exports", "module", "isnan", "dsnansumors", "N", "x", "stride", "sum", "ix", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "dsnansumors", "N", "x", "stride", "offset", "sum", "ix", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsnansumors", "ndarray", "join", "tryRequire", "isError", "main", "dsnansumors", "tmp"]
3
+ "sources": ["../lib/ndarray.js", "../lib/dsnansumors.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 isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.\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 = dsnansumors( 5, x, 2, 1 );\n* // returns 5.0\n*/\nfunction dsnansumors( N, x, strideX, offsetX ) {\n\tvar sum;\n\tvar ix;\n\tvar v;\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 ( isnan( x[ ix ] ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn N * x[ ix ];\n\t}\n\t// Find the first non-NaN element...\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( isnan( v ) === false ) {\n\t\t\tbreak;\n\t\t}\n\t\tix += strideX;\n\t}\n\tif ( i === N ) {\n\t\treturn 0.0;\n\t}\n\tsum = v;\n\tix += strideX;\n\ti += 1;\n\tfor ( ; i < N; i++ ) {\n\t\tif ( isnan( x[ ix ] ) === false ) {\n\t\t\tsum += x[ ix ];\n\t\t}\n\t\tix += strideX;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\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 ordinary recursive summation with extended accumulation, and returning an extended precision result.\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 = dsnansumors( x.length, x, 1 );\n* // returns 1.0\n*/\nfunction dsnansumors( N, x, strideX ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\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 dsnansumors = require( './dsnansumors.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( dsnansumors, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\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 ordinary recursive summation with extended accumulation, and returning an extended precision result.\n*\n* @module @stdlib/blas-ext-base-dsnansumors\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = dsnansumors( x.length, x, 1 );\n* // returns 1.0\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );\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 = dsnansumors.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 dsnansumors;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tdsnansumors = main;\n} else {\n\tdsnansumors = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = dsnansumors;\n\n// exports: { \"ndarray\": \"dsnansumors.ndarray\" }\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAsBvD,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAAU,CAC9C,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAKP,GAAK,EACT,MAAO,GAGR,GADAK,EAAKF,EACAD,IAAY,EAChB,OAAKJ,EAAOG,EAAGI,CAAG,CAAE,EACZ,EAEDL,EAAIC,EAAGI,CAAG,EAGlB,IAAME,EAAI,EAAGA,EAAIP,IAChBM,EAAIL,EAAGI,CAAG,EACLP,EAAOQ,CAAE,IAAM,IAFDC,IAKnBF,GAAMH,EAEP,GAAKK,IAAMP,EACV,MAAO,GAKR,IAHAI,EAAME,EACND,GAAMH,EACNK,GAAK,EACGA,EAAIP,EAAGO,IACTT,EAAOG,EAAGI,CAAG,CAAE,IAAM,KACzBD,GAAOH,EAAGI,CAAG,GAEdA,GAAMH,EAEP,OAAOE,CACR,CAKAP,EAAO,QAAUE,ICtFjB,IAAAS,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAqBd,SAASC,EAAaC,EAAGC,EAAGC,EAAU,CACrC,OAAOJ,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,CAAE,CAC5D,CAKAN,EAAO,QAAUG,ICnDjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7CH,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,EAAcD,EAEdC,EAAcC,EAMf,OAAO,QAAUD",
6
+ "names": ["require_ndarray", "__commonJSMin", "exports", "module", "isnan", "dsnansumors", "N", "x", "strideX", "offsetX", "sum", "ix", "v", "i", "require_dsnansumors", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "dsnansumors", "N", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "dsnansumors", "ndarray", "join", "tryRequire", "isError", "main", "dsnansumors", "tmp"]
7
7
  }
@@ -27,7 +27,7 @@ interface Routine {
27
27
  *
28
28
  * @param N - number of indexed elements
29
29
  * @param x - input array
30
- * @param stride - stride length
30
+ * @param strideX - stride length
31
31
  * @returns sum
32
32
  *
33
33
  * @example
@@ -38,15 +38,15 @@ interface Routine {
38
38
  * var v = dsnansumors( x.length, x, 1 );
39
39
  * // returns 1.0
40
40
  */
41
- ( N: number, x: Float32Array, stride: number ): number;
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 and using ordinary recursive summation with extended accumulation and alternative indexing semantics.
44
+ * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive 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 stride - stride length
49
- * @param offset - starting index
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 = dsnansumors.ndarray( x.length, x, 1, 0 );
58
58
  * // returns 1.0
59
59
  */
60
- ndarray( N: number, x: Float32Array, stride: number, offset: number ): number;
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 stride - stride length
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_DSNANSUMORS_H
23
20
  #define STDLIB_BLAS_EXT_BASE_DSNANSUMORS_H
24
21
 
25
- #include <stdint.h>
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.
@@ -34,7 +31,12 @@ extern "C" {
34
31
  /**
35
32
  * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.
36
33
  */
37
- double stdlib_strided_dsnansumors( const int64_t N, const float *X, const int64_t stride );
34
+ double API_SUFFIX(stdlib_strided_dsnansumors)( 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 and using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
38
+ */
39
+ double API_SUFFIX(stdlib_strided_dsnansumors_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
38
40
 
39
41
  #ifdef __cplusplus
40
42
  }
@@ -20,7 +20,8 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var isnan = require( '@stdlib/math-base-assert-is-nan' );
23
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
24
25
 
25
26
 
26
27
  // MAIN //
@@ -30,45 +31,19 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
30
31
  *
31
32
  * @param {PositiveInteger} N - number of indexed elements
32
33
  * @param {Float32Array} x - input array
33
- * @param {integer} stride - stride length
34
+ * @param {integer} strideX - stride length
34
35
  * @returns {number} sum
35
36
  *
36
37
  * @example
37
38
  * var Float32Array = require( '@stdlib/array-float32' );
38
39
  *
39
40
  * var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
40
- * var N = x.length;
41
41
  *
42
- * var v = dsnansumors( N, x, 1 );
42
+ * var v = dsnansumors( x.length, x, 1 );
43
43
  * // returns 1.0
44
44
  */
45
- function dsnansumors( N, x, stride ) {
46
- var sum;
47
- var ix;
48
- var i;
49
-
50
- sum = 0.0;
51
- if ( N <= 0 ) {
52
- return sum;
53
- }
54
- if ( N === 1 || stride === 0 ) {
55
- if ( isnan( x[ 0 ] ) ) {
56
- return sum;
57
- }
58
- return x[ 0 ];
59
- }
60
- if ( stride < 0 ) {
61
- ix = (1-N) * stride;
62
- } else {
63
- ix = 0;
64
- }
65
- for ( i = 0; i < N; i++ ) {
66
- if ( isnan( x[ ix ] ) === false ) {
67
- sum += x[ ix ];
68
- }
69
- ix += stride;
70
- }
71
- return sum;
45
+ function dsnansumors( N, x, strideX ) {
46
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
72
47
  }
73
48
 
74
49
 
@@ -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} stride - stride length
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 = dsnansumors( N, x, 1 );
41
+ * var v = dsnansumors( x.length, x, 1 );
43
42
  * // returns 1.0
44
43
  */
45
- function dsnansumors( N, x, stride ) {
46
- return addon( N, x, stride );
44
+ function dsnansumors( 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 dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );
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 = dsnansumors( N, x, 1 );
32
+ * var v = dsnansumors( 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 dsnansumors = require( '@stdlib/blas-ext-base-dsnansumors' );
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 = dsnansumors.ndarray( N, x, 2, 1 );
41
+ * var v = dsnansumors.ndarray( 5, x, 2, 1 );
45
42
  * // returns 5.0
46
43
  */
47
44
 
package/lib/ndarray.js CHANGED
@@ -30,41 +30,53 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
30
30
  *
31
31
  * @param {PositiveInteger} N - number of indexed elements
32
32
  * @param {Float32Array} x - input array
33
- * @param {integer} stride - stride length
34
- * @param {NonNegativeInteger} offset - starting index
33
+ * @param {integer} strideX - stride length
34
+ * @param {NonNegativeInteger} offsetX - starting index
35
35
  * @returns {number} sum
36
36
  *
37
37
  * @example
38
38
  * var Float32Array = require( '@stdlib/array-float32' );
39
- * var floor = require( '@stdlib/math-base-special-floor' );
40
39
  *
41
40
  * 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
41
  *
44
- * var v = dsnansumors( N, x, 2, 1 );
42
+ * var v = dsnansumors( 5, x, 2, 1 );
45
43
  * // returns 5.0
46
44
  */
47
- function dsnansumors( N, x, stride, offset ) {
45
+ function dsnansumors( N, x, strideX, offsetX ) {
48
46
  var sum;
49
47
  var ix;
48
+ var v;
50
49
  var i;
51
50
 
52
- sum = 0.0;
53
51
  if ( N <= 0 ) {
54
- return sum;
52
+ return 0.0;
55
53
  }
56
- if ( N === 1 || stride === 0 ) {
57
- if ( isnan( x[ offset ] ) ) {
58
- return sum;
54
+ ix = offsetX;
55
+ if ( strideX === 0 ) {
56
+ if ( isnan( x[ ix ] ) ) {
57
+ return 0.0;
59
58
  }
60
- return x[ offset ];
59
+ return N * x[ ix ];
61
60
  }
62
- ix = offset;
61
+ // Find the first non-NaN element...
63
62
  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++ ) {
64
76
  if ( isnan( x[ ix ] ) === false ) {
65
77
  sum += x[ ix ];
66
78
  }
67
- ix += stride;
79
+ ix += strideX;
68
80
  }
69
81
  return sum;
70
82
  }
@@ -20,8 +20,7 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var Float32Array = require( '@stdlib/array-float32' );
24
- var addon = require( './dsnansumors.native.js' );
23
+ var addon = require( './../src/addon.node' );
25
24
 
26
25
 
27
26
  // MAIN //
@@ -31,27 +30,20 @@ var addon = require( './dsnansumors.native.js' );
31
30
  *
32
31
  * @param {PositiveInteger} N - number of indexed elements
33
32
  * @param {Float32Array} x - input array
34
- * @param {integer} stride - stride length
35
- * @param {NonNegativeInteger} offset - starting index
33
+ * @param {integer} strideX - stride length
34
+ * @param {NonNegativeInteger} offsetX - starting index
36
35
  * @returns {number} sum
37
36
  *
38
37
  * @example
39
38
  * var Float32Array = require( '@stdlib/array-float32' );
40
- * var floor = require( '@stdlib/math-base-special-floor' );
41
39
  *
42
40
  * 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
41
  *
45
- * var v = dsnansumors( N, x, 2, 1 );
42
+ * var v = dsnansumors( 5, x, 2, 1 );
46
43
  * // returns 5.0
47
44
  */
48
- function dsnansumors( N, x, stride, offset ) {
49
- var view;
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 );
45
+ function dsnansumors( N, x, strideX, offsetX ) {
46
+ return addon.ndarray( N, x, strideX, offsetX );
55
47
  }
56
48
 
57
49
 
package/manifest.json CHANGED
@@ -1,42 +1,82 @@
1
1
  {
2
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [
28
- "./src/dsnansumors.c"
29
- ],
30
- "include": [
31
- "./include"
32
- ],
33
- "libraries": [
34
- "-lm"
35
- ],
36
- "libpath": [],
37
- "dependencies": [
38
- "@stdlib/math-base-assert-is-nanf"
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/blas-base-shared",
45
+ "@stdlib/strided-base-stride2offset",
46
+ "@stdlib/napi-create-double"
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/blas-base-shared",
62
+ "@stdlib/strided-base-stride2offset"
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/blas-base-shared",
78
+ "@stdlib/strided-base-stride2offset"
79
+ ]
80
+ }
81
+ ]
42
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/blas-ext-base-dsnansumors",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Calculate the sum of single-precision floating-point strided array elements, ignoring NaN values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -34,12 +34,19 @@
34
34
  "url": "https://github.com/stdlib-js/stdlib/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@stdlib/assert-is-error": "^0.2.1",
38
- "@stdlib/math-base-assert-is-nan": "^0.2.1",
39
- "@stdlib/math-base-assert-is-nanf": "^0.2.1",
40
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",
41
- "@stdlib/utils-library-manifest": "^0.2.1",
42
- "@stdlib/utils-try-require": "^0.2.1"
37
+ "@stdlib/assert-is-error": "^0.2.2",
38
+ "@stdlib/blas-base-shared": "^0.1.0",
39
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
40
+ "@stdlib/math-base-assert-is-nanf": "^0.2.2",
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",
47
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
48
+ "@stdlib/utils-library-manifest": "^0.2.3",
49
+ "@stdlib/utils-try-require": "^0.2.2"
43
50
  },
44
51
  "devDependencies": {},
45
52
  "engines": {
@@ -79,7 +86,6 @@
79
86
  "single",
80
87
  "float32array"
81
88
  ],
82
- "__stdlib__": {},
83
89
  "funding": {
84
90
  "type": "opencollective",
85
91
  "url": "https://opencollective.com/stdlib"
package/src/addon.c ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2018 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/dsnansumors.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/napi/create_double.h"
26
+ #include <node_api.h>
27
+
28
+ /**
29
+ * Receives JavaScript callback invocation data.
30
+ *
31
+ * @param env environment under which the function is invoked
32
+ * @param info callback data
33
+ * @return Node-API value
34
+ */
35
+ static napi_value addon( napi_env env, napi_callback_info info ) {
36
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
37
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
38
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
39
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
40
+ STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsnansumors)( N, X, strideX ), v );
41
+ return v;
42
+ }
43
+
44
+ /**
45
+ * Receives JavaScript callback invocation data.
46
+ *
47
+ * @param env environment under which the function is invoked
48
+ * @param info callback data
49
+ * @return Node-API value
50
+ */
51
+ static napi_value addon_method( napi_env env, napi_callback_info info ) {
52
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
53
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
54
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
55
+ STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 );
56
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
57
+ STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsnansumors_ndarray)( N, X, strideX, offsetX ), v );
58
+ return v;
59
+ }
60
+
61
+ STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )
package/src/main.c ADDED
@@ -0,0 +1,83 @@
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/dsnansumors.h"
20
+ #include "stdlib/math/base/assert/is_nanf.h"
21
+ #include "stdlib/blas/base/shared.h"
22
+ #include "stdlib/strided/base/stride2offset.h"
23
+
24
+ /**
25
+ * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.
26
+ *
27
+ * @param N number of indexed elements
28
+ * @param X input array
29
+ * @param strideX stride length
30
+ * @return output value
31
+ */
32
+ double API_SUFFIX(stdlib_strided_dsnansumors)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
33
+ CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
34
+ return API_SUFFIX(stdlib_strided_dsnansumors_ndarray)( N, X, strideX, ox );
35
+ }
36
+
37
+ /**
38
+ * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using ordinary recursive summation with extended accumulation and alternative indexing semantics, and returning an extended precision result.
39
+ *
40
+ * @param N number of indexed elements
41
+ * @param X input array
42
+ * @param strideX stride length
43
+ * @param offsetX starting index
44
+ * @return output value
45
+ */
46
+ double API_SUFFIX(stdlib_strided_dsnansumors_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
47
+ CBLAS_INT ix;
48
+ CBLAS_INT i;
49
+ double sum;
50
+ double v;
51
+
52
+ if ( N <= 0 ) {
53
+ return 0.0;
54
+ }
55
+ ix = offsetX;
56
+ if ( strideX == 0 ) {
57
+ if ( stdlib_base_is_nanf( X[ ix ] ) ) {
58
+ return 0.0;
59
+ }
60
+ return N * X[ ix ];
61
+ }
62
+ // Find the first non-NaN element...
63
+ 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++ ) {
77
+ if ( !stdlib_base_is_nanf( X[ ix ] ) ) {
78
+ sum += (double)X[ ix ];
79
+ }
80
+ ix += strideX;
81
+ }
82
+ return sum;
83
+ }
package/include.gypi DELETED
@@ -1,53 +0,0 @@
1
- # @license Apache-2.0
2
- #
3
- # Copyright (c) 2020 The Stdlib Authors.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- # A GYP include file for building a Node.js native add-on.
18
- #
19
- # Main documentation:
20
- #
21
- # [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
22
- # [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
23
- {
24
- # Define variables to be used throughout the configuration for all targets:
25
- 'variables': {
26
- # Source directory:
27
- 'src_dir': './src',
28
-
29
- # Include directories:
30
- 'include_dirs': [
31
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
32
- ],
33
-
34
- # Add-on destination directory:
35
- 'addon_output_dir': './src',
36
-
37
- # Source files:
38
- 'src_files': [
39
- '<(src_dir)/addon.cpp',
40
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
41
- ],
42
-
43
- # Library dependencies:
44
- 'libraries': [
45
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
46
- ],
47
-
48
- # Library directories:
49
- 'library_dirs': [
50
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
51
- ],
52
- }, # end variables
53
- }
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/dsnansumors.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_dsnansumors {
30
-
31
- /**
32
- * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive 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_dsnansumors( 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_dsnansumors( 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_dsnansumors, 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_dsnansumors
package/src/dsnansumors.c DELETED
@@ -1,58 +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/dsnansumors.h"
20
- #include "stdlib/math/base/assert/is_nanf.h"
21
- #include <stdint.h>
22
-
23
- /**
24
- * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using ordinary recursive summation with extended accumulation, and returning an extended precision result.
25
- *
26
- * @param N number of indexed elements
27
- * @param X input array
28
- * @param stride stride length
29
- * @return output value
30
- */
31
- double stdlib_strided_dsnansumors( const int64_t N, const float *X, const int64_t stride ) {
32
- double sum;
33
- int64_t ix;
34
- int64_t i;
35
-
36
- sum = 0.0;
37
- if ( N <= 0 ) {
38
- return sum;
39
- }
40
- if ( N == 1 || stride == 0 ) {
41
- if ( stdlib_base_is_nanf( X[ 0 ] ) ) {
42
- return sum;
43
- }
44
- return X[ 0 ];
45
- }
46
- if ( stride < 0 ) {
47
- ix = (1-N) * stride;
48
- } else {
49
- ix = 0;
50
- }
51
- for ( i = 0; i < N; i++ ) {
52
- if ( !stdlib_base_is_nanf( X[ ix ] ) ) {
53
- sum += (double)X[ ix ];
54
- }
55
- ix += stride;
56
- }
57
- return sum;
58
- }