@stdlib/blas-ext-base-gcusumors 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 = gcusumors( N, 0.0, x, 2, y, 1 );
95
+ var v = gcusumors( 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
- gcusumors( N, 0.0, x1, -2, y1, 1 );
114
+ gcusumors( 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
- gcusumors.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 );
141
+ gcusumors.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 @@ gcusumors.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
  - 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.
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 ([`dcusumors`][@stdlib/blas/ext/base/dcusumors], [`scusumors`][@stdlib/blas/ext/base/scusumors], etc.) are likely to be significantly more performant.
167
157
 
168
158
  </section>
@@ -176,20 +166,14 @@ gcusumors.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 gcusumors = require( '@stdlib/blas-ext-base-gcusumors' );
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
 
@@ -250,7 +234,7 @@ See [LICENSE][stdlib-license].
250
234
 
251
235
  ## Copyright
252
236
 
253
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
237
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
254
238
 
255
239
  </section>
256
240
 
@@ -263,8 +247,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
263
247
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-gcusumors.svg
264
248
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-gcusumors
265
249
 
266
- [test-image]: https://github.com/stdlib-js/blas-ext-base-gcusumors/actions/workflows/test.yml/badge.svg?branch=v0.2.2
267
- [test-url]: https://github.com/stdlib-js/blas-ext-base-gcusumors/actions/workflows/test.yml?query=branch:v0.2.2
250
+ [test-image]: https://github.com/stdlib-js/blas-ext-base-gcusumors/actions/workflows/test.yml/badge.svg?branch=v0.3.0
251
+ [test-url]: https://github.com/stdlib-js/blas-ext-base-gcusumors/actions/workflows/test.yml?query=branch:v0.3.0
268
252
 
269
253
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-gcusumors/main.svg
270
254
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-gcusumors?branch=main
@@ -276,8 +260,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
276
260
 
277
261
  -->
278
262
 
279
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
280
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
263
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
264
+ [chat-url]: https://stdlib.zulipchat.com
281
265
 
282
266
  [stdlib]: https://github.com/stdlib-js/stdlib
283
267
 
@@ -298,6 +282,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
298
282
 
299
283
  [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
300
284
 
285
+ [@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
286
+
301
287
  [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
302
288
 
303
289
  <!-- <related-links> -->
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
- "use strict";var c=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var l=c(function(h,x){
2
- function m(e,r,o,t,s,a){var u,n,i;if(e<=0)return s;for(t<0?u=(1-e)*t:u=0,a<0?n=(1-e)*a:n=0,i=0;i<e;i++)r+=o[u],s[n]=r,u+=t,n+=a;return s}x.exports=m
3
- });var q=c(function(j,p){
4
- function y(e,r,o,t,s,a,u,n){var i,v,f;if(e<=0)return a;for(i=s,v=n,f=0;f<e;f++)r+=o[i],a[v]=r,i+=t,v+=u;return a}p.exports=y
5
- });var O=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),g=l(),R=q();O(g,"ndarray",R);module.exports=g;
1
+ "use strict";var g=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=g(function(E,p){
2
+ function R(e,r,o,s,u,a,c,i){var v,n,x,f,t,q,y;for(v=o.data,n=a.data,x=o.accessors[0],f=a.accessors[1],t=u,q=i,y=0;y<e;y++)r+=x(v,t),f(n,q,r),t+=s,q+=c;return a}p.exports=R
3
+ });var l=g(function(F,P){
4
+ var d=require('@stdlib/array-base-arraylike2object/dist'),h=b();function w(e,r,o,s,u,a,c,i){var v,n,x,f,t;if(e<=0)return a;if(x=d(o),f=d(a),x.accessorProtocol||f.accessorProtocol)return h(e,r,x,s,u,f,c,i),a;for(v=u,n=i,t=0;t<e;t++)r+=o[v],a[n]=r,v+=s,n+=c;return a}P.exports=w
5
+ });var m=g(function(G,k){
6
+ var j=require('@stdlib/strided-base-stride2offset/dist'),z=l();function A(e,r,o,s,u,a){var c=j(e,s),i=j(e,a);return z(e,r,o,s,c,u,a,i)}k.exports=A
7
+ });var B=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=m(),C=l();B(O,"ndarray",C);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// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using ordinary recursive summation.\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 = gcusumors( x.length, 0.0, x, 1, y, 1 );\n* // returns [ 1.0, -1.0, 1.0 ]\n*/\nfunction gcusumors( N, sum, x, strideX, y, strideY ) {\n\tvar ix;\n\tvar iy;\n\tvar i;\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\tfor ( i = 0; i < N; i++ ) {\n\t\tsum += x[ ix ];\n\t\ty[ iy ] = sum;\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumors;\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// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using ordinary recursive summation.\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* gcusumors( 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 gcusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar ix;\n\tvar iy;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn y;\n\t}\n\tix = offsetX;\n\tiy = offsetY;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tsum += x[ ix ];\n\t\ty[ iy ] = sum;\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumors;\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 ordinary recursive summation.\n*\n* @module @stdlib/blas-ext-base-gcusumors\n*\n* @example\n* var gcusumors = require( '@stdlib/blas-ext-base-gcusumors' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* gcusumors( 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 gcusumors = require( '@stdlib/blas-ext-base-gcusumors' );\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* gcusumors.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,cAwCA,SAASC,EAAWC,EAAGC,EAAKC,EAAGC,EAASC,EAAGC,EAAU,CACpD,IAAIC,EACAC,EACA,EAEJ,GAAKP,GAAK,EACT,OAAOI,EAYR,IAVKD,EAAU,EACdG,GAAM,EAAEN,GAAKG,EAEbG,EAAK,EAEDD,EAAU,EACdE,GAAM,EAAEP,GAAKK,EAEbE,EAAK,EAEA,EAAI,EAAG,EAAIP,EAAG,IACnBC,GAAOC,EAAGI,CAAG,EACbF,EAAGG,CAAG,EAAIN,EACVK,GAAMH,EACNI,GAAMF,EAEP,OAAOD,CACR,CAKAN,EAAO,QAAUC,ICtEjB,IAAAS,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6CA,SAASC,EAAWC,EAAGC,EAAKC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CACtE,IAAIC,EACAC,EACAC,EAEJ,GAAKV,GAAK,EACT,OAAOK,EAIR,IAFAG,EAAKJ,EACLK,EAAKF,EACCG,EAAI,EAAGA,EAAIV,EAAGU,IACnBT,GAAOC,EAAGM,CAAG,EACbH,EAAGI,CAAG,EAAIR,EACVO,GAAML,EACNM,GAAMH,EAEP,OAAOD,CACR,CAKAP,EAAO,QAAUC,ICnBjB,IAAIY,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "gcusumors", "N", "sum", "x", "strideX", "y", "strideY", "ix", "iy", "require_ndarray", "__commonJSMin", "exports", "module", "gcusumors", "N", "sum", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "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// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using ordinary recursive summation.\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* gcusumors( 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 gcusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar xget;\n\tvar yset;\n\tvar ix;\n\tvar iy;\n\tvar i;\n\n\t// Cache reference to array data:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache reference to the element accessors:\n\txget = x.accessors[ 0 ];\n\tyset = y.accessors[ 1 ];\n\n\tix = offsetX;\n\tiy = offsetY;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tsum += xget( xbuf, ix );\n\t\tyset( ybuf, iy, sum );\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumors;\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 accessors = require( './accessors.js' );\n\n\n// MAIN //\n\n/**\n* Computes the cumulative sum of strided array elements using ordinary recursive summation.\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* gcusumors( 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 gcusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar ix;\n\tvar iy;\n\tvar ox;\n\tvar oy;\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\tfor ( i = 0; i < N; i++ ) {\n\t\tsum += x[ ix ];\n\t\ty[ iy ] = sum;\n\t\tix += strideX;\n\t\tiy += strideY;\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = gcusumors;\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 ordinary recursive summation.\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 = gcusumors( x.length, 0.0, x, 1, y, 1 );\n* // returns [ 1.0, -1.0, 1.0 ]\n*/\nfunction gcusumors( 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 = gcusumors;\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 ordinary recursive summation.\n*\n* @module @stdlib/blas-ext-base-gcusumors\n*\n* @example\n* var gcusumors = require( '@stdlib/blas-ext-base-gcusumors' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* gcusumors( x.length, 0.0, x, 1, y, 1 );\n* // y => [ 1.0, -1.0, 1.0 ]\n*\n* @example\n* var gcusumors = require( '@stdlib/blas-ext-base-gcusumors' );\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* gcusumors.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": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAkDA,SAASC,EAAWC,EAAGC,EAAKC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CACtE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAYJ,IATAN,EAAON,EAAE,KACTO,EAAOJ,EAAE,KAGTK,EAAOR,EAAE,UAAW,CAAE,EACtBS,EAAON,EAAE,UAAW,CAAE,EAEtBO,EAAKR,EACLS,EAAKN,EACCO,EAAI,EAAGA,EAAId,EAAGc,IACnBb,GAAOS,EAAMF,EAAMI,CAAG,EACtBD,EAAMF,EAAMI,EAAIZ,CAAI,EACpBW,GAAMT,EACNU,GAAMP,EAEP,OAAOD,CACR,CAKAP,EAAO,QAAUC,ICjFjB,IAAAgB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAY,IAyBhB,SAASC,EAAWC,EAAGC,EAAKC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CACtE,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKZ,GAAK,EACT,OAAOK,EAIR,GAFAK,EAAKb,EAAkBK,CAAE,EACzBS,EAAKd,EAAkBQ,CAAE,EACpBK,EAAG,kBAAoBC,EAAG,iBAC9B,OAAAb,EAAWE,EAAGC,EAAKS,EAAIP,EAASC,EAASO,EAAIL,EAASC,CAAQ,EACvDF,EAIR,IAFAG,EAAKJ,EACLK,EAAKF,EACCK,EAAI,EAAGA,EAAIZ,EAAGY,IACnBX,GAAOC,EAAGM,CAAG,EACbH,EAAGI,CAAG,EAAIR,EACVO,GAAML,EACNM,GAAMH,EAEP,OAAOD,CACR,CAKAT,EAAO,QAAUG,IC9EjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAuBd,SAASC,EAAWC,EAAGC,EAAKC,EAAGC,EAASC,EAAGC,EAAU,CACpD,IAAIC,EAAKT,EAAeG,EAAGG,CAAQ,EAC/BI,EAAKV,EAAeG,EAAGK,CAAQ,EACnC,OAAOP,EAASE,EAAGC,EAAKC,EAAGC,EAASG,EAAIF,EAAGC,EAASE,CAAG,CACxD,CAKAX,EAAO,QAAUG,ICTjB,IAAIS,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
+ "names": ["require_accessors", "__commonJSMin", "exports", "module", "gcusumors", "N", "sum", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "xbuf", "ybuf", "xget", "yset", "ix", "iy", "i", "require_ndarray", "__commonJSMin", "exports", "module", "arraylike2object", "accessors", "gcusumors", "N", "sum", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "ox", "oy", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "gcusumors", "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 `gcusumors`.
@@ -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
  * gcusumors( 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 ordinary recursive 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
  * gcusumors.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,82 @@
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
+ // MAIN //
22
+
23
+ /**
24
+ * Computes the cumulative sum of strided array elements using ordinary recursive summation.
25
+ *
26
+ * @private
27
+ * @param {PositiveInteger} N - number of indexed elements
28
+ * @param {number} sum - initial sum
29
+ * @param {Object} x - input array object
30
+ * @param {Collection} x.data - input array data
31
+ * @param {Array<Function>} x.accessors - array element accessors
32
+ * @param {integer} strideX - stride length for `x`
33
+ * @param {NonNegativeInteger} offsetX - starting index for `x`
34
+ * @param {Object} y - output array object
35
+ * @param {Collection} y.data - output array data
36
+ * @param {Array<Function>} y.accessors - array element accessors
37
+ * @param {integer} strideY - stride length for `y`
38
+ * @param {NonNegativeInteger} offsetY - starting index for `y`
39
+ * @returns {Object} output array object
40
+ *
41
+ * @example
42
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
43
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
44
+ *
45
+ * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
46
+ * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
47
+ *
48
+ * gcusumors( 4, 0.0, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );
49
+ * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
50
+ */
51
+ function gcusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
52
+ var xbuf;
53
+ var ybuf;
54
+ var xget;
55
+ var yset;
56
+ var ix;
57
+ var iy;
58
+ var i;
59
+
60
+ // Cache reference to array data:
61
+ xbuf = x.data;
62
+ ybuf = y.data;
63
+
64
+ // Cache reference to the element accessors:
65
+ xget = x.accessors[ 0 ];
66
+ yset = y.accessors[ 1 ];
67
+
68
+ ix = offsetX;
69
+ iy = offsetY;
70
+ for ( i = 0; i < N; i++ ) {
71
+ sum += xget( xbuf, ix );
72
+ yset( ybuf, iy, sum );
73
+ ix += strideX;
74
+ iy += strideY;
75
+ }
76
+ return y;
77
+ }
78
+
79
+
80
+ // EXPORTS //
81
+
82
+ module.exports = gcusumors;
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 gcusumors = require( '@stdlib/blas-ext-base-gcusumors' );
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
- * gcusumors.ndarray( N, 0.0, x, 2, 1, y, 1, 0 );
41
+ * gcusumors.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
@@ -18,6 +18,12 @@
18
18
 
19
19
  'use strict';
20
20
 
21
+ // MODULES //
22
+
23
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
25
+
26
+
21
27
  // MAIN //
22
28
 
23
29
  /**
@@ -26,9 +32,9 @@
26
32
  * @param {PositiveInteger} N - number of indexed elements
27
33
  * @param {number} sum - initial sum
28
34
  * @param {NumericArray} x - input array
29
- * @param {integer} strideX - `x` stride length
35
+ * @param {integer} strideX - stride length for `x`
30
36
  * @param {NumericArray} y - output array
31
- * @param {integer} strideY - `y` stride length
37
+ * @param {integer} strideY - stride length for `y`
32
38
  * @returns {NumericArray} output array
33
39
  *
34
40
  * @example
@@ -39,30 +45,9 @@
39
45
  * // returns [ 1.0, -1.0, 1.0 ]
40
46
  */
41
47
  function gcusumors( N, sum, x, strideX, y, strideY ) {
42
- var ix;
43
- var iy;
44
- var i;
45
-
46
- if ( N <= 0 ) {
47
- return y;
48
- }
49
- if ( strideX < 0 ) {
50
- ix = (1-N) * strideX;
51
- } else {
52
- ix = 0;
53
- }
54
- if ( strideY < 0 ) {
55
- iy = (1-N) * strideY;
56
- } else {
57
- iy = 0;
58
- }
59
- for ( i = 0; i < N; i++ ) {
60
- sum += x[ ix ];
61
- y[ iy ] = sum;
62
- ix += strideX;
63
- iy += strideY;
64
- }
65
- return y;
48
+ var ox = stride2offset( N, strideX );
49
+ var oy = stride2offset( N, strideY );
50
+ return ndarray( N, sum, x, strideX, ox, y, strideY, oy );
66
51
  }
67
52
 
68
53
 
package/lib/ndarray.js CHANGED
@@ -18,6 +18,12 @@
18
18
 
19
19
  'use strict';
20
20
 
21
+ // MODULES //
22
+
23
+ var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
24
+ var accessors = require( './accessors.js' );
25
+
26
+
21
27
  // MAIN //
22
28
 
23
29
  /**
@@ -26,31 +32,36 @@
26
32
  * @param {PositiveInteger} N - number of indexed elements
27
33
  * @param {number} sum - initial sum
28
34
  * @param {NumericArray} x - input array
29
- * @param {integer} strideX - `x` stride length
35
+ * @param {integer} strideX - stride length for `x`
30
36
  * @param {NonNegativeInteger} offsetX - starting index for `x`
31
37
  * @param {NumericArray} y - output array
32
- * @param {integer} strideY - `y` stride length
38
+ * @param {integer} strideY - stride length for `y`
33
39
  * @param {NonNegativeInteger} offsetY - starting index for `y`
34
40
  * @returns {NumericArray} output array
35
41
  *
36
42
  * @example
37
- * var floor = require( '@stdlib/math-base-special-floor' );
38
- *
39
43
  * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
40
44
  * 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
45
  *
43
- * gcusumors( N, 0.0, x, 2, 1, y, 1, 0 );
46
+ * gcusumors( 4, 0.0, x, 2, 1, y, 1, 0 );
44
47
  * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
45
48
  */
46
49
  function gcusumors( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
47
50
  var ix;
48
51
  var iy;
52
+ var ox;
53
+ var oy;
49
54
  var i;
50
55
 
51
56
  if ( N <= 0 ) {
52
57
  return y;
53
58
  }
59
+ ox = arraylike2object( x );
60
+ oy = arraylike2object( y );
61
+ if ( ox.accessorProtocol || oy.accessorProtocol ) {
62
+ accessors( N, sum, ox, strideX, offsetX, oy, strideY, offsetY );
63
+ return y;
64
+ }
54
65
  ix = offsetX;
55
66
  iy = offsetY;
56
67
  for ( i = 0; i < N; i++ ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/blas-ext-base-gcusumors",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Calculate the cumulative sum of strided array elements using ordinary recursive summation.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,6 +30,8 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
+ "@stdlib/array-base-arraylike2object": "^0.2.1",
34
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
33
35
  "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
34
36
  },
35
37
  "devDependencies": {},
@@ -68,7 +70,6 @@
68
70
  "typed",
69
71
  "array"
70
72
  ],
71
- "__stdlib__": {},
72
73
  "funding": {
73
74
  "type": "opencollective",
74
75
  "url": "https://opencollective.com/stdlib"