@stdlib/blas-ext-base-gnansumors 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-gnansumors
59
59
  var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );
60
60
  ```
61
61
 
62
- #### gnansumors( N, x, stride )
62
+ #### gnansumors( N, x, strideX )
63
63
 
64
64
  Computes the sum of strided array elements, ignoring `NaN` values and using ordinary recursive summation.
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 = gnansumors( N, x, 1 );
69
+ var v = gnansumors( 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 = gnansumors( N, x, 2 );
84
+ var v = gnansumors( 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 = gnansumors( N, x1, 2 );
98
+ var v = gnansumors( 4, x1, 2 );
106
99
  // returns 5.0
107
100
  ```
108
101
 
109
- #### gnansumors.ndarray( N, x, stride, offset )
102
+ #### gnansumors.ndarray( N, x, strideX, offsetX )
110
103
 
111
104
  Computes the sum of strided array elements, ignoring `NaN` values and using ordinary recursive summation 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 = gnansumors.ndarray( N, x, 1, 0 );
109
+ var v = gnansumors.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 = gnansumors.ndarray( N, x, 2, 1 );
122
+ var v = gnansumors.ndarray( 5, x, 2, 1 );
134
123
  // returns 5.0
135
124
  ```
136
125
 
@@ -143,6 +132,7 @@ var v = gnansumors.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
  - Ordinary recursive summation (i.e., a "simple" sum) is performant, but can incur significant numerical error. If performance is paramount and error tolerated, using ordinary recursive summation is acceptable; in all other cases, exercise due caution.
147
137
  - Depending on the environment, the typed versions ([`dnansumors`][@stdlib/blas/ext/base/dnansumors], [`snansumors`][@stdlib/blas/ext/base/snansumors], etc.) are likely to be significantly more performant.
148
138
 
@@ -157,22 +147,19 @@ var v = gnansumors.ndarray( N, x, 2, 1 );
157
147
  <!-- eslint no-undef: "error" -->
158
148
 
159
149
  ```javascript
160
- var randu = require( '@stdlib/random-base-randu' );
161
- var round = require( '@stdlib/math-base-special-round' );
162
- var Float64Array = require( '@stdlib/array-float64' );
150
+ var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
151
+ var bernoulli = require( '@stdlib/random-base-bernoulli' );
152
+ var filledarrayBy = require( '@stdlib/array-filled-by' );
163
153
  var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );
164
154
 
165
- var x;
166
- var i;
167
-
168
- x = new Float64Array( 10 );
169
- for ( i = 0; i < x.length; i++ ) {
170
- if ( randu() < 0.2 ) {
171
- x[ i ] = NaN;
172
- } else {
173
- x[ i ] = round( randu()*100.0 );
155
+ function rand() {
156
+ if ( bernoulli( 0.7 ) > 0 ) {
157
+ return discreteUniform( 0, 100 );
174
158
  }
159
+ return NaN;
175
160
  }
161
+
162
+ var x = filledarrayBy( 10, 'float64', rand );
176
163
  console.log( x );
177
164
 
178
165
  var v = gnansumors( x.length, x, 1 );
@@ -228,7 +215,7 @@ See [LICENSE][stdlib-license].
228
215
 
229
216
  ## Copyright
230
217
 
231
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
218
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
232
219
 
233
220
  </section>
234
221
 
@@ -241,8 +228,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
241
228
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-gnansumors.svg
242
229
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-gnansumors
243
230
 
244
- [test-image]: https://github.com/stdlib-js/blas-ext-base-gnansumors/actions/workflows/test.yml/badge.svg?branch=v0.2.2
245
- [test-url]: https://github.com/stdlib-js/blas-ext-base-gnansumors/actions/workflows/test.yml?query=branch:v0.2.2
231
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-gnansumors/actions/workflows/test.yml/badge.svg?branch=v0.3.0
232
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-gnansumors/actions/workflows/test.yml?query=branch:v0.3.0
246
233
 
247
234
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-gnansumors/main.svg
248
235
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-gnansumors?branch=main
@@ -254,8 +241,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
254
241
 
255
242
  -->
256
243
 
257
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
258
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
244
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
245
+ [chat-url]: https://stdlib.zulipchat.com
259
246
 
260
247
  [stdlib]: https://github.com/stdlib-js/stdlib
261
248
 
@@ -278,6 +265,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
278
265
 
279
266
  [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
280
267
 
268
+ [@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
269
+
281
270
  <!-- <related-links> -->
282
271
 
283
272
  [@stdlib/blas/ext/base/dnansumors]: https://www.npmjs.com/package/@stdlib/blas-ext-base-dnansumors
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
- "use strict";var t=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var o=t(function(b,v){
2
- var f=require('@stdlib/math-base-assert-is-nan/dist');function p(e,r,u){var a,n,i;if(n=0,e<=0)return n;if(e===1||u===0)return f(r[0])?n:r[0];for(u<0?a=(1-e)*u:a=0,i=0;i<e;i++)f(r[a])===!1&&(n+=r[a]),a+=u;return n}v.exports=p
3
- });var l=t(function(h,q){
4
- var c=require('@stdlib/math-base-assert-is-nan/dist');function y(e,r,u,a){var n,i,s;if(i=0,e<=0)return i;if(e===1||u===0)return c(r[a])?i:r[a];for(n=a,s=0;s<e;s++)c(r[n])===!1&&(i+=r[n]),n+=u;return i}q.exports=y
5
- });var g=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),m=o(),O=l();g(m,"ndarray",O);module.exports=m;
1
+ "use strict";var f=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=f(function(B,m){
2
+ var q=require('@stdlib/math-base-assert-is-nan/dist');function d(e,r,u,o){var s,a,i,n,t,v;if(s=r.data,a=r.accessors[0],n=o,u===0)return t=a(s,n),q(t)?0:e*t;for(i=0,v=0;v<e;v++)t=a(s,n),q(t)===!1&&(i+=t),n+=u;return i}m.exports=d
3
+ });var c=f(function(C,g){
4
+ var j=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/math-base-assert-is-nan/dist'),k=l();function O(e,r,u,o){var s,a,i,n;if(e<=0)return 0;if(i=j(r),i.accessorProtocol)return k(e,i,u,o);if(a=o,u===0)return y(r[a])?0:e*r[a];for(s=0,n=0;n<e;n++)y(r[a])===!1&&(s+=r[a]),a+=u;return s}g.exports=O
5
+ });var x=f(function(D,p){
6
+ var P=require('@stdlib/strided-base-stride2offset/dist'),R=c();function h(e,r,u){return R(e,r,u,P(e,u))}p.exports=h
7
+ });var w=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),b=x(),z=c();w(b,"ndarray",z);module.exports=b;
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' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using ordinary recursive summation.\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 = gnansumors( N, x, 1 );\n* // returns 1.0\n*/\nfunction gnansumors( N, x, stride ) {\n\tvar ix;\n\tvar s;\n\tvar i;\n\n\ts = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn s;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ 0 ] ) ) {\n\t\t\treturn s;\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\ts += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn s;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumors;\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 strided array elements, ignoring `NaN` values and using ordinary recursive summation.\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 = gnansumors( N, x, 2, 1 );\n* // returns 5.0\n*/\nfunction gnansumors( N, x, stride, offset ) {\n\tvar ix;\n\tvar s;\n\tvar i;\n\n\ts = 0.0;\n\tif ( N <= 0 ) {\n\t\treturn s;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tif ( isnan( x[ offset ] ) ) {\n\t\t\treturn s;\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\ts += x[ ix ];\n\t\t}\n\t\tix += stride;\n\t}\n\treturn s;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumors;\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 ordinary recursive summation.\n*\n* @module @stdlib/blas-ext-base-gnansumors\n*\n* @example\n* var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );\n*\n* var x = [ 1.0, -2.0, NaN, 2.0 ];\n* var N = x.length;\n*\n* var v = gnansumors( N, x, 1 );\n* // returns 1.0\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );\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 = gnansumors.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,EAoBvD,SAASC,EAAYC,EAAGC,EAAGC,EAAS,CACnC,IAAIC,EACAC,EACA,EAGJ,GADAA,EAAI,EACCJ,GAAK,EACT,OAAOI,EAER,GAAKJ,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAG,CAAE,CAAE,EACXG,EAEDH,EAAG,CAAE,EAOb,IALKC,EAAS,EACbC,GAAM,EAAEH,GAAKE,EAEbC,EAAK,EAEA,EAAI,EAAG,EAAIH,EAAG,IACdF,EAAOG,EAAGE,CAAG,CAAE,IAAM,KACzBC,GAAKH,EAAGE,CAAG,GAEZA,GAAMD,EAEP,OAAOE,CACR,CAKAP,EAAO,QAAUE,IC1EjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAuBvD,SAASC,EAAYC,EAAGC,EAAGC,EAAQC,EAAS,CAC3C,IAAIC,EACAC,EACAC,EAGJ,GADAD,EAAI,EACCL,GAAK,EACT,OAAOK,EAER,GAAKL,IAAM,GAAKE,IAAW,EAC1B,OAAKJ,EAAOG,EAAGE,CAAO,CAAE,EAChBE,EAEDJ,EAAGE,CAAO,EAGlB,IADAC,EAAKD,EACCG,EAAI,EAAGA,EAAIN,EAAGM,IACdR,EAAOG,EAAGG,CAAG,CAAE,IAAM,KACzBC,GAAKJ,EAAGG,CAAG,GAEZA,GAAMF,EAEP,OAAOG,CACR,CAKAR,EAAO,QAAUE,IC1BjB,IAAIQ,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "gnansumors", "N", "x", "stride", "ix", "s", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "gnansumors", "N", "x", "stride", "offset", "ix", "s", "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' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using ordinary recursive summation.\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 = gnansumors( 4, arraylike2object( x ), 2, 1 );\n* // returns 5.0\n*/\nfunction gnansumors( N, x, strideX, offsetX ) {\n\tvar xbuf;\n\tvar xget;\n\tvar sum;\n\tvar ix;\n\tvar v;\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\tv = xget( xbuf, ix );\n\t\tif ( isnan( v ) ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn N * v;\n\t}\n\tsum = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = xget( xbuf, ix );\n\t\tif ( isnan( v ) === false ) {\n\t\t\tsum += v;\n\t\t}\n\t\tix += strideX;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumors;\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 accessors = require( './accessors.js' );\n\n\n// MAIN //\n\n/**\n* Computes the sum of strided array elements, ignoring `NaN` values and using ordinary recursive summation.\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 = gnansumors( 4, x, 2, 1 );\n* // returns 5.0\n*/\nfunction gnansumors( N, x, strideX, offsetX ) {\n\tvar sum;\n\tvar ix;\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\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 += strideX;\n\t}\n\treturn sum;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumors;\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 ordinary recursive summation.\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 = gnansumors( x.length, x, 1 );\n* // returns 1.0\n*/\nfunction gnansumors( N, x, strideX ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = gnansumors;\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 ordinary recursive summation.\n*\n* @module @stdlib/blas-ext-base-gnansumors\n*\n* @example\n* var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );\n*\n* var x = [ 1.0, -2.0, NaN, 2.0 ];\n*\n* var v = gnansumors( x.length, x, 1 );\n* // returns 1.0\n*\n* @example\n* var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );\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 = gnansumors.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,EA0BvD,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EASJ,GANAL,EAAOH,EAAE,KAGTI,EAAOJ,EAAE,UAAW,CAAE,EAEtBM,EAAKJ,EACAD,IAAY,EAEhB,OADAM,EAAIH,EAAMD,EAAMG,CAAG,EACdT,EAAOU,CAAE,EACN,EAEDR,EAAIQ,EAGZ,IADAF,EAAM,EACAG,EAAI,EAAGA,EAAIT,EAAGS,IACnBD,EAAIH,EAAMD,EAAMG,CAAG,EACdT,EAAOU,CAAE,IAAM,KACnBF,GAAOE,GAERD,GAAML,EAEP,OAAOI,CACR,CAKAT,EAAO,QAAUE,ICpFjB,IAAAW,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAY,IAoBhB,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAAU,CAC7C,IAAIC,EACAC,EACAC,EACAC,EAEJ,GAAKP,GAAK,EACT,MAAO,GAGR,GADAM,EAAIV,EAAkBK,CAAE,EACnBK,EAAE,iBACN,OAAOR,EAAWE,EAAGM,EAAGJ,EAASC,CAAQ,EAG1C,GADAE,EAAKF,EACAD,IAAY,EAChB,OAAKL,EAAOI,EAAGI,CAAG,CAAE,EACZ,EAEDL,EAAIC,EAAGI,CAAG,EAGlB,IADAD,EAAM,EACAG,EAAI,EAAGA,EAAIP,EAAGO,IACdV,EAAOI,EAAGI,CAAG,CAAE,IAAM,KACzBD,GAAOH,EAAGI,CAAG,GAEdA,GAAMH,EAEP,OAAOE,CACR,CAKAT,EAAO,QAAUI,IC7EjB,IAAAS,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAmBd,SAASC,EAAYC,EAAGC,EAAGC,EAAU,CACpC,OAAOJ,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,CAAE,CAC5D,CAKAN,EAAO,QAAUG,ICLjB,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", "gnansumors", "N", "x", "strideX", "offsetX", "xbuf", "xget", "sum", "ix", "v", "i", "require_ndarray", "__commonJSMin", "exports", "module", "arraylike2object", "isnan", "accessors", "gnansumors", "N", "x", "strideX", "offsetX", "sum", "ix", "o", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "gnansumors", "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 `gnansumors`.
@@ -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 = gnansumors( 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 ordinary recursive summation 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 = gnansumors.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,85 @@
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
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the sum of strided array elements, ignoring `NaN` values and using ordinary recursive summation.
30
+ *
31
+ * @private
32
+ * @param {PositiveInteger} N - number of indexed elements
33
+ * @param {Object} x - input array object
34
+ * @param {Collection} x.data - input array data
35
+ * @param {Array<Function>} x.accessors - array element accessors
36
+ * @param {integer} strideX - stride length for `x`
37
+ * @param {NonNegativeInteger} offsetX - starting index for `x`
38
+ * @returns {number} sum
39
+ *
40
+ * @example
41
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
42
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
43
+ *
44
+ * var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
45
+ *
46
+ * var v = gnansumors( 4, arraylike2object( x ), 2, 1 );
47
+ * // returns 5.0
48
+ */
49
+ function gnansumors( N, x, strideX, offsetX ) {
50
+ var xbuf;
51
+ var xget;
52
+ var sum;
53
+ var ix;
54
+ var v;
55
+ var i;
56
+
57
+ // Cache reference to array data:
58
+ xbuf = x.data;
59
+
60
+ // Cache reference to the element accessors:
61
+ xget = x.accessors[ 0 ];
62
+
63
+ ix = offsetX;
64
+ if ( strideX === 0 ) {
65
+ v = xget( xbuf, ix );
66
+ if ( isnan( v ) ) {
67
+ return 0.0;
68
+ }
69
+ return N * v;
70
+ }
71
+ sum = 0.0;
72
+ for ( i = 0; i < N; i++ ) {
73
+ v = xget( xbuf, ix );
74
+ if ( isnan( v ) === false ) {
75
+ sum += v;
76
+ }
77
+ ix += strideX;
78
+ }
79
+ return sum;
80
+ }
81
+
82
+
83
+ // EXPORTS //
84
+
85
+ module.exports = gnansumors;
package/lib/index.js CHANGED
@@ -27,19 +27,16 @@
27
27
  * var gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );
28
28
  *
29
29
  * var x = [ 1.0, -2.0, NaN, 2.0 ];
30
- * var N = x.length;
31
30
  *
32
- * var v = gnansumors( N, x, 1 );
31
+ * var v = gnansumors( 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 gnansumors = require( '@stdlib/blas-ext-base-gnansumors' );
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 = gnansumors.ndarray( N, x, 2, 1 );
39
+ * var v = gnansumors.ndarray( 5, x, 2, 1 );
43
40
  * // returns 5.0
44
41
  */
45
42
 
package/lib/main.js CHANGED
@@ -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,43 +31,17 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
30
31
  *
31
32
  * @param {PositiveInteger} N - number of indexed elements
32
33
  * @param {NumericArray} 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 x = [ 1.0, -2.0, NaN, 2.0 ];
38
- * var N = x.length;
39
39
  *
40
- * var v = gnansumors( N, x, 1 );
40
+ * var v = gnansumors( x.length, x, 1 );
41
41
  * // returns 1.0
42
42
  */
43
- function gnansumors( N, x, stride ) {
44
- var ix;
45
- var s;
46
- var i;
47
-
48
- s = 0.0;
49
- if ( N <= 0 ) {
50
- return s;
51
- }
52
- if ( N === 1 || stride === 0 ) {
53
- if ( isnan( x[ 0 ] ) ) {
54
- return s;
55
- }
56
- return x[ 0 ];
57
- }
58
- if ( stride < 0 ) {
59
- ix = (1-N) * stride;
60
- } else {
61
- ix = 0;
62
- }
63
- for ( i = 0; i < N; i++ ) {
64
- if ( isnan( x[ ix ] ) === false ) {
65
- s += x[ ix ];
66
- }
67
- ix += stride;
68
- }
69
- return s;
43
+ function gnansumors( N, x, strideX ) {
44
+ return ndarray( N, x, strideX, stride2offset( N, strideX ) );
70
45
  }
71
46
 
72
47
 
package/lib/ndarray.js CHANGED
@@ -20,7 +20,9 @@
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' );
25
+ var accessors = require( './accessors.js' );
24
26
 
25
27
 
26
28
  // MAIN //
@@ -30,42 +32,44 @@ var isnan = require( '@stdlib/math-base-assert-is-nan' );
30
32
  *
31
33
  * @param {PositiveInteger} N - number of indexed elements
32
34
  * @param {NumericArray} x - input array
33
- * @param {integer} stride - stride length
34
- * @param {NonNegativeInteger} offset - starting index
35
+ * @param {integer} strideX - stride length
36
+ * @param {NonNegativeInteger} offsetX - starting index
35
37
  * @returns {number} sum
36
38
  *
37
39
  * @example
38
- * var floor = require( '@stdlib/math-base-special-floor' );
39
- *
40
40
  * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
41
- * var N = floor( x.length / 2 );
42
41
  *
43
- * var v = gnansumors( N, x, 2, 1 );
42
+ * var v = gnansumors( 4, x, 2, 1 );
44
43
  * // returns 5.0
45
44
  */
46
- function gnansumors( N, x, stride, offset ) {
45
+ function gnansumors( N, x, strideX, offsetX ) {
46
+ var sum;
47
47
  var ix;
48
- var s;
48
+ var o;
49
49
  var i;
50
50
 
51
- s = 0.0;
52
51
  if ( N <= 0 ) {
53
- return s;
52
+ return 0.0;
53
+ }
54
+ o = arraylike2object( x );
55
+ if ( o.accessorProtocol ) {
56
+ return accessors( N, o, strideX, offsetX );
54
57
  }
55
- if ( N === 1 || stride === 0 ) {
56
- if ( isnan( x[ offset ] ) ) {
57
- return s;
58
+ ix = offsetX;
59
+ if ( strideX === 0 ) {
60
+ if ( isnan( x[ ix ] ) ) {
61
+ return 0.0;
58
62
  }
59
- return x[ offset ];
63
+ return N * x[ ix ];
60
64
  }
61
- ix = offset;
65
+ sum = 0.0;
62
66
  for ( i = 0; i < N; i++ ) {
63
67
  if ( isnan( x[ ix ] ) === false ) {
64
- s += x[ ix ];
68
+ sum += x[ ix ];
65
69
  }
66
- ix += stride;
70
+ ix += strideX;
67
71
  }
68
- return s;
72
+ return sum;
69
73
  }
70
74
 
71
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/blas-ext-base-gnansumors",
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 ordinary recursive summation.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,7 +30,9 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/math-base-assert-is-nan": "^0.2.1",
33
+ "@stdlib/array-base-arraylike2object": "^0.2.1",
34
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
35
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
34
36
  "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
35
37
  },
36
38
  "devDependencies": {},
@@ -66,7 +68,6 @@
66
68
  "strided array",
67
69
  "array"
68
70
  ],
69
- "__stdlib__": {},
70
71
  "funding": {
71
72
  "type": "opencollective",
72
73
  "url": "https://opencollective.com/stdlib"