@stdlib/stats-base-cumax 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 +1 -1
- package/README.md +22 -25
- package/dist/index.js +8 -7
- package/dist/index.js.map +4 -4
- package/docs/types/index.d.ts +20 -10
- package/lib/accessors.js +110 -0
- package/lib/index.js +9 -5
- package/lib/main.js +23 -3
- package/lib/ndarray.js +13 -6
- package/package.json +5 -4
- package/lib/cumax.js +0 -99
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -75,11 +75,11 @@ The function has the following parameters:
|
|
|
75
75
|
|
|
76
76
|
- **N**: number of indexed elements.
|
|
77
77
|
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
|
|
78
|
-
- **strideX**:
|
|
78
|
+
- **strideX**: stride length for `x`.
|
|
79
79
|
- **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
|
|
80
|
-
- **strideY**:
|
|
80
|
+
- **strideY**: stride length for `y`.
|
|
81
81
|
|
|
82
|
-
The `N` and
|
|
82
|
+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative maximum of every other element in `x`,
|
|
83
83
|
|
|
84
84
|
```javascript
|
|
85
85
|
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
|
|
@@ -125,7 +125,7 @@ The function has the following additional parameters:
|
|
|
125
125
|
- **offsetX**: starting index for `x`.
|
|
126
126
|
- **offsetY**: starting index for `y`.
|
|
127
127
|
|
|
128
|
-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying
|
|
128
|
+
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 maximum of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element
|
|
129
129
|
|
|
130
130
|
```javascript
|
|
131
131
|
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
|
|
@@ -144,7 +144,8 @@ cumax.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
|
|
|
144
144
|
## Notes
|
|
145
145
|
|
|
146
146
|
- If `N <= 0`, both functions return `y` unchanged.
|
|
147
|
-
- Depending on the environment, the typed versions ([`dcumax`][@stdlib/stats/
|
|
147
|
+
- Depending on the environment, the typed versions ([`dcumax`][@stdlib/stats/strided/dcumax], [`scumax`][@stdlib/stats/strided/scumax], etc.) are likely to be significantly more performant.
|
|
148
|
+
- 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]).
|
|
148
149
|
|
|
149
150
|
</section>
|
|
150
151
|
|
|
@@ -157,20 +158,14 @@ cumax.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
|
|
|
157
158
|
<!-- eslint no-undef: "error" -->
|
|
158
159
|
|
|
159
160
|
```javascript
|
|
160
|
-
var
|
|
161
|
-
var round = require( '@stdlib/math-base-special-round' );
|
|
161
|
+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
|
|
162
162
|
var Float64Array = require( '@stdlib/array-float64' );
|
|
163
163
|
var cumax = require( '@stdlib/stats-base-cumax' );
|
|
164
164
|
|
|
165
|
-
var
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
x = new Float64Array( 10 );
|
|
170
|
-
y = new Float64Array( x.length );
|
|
171
|
-
for ( i = 0; i < x.length; i++ ) {
|
|
172
|
-
x[ i ] = round( randu()*100.0 );
|
|
173
|
-
}
|
|
165
|
+
var x = discreteUniform( 10, 0, 100, {
|
|
166
|
+
'dtype': 'float64'
|
|
167
|
+
});
|
|
168
|
+
var y = new Float64Array( x.length );
|
|
174
169
|
console.log( x );
|
|
175
170
|
console.log( y );
|
|
176
171
|
|
|
@@ -197,8 +192,8 @@ console.log( y );
|
|
|
197
192
|
## See Also
|
|
198
193
|
|
|
199
194
|
- <span class="package-name">[`@stdlib/stats-base/cumin`][@stdlib/stats/base/cumin]</span><span class="delimiter">: </span><span class="description">calculate the cumulative minimum of a strided array.</span>
|
|
200
|
-
- <span class="package-name">[`@stdlib/stats-
|
|
201
|
-
- <span class="package-name">[`@stdlib/stats-
|
|
195
|
+
- <span class="package-name">[`@stdlib/stats-strided/dcumax`][@stdlib/stats/strided/dcumax]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum of double-precision floating-point strided array elements.</span>
|
|
196
|
+
- <span class="package-name">[`@stdlib/stats-strided/scumax`][@stdlib/stats/strided/scumax]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum of single-precision floating-point strided array elements.</span>
|
|
202
197
|
|
|
203
198
|
</section>
|
|
204
199
|
|
|
@@ -230,7 +225,7 @@ See [LICENSE][stdlib-license].
|
|
|
230
225
|
|
|
231
226
|
## Copyright
|
|
232
227
|
|
|
233
|
-
Copyright © 2016-
|
|
228
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
234
229
|
|
|
235
230
|
</section>
|
|
236
231
|
|
|
@@ -243,8 +238,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
243
238
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-cumax.svg
|
|
244
239
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-cumax
|
|
245
240
|
|
|
246
|
-
[test-image]: https://github.com/stdlib-js/stats-base-cumax/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
247
|
-
[test-url]: https://github.com/stdlib-js/stats-base-cumax/actions/workflows/test.yml?query=branch:v0.
|
|
241
|
+
[test-image]: https://github.com/stdlib-js/stats-base-cumax/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
242
|
+
[test-url]: https://github.com/stdlib-js/stats-base-cumax/actions/workflows/test.yml?query=branch:v0.3.0
|
|
248
243
|
|
|
249
244
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-cumax/main.svg
|
|
250
245
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-cumax?branch=main
|
|
@@ -256,8 +251,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
256
251
|
|
|
257
252
|
-->
|
|
258
253
|
|
|
259
|
-
[chat-image]: https://img.shields.io/
|
|
260
|
-
[chat-url]: https://
|
|
254
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
255
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
261
256
|
|
|
262
257
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
263
258
|
|
|
@@ -278,15 +273,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
278
273
|
|
|
279
274
|
[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
280
275
|
|
|
276
|
+
[@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
|
|
277
|
+
|
|
281
278
|
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
|
282
279
|
|
|
283
280
|
<!-- <related-links> -->
|
|
284
281
|
|
|
285
282
|
[@stdlib/stats/base/cumin]: https://www.npmjs.com/package/@stdlib/stats-base-cumin
|
|
286
283
|
|
|
287
|
-
[@stdlib/stats/
|
|
284
|
+
[@stdlib/stats/strided/dcumax]: https://www.npmjs.com/package/@stdlib/stats-strided-dcumax
|
|
288
285
|
|
|
289
|
-
[@stdlib/stats/
|
|
286
|
+
[@stdlib/stats/strided/scumax]: https://www.npmjs.com/package/@stdlib/stats-strided-scumax
|
|
290
287
|
|
|
291
288
|
<!-- </related-links> -->
|
|
292
289
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var k=
|
|
4
|
-
var
|
|
5
|
-
});var
|
|
6
|
-
var
|
|
7
|
-
});var
|
|
1
|
+
"use strict";var b=function(v,o){return function(){return o||v((o={exports:{}}).exports,o),o.exports}};var Z=b(function(J,y){
|
|
2
|
+
var p=require('@stdlib/math-base-assert-is-nan/dist'),z=require('@stdlib/math-base-assert-is-positive-zero/dist');function A(v,o,f,l,a,c,m){var e,t,s,n,i,u,r,x,q;if(e=o.data,t=a.data,s=o.accessors[0],n=a.accessors[1],u=l,r=m,i=s(e,u),n(t,r,i),r+=c,q=1,p(i)===!1)for(q;q<v;q++){if(u+=f,x=s(e,u),p(x)){i=x;break}(x>i||x===i&&z(x))&&(i=x),n(t,r,i),r+=c}if(p(i))for(q;q<v;q++)n(t,r,i),r+=c;return a}y.exports=A
|
|
3
|
+
});var k=b(function(K,j){
|
|
4
|
+
var P=require('@stdlib/math-base-assert-is-nan/dist'),B=require('@stdlib/math-base-assert-is-positive-zero/dist'),g=require('@stdlib/array-base-arraylike2object/dist'),C=Z();function D(v,o,f,l,a,c,m){var e,t,s,n,i,u,r;if(v<=0)return a;if(n=g(o),i=g(a),n.accessorProtocol||i.accessorProtocol)return C(v,n,f,l,i,c,m),a;if(t=l,s=m,e=o[t],a[s]=e,s+=c,r=1,P(e)===!1)for(r;r<v;r++){if(t+=f,u=o[t],P(u)){e=u;break}(u>e||u===e&&B(u))&&(e=u),a[s]=e,s+=c}if(P(e))for(r;r<v;r++)a[s]=e,s+=c;return a}j.exports=D
|
|
5
|
+
});var h=b(function(L,R){
|
|
6
|
+
var O=require('@stdlib/strided-base-stride2offset/dist'),E=k();function F(v,o,f,l,a){var c=O(v,f),m=O(v,a);return E(v,o,f,c,l,a,m)}R.exports=F
|
|
7
|
+
});var G=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),w=h(),H=k();G(w,"ndarray",H);module.exports=w;
|
|
8
|
+
/** @license Apache-2.0 */
|
|
8
9
|
/** @license Apache-2.0 */
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../lib/
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c)
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAiB,QAAS,2CAA4C,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../lib/accessors.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );\n\n\n// MAIN //\n\n/**\n* Computes the cumulative maximum of a strided array.\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* @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* cumax( 4, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );\n* // y => [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];\n*/\nfunction cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar xbuf;\n\tvar ybuf;\n\tvar xget;\n\tvar yset;\n\tvar max;\n\tvar ix;\n\tvar iy;\n\tvar v;\n\tvar i;\n\n\t// Cache reference to array data:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache a reference to the element accessor:\n\txget = x.accessors[ 0 ];\n\tyset = y.accessors[ 1 ];\n\n\tix = offsetX;\n\tiy = offsetY;\n\n\tmax = xget( xbuf, ix );\n\tyset( ybuf, iy, max );\n\n\tiy += strideY;\n\ti = 1;\n\tif ( isnan( max ) === false ) {\n\t\tfor ( i; i < N; i++ ) {\n\t\t\tix += strideX;\n\t\t\tv = xget( xbuf, ix );\n\t\t\tif ( isnan( v ) ) {\n\t\t\t\tmax = v;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif ( v > max || ( v === max && isPositiveZero( v ) ) ) {\n\t\t\t\tmax = v;\n\t\t\t}\n\t\t\tyset( ybuf, iy, max );\n\t\t\tiy += strideY;\n\t\t}\n\t}\n\tif ( isnan( max ) ) {\n\t\tfor ( i; i < N; i++ ) {\n\t\t\tyset( ybuf, iy, max );\n\t\t\tiy += strideY;\n\t\t}\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = cumax;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar accessors = require( './accessors.js' );\n\n\n// MAIN //\n\n/**\n* Computes the cumulative maximum of a strided array.\n*\n* @param {PositiveInteger} N - number of indexed elements\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* var v = cumax( 4, x, 2, 1, y, 1, 0 );\n* // returns [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {\n\tvar max;\n\tvar ix;\n\tvar iy;\n\tvar ox;\n\tvar oy;\n\tvar v;\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, ox, strideX, offsetX, oy, strideY, offsetY );\n\t\treturn y;\n\t}\n\tix = offsetX;\n\tiy = offsetY;\n\n\tmax = x[ ix ];\n\ty[ iy ] = max;\n\n\tiy += strideY;\n\ti = 1;\n\tif ( isnan( max ) === false ) {\n\t\tfor ( i; i < N; i++ ) {\n\t\t\tix += strideX;\n\t\t\tv = x[ ix ];\n\t\t\tif ( isnan( v ) ) {\n\t\t\t\tmax = v;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif ( v > max || ( v === max && isPositiveZero( v ) ) ) {\n\t\t\t\tmax = v;\n\t\t\t}\n\t\t\ty[ iy ] = max;\n\t\t\tiy += strideY;\n\t\t}\n\t}\n\tif ( isnan( max ) ) {\n\t\tfor ( i; i < N; i++ ) {\n\t\t\ty[ iy ] = max;\n\t\t\tiy += strideY;\n\t\t}\n\t}\n\treturn y;\n}\n\n\n// EXPORTS //\n\nmodule.exports = cumax;\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 maximum of a strided array.\n*\n* @param {PositiveInteger} N - number of indexed elements\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 = cumax( 3, x, 1, y, 1 );\n* // returns [ 1.0, 1.0, 2.0 ]\n*/\nfunction cumax( N, x, strideX, y, strideY ) {\n\tvar ix = stride2offset( N, strideX );\n\tvar iy = stride2offset( N, strideY );\n\treturn ndarray( N, x, strideX, ix, y, strideY, iy );\n}\n\n\n// EXPORTS //\n\nmodule.exports = cumax;\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 maximum of a strided array.\n*\n* @module @stdlib/stats-base-cumax\n*\n* @example\n* var cumax = require( '@stdlib/stats-base-cumax' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n*\n* cumax( 3, x, 1, y, 1 );\n* // y => [ 1.0, 1.0, 2.0 ]\n*\n* @example\n* var cumax = require( '@stdlib/stats-base-cumax' );\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* cumax.ndarray( 4, x, 2, 1, y, 1, 0 );\n* // y => [ 1.0, 1.0, 2.0, 4.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\n// exports: { \"ndarray\": \"main.ndarray\" }\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["require_accessors", "__commonJSMin", "exports", "module", "isnan", "isPositiveZero", "cumax", "N", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "xbuf", "ybuf", "xget", "yset", "max", "ix", "iy", "v", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "isPositiveZero", "arraylike2object", "accessors", "cumax", "N", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "max", "ix", "iy", "ox", "oy", "v", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "cumax", "N", "x", "strideX", "y", "strideY", "ix", "iy", "setReadOnly", "main", "ndarray"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -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 `cumax`.
|
|
@@ -31,9 +41,9 @@ interface Routine {
|
|
|
31
41
|
*
|
|
32
42
|
* @param N - number of indexed elements
|
|
33
43
|
* @param x - input array
|
|
34
|
-
* @param strideX - `x`
|
|
44
|
+
* @param strideX - stride length for `x`
|
|
35
45
|
* @param y - output array
|
|
36
|
-
* @param strideY - `y`
|
|
46
|
+
* @param strideY - stride length for `y`
|
|
37
47
|
* @returns output array
|
|
38
48
|
*
|
|
39
49
|
* @example
|
|
@@ -43,17 +53,17 @@ interface Routine {
|
|
|
43
53
|
* cumax( x.length, x, 1, y, 1 );
|
|
44
54
|
* // y => [ 1.0, 1.0, 2.0 ]
|
|
45
55
|
*/
|
|
46
|
-
( N: number, x:
|
|
56
|
+
<T extends OutputArray>( N: number, x: InputArray, strideX: number, y: T, strideY: number ): T;
|
|
47
57
|
|
|
48
58
|
/**
|
|
49
59
|
* Computes the cumulative maximum of a strided array using alternative indexing semantics.
|
|
50
60
|
*
|
|
51
61
|
* @param N - number of indexed elements
|
|
52
62
|
* @param x - input array
|
|
53
|
-
* @param strideX - `x`
|
|
63
|
+
* @param strideX - stride length for `x`
|
|
54
64
|
* @param offsetX - starting index for `x`
|
|
55
65
|
* @param y - output array
|
|
56
|
-
* @param strideY - `y`
|
|
66
|
+
* @param strideY - stride length for `y`
|
|
57
67
|
* @param offsetY - starting index for `y`
|
|
58
68
|
* @returns output array
|
|
59
69
|
*
|
|
@@ -64,7 +74,7 @@ interface Routine {
|
|
|
64
74
|
* cumax.ndarray( x.length, x, 1, 0, y, 1, 0 );
|
|
65
75
|
* // y => [ 1.0, 1.0, 2.0 ]
|
|
66
76
|
*/
|
|
67
|
-
ndarray( N: number, x:
|
|
77
|
+
ndarray<T extends OutputArray>( N: number, x: InputArray, strideX: number, offsetX: number, y: T, strideY: number, offsetY: number ): T;
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/**
|
|
@@ -72,9 +82,9 @@ interface Routine {
|
|
|
72
82
|
*
|
|
73
83
|
* @param N - number of indexed elements
|
|
74
84
|
* @param x - input array
|
|
75
|
-
* @param strideX - `x`
|
|
85
|
+
* @param strideX - stride length for `x`
|
|
76
86
|
* @param y - output array
|
|
77
|
-
* @param strideY - `y`
|
|
87
|
+
* @param strideY - stride length for `y`
|
|
78
88
|
* @returns output array
|
|
79
89
|
*
|
|
80
90
|
* @example
|
|
@@ -85,7 +95,7 @@ interface Routine {
|
|
|
85
95
|
* // y => [ 1.0, 1.0, 2.0 ]
|
|
86
96
|
*
|
|
87
97
|
* @example
|
|
88
|
-
* var x = [ 1.0, -2.0, 2.0 ]
|
|
98
|
+
* var x = [ 1.0, -2.0, 2.0 ];
|
|
89
99
|
* var y = [ 0.0, 0.0, 0.0 ];
|
|
90
100
|
*
|
|
91
101
|
* cumax.ndarray( x.length, x, 1, 0, y, 1, 0 );
|
package/lib/accessors.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
24
|
+
var isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Computes the cumulative maximum of a strided array.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
34
|
+
* @param {Object} x - input array object
|
|
35
|
+
* @param {Collection} x.data - input array data
|
|
36
|
+
* @param {Array<Function>} x.accessors - array element accessors
|
|
37
|
+
* @param {integer} strideX - stride length for `x`
|
|
38
|
+
* @param {NonNegativeInteger} offsetX - starting index for `x`
|
|
39
|
+
* @param {Object} y - output array object
|
|
40
|
+
* @param {Collection} y.data - output array data
|
|
41
|
+
* @param {Array<Function>} y.accessors - array element accessors
|
|
42
|
+
* @param {integer} strideY - stride length for `y`
|
|
43
|
+
* @param {NonNegativeInteger} offsetY - starting index for `y`
|
|
44
|
+
* @returns {Object} output array object
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
|
|
48
|
+
* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
49
|
+
*
|
|
50
|
+
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
|
|
51
|
+
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
|
|
52
|
+
*
|
|
53
|
+
* cumax( 4, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );
|
|
54
|
+
* // y => [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];
|
|
55
|
+
*/
|
|
56
|
+
function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
|
|
57
|
+
var xbuf;
|
|
58
|
+
var ybuf;
|
|
59
|
+
var xget;
|
|
60
|
+
var yset;
|
|
61
|
+
var max;
|
|
62
|
+
var ix;
|
|
63
|
+
var iy;
|
|
64
|
+
var v;
|
|
65
|
+
var i;
|
|
66
|
+
|
|
67
|
+
// Cache reference to array data:
|
|
68
|
+
xbuf = x.data;
|
|
69
|
+
ybuf = y.data;
|
|
70
|
+
|
|
71
|
+
// Cache a reference to the element accessor:
|
|
72
|
+
xget = x.accessors[ 0 ];
|
|
73
|
+
yset = y.accessors[ 1 ];
|
|
74
|
+
|
|
75
|
+
ix = offsetX;
|
|
76
|
+
iy = offsetY;
|
|
77
|
+
|
|
78
|
+
max = xget( xbuf, ix );
|
|
79
|
+
yset( ybuf, iy, max );
|
|
80
|
+
|
|
81
|
+
iy += strideY;
|
|
82
|
+
i = 1;
|
|
83
|
+
if ( isnan( max ) === false ) {
|
|
84
|
+
for ( i; i < N; i++ ) {
|
|
85
|
+
ix += strideX;
|
|
86
|
+
v = xget( xbuf, ix );
|
|
87
|
+
if ( isnan( v ) ) {
|
|
88
|
+
max = v;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if ( v > max || ( v === max && isPositiveZero( v ) ) ) {
|
|
92
|
+
max = v;
|
|
93
|
+
}
|
|
94
|
+
yset( ybuf, iy, max );
|
|
95
|
+
iy += strideY;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if ( isnan( max ) ) {
|
|
99
|
+
for ( i; i < N; i++ ) {
|
|
100
|
+
yset( ybuf, iy, max );
|
|
101
|
+
iy += strideY;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return y;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
// EXPORTS //
|
|
109
|
+
|
|
110
|
+
module.exports = cumax;
|
package/lib/index.js
CHANGED
|
@@ -28,26 +28,30 @@
|
|
|
28
28
|
*
|
|
29
29
|
* var x = [ 1.0, -2.0, 2.0 ];
|
|
30
30
|
* var y = [ 0.0, 0.0, 0.0 ];
|
|
31
|
-
* var N = x.length;
|
|
32
31
|
*
|
|
33
|
-
* cumax(
|
|
32
|
+
* cumax( 3, x, 1, y, 1 );
|
|
34
33
|
* // y => [ 1.0, 1.0, 2.0 ]
|
|
35
34
|
*
|
|
36
35
|
* @example
|
|
37
|
-
* var floor = require( '@stdlib/math-base-special-floor' );
|
|
38
36
|
* var cumax = require( '@stdlib/stats-base-cumax' );
|
|
39
37
|
*
|
|
40
38
|
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
|
|
41
39
|
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
|
|
42
|
-
* var N = floor( x.length / 2 );
|
|
43
40
|
*
|
|
44
|
-
* cumax.ndarray(
|
|
41
|
+
* cumax.ndarray( 4, x, 2, 1, y, 1, 0 );
|
|
45
42
|
* // y => [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
|
|
46
43
|
*/
|
|
47
44
|
|
|
48
45
|
// MODULES //
|
|
49
46
|
|
|
47
|
+
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
50
48
|
var main = require( './main.js' );
|
|
49
|
+
var ndarray = require( './ndarray.js' );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// MAIN //
|
|
53
|
+
|
|
54
|
+
setReadOnly( main, 'ndarray', ndarray );
|
|
51
55
|
|
|
52
56
|
|
|
53
57
|
// EXPORTS //
|
package/lib/main.js
CHANGED
|
@@ -20,14 +20,34 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var cumax = require( './cumax.js' );
|
|
23
|
+
var stride2offset = require( '@stdlib/strided-base-stride2offset' );
|
|
25
24
|
var ndarray = require( './ndarray.js' );
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
// MAIN //
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Computes the cumulative maximum of a strided array.
|
|
31
|
+
*
|
|
32
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
33
|
+
* @param {NumericArray} x - input array
|
|
34
|
+
* @param {integer} strideX - stride length for `x`
|
|
35
|
+
* @param {NumericArray} y - output array
|
|
36
|
+
* @param {integer} strideY - stride length for `y`
|
|
37
|
+
* @returns {NumericArray} output array
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var x = [ 1.0, -2.0, 2.0 ];
|
|
41
|
+
* var y = [ 0.0, 0.0, 0.0 ];
|
|
42
|
+
*
|
|
43
|
+
* var v = cumax( 3, x, 1, y, 1 );
|
|
44
|
+
* // returns [ 1.0, 1.0, 2.0 ]
|
|
45
|
+
*/
|
|
46
|
+
function cumax( N, x, strideX, y, strideY ) {
|
|
47
|
+
var ix = stride2offset( N, strideX );
|
|
48
|
+
var iy = stride2offset( N, strideY );
|
|
49
|
+
return ndarray( N, x, strideX, ix, y, strideY, iy );
|
|
50
|
+
}
|
|
31
51
|
|
|
32
52
|
|
|
33
53
|
// EXPORTS //
|
package/lib/ndarray.js
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
24
24
|
var isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );
|
|
25
|
+
var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
26
|
+
var accessors = require( './accessors.js' );
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
// MAIN //
|
|
@@ -31,33 +33,38 @@ var isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );
|
|
|
31
33
|
*
|
|
32
34
|
* @param {PositiveInteger} N - number of indexed elements
|
|
33
35
|
* @param {NumericArray} x - input array
|
|
34
|
-
* @param {integer} strideX - `x`
|
|
36
|
+
* @param {integer} strideX - stride length for `x`
|
|
35
37
|
* @param {NonNegativeInteger} offsetX - starting index for `x`
|
|
36
38
|
* @param {NumericArray} y - output array
|
|
37
|
-
* @param {integer} strideY - `y`
|
|
39
|
+
* @param {integer} strideY - stride length for `y`
|
|
38
40
|
* @param {NonNegativeInteger} offsetY - starting index for `y`
|
|
39
41
|
* @returns {NumericArray} output array
|
|
40
42
|
*
|
|
41
43
|
* @example
|
|
42
|
-
* var floor = require( '@stdlib/math-base-special-floor' );
|
|
43
|
-
*
|
|
44
44
|
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
|
|
45
45
|
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
|
|
46
|
-
* var N = floor( x.length / 2 );
|
|
47
46
|
*
|
|
48
|
-
* var v = cumax(
|
|
47
|
+
* var v = cumax( 4, x, 2, 1, y, 1, 0 );
|
|
49
48
|
* // returns [ 1.0, 1.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
|
|
50
49
|
*/
|
|
51
50
|
function cumax( N, x, strideX, offsetX, y, strideY, offsetY ) {
|
|
52
51
|
var max;
|
|
53
52
|
var ix;
|
|
54
53
|
var iy;
|
|
54
|
+
var ox;
|
|
55
|
+
var oy;
|
|
55
56
|
var v;
|
|
56
57
|
var i;
|
|
57
58
|
|
|
58
59
|
if ( N <= 0 ) {
|
|
59
60
|
return y;
|
|
60
61
|
}
|
|
62
|
+
ox = arraylike2object( x );
|
|
63
|
+
oy = arraylike2object( y );
|
|
64
|
+
if ( ox.accessorProtocol || oy.accessorProtocol ) {
|
|
65
|
+
accessors( N, ox, strideX, offsetX, oy, strideY, offsetY );
|
|
66
|
+
return y;
|
|
67
|
+
}
|
|
61
68
|
ix = offsetX;
|
|
62
69
|
iy = offsetY;
|
|
63
70
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-cumax",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Calculate the cumulative maximum of a strided array.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -30,8 +30,10 @@
|
|
|
30
30
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@stdlib/
|
|
34
|
-
"@stdlib/math-base-assert-is-
|
|
33
|
+
"@stdlib/array-base-arraylike2object": "^0.2.1",
|
|
34
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
35
|
+
"@stdlib/math-base-assert-is-positive-zero": "^0.2.2",
|
|
36
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
35
37
|
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {},
|
|
@@ -69,7 +71,6 @@
|
|
|
69
71
|
"strided array",
|
|
70
72
|
"array"
|
|
71
73
|
],
|
|
72
|
-
"__stdlib__": {},
|
|
73
74
|
"funding": {
|
|
74
75
|
"type": "opencollective",
|
|
75
76
|
"url": "https://opencollective.com/stdlib"
|
package/lib/cumax.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
// MODULES //
|
|
22
|
-
|
|
23
|
-
var isnan = require( '@stdlib/math-base-assert-is-nan' );
|
|
24
|
-
var isPositiveZero = require( '@stdlib/math-base-assert-is-positive-zero' );
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// MAIN //
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Computes the cumulative maximum of a strided array.
|
|
31
|
-
*
|
|
32
|
-
* @param {PositiveInteger} N - number of indexed elements
|
|
33
|
-
* @param {NumericArray} x - input array
|
|
34
|
-
* @param {integer} strideX - `x` stride length
|
|
35
|
-
* @param {NumericArray} y - output array
|
|
36
|
-
* @param {integer} strideY - `y` stride length
|
|
37
|
-
* @returns {NumericArray} output array
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* var x = [ 1.0, -2.0, 2.0 ];
|
|
41
|
-
* var y = [ 0.0, 0.0, 0.0 ];
|
|
42
|
-
* var N = x.length;
|
|
43
|
-
*
|
|
44
|
-
* var v = cumax( N, x, 1, y, 1 );
|
|
45
|
-
* // returns [ 1.0, 1.0, 2.0 ]
|
|
46
|
-
*/
|
|
47
|
-
function cumax( N, x, strideX, y, strideY ) {
|
|
48
|
-
var max;
|
|
49
|
-
var ix;
|
|
50
|
-
var iy;
|
|
51
|
-
var v;
|
|
52
|
-
var i;
|
|
53
|
-
|
|
54
|
-
if ( N <= 0 ) {
|
|
55
|
-
return y;
|
|
56
|
-
}
|
|
57
|
-
if ( strideX < 0 ) {
|
|
58
|
-
ix = (1-N) * strideX;
|
|
59
|
-
} else {
|
|
60
|
-
ix = 0;
|
|
61
|
-
}
|
|
62
|
-
if ( strideY < 0 ) {
|
|
63
|
-
iy = (1-N) * strideY;
|
|
64
|
-
} else {
|
|
65
|
-
iy = 0;
|
|
66
|
-
}
|
|
67
|
-
max = x[ ix ];
|
|
68
|
-
y[ iy ] = max;
|
|
69
|
-
|
|
70
|
-
iy += strideY;
|
|
71
|
-
i = 1;
|
|
72
|
-
if ( isnan( max ) === false ) {
|
|
73
|
-
for ( i; i < N; i++ ) {
|
|
74
|
-
ix += strideX;
|
|
75
|
-
v = x[ ix ];
|
|
76
|
-
if ( isnan( v ) ) {
|
|
77
|
-
max = v;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
if ( v > max || ( v === max && isPositiveZero( v ) ) ) {
|
|
81
|
-
max = v;
|
|
82
|
-
}
|
|
83
|
-
y[ iy ] = max;
|
|
84
|
-
iy += strideY;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if ( isnan( max ) ) {
|
|
88
|
-
for ( i; i < N; i++ ) {
|
|
89
|
-
y[ iy ] = max;
|
|
90
|
-
iy += strideY;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return y;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// EXPORTS //
|
|
98
|
-
|
|
99
|
-
module.exports = cumax;
|