@stdlib/blas-ext-base-gnansumkbn 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -59,15 +59,14 @@ npm install @stdlib/blas-ext-base-gnansumkbn
59
59
  var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );
60
60
  ```
61
61
 
62
- #### gnansumkbn( N, x, stride )
62
+ #### gnansumkbn( N, x, strideX )
63
63
 
64
64
  Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
65
65
 
66
66
  ```javascript
67
67
  var x = [ 1.0, -2.0, NaN, 2.0 ];
68
- var N = x.length;
69
68
 
70
- var v = gnansumkbn( N, x, 1 );
69
+ var v = gnansumkbn( x.length, x, 1 );
71
70
  // returns 1.0
72
71
  ```
73
72
 
@@ -75,17 +74,14 @@ The function has the following parameters:
75
74
 
76
75
  - **N**: number of indexed elements.
77
76
  - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
78
- - **stride**: index increment for `x`.
77
+ - **strideX**: stride length for `x`.
79
78
 
80
- 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`,
79
+ 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:
81
80
 
82
81
  ```javascript
83
- var floor = require( '@stdlib/math-base-special-floor' );
84
-
85
82
  var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ];
86
- var N = floor( x.length / 2 );
87
83
 
88
- var v = gnansumkbn( N, x, 2 );
84
+ var v = gnansumkbn( 5, x, 2 );
89
85
  // returns 5.0
90
86
  ```
91
87
 
@@ -95,42 +91,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [
95
91
 
96
92
  ```javascript
97
93
  var Float64Array = require( '@stdlib/array-float64' );
98
- var floor = require( '@stdlib/math-base-special-floor' );
99
94
 
100
95
  var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
101
96
  var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
102
97
 
103
- var N = floor( x0.length / 2 );
104
-
105
- var v = gnansumkbn( N, x1, 2 );
98
+ var v = gnansumkbn( 4, x1, 2 );
106
99
  // returns 5.0
107
100
  ```
108
101
 
109
- #### gnansumkbn.ndarray( N, x, stride, offset )
102
+ #### gnansumkbn.ndarray( N, x, strideX, offsetX )
110
103
 
111
104
  Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
112
105
 
113
106
  ```javascript
114
107
  var x = [ 1.0, -2.0, NaN, 2.0 ];
115
- var N = x.length;
116
108
 
117
- var v = gnansumkbn.ndarray( N, x, 1, 0 );
109
+ var v = gnansumkbn.ndarray( x.length, x, 1, 0 );
118
110
  // returns 1.0
119
111
  ```
120
112
 
121
113
  The function has the following additional parameters:
122
114
 
123
- - **offset**: starting index for `x`.
115
+ - **offsetX**: starting index for `x`.
124
116
 
125
- 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
117
+ 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:
126
118
 
127
119
  ```javascript
128
- var floor = require( '@stdlib/math-base-special-floor' );
129
-
130
120
  var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ];
131
- var N = floor( x.length / 2 );
132
121
 
133
- var v = gnansumkbn.ndarray( N, x, 2, 1 );
122
+ var v = gnansumkbn.ndarray( 5, x, 2, 1 );
134
123
  // returns 5.0
135
124
  ```
136
125
 
@@ -143,6 +132,7 @@ var v = gnansumkbn.ndarray( N, x, 2, 1 );
143
132
  ## Notes
144
133
 
145
134
  - If `N <= 0`, both functions return `0.0`.
135
+ - Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array-base/accessor`][@stdlib/array/base/accessor]).
146
136
  - Depending on the environment, the typed versions ([`dnansumkbn`][@stdlib/blas/ext/base/dnansumkbn], [`snansumkbn`][@stdlib/blas/ext/base/snansumkbn], etc.) are likely to be significantly more performant.
147
137
 
148
138
  </section>
@@ -156,22 +146,19 @@ var v = gnansumkbn.ndarray( N, x, 2, 1 );
156
146
  <!-- eslint no-undef: "error" -->
157
147
 
158
148
  ```javascript
159
- var randu = require( '@stdlib/random-base-randu' );
160
- var round = require( '@stdlib/math-base-special-round' );
161
- var Float64Array = require( '@stdlib/array-float64' );
149
+ var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
150
+ var bernoulli = require( '@stdlib/random-base-bernoulli' );
151
+ var filledarrayBy = require( '@stdlib/array-filled-by' );
162
152
  var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );
163
153
 
164
- var x;
165
- var i;
166
-
167
- x = new Float64Array( 10 );
168
- for ( i = 0; i < x.length; i++ ) {
169
- if ( randu() < 0.2 ) {
170
- x[ i ] = NaN;
171
- } else {
172
- x[ i ] = round( randu()*100.0 );
154
+ function rand() {
155
+ if ( bernoulli( 0.7 ) > 0 ) {
156
+ return discreteUniform( 0, 100 );
173
157
  }
158
+ return NaN;
174
159
  }
160
+
161
+ var x = filledarrayBy( 10, 'float64', rand );
175
162
  console.log( x );
176
163
 
177
164
  var v = gnansumkbn( x.length, x, 1 );
@@ -240,7 +227,7 @@ See [LICENSE][stdlib-license].
240
227
 
241
228
  ## Copyright
242
229
 
243
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
230
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
244
231
 
245
232
  </section>
246
233
 
@@ -253,8 +240,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
253
240
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-gnansumkbn.svg
254
241
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-gnansumkbn
255
242
 
256
- [test-image]: https://github.com/stdlib-js/blas-ext-base-gnansumkbn/actions/workflows/test.yml/badge.svg?branch=v0.2.2
257
- [test-url]: https://github.com/stdlib-js/blas-ext-base-gnansumkbn/actions/workflows/test.yml?query=branch:v0.2.2
243
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-gnansumkbn/actions/workflows/test.yml/badge.svg?branch=v0.3.0
244
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-gnansumkbn/actions/workflows/test.yml?query=branch:v0.3.0
258
245
 
259
246
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-gnansumkbn/main.svg
260
247
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-gnansumkbn?branch=main
@@ -266,8 +253,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
266
253
 
267
254
  -->
268
255
 
269
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
270
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
256
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
257
+ [chat-url]: https://stdlib.zulipchat.com
271
258
 
272
259
  [stdlib]: https://github.com/stdlib-js/stdlib
273
260
 
@@ -290,6 +277,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
290
277
 
291
278
  [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
292
279
 
280
+ [@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
281
+
293
282
  [@neumaier:1974a]: https://doi.org/10.1002/zamm.19740540106
294
283
 
295
284
  [@stdlib/blas/ext/base/dnansumkbn]: https://www.npmjs.com/package/@stdlib/blas-ext-base-dnansumkbn
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
- "use strict";var c=function(n,r){return function(){return r||n((r={exports:{}}).exports,r),r.exports}};var o=c(function(w,m){
2
- var q=require('@stdlib/math-base-assert-is-nan/dist'),l=require('@stdlib/math-base-special-abs/dist');function x(n,r,t){var e,a,u,i,v,s;if(n<=0)return 0;if(n===1||t===0)return q(r[0])?0:r[0];for(t<0?a=(1-n)*t:a=0,e=0,v=0,s=0;s<n;s++)u=r[a],q(u)===!1&&(i=e+u,l(e)>=l(u)?v+=e-i+u:v+=u-i+e,e=i),a+=t;return e+v}m.exports=x
3
- });var g=c(function(z,y){
4
- var b=require('@stdlib/math-base-assert-is-nan/dist'),p=require('@stdlib/math-base-special-abs/dist');function O(n,r,t,e){var a,u,i,v,s,f;if(n<=0)return 0;if(n===1||t===0)return b(r[e])?0:r[e];for(u=e,a=0,s=0,f=0;f<n;f++)i=r[u],b(i)===!1&&(v=a+i,p(a)>=p(i)?s+=a-v+i:s+=i-v+a,a=v),u+=t;return a+s}y.exports=O
5
- });var R=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),k=o(),h=g();R(k,"ndarray",h);module.exports=k;
1
+ "use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var g=q(function(F,y){
2
+ var l=require('@stdlib/math-base-assert-is-nan/dist'),m=require('@stdlib/math-base-special-abs/dist');function P(e,r,t,c){var i,u,a,s,n,v,f,o;if(i=r.data,u=r.accessors[0],s=c,t===0)return l(u(i,s))?0:e*u(i,s);for(a=0,f=0,o=0;o<e;o++)n=u(i,s),l(n)===!1&&(v=a+n,m(a)>=m(n)?f+=a-v+n:f+=n-v+a,a=v),s+=t;return a+f}y.exports=P
3
+ });var b=q(function(G,x){
4
+ var R=require('@stdlib/array-base-arraylike2object/dist'),k=require('@stdlib/math-base-assert-is-nan/dist'),p=require('@stdlib/math-base-special-abs/dist'),h=g();function w(e,r,t,c){var i,u,a,s,n,v,f;if(e<=0)return 0;if(v=R(r),v.accessorProtocol)return h(e,v,t,c);if(u=c,t===0)return k(r[u])?0:e*r[u];for(i=0,n=0,f=0;f<e;f++)a=r[u],k(a)===!1&&(s=i+a,p(i)>=p(a)?n+=i-s+a:n+=a-s+i,i=s),u+=t;return i+n}x.exports=w
5
+ });var j=q(function(H,d){
6
+ var z=require('@stdlib/strided-base-stride2offset/dist'),A=b();function B(e,r,t){return A(e,r,t,z(e,t))}d.exports=B
7
+ });var C=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=j(),D=b();C(O,"ndarray",D);module.exports=O;
8
+ /** @license Apache-2.0 */
6
9
  /** @license Apache-2.0 */
7
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lib/main.js", "../lib/ndarray.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' );\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* ## Method\n*\n* - This implementation uses an \"improved Kahan\u2013Babu\u0161ka algorithm\", as described by Neumaier (1974).\n*\n* ## References\n*\n* - Neumaier, Arnold. 1974. \"Rounding Error Analysis of Some Methods for Summing Finite Sums.\" _Zeitschrift F\u00FCr Angewandte Mathematik Und Mechanik_ 54 (1): 39\u201351. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} stride - stride length\n* @returns {number} sum\n*\n* @example\n* var x = [ 1.0, -2.0, NaN, 2.0 ];\n* var N = x.length;\n*\n* var v = gnansumkbn( N, x, 1 );\n* // returns 1.0\n*/\nfunction gnansumkbn( N, x, stride ) {\n\tvar sum;\n\tvar ix;\n\tvar v;\n\tvar t;\n\tvar c;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( 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\tsum = 0.0;\n\tc = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( isnan( v ) === false ) {\n\t\t\tt = sum + v;\n\t\t\tif ( abs( sum ) >= abs( v ) ) {\n\t\t\t\tc += (sum-t) + v;\n\t\t\t} else {\n\t\t\t\tc += (v-t) + sum;\n\t\t\t}\n\t\t\tsum = t;\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum + c;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumkbn;\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' );\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* ## Method\n*\n* - This implementation uses an \"improved Kahan\u2013Babu\u0161ka algorithm\", as described by Neumaier (1974).\n*\n* ## References\n*\n* - Neumaier, Arnold. 1974. \"Rounding Error Analysis of Some Methods for Summing Finite Sums.\" _Zeitschrift F\u00FCr Angewandte Mathematik Und Mechanik_ 54 (1): 39\u201351. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} sum\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var N = floor( x.length / 2 );\n*\n* var v = gnansumkbn( N, x, 2, 1 );\n* // returns 5.0\n*/\nfunction gnansumkbn( N, x, stride, offset ) {\n\tvar sum;\n\tvar ix;\n\tvar v;\n\tvar t;\n\tvar c;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ offset ] ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn x[ offset ];\n\t}\n\tix = offset;\n\tsum = 0.0;\n\tc = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( isnan( v ) === false ) {\n\t\t\tt = sum + v;\n\t\t\tif ( abs( sum ) >= abs( v ) ) {\n\t\t\t\tc += (sum-t) + v;\n\t\t\t} else {\n\t\t\t\tc += (v-t) + sum;\n\t\t\t}\n\t\t\tsum = t;\n\t\t}\n\t\tix += stride;\n\t}\n\treturn sum + c;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumkbn;\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 strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* @module @stdlib/blas-ext-base-gnansumkbn\n*\n* @example\n* var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );\n*\n* var x = [ 1.0, -2.0, NaN, 2.0 ];\n* var N = x.length;\n*\n* var v = gnansumkbn( N, x, 1 );\n* // returns 1.0\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );\n*\n* var x = [ 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 = gnansumkbn.ndarray( N, x, 2, 1 );\n* // returns 5.0\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA4BnD,SAASC,EAAYC,EAAGC,EAAGC,EAAS,CACnC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKR,GAAK,EACT,MAAO,GAER,GAAKA,IAAM,GAAKE,IAAW,EAC1B,OAAKL,EAAOI,EAAG,CAAE,CAAE,EACX,EAEDA,EAAG,CAAE,EASb,IAPKC,EAAS,EACbE,GAAM,EAAEJ,GAAKE,EAEbE,EAAK,EAEND,EAAM,EACNI,EAAI,EACEC,EAAI,EAAGA,EAAIR,EAAGQ,IACnBH,EAAIJ,EAAGG,CAAG,EACLP,EAAOQ,CAAE,IAAM,KACnBC,EAAIH,EAAME,EACLP,EAAKK,CAAI,GAAKL,EAAKO,CAAE,EACzBE,GAAMJ,EAAIG,EAAKD,EAEfE,GAAMF,EAAEC,EAAKH,EAEdA,EAAMG,GAEPF,GAAMF,EAEP,OAAOC,EAAMI,CACd,CAKAX,EAAO,QAAUG,IC9FjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EA+BnD,SAASC,EAAYC,EAAGC,EAAGC,EAAQC,EAAS,CAC3C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKT,GAAK,EACT,MAAO,GAER,GAAKA,IAAM,GAAKE,IAAW,EAC1B,OAAKL,EAAOI,EAAGE,CAAO,CAAE,EAChB,EAEDF,EAAGE,CAAO,EAKlB,IAHAE,EAAKF,EACLC,EAAM,EACNI,EAAI,EACEC,EAAI,EAAGA,EAAIT,EAAGS,IACnBH,EAAIL,EAAGI,CAAG,EACLR,EAAOS,CAAE,IAAM,KACnBC,EAAIH,EAAME,EACLR,EAAKM,CAAI,GAAKN,EAAKQ,CAAE,EACzBE,GAAMJ,EAAIG,EAAKD,EAEfE,GAAMF,EAAEC,EAAKH,EAEdA,EAAMG,GAEPF,GAAMH,EAEP,OAAOE,EAAMI,CACd,CAKAZ,EAAO,QAAUG,IC9CjB,IAAIW,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "abs", "gnansumkbn", "N", "x", "stride", "sum", "ix", "v", "t", "c", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "abs", "gnansumkbn", "N", "x", "stride", "offset", "sum", "ix", "v", "t", "c", "i", "setReadOnly", "main", "ndarray"]
3
+ "sources": ["../lib/accessors.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 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' );\nvar abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* ## Method\n*\n* - This implementation uses an \"improved Kahan\u2013Babu\u0161ka algorithm\", as described by Neumaier (1974).\n*\n* ## References\n*\n* - Neumaier, Arnold. 1974. \"Rounding Error Analysis of Some Methods for Summing Finite Sums.\" _Zeitschrift F\u00FCr Angewandte Mathematik Und Mechanik_ 54 (1): 39\u201351. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).\n*\n* @private\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Object} x - input array object\n* @param {Collection} x.data - input array data\n* @param {Array<Function>} x.accessors - array element accessors\n* @param {integer} strideX - stride length for `x`\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @returns {number} sum\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );\n*\n* var v = gnansumkbn( 4, arraylike2object( x ), 2, 1 );\n* // returns 5.0\n*/\nfunction gnansumkbn( N, x, strideX, offsetX ) {\n\tvar xbuf;\n\tvar xget;\n\tvar sum;\n\tvar ix;\n\tvar v;\n\tvar t;\n\tvar c;\n\tvar i;\n\n\t// Cache reference to array data:\n\txbuf = x.data;\n\n\t// Cache reference to the element accessors:\n\txget = x.accessors[ 0 ];\n\n\tix = offsetX;\n\tif ( strideX === 0 ) {\n\t\tif ( isnan( xget( xbuf, ix ) ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn N * xget( xbuf, ix );\n\t}\n\tsum = 0.0;\n\tc = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = xget( xbuf, ix );\n\t\tif ( isnan( v ) === false ) {\n\t\t\tt = sum + v;\n\t\t\tif ( abs( sum ) >= abs( v ) ) {\n\t\t\t\tc += (sum-t) + v;\n\t\t\t} else {\n\t\t\t\tc += (v-t) + sum;\n\t\t\t}\n\t\t\tsum = t;\n\t\t}\n\t\tix += strideX;\n\t}\n\treturn sum + c;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumkbn;\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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar accessors = require( './accessors.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* ## Method\n*\n* - This implementation uses an \"improved Kahan\u2013Babu\u0161ka algorithm\", as described by Neumaier (1974).\n*\n* ## References\n*\n* - Neumaier, Arnold. 1974. \"Rounding Error Analysis of Some Methods for Summing Finite Sums.\" _Zeitschrift F\u00FCr Angewandte Mathematik Und Mechanik_ 54 (1): 39\u201351. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @returns {number} sum\n*\n* @example\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n*\n* var v = gnansumkbn( 4, x, 2, 1 );\n* // returns 5.0\n*/\nfunction gnansumkbn( N, x, strideX, offsetX ) {\n\tvar sum;\n\tvar ix;\n\tvar v;\n\tvar t;\n\tvar c;\n\tvar o;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn 0.0;\n\t}\n\to = arraylike2object( x );\n\tif ( o.accessorProtocol ) {\n\t\treturn accessors( N, o, strideX, offsetX );\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\tsum = 0.0;\n\tc = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( isnan( v ) === false ) {\n\t\t\tt = sum + v;\n\t\t\tif ( abs( sum ) >= abs( v ) ) {\n\t\t\t\tc += (sum-t) + v;\n\t\t\t} else {\n\t\t\t\tc += (v-t) + sum;\n\t\t\t}\n\t\t\tsum = t;\n\t\t}\n\t\tix += strideX;\n\t}\n\treturn sum + c;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumkbn;\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 strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* ## Method\n*\n* - This implementation uses an \"improved Kahan\u2013Babu\u0161ka algorithm\", as described by Neumaier (1974).\n*\n* ## References\n*\n* - Neumaier, Arnold. 1974. \"Rounding Error Analysis of Some Methods for Summing Finite Sums.\" _Zeitschrift F\u00FCr Angewandte Mathematik Und Mechanik_ 54 (1): 39\u201351. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} strideX - stride length\n* @returns {number} sum\n*\n* @example\n* var x = [ 1.0, -2.0, NaN, 2.0 ];\n*\n* var v = gnansumkbn( x.length, x, 1 );\n* // returns 1.0\n*/\nfunction gnansumkbn( N, x, strideX ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumkbn;\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 strided array elements, ignoring `NaN` values and using an improved Kahan\u2013Babu\u0161ka algorithm.\n*\n* @module @stdlib/blas-ext-base-gnansumkbn\n*\n* @example\n* var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );\n*\n* var x = [ 1.0, -2.0, NaN, 2.0 ];\n*\n* var v = gnansumkbn( x.length, x, 1 );\n* // returns 1.0\n*\n* @example\n* var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ];\n*\n* var v = gnansumkbn.ndarray( 5, x, 2, 1 );\n* // returns 5.0\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAkCnD,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,GANAP,EAAOH,EAAE,KAGTI,EAAOJ,EAAE,UAAW,CAAE,EAEtBM,EAAKJ,EACAD,IAAY,EAChB,OAAKL,EAAOQ,EAAMD,EAAMG,CAAG,CAAE,EACrB,EAEDP,EAAIK,EAAMD,EAAMG,CAAG,EAI3B,IAFAD,EAAM,EACNI,EAAI,EACEC,EAAI,EAAGA,EAAIX,EAAGW,IACnBH,EAAIH,EAAMD,EAAMG,CAAG,EACdV,EAAOW,CAAE,IAAM,KACnBC,EAAIH,EAAME,EACLV,EAAKQ,CAAI,GAAKR,EAAKU,CAAE,EACzBE,GAAMJ,EAAIG,EAAKD,EAEfE,GAAMF,EAAEC,EAAKH,EAEdA,EAAMG,GAEPF,GAAML,EAEP,OAAOI,EAAMI,CACd,CAKAd,EAAO,QAAUG,ICrGjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAY,IA4BhB,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKV,GAAK,EACT,MAAO,GAGR,GADAS,EAAId,EAAkBM,CAAE,EACnBQ,EAAE,iBACN,OAAOX,EAAWE,EAAGS,EAAGP,EAASC,CAAQ,EAG1C,GADAE,EAAKF,EACAD,IAAY,EAChB,OAAKN,EAAOK,EAAGI,CAAG,CAAE,EACZ,EAEDL,EAAIC,EAAGI,CAAG,EAIlB,IAFAD,EAAM,EACNI,EAAI,EACEE,EAAI,EAAGA,EAAIV,EAAGU,IACnBJ,EAAIL,EAAGI,CAAG,EACLT,EAAOU,CAAE,IAAM,KACnBC,EAAIH,EAAME,EACLT,EAAKO,CAAI,GAAKP,EAAKS,CAAE,EACzBE,GAAMJ,EAAIG,EAAKD,EAEfE,GAAMF,EAAEC,EAAKH,EAEdA,EAAMG,GAEPF,GAAMH,EAEP,OAAOE,EAAMI,CACd,CAKAd,EAAO,QAAUK,ICjGjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IA2Bd,SAASC,EAAYC,EAAGC,EAAGC,EAAU,CACpC,OAAOJ,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,CAAE,CAC5D,CAKAN,EAAO,QAAUG,ICbjB,IAAII,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
+ "names": ["require_accessors", "__commonJSMin", "exports", "module", "isnan", "abs", "gnansumkbn", "N", "x", "strideX", "offsetX", "xbuf", "xget", "sum", "ix", "v", "t", "c", "i", "require_ndarray", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "abs", "accessors", "gnansumkbn", "N", "x", "strideX", "offsetX", "sum", "ix", "v", "t", "c", "o", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "gnansumkbn", "N", "x", "strideX", "setReadOnly", "main", "ndarray"]
7
7
  }
@@ -20,7 +20,12 @@
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { NumericArray } from '@stdlib/types/array';
23
+ import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
24
+
25
+ /**
26
+ * Input array.
27
+ */
28
+ type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
24
29
 
25
30
  /**
26
31
  * Interface describing `gnansumkbn`.
@@ -31,7 +36,7 @@ interface Routine {
31
36
  *
32
37
  * @param N - number of indexed elements
33
38
  * @param x - input array
34
- * @param stride - stride length
39
+ * @param strideX - stride length
35
40
  * @returns sum
36
41
  *
37
42
  * @example
@@ -40,15 +45,15 @@ interface Routine {
40
45
  * var v = gnansumkbn( x.length, x, 1 );
41
46
  * // returns 1.0
42
47
  */
43
- ( N: number, x: NumericArray, stride: number ): number;
48
+ ( N: number, x: InputArray, strideX: number ): number;
44
49
 
45
50
  /**
46
51
  * Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics.
47
52
  *
48
53
  * @param N - number of indexed elements
49
54
  * @param x - input array
50
- * @param stride - stride length
51
- * @param offset - starting index
55
+ * @param strideX - stride length
56
+ * @param offsetX - starting index
52
57
  * @returns sum
53
58
  *
54
59
  * @example
@@ -57,7 +62,7 @@ interface Routine {
57
62
  * var v = gnansumkbn.ndarray( x.length, x, 1, 0 );
58
63
  * // returns 1.0
59
64
  */
60
- ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
65
+ ndarray( N: number, x: InputArray, strideX: number, offsetX: number ): number;
61
66
  }
62
67
 
63
68
  /**
@@ -65,7 +70,7 @@ interface Routine {
65
70
  *
66
71
  * @param N - number of indexed elements
67
72
  * @param x - input array
68
- * @param stride - stride length
73
+ * @param strideX - stride length
69
74
  * @returns sum
70
75
  *
71
76
  * @example
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isnan = require( '@stdlib/math-base-assert-is-nan' );
24
+ var abs = require( '@stdlib/math-base-special-abs' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm.
31
+ *
32
+ * ## Method
33
+ *
34
+ * - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974).
35
+ *
36
+ * ## References
37
+ *
38
+ * - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106).
39
+ *
40
+ * @private
41
+ * @param {PositiveInteger} N - number of indexed elements
42
+ * @param {Object} x - input array object
43
+ * @param {Collection} x.data - input array data
44
+ * @param {Array<Function>} x.accessors - array element accessors
45
+ * @param {integer} strideX - stride length for `x`
46
+ * @param {NonNegativeInteger} offsetX - starting index for `x`
47
+ * @returns {number} sum
48
+ *
49
+ * @example
50
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
51
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
52
+ *
53
+ * var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
54
+ *
55
+ * var v = gnansumkbn( 4, arraylike2object( x ), 2, 1 );
56
+ * // returns 5.0
57
+ */
58
+ function gnansumkbn( N, x, strideX, offsetX ) {
59
+ var xbuf;
60
+ var xget;
61
+ var sum;
62
+ var ix;
63
+ var v;
64
+ var t;
65
+ var c;
66
+ var i;
67
+
68
+ // Cache reference to array data:
69
+ xbuf = x.data;
70
+
71
+ // Cache reference to the element accessors:
72
+ xget = x.accessors[ 0 ];
73
+
74
+ ix = offsetX;
75
+ if ( strideX === 0 ) {
76
+ if ( isnan( xget( xbuf, ix ) ) ) {
77
+ return 0.0;
78
+ }
79
+ return N * xget( xbuf, ix );
80
+ }
81
+ sum = 0.0;
82
+ c = 0.0;
83
+ for ( i = 0; i < N; i++ ) {
84
+ v = xget( xbuf, ix );
85
+ if ( isnan( v ) === false ) {
86
+ t = sum + v;
87
+ if ( abs( sum ) >= abs( v ) ) {
88
+ c += (sum-t) + v;
89
+ } else {
90
+ c += (v-t) + sum;
91
+ }
92
+ sum = t;
93
+ }
94
+ ix += strideX;
95
+ }
96
+ return sum + c;
97
+ }
98
+
99
+
100
+ // EXPORTS //
101
+
102
+ module.exports = gnansumkbn;
package/lib/index.js CHANGED
@@ -27,19 +27,16 @@
27
27
  * var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );
28
28
  *
29
29
  * var x = [ 1.0, -2.0, NaN, 2.0 ];
30
- * var N = x.length;
31
30
  *
32
- * var v = gnansumkbn( N, x, 1 );
31
+ * var v = gnansumkbn( x.length, x, 1 );
33
32
  * // returns 1.0
34
33
  *
35
34
  * @example
36
- * var floor = require( '@stdlib/math-base-special-floor' );
37
35
  * var gnansumkbn = require( '@stdlib/blas-ext-base-gnansumkbn' );
38
36
  *
39
37
  * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ];
40
- * var N = floor( x.length / 2 );
41
38
  *
42
- * var v = gnansumkbn.ndarray( N, x, 2, 1 );
39
+ * var v = gnansumkbn.ndarray( 5, x, 2, 1 );
43
40
  * // returns 5.0
44
41
  */
45
42
 
package/lib/main.js CHANGED
@@ -20,8 +20,8 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var isnan = require( '@stdlib/math-base-assert-is-nan' );
24
- var abs = require( '@stdlib/math-base-special-abs' );
23
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
25
25
 
26
26
 
27
27
  // MAIN //
@@ -39,54 +39,17 @@ var abs = require( '@stdlib/math-base-special-abs' );
39
39
  *
40
40
  * @param {PositiveInteger} N - number of indexed elements
41
41
  * @param {NumericArray} x - input array
42
- * @param {integer} stride - stride length
42
+ * @param {integer} strideX - stride length
43
43
  * @returns {number} sum
44
44
  *
45
45
  * @example
46
46
  * var x = [ 1.0, -2.0, NaN, 2.0 ];
47
- * var N = x.length;
48
47
  *
49
- * var v = gnansumkbn( N, x, 1 );
48
+ * var v = gnansumkbn( x.length, x, 1 );
50
49
  * // returns 1.0
51
50
  */
52
- function gnansumkbn( N, x, stride ) {
53
- var sum;
54
- var ix;
55
- var v;
56
- var t;
57
- var c;
58
- var i;
59
-
60
- if ( N <= 0 ) {
61
- return 0.0;
62
- }
63
- if ( N === 1 || stride === 0 ) {
64
- if ( isnan( x[ 0 ] ) ) {
65
- return 0.0;
66
- }
67
- return x[ 0 ];
68
- }
69
- if ( stride < 0 ) {
70
- ix = (1-N) * stride;
71
- } else {
72
- ix = 0;
73
- }
74
- sum = 0.0;
75
- c = 0.0;
76
- for ( i = 0; i < N; i++ ) {
77
- v = x[ ix ];
78
- if ( isnan( v ) === false ) {
79
- t = sum + v;
80
- if ( abs( sum ) >= abs( v ) ) {
81
- c += (sum-t) + v;
82
- } else {
83
- c += (v-t) + sum;
84
- }
85
- sum = t;
86
- }
87
- ix += stride;
88
- }
89
- return sum + c;
51
+ function gnansumkbn( N, x, strideX ) {
52
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
90
53
  }
91
54
 
92
55
 
package/lib/ndarray.js CHANGED
@@ -20,8 +20,10 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
+ var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
23
24
  var isnan = require( '@stdlib/math-base-assert-is-nan' );
24
25
  var abs = require( '@stdlib/math-base-special-abs' );
26
+ var accessors = require( './accessors.js' );
25
27
 
26
28
 
27
29
  // MAIN //
@@ -39,37 +41,39 @@ var abs = require( '@stdlib/math-base-special-abs' );
39
41
  *
40
42
  * @param {PositiveInteger} N - number of indexed elements
41
43
  * @param {NumericArray} x - input array
42
- * @param {integer} stride - stride length
43
- * @param {NonNegativeInteger} offset - starting index
44
+ * @param {integer} strideX - stride length
45
+ * @param {NonNegativeInteger} offsetX - starting index
44
46
  * @returns {number} sum
45
47
  *
46
48
  * @example
47
- * var floor = require( '@stdlib/math-base-special-floor' );
48
- *
49
49
  * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
50
- * var N = floor( x.length / 2 );
51
50
  *
52
- * var v = gnansumkbn( N, x, 2, 1 );
51
+ * var v = gnansumkbn( 4, x, 2, 1 );
53
52
  * // returns 5.0
54
53
  */
55
- function gnansumkbn( N, x, stride, offset ) {
54
+ function gnansumkbn( N, x, strideX, offsetX ) {
56
55
  var sum;
57
56
  var ix;
58
57
  var v;
59
58
  var t;
60
59
  var c;
60
+ var o;
61
61
  var i;
62
62
 
63
63
  if ( N <= 0 ) {
64
64
  return 0.0;
65
65
  }
66
- if ( N === 1 || stride === 0 ) {
67
- if ( isnan( x[ offset ] ) ) {
66
+ o = arraylike2object( x );
67
+ if ( o.accessorProtocol ) {
68
+ return accessors( N, o, strideX, offsetX );
69
+ }
70
+ ix = offsetX;
71
+ if ( strideX === 0 ) {
72
+ if ( isnan( x[ ix ] ) ) {
68
73
  return 0.0;
69
74
  }
70
- return x[ offset ];
75
+ return N * x[ ix ];
71
76
  }
72
- ix = offset;
73
77
  sum = 0.0;
74
78
  c = 0.0;
75
79
  for ( i = 0; i < N; i++ ) {
@@ -83,7 +87,7 @@ function gnansumkbn( N, x, stride, offset ) {
83
87
  }
84
88
  sum = t;
85
89
  }
86
- ix += stride;
90
+ ix += strideX;
87
91
  }
88
92
  return sum + c;
89
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/blas-ext-base-gnansumkbn",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Calculate the sum of strided array elements, ignoring NaN values and using an improved Kahan–Babuška algorithm.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,8 +30,10 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
+ "@stdlib/array-base-arraylike2object": "^0.2.1",
33
34
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
34
35
  "@stdlib/math-base-special-abs": "^0.2.2",
36
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
35
37
  "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
36
38
  },
37
39
  "devDependencies": {},
@@ -69,7 +71,6 @@
69
71
  "strided array",
70
72
  "array"
71
73
  ],
72
- "__stdlib__": {},
73
74
  "funding": {
74
75
  "type": "opencollective",
75
76
  "url": "https://opencollective.com/stdlib"