@stdlib/stats-strided-nanrange-by 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 +177 -0
- package/NOTICE +1 -0
- package/README.md +350 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +216 -0
- package/lib/accessors.js +107 -0
- package/lib/index.js +67 -0
- package/lib/main.js +56 -0
- package/lib/ndarray.js +104 -0
- package/package.json +78 -0
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,350 @@
|
|
|
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
|
+
# nanrangeBy
|
|
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 via a callback function, 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-nanrange-by
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
</section>
|
|
55
|
+
|
|
56
|
+
<section class="usage">
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
var nanrangeBy = require( '@stdlib/stats-strided-nanrange-by' );
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### nanrangeBy( N, x, strideX, clbk\[, thisArg] )
|
|
65
|
+
|
|
66
|
+
Computes the [range][range] of a strided array via a callback function, ignoring `NaN` values.
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
function accessor( v ) {
|
|
70
|
+
return v * 2.0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0, NaN ];
|
|
74
|
+
|
|
75
|
+
var v = nanrangeBy( x.length, x, 1, accessor );
|
|
76
|
+
// returns 18.0
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The function has the following parameters:
|
|
80
|
+
|
|
81
|
+
- **N**: number of indexed elements.
|
|
82
|
+
- **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions).
|
|
83
|
+
- **strideX**: stride length.
|
|
84
|
+
- **clbk**: callback function.
|
|
85
|
+
- **thisArg**: execution context (_optional_).
|
|
86
|
+
|
|
87
|
+
The invoked callback is provided four arguments:
|
|
88
|
+
|
|
89
|
+
- **value**: array element.
|
|
90
|
+
- **aidx**: array index.
|
|
91
|
+
- **sidx**: strided index (`offset + aidx*stride`).
|
|
92
|
+
- **array**: input array/collection.
|
|
93
|
+
|
|
94
|
+
To set the callback execution context, provide a `thisArg`.
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
function accessor( v ) {
|
|
98
|
+
this.count += 1;
|
|
99
|
+
return v * 2.0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0, NaN ];
|
|
103
|
+
|
|
104
|
+
var context = {
|
|
105
|
+
'count': 0
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
var v = nanrangeBy( x.length, x, 1, accessor, context );
|
|
109
|
+
// returns 18.0
|
|
110
|
+
|
|
111
|
+
var cnt = context.count;
|
|
112
|
+
// returns 10
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
function accessor( v ) {
|
|
119
|
+
return v * 2.0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, NaN, NaN ];
|
|
123
|
+
|
|
124
|
+
var v = nanrangeBy( 5, x, 2, accessor );
|
|
125
|
+
// returns 12.0
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
|
|
129
|
+
|
|
130
|
+
```javascript
|
|
131
|
+
var Float64Array = require( '@stdlib/array-float64' );
|
|
132
|
+
|
|
133
|
+
function accessor( v ) {
|
|
134
|
+
return v * 2.0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Initial array...
|
|
138
|
+
var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
|
|
139
|
+
|
|
140
|
+
// Create an offset view...
|
|
141
|
+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
|
|
142
|
+
|
|
143
|
+
// Access every other element...
|
|
144
|
+
var v = nanrangeBy( 3, x1, 2, accessor );
|
|
145
|
+
// returns 8.0
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### nanrangeBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] )
|
|
149
|
+
|
|
150
|
+
Computes the [range][range] of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
function accessor( v ) {
|
|
154
|
+
return v * 2.0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0, NaN ];
|
|
158
|
+
|
|
159
|
+
var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );
|
|
160
|
+
// returns 18.0
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The function has the following additional parameters:
|
|
164
|
+
|
|
165
|
+
- **offsetX**: starting index.
|
|
166
|
+
|
|
167
|
+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`
|
|
168
|
+
|
|
169
|
+
```javascript
|
|
170
|
+
function accessor( v ) {
|
|
171
|
+
return v * 2.0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
|
|
175
|
+
|
|
176
|
+
var v = nanrangeBy.ndarray( 3, x, 1, x.length-3, accessor );
|
|
177
|
+
// returns 22.0
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
</section>
|
|
181
|
+
|
|
182
|
+
<!-- /.usage -->
|
|
183
|
+
|
|
184
|
+
<section class="notes">
|
|
185
|
+
|
|
186
|
+
## Notes
|
|
187
|
+
|
|
188
|
+
- If `N <= 0`, both functions return `NaN`.
|
|
189
|
+
- A provided callback function should return a numeric value.
|
|
190
|
+
- If a provided callback function returns `NaN`, the value is ignored.
|
|
191
|
+
- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
|
|
192
|
+
- 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]).
|
|
193
|
+
- When possible, prefer using [`dnanrange`][@stdlib/stats/strided/dnanrange], [`snanrange`][@stdlib/stats/strided/snanrange], and/or [`nanrange`][@stdlib/stats/strided/nanrange], as, depending on the environment, these interfaces are likely to be significantly more performant.
|
|
194
|
+
|
|
195
|
+
</section>
|
|
196
|
+
|
|
197
|
+
<!-- /.notes -->
|
|
198
|
+
|
|
199
|
+
<section class="examples">
|
|
200
|
+
|
|
201
|
+
## Examples
|
|
202
|
+
|
|
203
|
+
<!-- eslint no-undef: "error" -->
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
var uniform = require( '@stdlib/random-base-uniform' );
|
|
207
|
+
var filledarrayBy = require( '@stdlib/array-filled-by' );
|
|
208
|
+
var bernoulli = require( '@stdlib/random-base-bernoulli' );
|
|
209
|
+
var nanrangeBy = require( '@stdlib/stats-strided-nanrange-by' );
|
|
210
|
+
|
|
211
|
+
function rand() {
|
|
212
|
+
if ( bernoulli( 0.8 ) < 0.2 ) {
|
|
213
|
+
return NaN;
|
|
214
|
+
}
|
|
215
|
+
return uniform( -50.0, 50.0 );
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function accessor( v ) {
|
|
219
|
+
return v * 2.0;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
var x = filledarrayBy( 10, 'float64', rand );
|
|
223
|
+
console.log( x );
|
|
224
|
+
|
|
225
|
+
var v = nanrangeBy( x.length, x, 1, accessor );
|
|
226
|
+
console.log( v );
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
</section>
|
|
230
|
+
|
|
231
|
+
<!-- /.examples -->
|
|
232
|
+
|
|
233
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
234
|
+
|
|
235
|
+
<section class="related">
|
|
236
|
+
|
|
237
|
+
* * *
|
|
238
|
+
|
|
239
|
+
## See Also
|
|
240
|
+
|
|
241
|
+
- <span class="package-name">[`@stdlib/stats-strided/dnanrange`][@stdlib/stats/strided/dnanrange]</span><span class="delimiter">: </span><span class="description">calculate the range of a double-precision floating-point strided array, ignoring NaN values.</span>
|
|
242
|
+
- <span class="package-name">[`@stdlib/stats-strided/nanmax-by`][@stdlib/stats/strided/nanmax-by]</span><span class="delimiter">: </span><span class="description">calculate the maximum value of a strided array via a callback function, ignoring NaN values.</span>
|
|
243
|
+
- <span class="package-name">[`@stdlib/stats-strided/nanmin-by`][@stdlib/stats/strided/nanmin-by]</span><span class="delimiter">: </span><span class="description">calculate the minimum value of a strided array via a callback function, ignoring NaN values.</span>
|
|
244
|
+
- <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>
|
|
245
|
+
- <span class="package-name">[`@stdlib/stats-strided/range-by`][@stdlib/stats/strided/range-by]</span><span class="delimiter">: </span><span class="description">calculate the range of a strided array via a callback function.</span>
|
|
246
|
+
- <span class="package-name">[`@stdlib/stats-strided/snanrange`][@stdlib/stats/strided/snanrange]</span><span class="delimiter">: </span><span class="description">calculate the range of a single-precision floating-point strided array, ignoring NaN values.</span>
|
|
247
|
+
|
|
248
|
+
</section>
|
|
249
|
+
|
|
250
|
+
<!-- /.related -->
|
|
251
|
+
|
|
252
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
<section class="main-repo" >
|
|
256
|
+
|
|
257
|
+
* * *
|
|
258
|
+
|
|
259
|
+
## Notice
|
|
260
|
+
|
|
261
|
+
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.
|
|
262
|
+
|
|
263
|
+
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].
|
|
264
|
+
|
|
265
|
+
#### Community
|
|
266
|
+
|
|
267
|
+
[![Chat][chat-image]][chat-url]
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
See [LICENSE][stdlib-license].
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
## Copyright
|
|
277
|
+
|
|
278
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
279
|
+
|
|
280
|
+
</section>
|
|
281
|
+
|
|
282
|
+
<!-- /.stdlib -->
|
|
283
|
+
|
|
284
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
285
|
+
|
|
286
|
+
<section class="links">
|
|
287
|
+
|
|
288
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-strided-nanrange-by.svg
|
|
289
|
+
[npm-url]: https://npmjs.org/package/@stdlib/stats-strided-nanrange-by
|
|
290
|
+
|
|
291
|
+
[test-image]: https://github.com/stdlib-js/stats-strided-nanrange-by/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
292
|
+
[test-url]: https://github.com/stdlib-js/stats-strided-nanrange-by/actions/workflows/test.yml?query=branch:v0.1.0
|
|
293
|
+
|
|
294
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-strided-nanrange-by/main.svg
|
|
295
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/stats-strided-nanrange-by?branch=main
|
|
296
|
+
|
|
297
|
+
<!--
|
|
298
|
+
|
|
299
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/stats-strided-nanrange-by.svg
|
|
300
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/stats-strided-nanrange-by/main
|
|
301
|
+
|
|
302
|
+
-->
|
|
303
|
+
|
|
304
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
305
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
306
|
+
|
|
307
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
308
|
+
|
|
309
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
310
|
+
|
|
311
|
+
[umd]: https://github.com/umdjs/umd
|
|
312
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
313
|
+
|
|
314
|
+
[deno-url]: https://github.com/stdlib-js/stats-strided-nanrange-by/tree/deno
|
|
315
|
+
[deno-readme]: https://github.com/stdlib-js/stats-strided-nanrange-by/blob/deno/README.md
|
|
316
|
+
[umd-url]: https://github.com/stdlib-js/stats-strided-nanrange-by/tree/umd
|
|
317
|
+
[umd-readme]: https://github.com/stdlib-js/stats-strided-nanrange-by/blob/umd/README.md
|
|
318
|
+
[esm-url]: https://github.com/stdlib-js/stats-strided-nanrange-by/tree/esm
|
|
319
|
+
[esm-readme]: https://github.com/stdlib-js/stats-strided-nanrange-by/blob/esm/README.md
|
|
320
|
+
[branches-url]: https://github.com/stdlib-js/stats-strided-nanrange-by/blob/main/branches.md
|
|
321
|
+
|
|
322
|
+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-strided-nanrange-by/main/LICENSE
|
|
323
|
+
|
|
324
|
+
[range]: https://en.wikipedia.org/wiki/Range_%28statistics%29
|
|
325
|
+
|
|
326
|
+
[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
327
|
+
|
|
328
|
+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
|
|
329
|
+
|
|
330
|
+
[@stdlib/array/base/accessor]: https://www.npmjs.com/package/@stdlib/array-base-accessor
|
|
331
|
+
|
|
332
|
+
<!-- <related-links> -->
|
|
333
|
+
|
|
334
|
+
[@stdlib/stats/strided/dnanrange]: https://www.npmjs.com/package/@stdlib/stats-strided-dnanrange
|
|
335
|
+
|
|
336
|
+
[@stdlib/stats/strided/nanmax-by]: https://www.npmjs.com/package/@stdlib/stats-strided-nanmax-by
|
|
337
|
+
|
|
338
|
+
[@stdlib/stats/strided/nanmin-by]: https://www.npmjs.com/package/@stdlib/stats-strided-nanmin-by
|
|
339
|
+
|
|
340
|
+
[@stdlib/stats/strided/nanrange]: https://www.npmjs.com/package/@stdlib/stats-strided-nanrange
|
|
341
|
+
|
|
342
|
+
[@stdlib/stats/strided/range-by]: https://www.npmjs.com/package/@stdlib/stats-strided-range-by
|
|
343
|
+
|
|
344
|
+
[@stdlib/stats/strided/snanrange]: https://www.npmjs.com/package/@stdlib/stats-strided-snanrange
|
|
345
|
+
|
|
346
|
+
<!-- </related-links> -->
|
|
347
|
+
|
|
348
|
+
</section>
|
|
349
|
+
|
|
350
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";var q=function(n,e){return function(){return e||n((e={exports:{}}).exports,e),e.exports}};var p=q(function(I,m){
|
|
2
|
+
var d=require('@stdlib/math-base-assert-is-nan/dist');function P(n,e,t,c,f,s){var u,i,v,o,a,r,l;if(u=e.data,i=e.accessors[0],n===1||t===0)return r=f.call(s,i(u,c),0,c,u),r===void 0||d(r)?NaN:0;for(a=c,l=0;l<n&&(o=f.call(s,i(u,a),l,a,u),!(o===o&&o!==void 0));l++)a+=t;if(l===n)return NaN;for(v=o,l+=1,l;l<n;l++)a+=t,r=f.call(s,i(u,a),l,a,u),!(r===void 0||d(r))&&(r<o?o=r:r>v&&(v=r));return v-o}m.exports=P
|
|
3
|
+
});var y=q(function(J,x){
|
|
4
|
+
var B=require('@stdlib/math-base-assert-is-nan/dist'),R=require('@stdlib/array-base-arraylike2object/dist'),w=p();function z(n,e,t,c,f,s){var u,i,v,o,a,r;if(n<=0)return NaN;if(o=R(e),o.accessorProtocol)return w(n,o,t,c,f,s);if(n===1||t===0)return a=f.call(s,e[c],0,c,e),a===void 0||B(a)?NaN:0;for(v=c,r=0;r<n&&(i=f.call(s,e[v],r,v,e),!(i===i&&i!==void 0));r++)v+=t;if(r===n)return NaN;for(u=i,r+=1,r;r<n;r++)v+=t,a=f.call(s,e[v],r,v,e),!(a===void 0||B(a))&&(a<i?i=a:a>u&&(u=a));return u-i}x.exports=z
|
|
5
|
+
});var N=q(function(K,j){
|
|
6
|
+
var C=require('@stdlib/strided-base-stride2offset/dist'),D=y();function E(n,e,t,c,f){return D(n,e,t,C(n,t),c,f)}j.exports=E
|
|
7
|
+
});var F=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),O=N(),G=y();F(O,"ndarray",G);module.exports=O;
|
|
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 via a callback function, 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 data\n* @param {Array<Function>} x.accessors - array element accessors\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @param {Callback} clbk - callback\n* @param {*} [thisArg] - execution context\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, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ] );\n*\n* function accessor( v ) {\n* return v * 2.0;\n* }\n*\n* var v = nanrangeBy( x.length, arraylike2object( x ), 1, 0, accessor );\n* // returns 18.0\n*/\nfunction nanrangeBy( N, x, strideX, offsetX, clbk, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar max;\n\tvar min;\n\tvar ix;\n\tvar v;\n\tvar i;\n\n\t// Cache reference to array data:\n\txbuf = x.data;\n\n\t// Cache a reference to the element accessor:\n\tget = x.accessors[0];\n\n\tif ( N === 1 || strideX === 0 ) {\n\t\tv = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, xbuf );\n\t\tif ( v === void 0 || isnan( v ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn 0.0;\n\t}\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tmin = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );\n\t\tif ( min === min && min !== void 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\tix += strideX;\n\t}\n\tif ( i === N ) {\n\t\treturn NaN;\n\t}\n\tmax = min;\n\ti += 1;\n\tfor ( i; i < N; i++ ) {\n\t\tix += strideX;\n\t\tv = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );\n\t\tif ( v === void 0 || 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 = nanrangeBy;\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 via a callback function, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Collection} x - input array\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @param {Callback} clbk - callback\n* @param {*} [thisArg] - execution context\n* @returns {number} range\n*\n* @example\n* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];\n*\n* function accessor( v ) {\n* return v * 2.0;\n* }\n*\n* var v = nanrangeBy( x.length, x, 1, 0, accessor );\n* // returns 18.0\n*/\nfunction nanrangeBy( N, x, strideX, offsetX, clbk, thisArg ) {\n\tvar max;\n\tvar min;\n\tvar ix;\n\tvar o;\n\tvar v;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\to = arraylike2object( x );\n\tif ( o.accessorProtocol ) {\n\t\treturn accessors( N, o, strideX, offsetX, clbk, thisArg );\n\t}\n\tif ( N === 1 || strideX === 0 ) {\n\t\tv = clbk.call( thisArg, x[ offsetX ], 0, offsetX, x );\n\t\tif ( v === void 0 || isnan( v ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn 0.0;\n\t}\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tmin = clbk.call( thisArg, x[ ix ], i, ix, x );\n\t\tif ( min === min && min !== void 0 ) {\n\t\t\tbreak;\n\t\t}\n\t\tix += strideX;\n\t}\n\tif ( i === N ) {\n\t\treturn NaN;\n\t}\n\tmax = min;\n\ti += 1;\n\tfor ( i; i < N; i++ ) {\n\t\tix += strideX;\n\t\tv = clbk.call( thisArg, x[ ix ], i, ix, x );\n\t\tif ( v === void 0 || 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 = nanrangeBy;\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 via a callback function, ignoring `NaN` values.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Collection} x - input array\n* @param {integer} strideX - index increment\n* @param {Callback} clbk - callback\n* @param {*} [thisArg] - execution context\n* @returns {number} range\n*\n* @example\n* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];\n*\n* function accessor( v ) {\n* return v * 2.0;\n* }\n*\n* var v = nanrangeBy( x.length, x, 1, accessor );\n* // returns 18.0\n*/\nfunction nanrangeBy( N, x, strideX, clbk, thisArg ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg );\n}\n\n\n// EXPORTS //\n\nmodule.exports = nanrangeBy;\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 via a callback function and ignoring `NaN` values.\n*\n* @module @stdlib/stats-strided-nanrange-by\n*\n* @example\n* var nanrangeBy = require( '@stdlib/stats-strided-nanrange-by' );\n*\n* function accessor( v ) {\n* return v * 2.0;\n* }\n*\n* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];\n*\n* var v = nanrangeBy( x.length, x, 1, accessor );\n* // returns 18.0\n*\n* @example\n* var nanrangeBy = require( '@stdlib/stats-strided-nanrange-by' );\n*\n* function accessor( v ) {\n* return v * 2.0;\n* }\n*\n* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];\n*\n* var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );\n* // returns 18.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,EA+BvD,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAASC,EAAMC,EAAU,CAC5D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,GALAN,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAU,CAAC,EAEdD,IAAM,GAAKE,IAAY,EAE3B,OADAS,EAAIP,EAAK,KAAMC,EAASE,EAAKD,EAAMH,CAAQ,EAAG,EAAGA,EAASG,CAAK,EAC1DK,IAAM,QAAUb,EAAOa,CAAE,EACtB,IAED,EAGR,IADAD,EAAKP,EACCS,EAAI,EAAGA,EAAIZ,IAChBS,EAAML,EAAK,KAAMC,EAASE,EAAKD,EAAMI,CAAG,EAAGE,EAAGF,EAAIJ,CAAK,EAClD,EAAAG,IAAQA,GAAOA,IAAQ,SAFTG,IAKnBF,GAAMR,EAEP,GAAKU,IAAMZ,EACV,MAAO,KAIR,IAFAQ,EAAMC,EACNG,GAAK,EACCA,EAAGA,EAAIZ,EAAGY,IACfF,GAAMR,EACNS,EAAIP,EAAK,KAAMC,EAASE,EAAKD,EAAMI,CAAG,EAAGE,EAAGF,EAAIJ,CAAK,EAChD,EAAAK,IAAM,QAAUb,EAAOa,CAAE,KAGzBA,EAAIF,EACRA,EAAME,EACKA,EAAIH,IACfA,EAAMG,IAGR,OAAOH,EAAMC,CACd,CAKAZ,EAAO,QAAUE,IC1GjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAmB,QAAS,qCAAsC,EAClEC,EAAY,IA0BhB,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAASC,EAAMC,EAAU,CAC5D,IAAIC,EACAC,EACAC,EACA,EACAC,EACAC,EAEJ,GAAKV,GAAK,EACT,MAAO,KAGR,GADA,EAAIH,EAAkBI,CAAE,EACnB,EAAE,iBACN,OAAOH,EAAWE,EAAG,EAAGE,EAASC,EAASC,EAAMC,CAAQ,EAEzD,GAAKL,IAAM,GAAKE,IAAY,EAE3B,OADAO,EAAIL,EAAK,KAAMC,EAASJ,EAAGE,CAAQ,EAAG,EAAGA,EAASF,CAAE,EAC/CQ,IAAM,QAAUb,EAAOa,CAAE,EACtB,IAED,EAGR,IADAD,EAAKL,EACCO,EAAI,EAAGA,EAAIV,IAChBO,EAAMH,EAAK,KAAMC,EAASJ,EAAGO,CAAG,EAAGE,EAAGF,EAAIP,CAAE,EACvC,EAAAM,IAAQA,GAAOA,IAAQ,SAFTG,IAKnBF,GAAMN,EAEP,GAAKQ,IAAMV,EACV,MAAO,KAIR,IAFAM,EAAMC,EACNG,GAAK,EACCA,EAAGA,EAAIV,EAAGU,IACfF,GAAMN,EACNO,EAAIL,EAAK,KAAMC,EAASJ,EAAGO,CAAG,EAAGE,EAAGF,EAAIP,CAAE,EACrC,EAAAQ,IAAM,QAAUb,EAAOa,CAAE,KAGzBA,EAAIF,EACRA,EAAME,EACKA,EAAIH,IACfA,EAAMG,IAGR,OAAOH,EAAMC,CACd,CAKAZ,EAAO,QAAUI,ICvGjB,IAAAY,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAyBd,SAASC,EAAYC,EAAGC,EAAGC,EAASC,EAAMC,EAAU,CACnD,OAAON,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,EAAGC,EAAMC,CAAQ,CAC3E,CAKAR,EAAO,QAAUG,ICHjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_accessors", "__commonJSMin", "exports", "module", "isnan", "nanrangeBy", "N", "x", "strideX", "offsetX", "clbk", "thisArg", "xbuf", "get", "max", "min", "ix", "v", "i", "require_ndarray", "__commonJSMin", "exports", "module", "isnan", "arraylike2object", "accessors", "nanrangeBy", "N", "x", "strideX", "offsetX", "clbk", "thisArg", "max", "min", "ix", "v", "i", "require_main", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "nanrangeBy", "N", "x", "strideX", "clbk", "thisArg", "setReadOnly", "main", "ndarray"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
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 { Collection, AccessorArrayLike } from '@stdlib/types/array';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Input array.
|
|
27
|
+
*/
|
|
28
|
+
type InputArray<T> = Collection<T> | AccessorArrayLike<T>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns an accessed value.
|
|
32
|
+
*
|
|
33
|
+
* @returns accessed value
|
|
34
|
+
*/
|
|
35
|
+
type Nullary<U> = ( this: U ) => number | void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns an accessed value.
|
|
39
|
+
*
|
|
40
|
+
* @param value - array element
|
|
41
|
+
* @returns accessed value
|
|
42
|
+
*/
|
|
43
|
+
type Unary<T, U> = ( this: U, value: T ) => number | void;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns an accessed value.
|
|
47
|
+
*
|
|
48
|
+
* @param value - array element
|
|
49
|
+
* @param aidx - array index
|
|
50
|
+
* @returns accessed value
|
|
51
|
+
*/
|
|
52
|
+
type Binary<T, U> = ( this: U, value: T, aidx: number ) => number | void;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns an accessed value.
|
|
56
|
+
*
|
|
57
|
+
* @param value - array element
|
|
58
|
+
* @param aidx - array index
|
|
59
|
+
* @param sidx - strided index (offset + aidx*stride)
|
|
60
|
+
* @returns accessed value
|
|
61
|
+
*/
|
|
62
|
+
type Ternary<T, U> = ( this: U, value: T, aidx: number, sidx: number ) => number | void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns an accessed value.
|
|
66
|
+
*
|
|
67
|
+
* @param value - array element
|
|
68
|
+
* @param aidx - array index
|
|
69
|
+
* @param sidx - strided index (offset + aidx*stride)
|
|
70
|
+
* @param array - input array
|
|
71
|
+
* @returns accessed value
|
|
72
|
+
*/
|
|
73
|
+
type Quaternary<T, U> = ( this: U, value: T, aidx: number, sidx: number, array: Collection<T> ) => number | void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns an accessed value.
|
|
77
|
+
*
|
|
78
|
+
* @param value - array element
|
|
79
|
+
* @param aidx - array index
|
|
80
|
+
* @param sidx - strided index (offset + aidx*stride)
|
|
81
|
+
* @param array - input array
|
|
82
|
+
* @returns accessed value
|
|
83
|
+
*/
|
|
84
|
+
type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U> | Quaternary<T, U>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Interface describing `nanrangeBy`.
|
|
88
|
+
*/
|
|
89
|
+
interface Routine {
|
|
90
|
+
/**
|
|
91
|
+
* Computes the range of a strided array via a callback function, ignoring `NaN` values.
|
|
92
|
+
*
|
|
93
|
+
* ## Notes
|
|
94
|
+
*
|
|
95
|
+
* - The callback function is provided four arguments:
|
|
96
|
+
*
|
|
97
|
+
* - `value`: array element
|
|
98
|
+
* - `aidx`: array index
|
|
99
|
+
* - `sidx`: strided index (offset + aidx*stride)
|
|
100
|
+
* - `array`: input array
|
|
101
|
+
*
|
|
102
|
+
* - The callback function should return a numeric value.
|
|
103
|
+
*
|
|
104
|
+
* - If the callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
|
|
105
|
+
*
|
|
106
|
+
* - If the callback function returns `NaN`, the value is ignored.
|
|
107
|
+
*
|
|
108
|
+
* @param N - number of indexed elements
|
|
109
|
+
* @param x - input array
|
|
110
|
+
* @param strideX - stride length
|
|
111
|
+
* @param clbk - callback
|
|
112
|
+
* @param thisArg - execution context
|
|
113
|
+
* @returns range
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
117
|
+
*
|
|
118
|
+
* function accessor( v ) {
|
|
119
|
+
* return v * 2.0;
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* var v = nanrangeBy( x.length, x, 1, accessor );
|
|
123
|
+
* // returns 18.0
|
|
124
|
+
*/
|
|
125
|
+
<T = unknown, U = unknown>( N: number, x: InputArray<T>, strideX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Computes the range of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
|
|
129
|
+
*
|
|
130
|
+
* ## Notes
|
|
131
|
+
*
|
|
132
|
+
* - The callback function is provided four arguments:
|
|
133
|
+
*
|
|
134
|
+
* - `value`: array element
|
|
135
|
+
* - `aidx`: array index
|
|
136
|
+
* - `sidx`: strided index (offset + aidx*stride)
|
|
137
|
+
* - `array`: input array
|
|
138
|
+
*
|
|
139
|
+
* - The callback function should return a numeric value.
|
|
140
|
+
*
|
|
141
|
+
* - If the callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
|
|
142
|
+
*
|
|
143
|
+
* - If the callback function returns `NaN`, the value is ignored.
|
|
144
|
+
*
|
|
145
|
+
* @param N - number of indexed elements
|
|
146
|
+
* @param x - input array
|
|
147
|
+
* @param strideX - stride length
|
|
148
|
+
* @param offsetX - starting index
|
|
149
|
+
* @param clbk - callback
|
|
150
|
+
* @param thisArg - execution context
|
|
151
|
+
* @returns range
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
155
|
+
*
|
|
156
|
+
* function accessor( v ) {
|
|
157
|
+
* return v * 2.0;
|
|
158
|
+
* }
|
|
159
|
+
*
|
|
160
|
+
* var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );
|
|
161
|
+
* // returns 18.0
|
|
162
|
+
*/
|
|
163
|
+
ndarray<T = unknown, U = unknown>( N: number, x: InputArray<T>, strideX: number, offsetX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Computes the range of a strided array via a callback function, ignoring `NaN` values.
|
|
168
|
+
*
|
|
169
|
+
* ## Notes
|
|
170
|
+
*
|
|
171
|
+
* - The callback function is provided four arguments:
|
|
172
|
+
*
|
|
173
|
+
* - `value`: array element
|
|
174
|
+
* - `aidx`: array index
|
|
175
|
+
* - `sidx`: strided index (offset + aidx*stride)
|
|
176
|
+
* - `array`: input array
|
|
177
|
+
*
|
|
178
|
+
* - The callback function should return a numeric value.
|
|
179
|
+
*
|
|
180
|
+
* - If the callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
|
|
181
|
+
*
|
|
182
|
+
* - If the callback function returns `NaN`, the value is ignored.
|
|
183
|
+
*
|
|
184
|
+
* @param N - number of indexed elements
|
|
185
|
+
* @param x - input array
|
|
186
|
+
* @param strideX - stride length
|
|
187
|
+
* @param clbk - callback
|
|
188
|
+
* @param thisArg - execution context
|
|
189
|
+
* @returns range
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
193
|
+
*
|
|
194
|
+
* function accessor( v ) {
|
|
195
|
+
* return v * 2.0;
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* var v = nanrangeBy( x.length, x, 1, accessor );
|
|
199
|
+
* // returns 18.0
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
203
|
+
*
|
|
204
|
+
* function accessor( v ) {
|
|
205
|
+
* return v * 2.0;
|
|
206
|
+
* }
|
|
207
|
+
*
|
|
208
|
+
* var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );
|
|
209
|
+
* // returns 18.0
|
|
210
|
+
*/
|
|
211
|
+
declare var nanrangeBy: Routine;
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
// EXPORTS //
|
|
215
|
+
|
|
216
|
+
export = nanrangeBy;
|
package/lib/accessors.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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 via a callback function, 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 data
|
|
34
|
+
* @param {Array<Function>} x.accessors - array element accessors
|
|
35
|
+
* @param {integer} strideX - stride length
|
|
36
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
37
|
+
* @param {Callback} clbk - callback
|
|
38
|
+
* @param {*} [thisArg] - execution context
|
|
39
|
+
* @returns {number} range
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
|
|
43
|
+
* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
44
|
+
*
|
|
45
|
+
* var x = toAccessorArray( [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ] );
|
|
46
|
+
*
|
|
47
|
+
* function accessor( v ) {
|
|
48
|
+
* return v * 2.0;
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* var v = nanrangeBy( x.length, arraylike2object( x ), 1, 0, accessor );
|
|
52
|
+
* // returns 18.0
|
|
53
|
+
*/
|
|
54
|
+
function nanrangeBy( N, x, strideX, offsetX, clbk, thisArg ) {
|
|
55
|
+
var xbuf;
|
|
56
|
+
var get;
|
|
57
|
+
var max;
|
|
58
|
+
var min;
|
|
59
|
+
var ix;
|
|
60
|
+
var v;
|
|
61
|
+
var i;
|
|
62
|
+
|
|
63
|
+
// Cache reference to array data:
|
|
64
|
+
xbuf = x.data;
|
|
65
|
+
|
|
66
|
+
// Cache a reference to the element accessor:
|
|
67
|
+
get = x.accessors[0];
|
|
68
|
+
|
|
69
|
+
if ( N === 1 || strideX === 0 ) {
|
|
70
|
+
v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, xbuf );
|
|
71
|
+
if ( v === void 0 || isnan( v ) ) {
|
|
72
|
+
return NaN;
|
|
73
|
+
}
|
|
74
|
+
return 0.0;
|
|
75
|
+
}
|
|
76
|
+
ix = offsetX;
|
|
77
|
+
for ( i = 0; i < N; i++ ) {
|
|
78
|
+
min = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );
|
|
79
|
+
if ( min === min && min !== void 0 ) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
ix += strideX;
|
|
83
|
+
}
|
|
84
|
+
if ( i === N ) {
|
|
85
|
+
return NaN;
|
|
86
|
+
}
|
|
87
|
+
max = min;
|
|
88
|
+
i += 1;
|
|
89
|
+
for ( i; i < N; i++ ) {
|
|
90
|
+
ix += strideX;
|
|
91
|
+
v = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );
|
|
92
|
+
if ( v === void 0 || isnan( v ) ) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if ( v < min ) {
|
|
96
|
+
min = v;
|
|
97
|
+
} else if ( v > max ) {
|
|
98
|
+
max = v;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return max - min;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// EXPORTS //
|
|
106
|
+
|
|
107
|
+
module.exports = nanrangeBy;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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 via a callback function and ignoring `NaN` values.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/stats-strided-nanrange-by
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var nanrangeBy = require( '@stdlib/stats-strided-nanrange-by' );
|
|
28
|
+
*
|
|
29
|
+
* function accessor( v ) {
|
|
30
|
+
* return v * 2.0;
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
34
|
+
*
|
|
35
|
+
* var v = nanrangeBy( x.length, x, 1, accessor );
|
|
36
|
+
* // returns 18.0
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* var nanrangeBy = require( '@stdlib/stats-strided-nanrange-by' );
|
|
40
|
+
*
|
|
41
|
+
* function accessor( v ) {
|
|
42
|
+
* return v * 2.0;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
46
|
+
*
|
|
47
|
+
* var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor );
|
|
48
|
+
* // returns 18.0
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
// MODULES //
|
|
52
|
+
|
|
53
|
+
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
54
|
+
var main = require( './main.js' );
|
|
55
|
+
var ndarray = require( './ndarray.js' );
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// MAIN //
|
|
59
|
+
|
|
60
|
+
setReadOnly( main, 'ndarray', ndarray );
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// EXPORTS //
|
|
64
|
+
|
|
65
|
+
module.exports = main;
|
|
66
|
+
|
|
67
|
+
// exports: { "ndarray": "main.ndarray" }
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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 via a callback function, ignoring `NaN` values.
|
|
31
|
+
*
|
|
32
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
33
|
+
* @param {Collection} x - input array
|
|
34
|
+
* @param {integer} strideX - index increment
|
|
35
|
+
* @param {Callback} clbk - callback
|
|
36
|
+
* @param {*} [thisArg] - execution context
|
|
37
|
+
* @returns {number} range
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
41
|
+
*
|
|
42
|
+
* function accessor( v ) {
|
|
43
|
+
* return v * 2.0;
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* var v = nanrangeBy( x.length, x, 1, accessor );
|
|
47
|
+
* // returns 18.0
|
|
48
|
+
*/
|
|
49
|
+
function nanrangeBy( N, x, strideX, clbk, thisArg ) {
|
|
50
|
+
return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// EXPORTS //
|
|
55
|
+
|
|
56
|
+
module.exports = nanrangeBy;
|
package/lib/ndarray.js
ADDED
|
@@ -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
|
+
'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 via a callback function, ignoring `NaN` values.
|
|
32
|
+
*
|
|
33
|
+
* @param {PositiveInteger} N - number of indexed elements
|
|
34
|
+
* @param {Collection} x - input array
|
|
35
|
+
* @param {integer} strideX - stride length
|
|
36
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
37
|
+
* @param {Callback} clbk - callback
|
|
38
|
+
* @param {*} [thisArg] - execution context
|
|
39
|
+
* @returns {number} range
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
|
|
43
|
+
*
|
|
44
|
+
* function accessor( v ) {
|
|
45
|
+
* return v * 2.0;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* var v = nanrangeBy( x.length, x, 1, 0, accessor );
|
|
49
|
+
* // returns 18.0
|
|
50
|
+
*/
|
|
51
|
+
function nanrangeBy( N, x, strideX, offsetX, clbk, thisArg ) {
|
|
52
|
+
var max;
|
|
53
|
+
var min;
|
|
54
|
+
var ix;
|
|
55
|
+
var o;
|
|
56
|
+
var v;
|
|
57
|
+
var i;
|
|
58
|
+
|
|
59
|
+
if ( N <= 0 ) {
|
|
60
|
+
return NaN;
|
|
61
|
+
}
|
|
62
|
+
o = arraylike2object( x );
|
|
63
|
+
if ( o.accessorProtocol ) {
|
|
64
|
+
return accessors( N, o, strideX, offsetX, clbk, thisArg );
|
|
65
|
+
}
|
|
66
|
+
if ( N === 1 || strideX === 0 ) {
|
|
67
|
+
v = clbk.call( thisArg, x[ offsetX ], 0, offsetX, x );
|
|
68
|
+
if ( v === void 0 || isnan( v ) ) {
|
|
69
|
+
return NaN;
|
|
70
|
+
}
|
|
71
|
+
return 0.0;
|
|
72
|
+
}
|
|
73
|
+
ix = offsetX;
|
|
74
|
+
for ( i = 0; i < N; i++ ) {
|
|
75
|
+
min = clbk.call( thisArg, x[ ix ], i, ix, x );
|
|
76
|
+
if ( min === min && min !== void 0 ) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
ix += strideX;
|
|
80
|
+
}
|
|
81
|
+
if ( i === N ) {
|
|
82
|
+
return NaN;
|
|
83
|
+
}
|
|
84
|
+
max = min;
|
|
85
|
+
i += 1;
|
|
86
|
+
for ( i; i < N; i++ ) {
|
|
87
|
+
ix += strideX;
|
|
88
|
+
v = clbk.call( thisArg, x[ ix ], i, ix, x );
|
|
89
|
+
if ( v === void 0 || isnan( v ) ) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if ( v < min ) {
|
|
93
|
+
min = v;
|
|
94
|
+
} else if ( v > max ) {
|
|
95
|
+
max = v;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return max - min;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// EXPORTS //
|
|
103
|
+
|
|
104
|
+
module.exports = nanrangeBy;
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/stats-strided-nanrange-by",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Calculate the range of a strided array via a callback function, 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-nanrange-by.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
|
+
"dispersion",
|
|
68
|
+
"domain",
|
|
69
|
+
"extent",
|
|
70
|
+
"strided",
|
|
71
|
+
"strided array",
|
|
72
|
+
"array"
|
|
73
|
+
],
|
|
74
|
+
"funding": {
|
|
75
|
+
"type": "opencollective",
|
|
76
|
+
"url": "https://opencollective.com/stdlib"
|
|
77
|
+
}
|
|
78
|
+
}
|