@stdlib/blas-ext-base-gcusumpw 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
@@ -82,21 +82,17 @@ The function has the following parameters:
82
82
  - **N**: number of indexed elements.
83
83
  - **sum**: initial sum.
84
84
  - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
85
- - **strideX**: index increment for `x`.
85
+ - **strideX**: stride length for `x`.
86
86
  - **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
87
- - **strideY**: index increment for `y`.
87
+ - **strideY**: stride length for `y`.
88
88
 
89
- The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`,
89
+ The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element:
90
90
 
91
91
  ```javascript
92
- var floor = require( '@stdlib/math-base-special-floor' );
93
-
94
92
  var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
95
93
  var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
96
94
 
97
- var N = floor( x.length / 2 );
98
-
99
- var v = gcusumpw( N, 0.0, x, 2, y, 1 );
95
+ var v = gcusumpw( 4, 0.0, x, 2, y, 1 );
100
96
  // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
101
97
  ```
102
98
 
@@ -106,7 +102,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [
106
102
 
107
103
  ```javascript
108
104
  var Float64Array = require( '@stdlib/array-float64' );
109
- var floor = require( '@stdlib/math-base-special-floor' );
110
105
 
111
106
  // Initial arrays...
112
107
  var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
@@ -116,9 +111,7 @@ var y0 = new Float64Array( x0.length );
116
111
  var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
117
112
  var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element
118
113
 
119
- var N = floor( x0.length / 2 );
120
-
121
- gcusumpw( N, 0.0, x1, -2, y1, 1 );
114
+ gcusumpw( 4, 0.0, x1, -2, y1, 1 );
122
115
  // y0 => <Float64Array>[ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ]
123
116
  ```
124
117
 
@@ -139,17 +132,13 @@ The function has the following additional parameters:
139
132
  - **offsetX**: starting index for `x`.
140
133
  - **offsetY**: starting index for `y`.
141
134
 
142
- While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element
135
+ While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative sum of every other element in the strided input array starting from the second element and to store in the last `N` elements of the strided output array starting from the last element:
143
136
 
144
137
  ```javascript
145
- var floor = require( '@stdlib/math-base-special-floor' );
146
-
147
138
  var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
148
139
  var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
149
140
 
150
- var N = floor( x.length / 2 );
151
-
152
- gcusumpw.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
141
+ gcusumpw.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 );
153
142
  // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ]
154
143
  ```
155
144
 
@@ -163,6 +152,7 @@ gcusumpw.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
163
152
 
164
153
  - If `N <= 0`, both functions return `y` unchanged.
165
154
  - In general, pairwise summation is more numerically stable than ordinary recursive summation (i.e., "simple" summation), with slightly worse performance. While not the most numerically stable summation technique (e.g., compensated summation techniques such as the Kahan–Babuška-Neumaier algorithm are generally more numerically stable), pairwise summation strikes a reasonable balance between numerical stability and performance. If either numerical stability or performance is more desirable for your use case, consider alternative summation techniques.
155
+ - 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]).
166
156
  - Depending on the environment, the typed versions ([`dcusumpw`][@stdlib/blas/ext/base/dcusumpw], [`scusumpw`][@stdlib/blas/ext/base/scusumpw], etc.) are likely to be significantly more performant.
167
157
 
168
158
  </section>
@@ -176,20 +166,14 @@ gcusumpw.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
176
166
  <!-- eslint no-undef: "error" -->
177
167
 
178
168
  ```javascript
179
- var randu = require( '@stdlib/random-base-randu' );
180
- var round = require( '@stdlib/math-base-special-round' );
169
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
181
170
  var Float64Array = require( '@stdlib/array-float64' );
182
171
  var gcusumpw = require( '@stdlib/blas-ext-base-gcusumpw' );
183
172
 
184
- var y;
185
- var x;
186
- var i;
187
-
188
- x = new Float64Array( 10 );
189
- y = new Float64Array( x.length );
190
- for ( i = 0; i < x.length; i++ ) {
191
- x[ i ] = round( randu()*100.0 );
192
- }
173
+ var x = discreteUniform( 10, -100, 100, {
174
+ 'dtype': 'float64'
175
+ });
176
+ var y = new Float64Array( x.length );
193
177
  console.log( x );
194
178
  console.log( y );
195
179
 
@@ -255,7 +239,7 @@ See [LICENSE][stdlib-license].
255
239
 
256
240
  ## Copyright
257
241
 
258
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
242
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
259
243
 
260
244
  </section>
261
245
 
@@ -268,8 +252,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
268
252
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-gcusumpw.svg
269
253
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-gcusumpw
270
254
 
271
- [test-image]: https://github.com/stdlib-js/blas-ext-base-gcusumpw/actions/workflows/test.yml/badge.svg?branch=v0.2.2
272
- [test-url]: https://github.com/stdlib-js/blas-ext-base-gcusumpw/actions/workflows/test.yml?query=branch:v0.2.2
255
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-gcusumpw/actions/workflows/test.yml/badge.svg?branch=v0.3.0
256
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-gcusumpw/actions/workflows/test.yml?query=branch:v0.3.0
273
257
 
274
258
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-gcusumpw/main.svg
275
259
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-gcusumpw?branch=main
@@ -281,8 +265,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
281
265
 
282
266
  -->
283
267
 
284
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
285
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
268
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
269
+ [chat-url]: https://stdlib.zulipchat.com
286
270
 
287
271
  [stdlib]: https://github.com/stdlib-js/stdlib
288
272
 
@@ -305,6 +289,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
305
289
 
306
290
  [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
307
291
 
292
+ [@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
293
+
308
294
  [@higham:1993a]: https://doi.org/10.1137/0914050
309
295
 
310
296
  <!-- <related-links> -->
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
- "use strict";var m=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var s=m(function(S,x){
2
- var B=require('@stdlib/math-base-special-floor/dist'),C=128;function l(r,a,i,n,t,u,e,f){var c,v,p,o,q;if(r<=0)return u;if(c=t,v=f,r<=C){for(p=0,q=0;q<r;q++)p+=i[c],u[v]=a+p,c+=n,v+=e;return u}return o=B(r/2),l(o,a,i,n,c,u,e,v),v+=(o-1)*e,l(r-o,u[v],i,n,c+o*n,u,e,v+e),u}x.exports=l
3
- });var w=m(function(Z,g){
4
- var E=s();function I(r,a,i,n,t,u){var e,f;return r<=0?t:(n<0?e=(1-r)*n:e=0,u<0?f=(1-r)*u:f=0,E(r,a,i,n,e,t,u,f))}g.exports=I
5
- });var K=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=w(),L=s();K(O,"ndarray",L);module.exports=O;
1
+ "use strict";var x=function(a,o){return function(){return o||a((o={exports:{}}).exports,o),o.exports}};var I=x(function(M,E){
2
+ var k=require('@stdlib/math-base-special-floor/dist'),R=128;function O(a,o,f,u,i,r,v,p){var q,c,s,l,t,e,n,b,g,w;if(q=f.data,c=r.data,s=f.accessors[0],l=r.accessors[0],t=r.accessors[1],e=i,n=p,a<=R){for(b=s(q,e),t(c,n,o+b),e+=u,n+=v,w=1;w<a;w++)b+=s(q,e),t(c,n,o+b),e+=u,n+=v;return r}return g=k(a/2),O(g,o,f,u,e,r,v,n),n+=(g-1)*v,O(a-g,l(c,n),f,u,e+g*u,r,v,n+v),r}E.exports=O
3
+ });var C=x(function(Q,L){
4
+ var K=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/math-base-special-floor/dist'),z=I(),A=128;function B(a,o,f,u,i,r,v,p){var q,c,s,l,t,e,n;if(a<=0)return r;if(s=K(f),l=K(r),s.accessorProtocol||l.accessorProtocol)return z(a,o,s,u,i,l,v,p),r;if(q=i,c=p,a<=A){for(t=f[q],r[c]=o+t,q+=u,c+=v,n=1;n<a;n++)t+=f[q],r[c]=o+t,q+=u,c+=v;return r}return e=h(a/2),B(e,o,f,u,q,r,v,c),c+=(e-1)*v,B(a-e,r[c],f,u,q+e*u,r,v,c+v),r}L.exports=B
5
+ });var Z=x(function(T,S){
6
+ var P=require('@stdlib/strided-base-stride2offset/dist'),D=C();function F(a,o,f,u,i,r){var v=P(a,u),p=P(a,r);return D(a,o,f,u,v,i,r,p)}S.exports=F
7
+ });var G=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=Z(),H=C();G(j,"ndarray",H);module.exports=j;
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/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 floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\n// Blocksize for pairwise summation:\nvar BLOCKSIZE = 128;\n\n\n// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using pairwise summation.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} sum - initial sum\n* @param {NumericArray} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @param {NumericArray} y - output array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - starting index for `y`\n* @returns {NumericArray} output array\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 y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];\n* var N = floor( x.length / 2 );\n*\n* gcusumpw( N, 0.0, x, 2, 1, y, 1, 0 );\n* // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar ix;\n\tvar iy;\n\tvar s;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn y;\n\t}\n\tix = offsetX;\n\tiy = offsetY;\n\tif ( N <= BLOCKSIZE ) {\n\t\ts = 0.0;\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\ts += x[ ix ];\n\t\t\ty[ iy ] = sum + s;\n\t\t\tix += strideX;\n\t\t\tiy += strideY;\n\t\t}\n\t\treturn y;\n\t}\n\tn = floor( N/2 );\n\tgcusumpw( n, sum, x, strideX, ix, y, strideY, iy );\n\tiy += (n-1) * strideY;\n\tgcusumpw( N-n, y[ iy ], x, strideX, ix+(n*strideX), y, strideY, iy+strideY ); // eslint-disable-line max-len\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumpw;\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 cusum = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using pairwise summation.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} sum - initial sum\n* @param {NumericArray} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {NumericArray} y - output array\n* @param {integer} strideY - `y` stride length\n* @returns {NumericArray} output array\n*\n* @example\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* var v = gcusumpw( x.length, 0.0, x, 1, y, 1 );\n* // returns [ 1.0, -1.0, 1.0 ]\n*/\nfunction gcusumpw( N, sum, x, strideX, y, strideY ) {\n\tvar ix;\n\tvar iy;\n\n\tif ( N <= 0 ) {\n\t\treturn y;\n\t}\n\tif ( strideX < 0 ) {\n\t\tix = (1-N) * strideX;\n\t} else {\n\t\tix = 0;\n\t}\n\tif ( strideY < 0 ) {\n\t\tiy = (1-N) * strideY;\n\t} else {\n\t\tiy = 0;\n\t}\n\treturn cusum( N, sum, x, strideX, ix, y, strideY, iy );\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumpw;\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 cumulative sum of strided array elements using pairwise summation.\n*\n* @module @stdlib/blas-ext-base-gcusumpw\n*\n* @example\n* var gcusumpw = require( '@stdlib/blas-ext-base-gcusumpw' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* gcusumpw( x.length, 0.0, x, 1, y, 1 );\n* // y => [ 1.0, -1.0, 1.0 ]\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var gcusumpw = require( '@stdlib/blas-ext-base-gcusumpw' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];\n* var N = floor( x.length / 2 );\n*\n* gcusumpw.ndarray( N, 0.0, x, 2, 1, y, 1, 0 );\n* // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.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,EAMnDC,EAAY,IAoChB,SAASC,EAAUC,EAAGC,EAAKC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CACrE,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKZ,GAAK,EACT,OAAOK,EAIR,GAFAG,EAAKJ,EACLK,EAAKF,EACAP,GAAKF,EAAY,CAErB,IADAY,EAAI,EACEE,EAAI,EAAGA,EAAIZ,EAAGY,IACnBF,GAAKR,EAAGM,CAAG,EACXH,EAAGI,CAAG,EAAIR,EAAMS,EAChBF,GAAML,EACNM,GAAMH,EAEP,OAAOD,CACR,CACA,OAAAM,EAAId,EAAOG,EAAE,CAAE,EACfD,EAAUY,EAAGV,EAAKC,EAAGC,EAASK,EAAIH,EAAGC,EAASG,CAAG,EACjDA,IAAOE,EAAE,GAAKL,EACdP,EAAUC,EAAEW,EAAGN,EAAGI,CAAG,EAAGP,EAAGC,EAASK,EAAIG,EAAER,EAAUE,EAAGC,EAASG,EAAGH,CAAQ,EACpED,CACR,CAKAT,EAAO,QAAUG,IChGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,IA+BZ,SAASC,EAAUC,EAAGC,EAAKC,EAAGC,EAASC,EAAGC,EAAU,CACnD,IAAIC,EACAC,EAEJ,OAAKP,GAAK,EACFI,GAEHD,EAAU,EACdG,GAAM,EAAEN,GAAKG,EAEbG,EAAK,EAEDD,EAAU,EACdE,GAAM,EAAEP,GAAKK,EAEbE,EAAK,EAECT,EAAOE,EAAGC,EAAKC,EAAGC,EAASG,EAAIF,EAAGC,EAASE,CAAG,EACtD,CAKAV,EAAO,QAAUE,IC5BjB,IAAIS,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
- "names": ["require_ndarray", "__commonJSMin", "exports", "module", "floor", "BLOCKSIZE", "gcusumpw", "N", "sum", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "s", "n", "i", "require_main", "__commonJSMin", "exports", "module", "cusum", "gcusumpw", "N", "sum", "x", "strideX", "y", "strideY", "ix", "iy", "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 floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\n// Blocksize for pairwise summation:\nvar BLOCKSIZE = 128;\n\n\n// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using pairwise summation.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @private\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} sum - initial sum\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* @param {Object} y - output array object\n* @param {Collection} y.data - output array data\n* @param {Array<Function>} y.accessors - array element accessors\n* @param {integer} strideY - stride length for `y`\n* @param {NonNegativeInteger} offsetY - starting index for `y`\n* @returns {Object} output array object\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 = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];\n*\n* gcusumpw( 4, 0.0, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );\n* // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar xget;\n\tvar yget;\n\tvar yset;\n\tvar ix;\n\tvar iy;\n\tvar s;\n\tvar n;\n\tvar i;\n\n\t// Cache reference to array data:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache references to the element accessors:\n\txget = x.accessors[ 0 ];\n\tyget = y.accessors[ 0 ];\n\tyset = y.accessors[ 1 ];\n\n\tix = offsetX;\n\tiy = offsetY;\n\tif ( N <= BLOCKSIZE ) {\n\t\ts = xget( xbuf, ix );\n\t\tyset( ybuf, iy, sum + s);\n\t\tix += strideX;\n\t\tiy += strideY;\n\t\tfor ( i = 1; i < N; i++ ) {\n\t\t\ts += xget( xbuf, ix );\n\t\t\tyset( ybuf, iy, sum + s);\n\t\t\tix += strideX;\n\t\t\tiy += strideY;\n\t\t}\n\t\treturn y;\n\t}\n\tn = floor( N/2 );\n\tgcusumpw( n, sum, x, strideX, ix, y, strideY, iy );\n\tiy += (n-1) * strideY;\n\tgcusumpw( N-n, yget( ybuf, iy ), x, strideX, ix+(n*strideX), y, strideY, iy+strideY ); // eslint-disable-line max-len\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumpw;\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 floor = require( '@stdlib/math-base-special-floor' );\nvar accessors = require( './accessors.js' );\n\n\n// VARIABLES //\n\n// Blocksize for pairwise summation:\nvar BLOCKSIZE = 128;\n\n\n// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using pairwise summation.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} sum - initial sum\n* @param {NumericArray} x - input array\n* @param {integer} strideX - stride length for `x`\n* @param {NonNegativeInteger} offsetX - starting index for `x`\n* @param {NumericArray} y - output array\n* @param {integer} strideY - stride length for `y`\n* @param {NonNegativeInteger} offsetY - starting index for `y`\n* @returns {NumericArray} output array\n*\n* @example\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];\n*\n* gcusumpw( 4, 0.0, x, 2, 1, y, 1, 0 );\n* // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar ix;\n\tvar iy;\n\tvar ox;\n\tvar oy;\n\tvar s;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn y;\n\t}\n\tox = arraylike2object( x );\n\toy = arraylike2object( y );\n\tif ( ox.accessorProtocol || oy.accessorProtocol ) {\n\t\taccessors( N, sum, ox, strideX, offsetX, oy, strideY, offsetY );\n\t\treturn y;\n\t}\n\tix = offsetX;\n\tiy = offsetY;\n\tif ( N <= BLOCKSIZE ) {\n\t\ts = x[ ix ];\n\t\ty[ iy ] = sum + s;\n\t\tix += strideX;\n\t\tiy += strideY;\n\t\tfor ( i = 1; i < N; i++ ) {\n\t\t\ts += x[ ix ];\n\t\t\ty[ iy ] = sum + s;\n\t\t\tix += strideX;\n\t\t\tiy += strideY;\n\t\t}\n\t\treturn y;\n\t}\n\tn = floor( N/2 );\n\tgcusumpw( n, sum, x, strideX, ix, y, strideY, iy );\n\tiy += (n-1) * strideY;\n\tgcusumpw( N-n, y[ iy ], x, strideX, ix+(n*strideX), y, strideY, iy+strideY ); // eslint-disable-line max-len\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumpw;\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 cumulative sum of strided array elements using pairwise summation.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} sum - initial sum\n* @param {NumericArray} x - input array\n* @param {integer} strideX - stride length for `x`\n* @param {NumericArray} y - output array\n* @param {integer} strideY - stride length for `y`\n* @returns {NumericArray} output array\n*\n* @example\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* var v = gcusumpw( x.length, 0.0, x, 1, y, 1 );\n* // returns [ 1.0, -1.0, 1.0 ]\n*/\nfunction gcusumpw( N, sum, x, strideX, y, strideY ) {\n\tvar ox = stride2offset( N, strideX );\n\tvar oy = stride2offset( N, strideY );\n\treturn ndarray( N, sum, x, strideX, ox, y, strideY, oy );\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumpw;\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 cumulative sum of strided array elements using pairwise summation.\n*\n* @module @stdlib/blas-ext-base-gcusumpw\n*\n* @example\n* var gcusumpw = require( '@stdlib/blas-ext-base-gcusumpw' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* gcusumpw( x.length, 0.0, x, 1, y, 1 );\n* // y => [ 1.0, -1.0, 1.0 ]\n*\n* @example\n* var gcusumpw = require( '@stdlib/blas-ext-base-gcusumpw' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];\n*\n* gcusumpw.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 );\n* // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.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": "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",
6
+ "names": ["require_accessors", "__commonJSMin", "exports", "module", "floor", "BLOCKSIZE", "gcusumpw", "N", "sum", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "xbuf", "ybuf", "xget", "yget", "yset", "ix", "iy", "s", "n", "i", "require_ndarray", "__commonJSMin", "exports", "module", "arraylike2object", "floor", "accessors", "BLOCKSIZE", "gcusumpw", "N", "sum", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "ox", "oy", "s", "n", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "gcusumpw", "N", "sum", "x", "strideX", "y", "strideY", "ox", "oy", "setReadOnly", "main", "ndarray"]
7
7
  }
@@ -20,7 +20,17 @@
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>;
29
+
30
+ /**
31
+ * Output array.
32
+ */
33
+ type OutputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
24
34
 
25
35
  /**
26
36
  * Interface describing `gcusumpw`.
@@ -32,9 +42,9 @@ interface Routine {
32
42
  * @param N - number of indexed elements
33
43
  * @param sum - initial sum
34
44
  * @param x - input array
35
- * @param strideX - `x` stride length
45
+ * @param strideX - stride length for `x`
36
46
  * @param y - output array
37
- * @param strideY - `y` stride length
47
+ * @param strideY - stride length for `y`
38
48
  * @returns output array
39
49
  *
40
50
  * @example
@@ -44,7 +54,7 @@ interface Routine {
44
54
  * gcusumpw( x.length, 0.0, x, 1, y, 1 );
45
55
  * // y => [ 1.0, -1.0, 1.0 ]
46
56
  */
47
- ( N: number, sum: number, x: NumericArray, strideX: number, y: NumericArray, strideY: number ): NumericArray;
57
+ <T extends OutputArray>( N: number, sum: number, x: InputArray, strideX: number, y: T, strideY: number ): T;
48
58
 
49
59
  /**
50
60
  * Computes the cumulative sum of strided array elements using pairwise summation and alternative indexing semantics.
@@ -52,10 +62,10 @@ interface Routine {
52
62
  * @param N - number of indexed elements
53
63
  * @param sum - initial sum
54
64
  * @param x - input array
55
- * @param strideX - `x` stride length
65
+ * @param strideX - stride length for `x`
56
66
  * @param offsetX - starting index for `x`
57
67
  * @param y - output array
58
- * @param strideY - `y` stride length
68
+ * @param strideY - stride length for `y`
59
69
  * @param offsetY - starting index for `y`
60
70
  * @returns output array
61
71
  *
@@ -66,7 +76,7 @@ interface Routine {
66
76
  * gcusumpw.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 );
67
77
  * // y => [ 1.0, -1.0, 1.0 ]
68
78
  */
69
- ndarray( N: number, sum: number, x: NumericArray, strideX: number, offsetX: number, y: NumericArray, strideY: number, offsetY: number ): NumericArray;
79
+ ndarray<T extends OutputArray>( N: number, sum: number, x: InputArray, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number ): T;
70
80
  }
71
81
 
72
82
  /**
@@ -75,9 +85,9 @@ interface Routine {
75
85
  * @param N - number of indexed elements
76
86
  * @param sum - initial sum
77
87
  * @param x - input array
78
- * @param strideX - `x` stride length
88
+ * @param strideX - stride length for `x`
79
89
  * @param y - output array
80
- * @param strideY - `y` stride length
90
+ * @param strideY - stride length for `y`
81
91
  * @returns output array
82
92
  *
83
93
  * @example
@@ -0,0 +1,116 @@
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 floor = require( '@stdlib/math-base-special-floor' );
24
+
25
+
26
+ // VARIABLES //
27
+
28
+ // Blocksize for pairwise summation:
29
+ var BLOCKSIZE = 128;
30
+
31
+
32
+ // MAIN //
33
+
34
+ /**
35
+ * Computes the cumulative sum of strided array elements using pairwise summation.
36
+ *
37
+ * ## Method
38
+ *
39
+ * - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.
40
+ *
41
+ * ## References
42
+ *
43
+ * - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).
44
+ *
45
+ * @private
46
+ * @param {PositiveInteger} N - number of indexed elements
47
+ * @param {number} sum - initial sum
48
+ * @param {Object} x - input array object
49
+ * @param {Collection} x.data - input array data
50
+ * @param {Array<Function>} x.accessors - array element accessors
51
+ * @param {integer} strideX - stride length for `x`
52
+ * @param {NonNegativeInteger} offsetX - starting index for `x`
53
+ * @param {Object} y - output array object
54
+ * @param {Collection} y.data - output array data
55
+ * @param {Array<Function>} y.accessors - array element accessors
56
+ * @param {integer} strideY - stride length for `y`
57
+ * @param {NonNegativeInteger} offsetY - starting index for `y`
58
+ * @returns {Object} output array object
59
+ *
60
+ * @example
61
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
62
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
63
+ *
64
+ * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
65
+ * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
66
+ *
67
+ * gcusumpw( 4, 0.0, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );
68
+ * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
69
+ */
70
+ function gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
71
+ var xbuf;
72
+ var ybuf;
73
+ var xget;
74
+ var yget;
75
+ var yset;
76
+ var ix;
77
+ var iy;
78
+ var s;
79
+ var n;
80
+ var i;
81
+
82
+ // Cache reference to array data:
83
+ xbuf = x.data;
84
+ ybuf = y.data;
85
+
86
+ // Cache references to the element accessors:
87
+ xget = x.accessors[ 0 ];
88
+ yget = y.accessors[ 0 ];
89
+ yset = y.accessors[ 1 ];
90
+
91
+ ix = offsetX;
92
+ iy = offsetY;
93
+ if ( N <= BLOCKSIZE ) {
94
+ s = xget( xbuf, ix );
95
+ yset( ybuf, iy, sum + s);
96
+ ix += strideX;
97
+ iy += strideY;
98
+ for ( i = 1; i < N; i++ ) {
99
+ s += xget( xbuf, ix );
100
+ yset( ybuf, iy, sum + s);
101
+ ix += strideX;
102
+ iy += strideY;
103
+ }
104
+ return y;
105
+ }
106
+ n = floor( N/2 );
107
+ gcusumpw( n, sum, x, strideX, ix, y, strideY, iy );
108
+ iy += (n-1) * strideY;
109
+ gcusumpw( N-n, yget( ybuf, iy ), x, strideX, ix+(n*strideX), y, strideY, iy+strideY ); // eslint-disable-line max-len
110
+ return y;
111
+ }
112
+
113
+
114
+ // EXPORTS //
115
+
116
+ module.exports = gcusumpw;
package/lib/index.js CHANGED
@@ -33,14 +33,12 @@
33
33
  * // y => [ 1.0, -1.0, 1.0 ]
34
34
  *
35
35
  * @example
36
- * var floor = require( '@stdlib/math-base-special-floor' );
37
36
  * var gcusumpw = require( '@stdlib/blas-ext-base-gcusumpw' );
38
37
  *
39
38
  * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
40
39
  * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
41
- * var N = floor( x.length / 2 );
42
40
  *
43
- * gcusumpw.ndarray( N, 0.0, x, 2, 1, y, 1, 0 );
41
+ * gcusumpw.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 );
44
42
  * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
45
43
  */
46
44
 
package/lib/main.js CHANGED
@@ -20,7 +20,8 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var cusum = require( './ndarray.js' );
23
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
24
25
 
25
26
 
26
27
  // MAIN //
@@ -39,9 +40,9 @@ var cusum = require( './ndarray.js' );
39
40
  * @param {PositiveInteger} N - number of indexed elements
40
41
  * @param {number} sum - initial sum
41
42
  * @param {NumericArray} x - input array
42
- * @param {integer} strideX - `x` stride length
43
+ * @param {integer} strideX - stride length for `x`
43
44
  * @param {NumericArray} y - output array
44
- * @param {integer} strideY - `y` stride length
45
+ * @param {integer} strideY - stride length for `y`
45
46
  * @returns {NumericArray} output array
46
47
  *
47
48
  * @example
@@ -52,23 +53,9 @@ var cusum = require( './ndarray.js' );
52
53
  * // returns [ 1.0, -1.0, 1.0 ]
53
54
  */
54
55
  function gcusumpw( N, sum, x, strideX, y, strideY ) {
55
- var ix;
56
- var iy;
57
-
58
- if ( N <= 0 ) {
59
- return y;
60
- }
61
- if ( strideX < 0 ) {
62
- ix = (1-N) * strideX;
63
- } else {
64
- ix = 0;
65
- }
66
- if ( strideY < 0 ) {
67
- iy = (1-N) * strideY;
68
- } else {
69
- iy = 0;
70
- }
71
- return cusum( N, sum, x, strideX, ix, y, strideY, iy );
56
+ var ox = stride2offset( N, strideX );
57
+ var oy = stride2offset( N, strideY );
58
+ return ndarray( N, sum, x, strideX, ox, y, strideY, oy );
72
59
  }
73
60
 
74
61
 
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 floor = require( '@stdlib/math-base-special-floor' );
25
+ var accessors = require( './accessors.js' );
24
26
 
25
27
 
26
28
  // VARIABLES //
@@ -45,26 +47,25 @@ var BLOCKSIZE = 128;
45
47
  * @param {PositiveInteger} N - number of indexed elements
46
48
  * @param {number} sum - initial sum
47
49
  * @param {NumericArray} x - input array
48
- * @param {integer} strideX - `x` stride length
50
+ * @param {integer} strideX - stride length for `x`
49
51
  * @param {NonNegativeInteger} offsetX - starting index for `x`
50
52
  * @param {NumericArray} y - output array
51
- * @param {integer} strideY - `y` stride length
53
+ * @param {integer} strideY - stride length for `y`
52
54
  * @param {NonNegativeInteger} offsetY - starting index for `y`
53
55
  * @returns {NumericArray} output array
54
56
  *
55
57
  * @example
56
- * var floor = require( '@stdlib/math-base-special-floor' );
57
- *
58
58
  * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
59
59
  * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
60
- * var N = floor( x.length / 2 );
61
60
  *
62
- * gcusumpw( N, 0.0, x, 2, 1, y, 1, 0 );
61
+ * gcusumpw( 4, 0.0, x, 2, 1, y, 1, 0 );
63
62
  * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
64
63
  */
65
64
  function gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
66
65
  var ix;
67
66
  var iy;
67
+ var ox;
68
+ var oy;
68
69
  var s;
69
70
  var n;
70
71
  var i;
@@ -72,11 +73,20 @@ function gcusumpw( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
72
73
  if ( N <= 0 ) {
73
74
  return y;
74
75
  }
76
+ ox = arraylike2object( x );
77
+ oy = arraylike2object( y );
78
+ if ( ox.accessorProtocol || oy.accessorProtocol ) {
79
+ accessors( N, sum, ox, strideX, offsetX, oy, strideY, offsetY );
80
+ return y;
81
+ }
75
82
  ix = offsetX;
76
83
  iy = offsetY;
77
84
  if ( N <= BLOCKSIZE ) {
78
- s = 0.0;
79
- for ( i = 0; i < N; i++ ) {
85
+ s = x[ ix ];
86
+ y[ iy ] = sum + s;
87
+ ix += strideX;
88
+ iy += strideY;
89
+ for ( i = 1; i < N; i++ ) {
80
90
  s += x[ ix ];
81
91
  y[ iy ] = sum + s;
82
92
  ix += strideX;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/blas-ext-base-gcusumpw",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Calculate the cumulative sum of strided array elements using pairwise 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/array-base-arraylike2object": "^0.2.1",
33
34
  "@stdlib/math-base-special-floor": "^0.2.3",
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": {},
@@ -69,7 +71,6 @@
69
71
  "typed",
70
72
  "array"
71
73
  ],
72
- "__stdlib__": {},
73
74
  "funding": {
74
75
  "type": "opencollective",
75
76
  "url": "https://opencollective.com/stdlib"