@stdlib/stats-strided-nanmskrange 0.1.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/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,305 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2020 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # nanmskrange
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Calculate the [range][range] of a strided array according to a mask, ignoring `NaN` values.
37
+
38
+ <section class="intro">
39
+
40
+ The [**range**][range] is defined as the difference between the maximum and minimum values.
41
+
42
+ </section>
43
+
44
+ <!-- /.intro -->
45
+
46
+ <section class="installation">
47
+
48
+ ## Installation
49
+
50
+ ```bash
51
+ npm install @stdlib/stats-strided-nanmskrange
52
+ ```
53
+
54
+ </section>
55
+
56
+ <section class="usage">
57
+
58
+ ## Usage
59
+
60
+ ```javascript
61
+ var nanmskrange = require( '@stdlib/stats-strided-nanmskrange' );
62
+ ```
63
+
64
+ #### nanmskrange( N, x, strideX, mask, strideMask )
65
+
66
+ Computes the [range][range] of a strided array according to a mask, ignoring `NaN` values.
67
+
68
+ ```javascript
69
+ var x = [ 1.0, -2.0, 4.0, 2.0, NaN, NaN ];
70
+ var mask = [ 0, 0, 1, 0, 0, 0 ];
71
+
72
+ var v = nanmskrange( 6, x, 1, mask, 1 );
73
+ // returns 4.0
74
+ ```
75
+
76
+ The function has the following parameters:
77
+
78
+ - **N**: number of indexed elements.
79
+ - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
80
+ - **strideX**: stride length for `x`.
81
+ - **mask**: mask [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. If a `mask` array element is `0`, the corresponding element in `x` is considered valid and **included** in computation. If a `mask` array element is `1`, the corresponding element in `x` is considered invalid/missing and **excluded** from computation.
82
+ - **strideMask**: stride length for `mask`.
83
+
84
+ The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the [range][range] of every other element in `x`,
85
+
86
+ ```javascript
87
+ var x = [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, 5.0, 6.0 ];
88
+ var mask = [ 0, 0, 0, 0, 0, 0, 1, 1 ];
89
+
90
+ var v = nanmskrange( 4, x, 2, mask, 2 );
91
+ // returns 11.0
92
+ ```
93
+
94
+ Note that indexing is relative to the first index. To introduce offsets, use [`typed array`][mdn-typed-array] views.
95
+
96
+ <!-- eslint-disable stdlib/capitalized-comments, max-len -->
97
+
98
+ ```javascript
99
+ var Float64Array = require( '@stdlib/array-float64' );
100
+ var Uint8Array = require( '@stdlib/array-uint8' );
101
+
102
+ var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0, NaN, NaN ] );
103
+ var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
104
+
105
+ var mask0 = new Uint8Array( [ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ] );
106
+ var mask1 = new Uint8Array( mask0.buffer, mask0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
107
+
108
+ var v = nanmskrange( 5, x1, 2, mask1, 2 );
109
+ // returns 6.0
110
+ ```
111
+
112
+ #### nanmskrange.ndarray( N, x, strideX, offsetX, mask, strideMask, offsetMask )
113
+
114
+ Computes the [range][range] of a strided array according to a mask, ignoring `NaN` values and using alternative indexing semantics.
115
+
116
+ ```javascript
117
+ var x = [ 1.0, -2.0, 4.0, 2.0, NaN, NaN ];
118
+ var mask = [ 0, 0, 1, 0, 0, 0 ];
119
+
120
+ var v = nanmskrange.ndarray( 6, x, 1, 0, mask, 1, 0 );
121
+ // returns 4.0
122
+ ```
123
+
124
+ The function has the following additional parameters:
125
+
126
+ - **offsetX**: starting index for `x`.
127
+ - **offsetMask**: starting index for `mask`.
128
+
129
+ While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on a starting indices. For example, to calculate the [range][range] for every other value in `x` starting from the second value
130
+
131
+ ```javascript
132
+ var x = [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, 5.0, 6.0 ];
133
+ var mask = [ 0, 0, 0, 0, 0, 0, 1, 1 ];
134
+
135
+ var v = nanmskrange.ndarray( 4, x, 2, 1, mask, 2, 1 );
136
+ // returns 6.0
137
+ ```
138
+
139
+ </section>
140
+
141
+ <!-- /.usage -->
142
+
143
+ <section class="notes">
144
+
145
+ ## Notes
146
+
147
+ - If `N <= 0`, both functions return `NaN`.
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]).
149
+ - Depending on the environment, the typed versions ([`dnanmskrange`][@stdlib/stats/strided/dnanmskrange], [`snanmskrange`][@stdlib/stats/strided/snanmskrange], etc.) are likely to be significantly more performant.
150
+
151
+ </section>
152
+
153
+ <!-- /.notes -->
154
+
155
+ <section class="examples">
156
+
157
+ ## Examples
158
+
159
+ <!-- eslint no-undef: "error" -->
160
+
161
+ ```javascript
162
+ var uniform = require( '@stdlib/random-base-uniform' );
163
+ var bernoulli = require( '@stdlib/random-base-bernoulli' );
164
+ var filledarrayBy = require( '@stdlib/array-filled-by' );
165
+ var nanmskrange = require( '@stdlib/stats-strided-nanmskrange' );
166
+
167
+ function rand() {
168
+ if ( bernoulli( 0.8 ) < 1 ) {
169
+ return NaN;
170
+ }
171
+ return uniform( -50.0, 50.0 );
172
+ }
173
+
174
+ var x = filledarrayBy( 10, 'float64', rand );
175
+ console.log( x );
176
+
177
+ var mask = filledarrayBy( x.length, 'uint8', bernoulli.factory( 0.2 ) );
178
+ console.log( mask );
179
+
180
+ var v = nanmskrange( x.length, x, 1, mask, 1 );
181
+ console.log( v );
182
+ ```
183
+
184
+ </section>
185
+
186
+ <!-- /.examples -->
187
+
188
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
189
+
190
+ <section class="related">
191
+
192
+ * * *
193
+
194
+ ## See Also
195
+
196
+ - <span class="package-name">[`@stdlib/stats-strided/dnanmskrange`][@stdlib/stats/strided/dnanmskrange]</span><span class="delimiter">: </span><span class="description">calculate the range of a double-precision floating-point strided array according to a mask, ignoring NaN values.</span>
197
+ - <span class="package-name">[`@stdlib/stats-strided/mskrange`][@stdlib/stats/strided/mskrange]</span><span class="delimiter">: </span><span class="description">calculate the range of a strided array according to a mask.</span>
198
+ - <span class="package-name">[`@stdlib/stats-strided/nanrange`][@stdlib/stats/strided/nanrange]</span><span class="delimiter">: </span><span class="description">calculate the range of a strided array, ignoring NaN values.</span>
199
+ - <span class="package-name">[`@stdlib/stats-strided/nanmskmax`][@stdlib/stats/strided/nanmskmax]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array according to a mask, ignoring NaN values.</span>
200
+ - <span class="package-name">[`@stdlib/stats-strided/nanmskmin`][@stdlib/stats/strided/nanmskmin]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a strided array according to a mask, ignoring NaN values.</span>
201
+ - <span class="package-name">[`@stdlib/stats-strided/snanmskrange`][@stdlib/stats/strided/snanmskrange]</span><span class="delimiter">: </span><span class="description">calculate the range of a single-precision floating-point strided array according to a mask, ignoring NaN values.</span>
202
+
203
+ </section>
204
+
205
+ <!-- /.related -->
206
+
207
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
208
+
209
+
210
+ <section class="main-repo" >
211
+
212
+ * * *
213
+
214
+ ## Notice
215
+
216
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
217
+
218
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
219
+
220
+ #### Community
221
+
222
+ [![Chat][chat-image]][chat-url]
223
+
224
+ ---
225
+
226
+ ## License
227
+
228
+ See [LICENSE][stdlib-license].
229
+
230
+
231
+ ## Copyright
232
+
233
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
234
+
235
+ </section>
236
+
237
+ <!-- /.stdlib -->
238
+
239
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
240
+
241
+ <section class="links">
242
+
243
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-strided-nanmskrange.svg
244
+ [npm-url]: https://npmjs.org/package/@stdlib/stats-strided-nanmskrange
245
+
246
+ [test-image]: https://github.com/stdlib-js/stats-strided-nanmskrange/actions/workflows/test.yml/badge.svg?branch=v0.1.0
247
+ [test-url]: https://github.com/stdlib-js/stats-strided-nanmskrange/actions/workflows/test.yml?query=branch:v0.1.0
248
+
249
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-strided-nanmskrange/main.svg
250
+ [coverage-url]: https://codecov.io/github/stdlib-js/stats-strided-nanmskrange?branch=main
251
+
252
+ <!--
253
+
254
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/stats-strided-nanmskrange.svg
255
+ [dependencies-url]: https://david-dm.org/stdlib-js/stats-strided-nanmskrange/main
256
+
257
+ -->
258
+
259
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
260
+ [chat-url]: https://stdlib.zulipchat.com
261
+
262
+ [stdlib]: https://github.com/stdlib-js/stdlib
263
+
264
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
265
+
266
+ [umd]: https://github.com/umdjs/umd
267
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
268
+
269
+ [deno-url]: https://github.com/stdlib-js/stats-strided-nanmskrange/tree/deno
270
+ [deno-readme]: https://github.com/stdlib-js/stats-strided-nanmskrange/blob/deno/README.md
271
+ [umd-url]: https://github.com/stdlib-js/stats-strided-nanmskrange/tree/umd
272
+ [umd-readme]: https://github.com/stdlib-js/stats-strided-nanmskrange/blob/umd/README.md
273
+ [esm-url]: https://github.com/stdlib-js/stats-strided-nanmskrange/tree/esm
274
+ [esm-readme]: https://github.com/stdlib-js/stats-strided-nanmskrange/blob/esm/README.md
275
+ [branches-url]: https://github.com/stdlib-js/stats-strided-nanmskrange/blob/main/branches.md
276
+
277
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-strided-nanmskrange/main/LICENSE
278
+
279
+ [range]: https://en.wikipedia.org/wiki/Range_%28statistics%29
280
+
281
+ [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
282
+
283
+ [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
284
+
285
+ [@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
286
+
287
+ <!-- <related-links> -->
288
+
289
+ [@stdlib/stats/strided/dnanmskrange]: https://www.npmjs.com/package/@stdlib/stats-strided-dnanmskrange
290
+
291
+ [@stdlib/stats/strided/mskrange]: https://www.npmjs.com/package/@stdlib/stats-strided-mskrange
292
+
293
+ [@stdlib/stats/strided/nanrange]: https://www.npmjs.com/package/@stdlib/stats-strided-nanrange
294
+
295
+ [@stdlib/stats/strided/nanmskmax]: https://www.npmjs.com/package/@stdlib/stats-strided-nanmskmax
296
+
297
+ [@stdlib/stats/strided/nanmskmin]: https://www.npmjs.com/package/@stdlib/stats-strided-nanmskmin
298
+
299
+ [@stdlib/stats/strided/snanmskrange]: https://www.npmjs.com/package/@stdlib/stats-strided-snanmskrange
300
+
301
+ <!-- </related-links> -->
302
+
303
+ </section>
304
+
305
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import nanmskrange from '../docs/types/index';
3
+ export = nanmskrange;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";var b=function(a,n){return function(){return n||a((n={exports:{}}).exports,n),n.exports}};var P=b(function(K,p){
2
+ var A=require('@stdlib/math-base-assert-is-nan/dist');function B(a,n,v,g,u,s,l){var m,o,t,c,q,f,r,e,i,x;for(m=n.data,o=u.data,c=n.accessors[0],t=u.accessors[0],r=g,e=l,x=0;x<a&&(i=c(m,r),!(i===i&&t(o,e)===0));x++)r+=v,e+=s;if(x===a)return NaN;for(f=i,q=f,x+=1,x;x<a;x++)r+=v,e+=s,!t(o,e)&&(i=c(m,r),!A(i)&&(i<f?f=i:i>q&&(q=i)));return q-f}p.exports=B
3
+ });var y=b(function(L,O){
4
+ var C=require('@stdlib/math-base-assert-is-nan/dist'),j=require('@stdlib/array-base-arraylike2object/dist'),D=P();function E(a,n,v,g,u,s,l){var m,o,t,c,q,f,r,e;if(a<=0)return NaN;if(q=j(n),f=j(u),q.accessorProtocol||f.accessorProtocol)return D(a,q,v,g,f,s,l);for(t=g,c=l,e=0;e<a&&(r=n[t],!(r===r&&u[c]===0));e++)t+=v,c+=s;if(e===a)return NaN;for(o=r,m=o,e+=1,e;e<a;e++)t+=v,c+=s,!u[c]&&(r=n[t],!C(r)&&(r<o?o=r:r>m&&(m=r)));return m-o}O.exports=E
5
+ });var w=b(function(Q,h){
6
+ var R=require('@stdlib/strided-base-stride2offset/dist'),F=y();function G(a,n,v,g,u){var s=R(a,v),l=R(a,u);return F(a,n,v,s,g,u,l)}h.exports=G
7
+ });var H=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),z=w(),I=y();H(z,"ndarray",I);module.exports=z;
8
+ /** @license Apache-2.0 */
9
+ /** @license Apache-2.0 */
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/accessors.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\n\n\n// MAIN //\n\n/**\n* Computes the range of a strided array according to a mask, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Object} x - input array object\n* @param {Collection} x.data - input array element\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} mask - mask array object\n* @param {Collection} mask.data - mask array element\n* @param {Array<Function>} mask.accessors - mask array element accessors\n* @param {integer} strideMask - stride length `mask`\n* @param {NonNegativeInteger} offsetMask - starting index `mask`\n* @returns {number} range\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );\n* var mask = toAccessorArray( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );\n*\n* var v = nanmskrange( 5, arraylike2object( x ), 2, 1, arraylike2object( mask ), 2, 1 );\n* // returns 6.0\n*/\nfunction nanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {\n\tvar xbuf;\n\tvar mbuf;\n\tvar mget;\n\tvar xget;\n\tvar max;\n\tvar min;\n\tvar ix;\n\tvar im;\n\tvar v;\n\tvar i;\n\n\t// Cache references to array data:\n\txbuf = x.data;\n\tmbuf = mask.data;\n\n\t// Cache references to element accessors:\n\txget = x.accessors[ 0 ];\n\tmget = mask.accessors[ 0 ];\n\n\tix = offsetX;\n\tim = offsetMask;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = xget( xbuf, ix );\n\t\tif ( v === v && mget( mbuf, im ) === 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\tix += strideX;\n\t\tim += strideMask;\n\t}\n\tif ( i === N ) {\n\t\treturn NaN;\n\t}\n\tmin = v;\n\tmax = min;\n\ti += 1;\n\tfor ( i; i < N; i++ ) {\n\t\tix += strideX;\n\t\tim += strideMask;\n\t\tif ( mget( mbuf, im ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tv = xget( xbuf, ix );\n\t\tif ( isnan( v ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( v < min ) {\n\t\t\tmin = v;\n\t\t} else if ( v > max ) {\n\t\t\tmax = v;\n\t\t}\n\t}\n\treturn max - min;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nanmskrange;\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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar accessors = require( './accessors.js' );\n\n\n// MAIN //\n\n/**\n* Computes the range of a strided array according to a mask, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {NumericArray} mask - mask array\n* @param {integer} strideMask - `mask` stride length\n* @param {NonNegativeInteger} offsetMask - `mask` starting index\n* @returns {number} range\n*\n* @example\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var mask = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ];\n*\n* var v = nanmskrange( 5, x, 2, 1, mask, 2, 1 );\n* // returns 6.0\n*/\nfunction nanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {\n\tvar max;\n\tvar min;\n\tvar ix;\n\tvar im;\n\tvar ox;\n\tvar om;\n\tvar v;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\tox = arraylike2object( x );\n\tom = arraylike2object( mask );\n\tif ( ox.accessorProtocol || om.accessorProtocol ) {\n\t\treturn accessors( N, ox, strideX, offsetX, om, strideMask, offsetMask );\n\t}\n\tix = offsetX;\n\tim = offsetMask;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( v === v && mask[ im ] === 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\tix += strideX;\n\t\tim += strideMask;\n\t}\n\tif ( i === N ) {\n\t\treturn NaN;\n\t}\n\tmin = v;\n\tmax = min;\n\ti += 1;\n\tfor ( i; i < N; i++ ) {\n\t\tix += strideX;\n\t\tim += strideMask;\n\t\tif ( mask[ im ] ) {\n\t\t\tcontinue;\n\t\t}\n\t\tv = x[ ix ];\n\t\tif ( isnan( v ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( v < min ) {\n\t\t\tmin = v;\n\t\t} else if ( v > max ) {\n\t\t\tmax = v;\n\t\t}\n\t}\n\treturn max - min;\n}\n\n\n// EXPORTS //\n\nmodule.exports = nanmskrange;\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 range of a strided array according to a mask, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} strideX - `x` stride length\n* @param {NumericArray} mask - mask array\n* @param {integer} strideMask - `mask` stride length\n* @returns {number} range\n*\n* @example\n* var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];\n* var mask = [ 0, 0, 1, 0, 0 ];\n*\n* var v = nanmskrange( x.length, x, 1, mask, 1 );\n* // returns 4.0\n*/\nfunction nanmskrange( N, x, strideX, mask, strideMask ) {\n\tvar ix = stride2offset( N, strideX );\n\tvar im = stride2offset( N, strideMask);\n\treturn ndarray( N, x, strideX, ix, mask, strideMask, im );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nanmskrange;\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 range of a strided array according to a mask, ignoring `NaN` values.\n*\n* @module @stdlib/stats-strided-nanmskrange\n*\n* @example\n* var nanmskrange = require( '@stdlib/stats-strided-nanmskrange' );\n*\n* var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];\n* var mask = [ 0, 0, 1, 0, 0 ];\n*\n* var v = nanmskrange( x.length, x, 1, mask, 1 );\n* // returns 4.0\n*\n* @example\n* var nanmskrange = require( '@stdlib/stats-strided-nanmskrange' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];\n* var mask = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ];\n*\n* var v = nanmskrange.ndarray( 5, x, 2, 1, mask, 2, 1 );\n* // returns 6.0\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar nanmskrange = require( './main.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( nanmskrange, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = nanmskrange;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EA+BvD,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAASC,EAAMC,EAAYC,EAAa,CAC5E,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAYJ,IATAT,EAAON,EAAE,KACTO,EAAOJ,EAAK,KAGZM,EAAOT,EAAE,UAAW,CAAE,EACtBQ,EAAOL,EAAK,UAAW,CAAE,EAEzBS,EAAKV,EACLW,EAAKR,EACCU,EAAI,EAAGA,EAAIhB,IAChBe,EAAIL,EAAMH,EAAMM,CAAG,EACd,EAAAE,IAAMA,GAAKN,EAAMD,EAAMM,CAAG,IAAM,IAFlBE,IAKnBH,GAAMX,EACNY,GAAMT,EAEP,GAAKW,IAAMhB,EACV,MAAO,KAKR,IAHAY,EAAMG,EACNJ,EAAMC,EACNI,GAAK,EACCA,EAAGA,EAAIhB,EAAGgB,IACfH,GAAMX,EACNY,GAAMT,EACD,CAAAI,EAAMD,EAAMM,CAAG,IAGpBC,EAAIL,EAAMH,EAAMM,CAAG,EACd,CAAAf,EAAOiB,CAAE,IAGTA,EAAIH,EACRA,EAAMG,EACKA,EAAIJ,IACfA,EAAMI,KAGR,OAAOJ,EAAMC,CACd,CAKAf,EAAO,QAAUE,IC/GjB,IAAAkB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAmB,QAAS,qCAAsC,EAClEC,EAAY,IAwBhB,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAASC,EAAMC,EAAYC,EAAa,CAC5E,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAKd,GAAK,EACT,MAAO,KAIR,GAFAW,EAAKd,EAAkBI,CAAE,EACzBW,EAAKf,EAAkBO,CAAK,EACvBO,EAAG,kBAAoBC,EAAG,iBAC9B,OAAOd,EAAWE,EAAGW,EAAIT,EAASC,EAASS,EAAIP,EAAYC,CAAW,EAIvE,IAFAG,EAAKN,EACLO,EAAKJ,EACCQ,EAAI,EAAGA,EAAId,IAChBa,EAAIZ,EAAGQ,CAAG,EACL,EAAAI,IAAMA,GAAKT,EAAMM,CAAG,IAAM,IAFZI,IAKnBL,GAAMP,EACNQ,GAAML,EAEP,GAAKS,IAAMd,EACV,MAAO,KAKR,IAHAQ,EAAMK,EACNN,EAAMC,EACNM,GAAK,EACCA,EAAGA,EAAId,EAAGc,IACfL,GAAMP,EACNQ,GAAML,EACD,CAAAD,EAAMM,CAAG,IAGdG,EAAIZ,EAAGQ,CAAG,EACL,CAAAb,EAAOiB,CAAE,IAGTA,EAAIL,EACRA,EAAMK,EACKA,EAAIN,IACfA,EAAMM,KAGR,OAAON,EAAMC,CACd,CAKAb,EAAO,QAAUI,ICxGjB,IAAAgB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAsBd,SAASC,EAAaC,EAAGC,EAAGC,EAASC,EAAMC,EAAa,CACvD,IAAIC,EAAKR,EAAeG,EAAGE,CAAQ,EAC/BI,EAAKT,EAAeG,EAAGI,CAAU,EACrC,OAAON,EAASE,EAAGC,EAAGC,EAASG,EAAIF,EAAMC,EAAYE,CAAG,CACzD,CAKAV,EAAO,QAAUG,ICRjB,IAAIQ,EAAc,QAAS,uDAAwD,EAC/EC,EAAc,IACdC,EAAU,IAKdF,EAAaC,EAAa,UAAWC,CAAQ,EAK7C,OAAO,QAAUD",
6
+ "names": ["require_accessors", "__commonJSMin", "exports", "module", "isnan", "nanmskrange", "N", "x", "strideX", "offsetX", "mask", "strideMask", "offsetMask", "xbuf", "mbuf", "mget", "xget", "max", "min", "ix", "im", "v", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "arraylike2object", "accessors", "nanmskrange", "N", "x", "strideX", "offsetX", "mask", "strideMask", "offsetMask", "max", "min", "ix", "im", "ox", "om", "v", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "nanmskrange", "N", "x", "strideX", "mask", "strideMask", "ix", "im", "setReadOnly", "nanmskrange", "ndarray"]
7
+ }
@@ -0,0 +1,104 @@
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
+ // TypeScript Version: 4.1
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
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
+ * Interface describing `nanmskrange`.
32
+ */
33
+ interface Routine {
34
+ /**
35
+ * Computes the range of a strided array according to a mask, ignoring `NaN` values.
36
+ *
37
+ * @param N - number of indexed elements
38
+ * @param x - input array
39
+ * @param strideX - stride length for `x`
40
+ * @param mask - mask array
41
+ * @param strideMask - stride length for `mask`
42
+ * @returns range
43
+ *
44
+ * @example
45
+ * var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];
46
+ * var mask = [ 0, 0, 1, 0, 0 ];
47
+ *
48
+ * var v = nanmskrange( x.length, x, 1, mask, 1 );
49
+ * // returns 4.0
50
+ */
51
+ ( N: number, x: InputArray, strideX: number, mask: InputArray, strideMask: number ): number;
52
+
53
+ /**
54
+ * Computes the range of a strided array according to a mask, ignoring `NaN` values and using alternative indexing semantics.
55
+ *
56
+ * @param N - number of indexed elements
57
+ * @param x - input array
58
+ * @param strideX - stride length for `x`
59
+ * @param offsetX - `x` starting index
60
+ * @param mask - mask array
61
+ * @param strideMask - stride length for `mask`
62
+ * @param offsetMask - `mask` starting index
63
+ * @returns range
64
+ *
65
+ * @example
66
+ * var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];
67
+ * var mask = [ 0, 0, 1, 0, 0 ];
68
+ *
69
+ * var v = nanmskrange.ndarray( x.length, x, 1, 0, mask, 1, 0 );
70
+ * // returns 4.0
71
+ */
72
+ ndarray( N: number, x: InputArray, strideX: number, offsetX: number, mask: InputArray, strideMask: number, offsetMask: number ): number;
73
+ }
74
+
75
+ /**
76
+ * Computes the range of a strided array according to a mask, ignoring `NaN` values.
77
+ *
78
+ * @param N - number of indexed elements
79
+ * @param x - input array
80
+ * @param strideX - stride length for `x`
81
+ * @param mask - mask array
82
+ * @param strideMask - stride length for `x`
83
+ * @returns range
84
+ *
85
+ * @example
86
+ * var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];
87
+ * var mask = [ 0, 0, 1, 0, 0 ];
88
+ *
89
+ * var v = nanmskrange( x.length, x, 1, mask, 1 );
90
+ * // returns 4.0
91
+ *
92
+ * @example
93
+ * var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];
94
+ * var mask = [ 0, 0, 1, 0, 0 ];
95
+ *
96
+ * var v = nanmskrange.ndarray( x.length, x, 1, 0, mask, 1, 0 );
97
+ * // returns 4.0
98
+ */
99
+ declare var nanmskrange: Routine;
100
+
101
+
102
+ // EXPORTS //
103
+
104
+ export = nanmskrange;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isnan = require( '@stdlib/math-base-assert-is-nan' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the range of a strided array according to a mask, ignoring `NaN` values.
30
+ *
31
+ * @param {PositiveInteger} N - number of indexed elements
32
+ * @param {Object} x - input array object
33
+ * @param {Collection} x.data - input array element
34
+ * @param {Array<Function>} x.accessors - array element accessors
35
+ * @param {integer} strideX - stride length for `x`
36
+ * @param {NonNegativeInteger} offsetX - starting index for `x`
37
+ * @param {Object} mask - mask array object
38
+ * @param {Collection} mask.data - mask array element
39
+ * @param {Array<Function>} mask.accessors - mask array element accessors
40
+ * @param {integer} strideMask - stride length `mask`
41
+ * @param {NonNegativeInteger} offsetMask - starting index `mask`
42
+ * @returns {number} range
43
+ *
44
+ * @example
45
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
46
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
47
+ *
48
+ * var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
49
+ * var mask = toAccessorArray( [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ] );
50
+ *
51
+ * var v = nanmskrange( 5, arraylike2object( x ), 2, 1, arraylike2object( mask ), 2, 1 );
52
+ * // returns 6.0
53
+ */
54
+ function nanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {
55
+ var xbuf;
56
+ var mbuf;
57
+ var mget;
58
+ var xget;
59
+ var max;
60
+ var min;
61
+ var ix;
62
+ var im;
63
+ var v;
64
+ var i;
65
+
66
+ // Cache references to array data:
67
+ xbuf = x.data;
68
+ mbuf = mask.data;
69
+
70
+ // Cache references to element accessors:
71
+ xget = x.accessors[ 0 ];
72
+ mget = mask.accessors[ 0 ];
73
+
74
+ ix = offsetX;
75
+ im = offsetMask;
76
+ for ( i = 0; i < N; i++ ) {
77
+ v = xget( xbuf, ix );
78
+ if ( v === v && mget( mbuf, im ) === 0 ) {
79
+ break;
80
+ }
81
+ ix += strideX;
82
+ im += strideMask;
83
+ }
84
+ if ( i === N ) {
85
+ return NaN;
86
+ }
87
+ min = v;
88
+ max = min;
89
+ i += 1;
90
+ for ( i; i < N; i++ ) {
91
+ ix += strideX;
92
+ im += strideMask;
93
+ if ( mget( mbuf, im ) ) {
94
+ continue;
95
+ }
96
+ v = xget( xbuf, ix );
97
+ if ( isnan( v ) ) {
98
+ continue;
99
+ }
100
+ if ( v < min ) {
101
+ min = v;
102
+ } else if ( v > max ) {
103
+ max = v;
104
+ }
105
+ }
106
+ return max - min;
107
+ }
108
+
109
+
110
+ // EXPORTS //
111
+
112
+ module.exports = nanmskrange;
package/lib/index.js ADDED
@@ -0,0 +1,59 @@
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
+ /**
22
+ * Compute the range of a strided array according to a mask, ignoring `NaN` values.
23
+ *
24
+ * @module @stdlib/stats-strided-nanmskrange
25
+ *
26
+ * @example
27
+ * var nanmskrange = require( '@stdlib/stats-strided-nanmskrange' );
28
+ *
29
+ * var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];
30
+ * var mask = [ 0, 0, 1, 0, 0 ];
31
+ *
32
+ * var v = nanmskrange( x.length, x, 1, mask, 1 );
33
+ * // returns 4.0
34
+ *
35
+ * @example
36
+ * var nanmskrange = require( '@stdlib/stats-strided-nanmskrange' );
37
+ *
38
+ * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
39
+ * var mask = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ];
40
+ *
41
+ * var v = nanmskrange.ndarray( 5, x, 2, 1, mask, 2, 1 );
42
+ * // returns 6.0
43
+ */
44
+
45
+ // MODULES //
46
+
47
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
48
+ var nanmskrange = require( './main.js' );
49
+ var ndarray = require( './ndarray.js' );
50
+
51
+
52
+ // MAIN //
53
+
54
+ setReadOnly( nanmskrange, 'ndarray', ndarray );
55
+
56
+
57
+ // EXPORTS //
58
+
59
+ module.exports = nanmskrange;
package/lib/main.js ADDED
@@ -0,0 +1,55 @@
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 stride2offset = require( '@stdlib/strided-base-stride2offset' );
24
+ var ndarray = require( './ndarray.js' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the range of a strided array according to a mask, ignoring `NaN` values.
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} mask - mask array
36
+ * @param {integer} strideMask - `mask` stride length
37
+ * @returns {number} range
38
+ *
39
+ * @example
40
+ * var x = [ 1.0, -2.0, 4.0, 2.0, NaN ];
41
+ * var mask = [ 0, 0, 1, 0, 0 ];
42
+ *
43
+ * var v = nanmskrange( x.length, x, 1, mask, 1 );
44
+ * // returns 4.0
45
+ */
46
+ function nanmskrange( N, x, strideX, mask, strideMask ) {
47
+ var ix = stride2offset( N, strideX );
48
+ var im = stride2offset( N, strideMask);
49
+ return ndarray( N, x, strideX, ix, mask, strideMask, im );
50
+ }
51
+
52
+
53
+ // EXPORTS //
54
+
55
+ module.exports = nanmskrange;
package/lib/ndarray.js ADDED
@@ -0,0 +1,105 @@
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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );
25
+ var accessors = require( './accessors.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Computes the range of a strided array according to a mask, ignoring `NaN` values.
32
+ *
33
+ * @param {PositiveInteger} N - number of indexed elements
34
+ * @param {NumericArray} x - input array
35
+ * @param {integer} strideX - `x` stride length
36
+ * @param {NonNegativeInteger} offsetX - `x` starting index
37
+ * @param {NumericArray} mask - mask array
38
+ * @param {integer} strideMask - `mask` stride length
39
+ * @param {NonNegativeInteger} offsetMask - `mask` starting index
40
+ * @returns {number} range
41
+ *
42
+ * @example
43
+ * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
44
+ * var mask = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 ];
45
+ *
46
+ * var v = nanmskrange( 5, x, 2, 1, mask, 2, 1 );
47
+ * // returns 6.0
48
+ */
49
+ function nanmskrange( N, x, strideX, offsetX, mask, strideMask, offsetMask ) {
50
+ var max;
51
+ var min;
52
+ var ix;
53
+ var im;
54
+ var ox;
55
+ var om;
56
+ var v;
57
+ var i;
58
+
59
+ if ( N <= 0 ) {
60
+ return NaN;
61
+ }
62
+ ox = arraylike2object( x );
63
+ om = arraylike2object( mask );
64
+ if ( ox.accessorProtocol || om.accessorProtocol ) {
65
+ return accessors( N, ox, strideX, offsetX, om, strideMask, offsetMask );
66
+ }
67
+ ix = offsetX;
68
+ im = offsetMask;
69
+ for ( i = 0; i < N; i++ ) {
70
+ v = x[ ix ];
71
+ if ( v === v && mask[ im ] === 0 ) {
72
+ break;
73
+ }
74
+ ix += strideX;
75
+ im += strideMask;
76
+ }
77
+ if ( i === N ) {
78
+ return NaN;
79
+ }
80
+ min = v;
81
+ max = min;
82
+ i += 1;
83
+ for ( i; i < N; i++ ) {
84
+ ix += strideX;
85
+ im += strideMask;
86
+ if ( mask[ im ] ) {
87
+ continue;
88
+ }
89
+ v = x[ ix ];
90
+ if ( isnan( v ) ) {
91
+ continue;
92
+ }
93
+ if ( v < min ) {
94
+ min = v;
95
+ } else if ( v > max ) {
96
+ max = v;
97
+ }
98
+ }
99
+ return max - min;
100
+ }
101
+
102
+
103
+ // EXPORTS //
104
+
105
+ module.exports = nanmskrange;
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@stdlib/stats-strided-nanmskrange",
3
+ "version": "0.1.0",
4
+ "description": "Calculate the range of a strided array according to a mask, ignoring NaN values.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "doc": "./docs",
19
+ "lib": "./lib",
20
+ "dist": "./dist"
21
+ },
22
+ "types": "./docs/types",
23
+ "scripts": {},
24
+ "homepage": "https://stdlib.io",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/stdlib-js/stats-strided-nanmskrange.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/stdlib-js/stdlib/issues"
31
+ },
32
+ "dependencies": {
33
+ "@stdlib/array-base-arraylike2object": "^0.2.1",
34
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
35
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
36
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
37
+ },
38
+ "devDependencies": {},
39
+ "engines": {
40
+ "node": ">=0.10.0",
41
+ "npm": ">2.7.0"
42
+ },
43
+ "os": [
44
+ "aix",
45
+ "darwin",
46
+ "freebsd",
47
+ "linux",
48
+ "macos",
49
+ "openbsd",
50
+ "sunos",
51
+ "win32",
52
+ "windows"
53
+ ],
54
+ "keywords": [
55
+ "stdlib",
56
+ "stdmath",
57
+ "statistics",
58
+ "stats",
59
+ "mathematics",
60
+ "math",
61
+ "maximum",
62
+ "max",
63
+ "minimum",
64
+ "min",
65
+ "range",
66
+ "extremes",
67
+ "domain",
68
+ "extent",
69
+ "dispersion",
70
+ "strided",
71
+ "strided array",
72
+ "masked",
73
+ "mask",
74
+ "masked array",
75
+ "typed",
76
+ "array"
77
+ ],
78
+ "funding": {
79
+ "type": "opencollective",
80
+ "url": "https://opencollective.com/stdlib"
81
+ }
82
+ }