@stdlib/stats-base-cumaxabs 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 +7 -0
- package/lib/main.js +24 -3
- package/lib/ndarray.js +13 -6
- package/package.json +4 -3
- package/lib/cumaxabs.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 absolute value 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 a starting indices. For example, to calculate the cumulative maximum absolute value 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
|
|
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 @@ cumaxabs.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 ([`dcumaxabs`][@stdlib/stats/
|
|
147
|
+
- Depending on the environment, the typed versions ([`dcumaxabs`][@stdlib/stats/strided/dcumaxabs], [`scumaxabs`][@stdlib/stats/strided/scumaxabs], 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 @@ cumaxabs.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 cumaxabs = require( '@stdlib/stats-base-cumaxabs' );
|
|
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
|
|
|
@@ -198,8 +193,8 @@ console.log( y );
|
|
|
198
193
|
|
|
199
194
|
- <span class="package-name">[`@stdlib/stats-base/cumax`][@stdlib/stats/base/cumax]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum of a strided array.</span>
|
|
200
195
|
- <span class="package-name">[`@stdlib/stats-base/cuminabs`][@stdlib/stats/base/cuminabs]</span><span class="delimiter">: </span><span class="description">calculate the cumulative minimum absolute value of a strided array.</span>
|
|
201
|
-
- <span class="package-name">[`@stdlib/stats-
|
|
202
|
-
- <span class="package-name">[`@stdlib/stats-
|
|
196
|
+
- <span class="package-name">[`@stdlib/stats-strided/dcumaxabs`][@stdlib/stats/strided/dcumaxabs]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum absolute value of double-precision floating-point strided array elements.</span>
|
|
197
|
+
- <span class="package-name">[`@stdlib/stats-strided/scumaxabs`][@stdlib/stats/strided/scumaxabs]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum absolute value of single-precision floating-point strided array elements.</span>
|
|
203
198
|
|
|
204
199
|
</section>
|
|
205
200
|
|
|
@@ -231,7 +226,7 @@ See [LICENSE][stdlib-license].
|
|
|
231
226
|
|
|
232
227
|
## Copyright
|
|
233
228
|
|
|
234
|
-
Copyright © 2016-
|
|
229
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
235
230
|
|
|
236
231
|
</section>
|
|
237
232
|
|
|
@@ -244,8 +239,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
244
239
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-cumaxabs.svg
|
|
245
240
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-cumaxabs
|
|
246
241
|
|
|
247
|
-
[test-image]: https://github.com/stdlib-js/stats-base-cumaxabs/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
248
|
-
[test-url]: https://github.com/stdlib-js/stats-base-cumaxabs/actions/workflows/test.yml?query=branch:v0.
|
|
242
|
+
[test-image]: https://github.com/stdlib-js/stats-base-cumaxabs/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
243
|
+
[test-url]: https://github.com/stdlib-js/stats-base-cumaxabs/actions/workflows/test.yml?query=branch:v0.3.0
|
|
249
244
|
|
|
250
245
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-cumaxabs/main.svg
|
|
251
246
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-cumaxabs?branch=main
|
|
@@ -257,8 +252,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
257
252
|
|
|
258
253
|
-->
|
|
259
254
|
|
|
260
|
-
[chat-image]: https://img.shields.io/
|
|
261
|
-
[chat-url]: https://
|
|
255
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
256
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
262
257
|
|
|
263
258
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
264
259
|
|
|
@@ -279,6 +274,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
279
274
|
|
|
280
275
|
[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
281
276
|
|
|
277
|
+
[@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
|
|
278
|
+
|
|
282
279
|
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
|
283
280
|
|
|
284
281
|
<!-- <related-links> -->
|
|
@@ -287,9 +284,9 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
287
284
|
|
|
288
285
|
[@stdlib/stats/base/cuminabs]: https://www.npmjs.com/package/@stdlib/stats-base-cuminabs
|
|
289
286
|
|
|
290
|
-
[@stdlib/stats/
|
|
287
|
+
[@stdlib/stats/strided/dcumaxabs]: https://www.npmjs.com/package/@stdlib/stats-strided-dcumaxabs
|
|
291
288
|
|
|
292
|
-
[@stdlib/stats/
|
|
289
|
+
[@stdlib/stats/strided/scumaxabs]: https://www.npmjs.com/package/@stdlib/stats-strided-scumaxabs
|
|
293
290
|
|
|
294
291
|
<!-- </related-links> -->
|
|
295
292
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
4
|
-
var
|
|
5
|
-
});var
|
|
6
|
-
var
|
|
7
|
-
});var
|
|
1
|
+
"use strict";var m=function(e,i){return function(){return i||e((i={exports:{}}).exports,i),i.exports}};var j=m(function(K,g){
|
|
2
|
+
var p=require('@stdlib/math-base-assert-is-nan/dist'),P=require('@stdlib/math-base-special-abs/dist');function C(e,i,f,q,a,o,b){var v,n,u,t,s,c,r,l,x;if(v=i.data,n=a.data,u=i.accessors[0],t=a.accessors[1],c=q,r=b,s=P(u(v,c)),t(n,r,s),r+=o,x=1,p(s)===!1)for(x;x<e;x++){if(c+=f,l=P(u(v,c)),p(l)){s=l;break}l>s&&(s=l),t(n,r,s),r+=o}if(p(s))for(x;x<e;x++)t(n,r,s),r+=o;return a}g.exports=C
|
|
3
|
+
});var y=m(function(L,h){
|
|
4
|
+
var k=require('@stdlib/math-base-assert-is-nan/dist'),O=require('@stdlib/math-base-special-abs/dist'),R=require('@stdlib/array-base-arraylike2object/dist'),D=j();function E(e,i,f,q,a,o,b){var v,n,u,t,s,c,r;if(e<=0)return a;if(t=R(i),s=R(a),t.accessorProtocol||s.accessorProtocol)return D(e,t,f,q,s,o,b),a;if(n=q,u=b,v=O(i[n]),a[u]=v,u+=o,r=1,k(v)===!1)for(r;r<e;r++){if(n+=f,c=O(i[n]),k(c)){v=c;break}c>v&&(v=c),a[u]=v,u+=o}if(k(v))for(r;r<e;r++)a[u]=v,u+=o;return a}h.exports=E
|
|
5
|
+
});var A=m(function(M,z){
|
|
6
|
+
var w=require('@stdlib/strided-base-stride2offset/dist'),F=y();function G(e,i,f,q,a){var o=w(e,f),b=w(e,a);return F(e,i,f,o,q,a,b)}z.exports=G
|
|
7
|
+
});var H=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),B=A(),I=y();H(B,"ndarray",I);module.exports=B;
|
|
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,EAAM,QAAS,+BAAgC,
|
|
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 abs = require( '@stdlib/math-base-special-abs' );\n\n\n// MAIN //\n\n/**\n* Computes the cumulative maximum absolute value 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* cumaxabs( 4, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );\n* // y => [ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];\n*/\nfunction cumaxabs( 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 references to array data:\n\txbuf = x.data;\n\tybuf = y.data;\n\n\t// Cache references to element accessors:\n\txget = x.accessors[ 0 ];\n\tyset = y.accessors[ 1 ];\n\n\tix = offsetX;\n\tiy = offsetY;\n\n\tmax = abs( 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 = abs( 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 ) {\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 = cumaxabs;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar accessors = require( './accessors.js' );\n\n\n// MAIN //\n\n/**\n* Computes the cumulative maximum absolute value 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 = cumaxabs( 4, x, 2, 1, y, 1, 0 );\n* // returns [ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction cumaxabs( 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 = abs( 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 = abs( 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 ) {\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 = cumaxabs;\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 absolute value 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* var N = x.length;\n*\n* var v = cumaxabs( N, x, 1, y, 1 );\n* // returns [ 1.0, 2.0, 2.0 ]\n*/\nfunction cumaxabs( 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 = cumaxabs;\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 absolute value of a strided array.\n*\n* @module @stdlib/stats-base-cumaxabs\n*\n* @example\n* var cumaxabs = require( '@stdlib/stats-base-cumaxabs' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var y = [ 0.0, 0.0, 0.0 ];\n* var N = x.length;\n*\n* cumaxabs( N, x, 1, y, 1 );\n* // y => [ 1.0, 2.0, 2.0 ]\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var cumaxabs = require( '@stdlib/stats-base-cumaxabs' );\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* cumaxabs.ndarray( N, x, 2, 1, y, 1, 0 );\n* // y => [ 1.0, 2.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": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAgCnD,SAASC,EAAUC,EAAGC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAkBJ,GAfAR,EAAON,EAAE,KACTO,EAAOJ,EAAE,KAGTK,EAAOR,EAAE,UAAW,CAAE,EACtBS,EAAON,EAAE,UAAW,CAAE,EAEtBQ,EAAKT,EACLU,EAAKP,EAELK,EAAMb,EAAKW,EAAMF,EAAMK,CAAG,CAAE,EAC5BF,EAAMF,EAAMK,EAAIF,CAAI,EAEpBE,GAAMR,EACNU,EAAI,EACClB,EAAOc,CAAI,IAAM,GACrB,IAAMI,EAAGA,EAAIf,EAAGe,IAAM,CAGrB,GAFAH,GAAMV,EACNY,EAAIhB,EAAKW,EAAMF,EAAMK,CAAG,CAAE,EACrBf,EAAOiB,CAAE,EAAI,CACjBH,EAAMG,EACN,KACD,CACKA,EAAIH,IACRA,EAAMG,GAEPJ,EAAMF,EAAMK,EAAIF,CAAI,EACpBE,GAAMR,CACP,CAED,GAAKR,EAAOc,CAAI,EACf,IAAMI,EAAGA,EAAIf,EAAGe,IACfL,EAAMF,EAAMK,EAAIF,CAAI,EACpBE,GAAMR,EAGR,OAAOD,CACR,CAKAR,EAAO,QAAUG,IC7GjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAmB,QAAS,qCAAsC,EAClEC,EAAY,IAwBhB,SAASC,EAAUC,EAAGC,EAAGC,EAASC,EAASC,EAAGC,EAASC,EAAU,CAChE,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKb,GAAK,EACT,OAAOI,EAIR,GAFAM,EAAKb,EAAkBI,CAAE,EACzBU,EAAKd,EAAkBO,CAAE,EACpBM,EAAG,kBAAoBC,EAAG,iBAC9B,OAAAb,EAAWE,EAAGU,EAAIR,EAASC,EAASQ,EAAIN,EAASC,CAAQ,EAClDF,EAUR,GARAI,EAAKL,EACLM,EAAKH,EAELC,EAAMX,EAAKK,EAAGO,CAAG,CAAE,EACnBJ,EAAGK,CAAG,EAAIF,EAEVE,GAAMJ,EACNQ,EAAI,EACClB,EAAOY,CAAI,IAAM,GACrB,IAAMM,EAAGA,EAAIb,EAAGa,IAAM,CAGrB,GAFAL,GAAMN,EACNU,EAAIhB,EAAKK,EAAGO,CAAG,CAAE,EACZb,EAAOiB,CAAE,EAAI,CACjBL,EAAMK,EACN,KACD,CACKA,EAAIL,IACRA,EAAMK,GAEPR,EAAGK,CAAG,EAAIF,EACVE,GAAMJ,CACP,CAED,GAAKV,EAAOY,CAAI,EACf,IAAMM,EAAGA,EAAIb,EAAGa,IACfT,EAAGK,CAAG,EAAIF,EACVE,GAAMJ,EAGR,OAAOD,CACR,CAKAV,EAAO,QAAUK,ICtGjB,IAAAe,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAuBd,SAASC,EAAUC,EAAGC,EAAGC,EAASC,EAAGC,EAAU,CAC9C,IAAIC,EAAKR,EAAeG,EAAGE,CAAQ,EAC/BI,EAAKT,EAAeG,EAAGI,CAAQ,EACnC,OAAON,EAASE,EAAGC,EAAGC,EAASG,EAAIF,EAAGC,EAASE,CAAG,CACnD,CAKAV,EAAO,QAAUG,ICNjB,IAAIQ,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_accessors", "__commonJSMin", "exports", "module", "isnan", "abs", "cumaxabs", "N", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "xbuf", "ybuf", "xget", "yset", "max", "ix", "iy", "v", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "abs", "arraylike2object", "accessors", "cumaxabs", "N", "x", "strideX", "offsetX", "y", "strideY", "offsetY", "max", "ix", "iy", "ox", "oy", "v", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "cumaxabs", "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 `cumaxabs`.
|
|
@@ -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
|
* cumaxabs( x.length, x, 1, y, 1 );
|
|
44
54
|
* // y => [ 1.0, 2.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 absolute value 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
|
* cumaxabs.ndarray( x.length, x, 1, 0, y, 1, 0 );
|
|
65
75
|
* // y => [ 1.0, 2.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, 2.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
|
* cumaxabs.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 abs = require( '@stdlib/math-base-special-abs' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Computes the cumulative maximum absolute value 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
|
+
* cumaxabs( 4, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );
|
|
54
|
+
* // y => [ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ];
|
|
55
|
+
*/
|
|
56
|
+
function cumaxabs( 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 references to array data:
|
|
68
|
+
xbuf = x.data;
|
|
69
|
+
ybuf = y.data;
|
|
70
|
+
|
|
71
|
+
// Cache references to element accessors:
|
|
72
|
+
xget = x.accessors[ 0 ];
|
|
73
|
+
yset = y.accessors[ 1 ];
|
|
74
|
+
|
|
75
|
+
ix = offsetX;
|
|
76
|
+
iy = offsetY;
|
|
77
|
+
|
|
78
|
+
max = abs( 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 = abs( xget( xbuf, ix ) );
|
|
87
|
+
if ( isnan( v ) ) {
|
|
88
|
+
max = v;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if ( v > max ) {
|
|
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 = cumaxabs;
|
package/lib/index.js
CHANGED
|
@@ -47,7 +47,14 @@
|
|
|
47
47
|
|
|
48
48
|
// MODULES //
|
|
49
49
|
|
|
50
|
+
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
50
51
|
var main = require( './main.js' );
|
|
52
|
+
var ndarray = require( './ndarray.js' );
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// MAIN //
|
|
56
|
+
|
|
57
|
+
setReadOnly( main, 'ndarray', ndarray );
|
|
51
58
|
|
|
52
59
|
|
|
53
60
|
// EXPORTS //
|
package/lib/main.js
CHANGED
|
@@ -20,14 +20,35 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var cumaxabs = require( './cumaxabs.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 absolute value 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
|
+
* var N = x.length;
|
|
43
|
+
*
|
|
44
|
+
* var v = cumaxabs( N, x, 1, y, 1 );
|
|
45
|
+
* // returns [ 1.0, 2.0, 2.0 ]
|
|
46
|
+
*/
|
|
47
|
+
function cumaxabs( N, x, strideX, y, strideY ) {
|
|
48
|
+
var ix = stride2offset( N, strideX );
|
|
49
|
+
var iy = stride2offset( N, strideY );
|
|
50
|
+
return ndarray( N, x, strideX, ix, y, strideY, iy );
|
|
51
|
+
}
|
|
31
52
|
|
|
32
53
|
|
|
33
54
|
// 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 abs = require( '@stdlib/math-base-special-abs' );
|
|
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 abs = require( '@stdlib/math-base-special-abs' );
|
|
|
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 = cumaxabs(
|
|
47
|
+
* var v = cumaxabs( 4, x, 2, 1, y, 1, 0 );
|
|
49
48
|
* // returns [ 1.0, 2.0, 2.0, 4.0, 0.0, 0.0, 0.0, 0.0 ]
|
|
50
49
|
*/
|
|
51
50
|
function cumaxabs( 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-cumaxabs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Calculate the cumulative maximum absolute value 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/array-base-arraylike2object": "^0.2.1",
|
|
33
34
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
34
|
-
"@stdlib/math-base-special-abs": "^0.2.
|
|
35
|
+
"@stdlib/math-base-special-abs": "^0.2.2",
|
|
36
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
35
37
|
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {},
|
|
@@ -73,7 +75,6 @@
|
|
|
73
75
|
"strided array",
|
|
74
76
|
"array"
|
|
75
77
|
],
|
|
76
|
-
"__stdlib__": {},
|
|
77
78
|
"funding": {
|
|
78
79
|
"type": "opencollective",
|
|
79
80
|
"url": "https://opencollective.com/stdlib"
|
package/lib/cumaxabs.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 abs = require( '@stdlib/math-base-special-abs' );
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// MAIN //
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Computes the cumulative maximum absolute value 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 = cumaxabs( N, x, 1, y, 1 );
|
|
45
|
-
* // returns [ 1.0, 2.0, 2.0 ]
|
|
46
|
-
*/
|
|
47
|
-
function cumaxabs( 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 = abs( 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 = abs( x[ ix ] );
|
|
76
|
-
if ( isnan( v ) ) {
|
|
77
|
-
max = v;
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
if ( v > max ) {
|
|
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 = cumaxabs;
|