@ohos-ports/stats-base-meanpn 0.0.0-stage → 0.2.2-beta.1

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-2024 The Stdlib Authors.
package/README.md CHANGED
@@ -1,3 +1,318 @@
1
- # Temporary Holding Version
1
+ <!--
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ # meanpn
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 [arithmetic mean][arithmetic-mean] of a strided array using a two-pass error correction algorithm.
37
+
38
+ <section class="intro">
39
+
40
+ The [arithmetic mean][arithmetic-mean] is defined as
41
+
42
+ <!-- <equation class="equation" label="eq:arithmetic_mean" align="center" raw="\mu = \frac{1}{n} \sum_{i=0}^{n-1} x_i" alt="Equation for the arithmetic mean."> -->
43
+
44
+ <div class="equation" align="center" data-raw-text="\mu = \frac{1}{n} \sum_{i=0}^{n-1} x_i" data-equation="eq:arithmetic_mean">
45
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@7158616c9399e313d462e91b1a5c0f82d090c372/lib/node_modules/@stdlib/stats/base/meanpn/docs/img/equation_arithmetic_mean.svg" alt="Equation for the arithmetic mean.">
46
+ <br>
47
+ </div>
48
+
49
+ <!-- </equation> -->
50
+
51
+ </section>
52
+
53
+ <!-- /.intro -->
54
+
55
+ <section class="installation">
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ npm install @stdlib/stats-base-meanpn
61
+ ```
62
+
63
+ </section>
64
+
65
+ <section class="usage">
66
+
67
+ ## Usage
68
+
69
+ ```javascript
70
+ var meanpn = require( '@stdlib/stats-base-meanpn' );
71
+ ```
72
+
73
+ #### meanpn( N, x, stride )
74
+
75
+ Computes the [arithmetic mean][arithmetic-mean] of a strided array `x` using a two-pass error correction algorithm.
76
+
77
+ ```javascript
78
+ var x = [ 1.0, -2.0, 2.0 ];
79
+ var N = x.length;
80
+
81
+ var v = meanpn( N, x, 1 );
82
+ // returns ~0.3333
83
+ ```
84
+
85
+ The function has the following parameters:
86
+
87
+ - **N**: number of indexed elements.
88
+ - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
89
+ - **stride**: index increment for `x`.
90
+
91
+ The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
92
+
93
+ ```javascript
94
+ var floor = require( '@stdlib/math-base-special-floor' );
95
+
96
+ var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
97
+ var N = floor( x.length / 2 );
98
+
99
+ var v = meanpn( N, x, 2 );
100
+ // returns 1.25
101
+ ```
102
+
103
+ Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
104
+
105
+ <!-- eslint-disable stdlib/capitalized-comments -->
106
+
107
+ ```javascript
108
+ var Float64Array = require( '@stdlib/array-float64' );
109
+ var floor = require( '@stdlib/math-base-special-floor' );
110
+
111
+ var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
112
+ var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
113
+
114
+ var N = floor( x0.length / 2 );
115
+
116
+ var v = meanpn( N, x1, 2 );
117
+ // returns 1.25
118
+ ```
119
+
120
+ #### meanpn.ndarray( N, x, stride, offset )
121
+
122
+ Computes the [arithmetic mean][arithmetic-mean] of a strided array using a two-pass error correction algorithm and alternative indexing semantics.
123
+
124
+ ```javascript
125
+ var x = [ 1.0, -2.0, 2.0 ];
126
+ var N = x.length;
127
+
128
+ var v = meanpn.ndarray( N, x, 1, 0 );
129
+ // returns ~0.33333
130
+ ```
131
+
132
+ The function has the following additional parameters:
133
+
134
+ - **offset**: starting index for `x`.
135
+
136
+ 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 calculate the [arithmetic mean][arithmetic-mean] for every other value in `x` starting from the second value
137
+
138
+ ```javascript
139
+ var floor = require( '@stdlib/math-base-special-floor' );
140
+
141
+ var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
142
+ var N = floor( x.length / 2 );
143
+
144
+ var v = meanpn.ndarray( N, x, 2, 1 );
145
+ // returns 1.25
146
+ ```
147
+
148
+ </section>
149
+
150
+ <!-- /.usage -->
151
+
152
+ <section class="notes">
153
+
154
+ ## Notes
155
+
156
+ - If `N <= 0`, both functions return `NaN`.
157
+ - Depending on the environment, the typed versions ([`dmeanpn`][@stdlib/stats/base/dmeanpn], [`smeanpn`][@stdlib/stats/base/smeanpn], etc.) are likely to be significantly more performant.
158
+
159
+ </section>
160
+
161
+ <!-- /.notes -->
162
+
163
+ <section class="examples">
164
+
165
+ ## Examples
166
+
167
+ <!-- eslint no-undef: "error" -->
168
+
169
+ ```javascript
170
+ var randu = require( '@stdlib/random-base-randu' );
171
+ var round = require( '@stdlib/math-base-special-round' );
172
+ var Float64Array = require( '@stdlib/array-float64' );
173
+ var meanpn = require( '@stdlib/stats-base-meanpn' );
174
+
175
+ var x;
176
+ var i;
177
+
178
+ x = new Float64Array( 10 );
179
+ for ( i = 0; i < x.length; i++ ) {
180
+ x[ i ] = round( (randu()*100.0) - 50.0 );
181
+ }
182
+ console.log( x );
183
+
184
+ var v = meanpn( x.length, x, 1 );
185
+ console.log( v );
186
+ ```
187
+
188
+ </section>
189
+
190
+ <!-- /.examples -->
191
+
192
+ * * *
193
+
194
+ <section class="references">
195
+
196
+ ## References
197
+
198
+ - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958][@neely:1966a].
199
+ - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036][@schubert:2018a].
200
+
201
+ </section>
202
+
203
+ <!-- /.references -->
204
+
205
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
206
+
207
+ <section class="related">
208
+
209
+ * * *
210
+
211
+ ## See Also
212
+
213
+ - <span class="package-name">[`@stdlib/stats-base/dmeanpn`][@stdlib/stats/base/dmeanpn]</span><span class="delimiter">: </span><span class="description">calculate the arithmetic mean of a double-precision floating-point strided array using a two-pass error correction algorithm.</span>
214
+ - <span class="package-name">[`@stdlib/stats-base/mean`][@stdlib/stats/base/mean]</span><span class="delimiter">: </span><span class="description">calculate the arithmetic mean of a strided array.</span>
215
+ - <span class="package-name">[`@stdlib/stats-base/nanmeanpn`][@stdlib/stats/base/nanmeanpn]</span><span class="delimiter">: </span><span class="description">calculate the arithmetic mean of a strided array, ignoring NaN values and using a two-pass error correction algorithm.</span>
216
+ - <span class="package-name">[`@stdlib/stats-base/smeanpn`][@stdlib/stats/base/smeanpn]</span><span class="delimiter">: </span><span class="description">calculate the arithmetic mean of a single-precision floating-point strided array using a two-pass error correction algorithm.</span>
217
+
218
+ </section>
219
+
220
+ <!-- /.related -->
221
+
222
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
223
+
224
+
225
+ <section class="main-repo" >
226
+
227
+ * * *
228
+
229
+ ## Notice
230
+
231
+ 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.
232
+
233
+ 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].
234
+
235
+ #### Community
236
+
237
+ [![Chat][chat-image]][chat-url]
238
+
239
+ ---
240
+
241
+ ## License
242
+
243
+ See [LICENSE][stdlib-license].
244
+
245
+
246
+ ## Copyright
247
+
248
+ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
249
+
250
+ </section>
251
+
252
+ <!-- /.stdlib -->
253
+
254
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
255
+
256
+ <section class="links">
257
+
258
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-meanpn.svg
259
+ [npm-url]: https://npmjs.org/package/@stdlib/stats-base-meanpn
260
+
261
+ [test-image]: https://github.com/stdlib-js/stats-base-meanpn/actions/workflows/test.yml/badge.svg?branch=v0.2.2
262
+ [test-url]: https://github.com/stdlib-js/stats-base-meanpn/actions/workflows/test.yml?query=branch:v0.2.2
263
+
264
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-meanpn/main.svg
265
+ [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-meanpn?branch=main
266
+
267
+ <!--
268
+
269
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/stats-base-meanpn.svg
270
+ [dependencies-url]: https://david-dm.org/stdlib-js/stats-base-meanpn/main
271
+
272
+ -->
273
+
274
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
275
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
276
+
277
+ [stdlib]: https://github.com/stdlib-js/stdlib
278
+
279
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
280
+
281
+ [umd]: https://github.com/umdjs/umd
282
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
283
+
284
+ [deno-url]: https://github.com/stdlib-js/stats-base-meanpn/tree/deno
285
+ [deno-readme]: https://github.com/stdlib-js/stats-base-meanpn/blob/deno/README.md
286
+ [umd-url]: https://github.com/stdlib-js/stats-base-meanpn/tree/umd
287
+ [umd-readme]: https://github.com/stdlib-js/stats-base-meanpn/blob/umd/README.md
288
+ [esm-url]: https://github.com/stdlib-js/stats-base-meanpn/tree/esm
289
+ [esm-readme]: https://github.com/stdlib-js/stats-base-meanpn/blob/esm/README.md
290
+ [branches-url]: https://github.com/stdlib-js/stats-base-meanpn/blob/main/branches.md
291
+
292
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-base-meanpn/main/LICENSE
293
+
294
+ [arithmetic-mean]: https://en.wikipedia.org/wiki/Arithmetic_mean
295
+
296
+ [mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
297
+
298
+ [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
299
+
300
+ [@neely:1966a]: https://doi.org/10.1145/365719.365958
301
+
302
+ [@schubert:2018a]: https://doi.org/10.1145/3221269.3223036
303
+
304
+ <!-- <related-links> -->
305
+
306
+ [@stdlib/stats/base/dmeanpn]: https://www.npmjs.com/package/@stdlib/stats-base-dmeanpn
307
+
308
+ [@stdlib/stats/base/mean]: https://www.npmjs.com/package/@stdlib/stats-base-mean
309
+
310
+ [@stdlib/stats/base/nanmeanpn]: https://www.npmjs.com/package/@stdlib/stats-base-nanmeanpn
311
+
312
+ [@stdlib/stats/base/smeanpn]: https://www.npmjs.com/package/@stdlib/stats-base-smeanpn
313
+
314
+ <!-- </related-links> -->
315
+
316
+ </section>
317
+
318
+ <!-- /.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 meanpn from '../docs/types/index';
3
+ export = meanpn;
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";var t=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var v=t(function(h,p){
2
+ var g=require('@stdlib/blas-ext-base-gsumpw/dist'),o=require('@stdlib/blas-ext-base-gapxsumpw/dist');function w(r,e,a){var u,n;return r<=0?NaN:r===1||a===0?e[0]:(u=g(r,e,a)/r,n=o(r,-u,e,a)/r,u+n)}p.exports=w
3
+ });var m=t(function(j,s){
4
+ var f=require('@stdlib/blas-ext-base-gsumpw/dist').ndarray,x=require('@stdlib/blas-ext-base-gapxsumpw/dist').ndarray;function d(r,e,a,u){var n,i;return r<=0?NaN:r===1||a===0?e[u]:(n=f(r,e,a,u)/r,i=x(r,-n,e,a,u)/r,n+i)}s.exports=d
5
+ });var y=t(function(k,q){
6
+ var l=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),c=v(),O=m();l(c,"ndarray",O);q.exports=c
7
+ });var R=y();module.exports=R;
8
+ /** @license Apache-2.0 */
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/meanpn.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar gsumpw = require( '@stdlib/blas-ext-base-gsumpw' );\nvar gapxsumpw = require( '@stdlib/blas-ext-base-gapxsumpw' );\n\n\n// MAIN //\n\n/**\n* Computes the arithmetic mean of a strided array using a two-pass error correction algorithm.\n*\n* ## Method\n*\n* - This implementation uses a two-pass approach, as suggested by Neely (1966).\n*\n* ## References\n*\n* - Neely, Peter M. 1966. \"Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients.\" _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496\u201399. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).\n* - Schubert, Erich, and Michael Gertz. 2018. \"Numerically Stable Parallel Computation of (Co-)Variance.\" In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} stride - stride length\n* @returns {number} arithmetic mean\n*\n* @example\n* var x = [ 1.0, -2.0, 2.0 ];\n* var N = x.length;\n*\n* var v = meanpn( N, x, 1 );\n* // returns ~0.3333\n*/\nfunction meanpn( N, x, stride ) {\n\tvar mu;\n\tvar c;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\treturn x[ 0 ];\n\t}\n\t// Compute an estimate for the meanpn:\n\tmu = gsumpw( N, x, stride ) / N;\n\n\t// Compute an error term:\n\tc = gapxsumpw( N, -mu, x, stride ) / N;\n\n\treturn mu + c;\n}\n\n\n// EXPORTS //\n\nmodule.exports = meanpn;\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 gsumpw = require( '@stdlib/blas-ext-base-gsumpw' ).ndarray;\nvar gapxsumpw = require( '@stdlib/blas-ext-base-gapxsumpw' ).ndarray;\n\n\n// MAIN //\n\n/**\n* Computes the arithmetic mean of a strided array using a two-pass error correction algorithm.\n*\n* ## Method\n*\n* - This implementation uses a two-pass approach, as suggested by Neely (1966).\n*\n* ## References\n*\n* - Neely, Peter M. 1966. \"Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients.\" _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496\u201399. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).\n* - Schubert, Erich, and Michael Gertz. 2018. \"Numerically Stable Parallel Computation of (Co-)Variance.\" In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} arithmetic mean\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var N = floor( x.length / 2 );\n*\n* var v = meanpn( N, x, 2, 1 );\n* // returns 1.25\n*/\nfunction meanpn( N, x, stride, offset ) {\n\tvar mu;\n\tvar c;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\treturn x[ offset ];\n\t}\n\t// Compute an estimate for the meanpn:\n\tmu = gsumpw( N, x, stride, offset ) / N;\n\n\t// Compute an error term:\n\tc = gapxsumpw( N, -mu, x, stride, offset ) / N;\n\n\treturn mu + c;\n}\n\n\n// EXPORTS //\n\nmodule.exports = meanpn;\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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar meanpn = require( './meanpn.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( meanpn, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = meanpn;\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 arithmetic mean of a strided array using a two-pass error correction algorithm.\n*\n* @module @stdlib/stats-base-meanpn\n*\n* @example\n* var meanpn = require( '@stdlib/stats-base-meanpn' );\n*\n* var x = [ 1.0, -2.0, 2.0 ];\n* var N = x.length;\n*\n* var v = meanpn( N, x, 1 );\n* // returns ~0.3333\n*\n* @example\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var meanpn = require( '@stdlib/stats-base-meanpn' );\n*\n* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];\n* var N = floor( x.length / 2 );\n*\n* var v = meanpn.ndarray( N, x, 2, 1 );\n* // returns 1.25\n*/\n\n// MODULES //\n\nvar meanpn = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = meanpn;\n\n// exports: { \"ndarray\": \"meanpn.ndarray\" }\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,8BAA+B,EACjDC,EAAY,QAAS,iCAAkC,EA6B3D,SAASC,EAAQC,EAAGC,EAAGC,EAAS,CAC/B,IAAIC,EACAC,EAEJ,OAAKJ,GAAK,EACF,IAEHA,IAAM,GAAKE,IAAW,EACnBD,EAAG,CAAE,GAGbE,EAAKN,EAAQG,EAAGC,EAAGC,CAAO,EAAIF,EAG9BI,EAAIN,EAAWE,EAAG,CAACG,EAAIF,EAAGC,CAAO,EAAIF,EAE9BG,EAAKC,EACb,CAKAR,EAAO,QAAUG,IC1EjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,8BAA+B,EAAE,QACnDC,EAAY,QAAS,iCAAkC,EAAE,QAgC7D,SAASC,EAAQC,EAAGC,EAAGC,EAAQC,EAAS,CACvC,IAAIC,EACAC,EAEJ,OAAKL,GAAK,EACF,IAEHA,IAAM,GAAKE,IAAW,EACnBD,EAAGE,CAAO,GAGlBC,EAAKP,EAAQG,EAAGC,EAAGC,EAAQC,CAAO,EAAIH,EAGtCK,EAAIP,EAAWE,EAAG,CAACI,EAAIH,EAAGC,EAAQC,CAAO,EAAIH,EAEtCI,EAAKC,EACb,CAKAT,EAAO,QAAUG,IC7EjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAS,IACTC,EAAU,IAKdF,EAAaC,EAAQ,UAAWC,CAAQ,EAKxCH,EAAO,QAAUE,ICajB,IAAIE,EAAS,IAKb,OAAO,QAAUA",
6
+ "names": ["require_meanpn", "__commonJSMin", "exports", "module", "gsumpw", "gapxsumpw", "meanpn", "N", "x", "stride", "mu", "c", "require_ndarray", "__commonJSMin", "exports", "module", "gsumpw", "gapxsumpw", "meanpn", "N", "x", "stride", "offset", "mu", "c", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "meanpn", "ndarray", "meanpn"]
7
+ }
@@ -0,0 +1,42 @@
1
+ <svg xmlns:xlink="http://www.w3.org/1999/xlink" width="12.99ex" height="7.343ex" style="vertical-align: -3.005ex;" viewBox="0 -1867.7 5592.7 3161.4" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
2
+ <title id="MathJax-SVG-1-Title">mu equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i</title>
3
+ <defs aria-hidden="true">
4
+ <path stroke-width="1" id="E1-MJMATHI-3BC" d="M58 -216Q44 -216 34 -208T23 -186Q23 -176 96 116T173 414Q186 442 219 442Q231 441 239 435T249 423T251 413Q251 401 220 279T187 142Q185 131 185 107V99Q185 26 252 26Q261 26 270 27T287 31T302 38T315 45T327 55T338 65T348 77T356 88T365 100L372 110L408 253Q444 395 448 404Q461 431 491 431Q504 431 512 424T523 412T525 402L449 84Q448 79 448 68Q448 43 455 35T476 26Q485 27 496 35Q517 55 537 131Q543 151 547 152Q549 153 557 153H561Q580 153 580 144Q580 138 575 117T555 63T523 13Q510 0 491 -8Q483 -10 467 -10Q446 -10 429 -4T402 11T385 29T376 44T374 51L368 45Q362 39 350 30T324 12T288 -4T246 -11Q199 -11 153 12L129 -85Q108 -167 104 -180T92 -202Q76 -216 58 -216Z"></path>
5
+ <path stroke-width="1" id="E1-MJMAIN-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path>
6
+ <path stroke-width="1" id="E1-MJMAIN-31" d="M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z"></path>
7
+ <path stroke-width="1" id="E1-MJMATHI-6E" d="M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z"></path>
8
+ <path stroke-width="1" id="E1-MJSZ2-2211" d="M60 948Q63 950 665 950H1267L1325 815Q1384 677 1388 669H1348L1341 683Q1320 724 1285 761Q1235 809 1174 838T1033 881T882 898T699 902H574H543H251L259 891Q722 258 724 252Q725 250 724 246Q721 243 460 -56L196 -356Q196 -357 407 -357Q459 -357 548 -357T676 -358Q812 -358 896 -353T1063 -332T1204 -283T1307 -196Q1328 -170 1348 -124H1388Q1388 -125 1381 -145T1356 -210T1325 -294L1267 -449L666 -450Q64 -450 61 -448Q55 -446 55 -439Q55 -437 57 -433L590 177Q590 178 557 222T452 366T322 544L56 909L55 924Q55 945 60 948Z"></path>
9
+ <path stroke-width="1" id="E1-MJMATHI-69" d="M184 600Q184 624 203 642T247 661Q265 661 277 649T290 619Q290 596 270 577T226 557Q211 557 198 567T184 600ZM21 287Q21 295 30 318T54 369T98 420T158 442Q197 442 223 419T250 357Q250 340 236 301T196 196T154 83Q149 61 149 51Q149 26 166 26Q175 26 185 29T208 43T235 78T260 137Q263 149 265 151T282 153Q302 153 302 143Q302 135 293 112T268 61T223 11T161 -11Q129 -11 102 10T74 74Q74 91 79 106T122 220Q160 321 166 341T173 380Q173 404 156 404H154Q124 404 99 371T61 287Q60 286 59 284T58 281T56 279T53 278T49 278T41 278H27Q21 284 21 287Z"></path>
10
+ <path stroke-width="1" id="E1-MJMAIN-30" d="M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z"></path>
11
+ <path stroke-width="1" id="E1-MJMAIN-2212" d="M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z"></path>
12
+ <path stroke-width="1" id="E1-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path>
13
+ </defs>
14
+ <g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
15
+ <use xlink:href="#E1-MJMATHI-3BC" x="0" y="0"></use>
16
+ <use xlink:href="#E1-MJMAIN-3D" x="881" y="0"></use>
17
+ <g transform="translate(1659,0)">
18
+ <g transform="translate(397,0)">
19
+ <rect stroke="none" width="720" height="60" x="0" y="220"></rect>
20
+ <use xlink:href="#E1-MJMAIN-31" x="110" y="676"></use>
21
+ <use xlink:href="#E1-MJMATHI-6E" x="60" y="-686"></use>
22
+ </g>
23
+ </g>
24
+ <g transform="translate(3064,0)">
25
+ <use xlink:href="#E1-MJSZ2-2211" x="0" y="0"></use>
26
+ <g transform="translate(147,-1090)">
27
+ <use transform="scale(0.707)" xlink:href="#E1-MJMATHI-69" x="0" y="0"></use>
28
+ <use transform="scale(0.707)" xlink:href="#E1-MJMAIN-3D" x="345" y="0"></use>
29
+ <use transform="scale(0.707)" xlink:href="#E1-MJMAIN-30" x="1124" y="0"></use>
30
+ </g>
31
+ <g transform="translate(57,1151)">
32
+ <use transform="scale(0.707)" xlink:href="#E1-MJMATHI-6E" x="0" y="0"></use>
33
+ <use transform="scale(0.707)" xlink:href="#E1-MJMAIN-2212" x="600" y="0"></use>
34
+ <use transform="scale(0.707)" xlink:href="#E1-MJMAIN-31" x="1379" y="0"></use>
35
+ </g>
36
+ </g>
37
+ <g transform="translate(4675,0)">
38
+ <use xlink:href="#E1-MJMATHI-78" x="0" y="0"></use>
39
+ <use transform="scale(0.707)" xlink:href="#E1-MJMATHI-69" x="809" y="-213"></use>
40
+ </g>
41
+ </g>
42
+ </svg>
@@ -0,0 +1,88 @@
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 } from '@stdlib/types/array';
24
+
25
+ /**
26
+ * Interface describing `meanpn`.
27
+ */
28
+ interface Routine {
29
+ /**
30
+ * Computes the arithmetic mean of a strided array using a two-pass error correction algorithm.
31
+ *
32
+ * @param N - number of indexed elements
33
+ * @param x - input array
34
+ * @param stride - stride length
35
+ * @returns arithmetic mean
36
+ *
37
+ * @example
38
+ * var x = [ 1.0, -2.0, 2.0 ];
39
+ *
40
+ * var v = meanpn( x.length, x, 1 );
41
+ * // returns ~0.3333
42
+ */
43
+ ( N: number, x: NumericArray, stride: number ): number;
44
+
45
+ /**
46
+ * Computes the arithmetic mean of a strided array using a two-pass error correction algorithm and alternative indexing semantics.
47
+ *
48
+ * @param N - number of indexed elements
49
+ * @param x - input array
50
+ * @param stride - stride length
51
+ * @param offset - starting index
52
+ * @returns arithmetic mean
53
+ *
54
+ * @example
55
+ * var x = [ 1.0, -2.0, 2.0 ];
56
+ *
57
+ * var v = meanpn.ndarray( x.length, x, 1, 0 );
58
+ * // returns ~0.3333
59
+ */
60
+ ndarray( N: number, x: NumericArray, stride: number, offset: number ): number;
61
+ }
62
+
63
+ /**
64
+ * Computes the arithmetic mean of a strided array using a two-pass error correction algorithm.
65
+ *
66
+ * @param N - number of indexed elements
67
+ * @param x - input array
68
+ * @param stride - stride length
69
+ * @returns arithmetic mean
70
+ *
71
+ * @example
72
+ * var x = [ 1.0, -2.0, 2.0 ];
73
+ *
74
+ * var v = meanpn( x.length, x, 1 );
75
+ * // returns ~0.3333
76
+ *
77
+ * @example
78
+ * var x = [ 1.0, -2.0, 2.0 ];
79
+ *
80
+ * var v = meanpn.ndarray( x.length, x, 1, 0 );
81
+ * // returns ~0.3333
82
+ */
83
+ declare var meanpn: Routine;
84
+
85
+
86
+ // EXPORTS //
87
+
88
+ export = meanpn;
package/lib/index.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
+ /**
22
+ * Compute the arithmetic mean of a strided array using a two-pass error correction algorithm.
23
+ *
24
+ * @module @stdlib/stats-base-meanpn
25
+ *
26
+ * @example
27
+ * var meanpn = require( '@stdlib/stats-base-meanpn' );
28
+ *
29
+ * var x = [ 1.0, -2.0, 2.0 ];
30
+ * var N = x.length;
31
+ *
32
+ * var v = meanpn( N, x, 1 );
33
+ * // returns ~0.3333
34
+ *
35
+ * @example
36
+ * var floor = require( '@stdlib/math-base-special-floor' );
37
+ * var meanpn = require( '@stdlib/stats-base-meanpn' );
38
+ *
39
+ * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
40
+ * var N = floor( x.length / 2 );
41
+ *
42
+ * var v = meanpn.ndarray( N, x, 2, 1 );
43
+ * // returns 1.25
44
+ */
45
+
46
+ // MODULES //
47
+
48
+ var meanpn = require( './main.js' );
49
+
50
+
51
+ // EXPORTS //
52
+
53
+ module.exports = meanpn;
54
+
55
+ // exports: { "ndarray": "meanpn.ndarray" }
package/lib/main.js ADDED
@@ -0,0 +1,35 @@
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 setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
24
+ var meanpn = require( './meanpn.js' );
25
+ var ndarray = require( './ndarray.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( meanpn, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = meanpn;
package/lib/meanpn.js ADDED
@@ -0,0 +1,75 @@
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 gsumpw = require( '@stdlib/blas-ext-base-gsumpw' );
24
+ var gapxsumpw = require( '@stdlib/blas-ext-base-gapxsumpw' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the arithmetic mean of a strided array using a two-pass error correction algorithm.
31
+ *
32
+ * ## Method
33
+ *
34
+ * - This implementation uses a two-pass approach, as suggested by Neely (1966).
35
+ *
36
+ * ## References
37
+ *
38
+ * - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).
39
+ * - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).
40
+ *
41
+ * @param {PositiveInteger} N - number of indexed elements
42
+ * @param {NumericArray} x - input array
43
+ * @param {integer} stride - stride length
44
+ * @returns {number} arithmetic mean
45
+ *
46
+ * @example
47
+ * var x = [ 1.0, -2.0, 2.0 ];
48
+ * var N = x.length;
49
+ *
50
+ * var v = meanpn( N, x, 1 );
51
+ * // returns ~0.3333
52
+ */
53
+ function meanpn( N, x, stride ) {
54
+ var mu;
55
+ var c;
56
+
57
+ if ( N <= 0 ) {
58
+ return NaN;
59
+ }
60
+ if ( N === 1 || stride === 0 ) {
61
+ return x[ 0 ];
62
+ }
63
+ // Compute an estimate for the meanpn:
64
+ mu = gsumpw( N, x, stride ) / N;
65
+
66
+ // Compute an error term:
67
+ c = gapxsumpw( N, -mu, x, stride ) / N;
68
+
69
+ return mu + c;
70
+ }
71
+
72
+
73
+ // EXPORTS //
74
+
75
+ module.exports = meanpn;
package/lib/ndarray.js ADDED
@@ -0,0 +1,78 @@
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 gsumpw = require( '@stdlib/blas-ext-base-gsumpw' ).ndarray;
24
+ var gapxsumpw = require( '@stdlib/blas-ext-base-gapxsumpw' ).ndarray;
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the arithmetic mean of a strided array using a two-pass error correction algorithm.
31
+ *
32
+ * ## Method
33
+ *
34
+ * - This implementation uses a two-pass approach, as suggested by Neely (1966).
35
+ *
36
+ * ## References
37
+ *
38
+ * - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).
39
+ * - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).
40
+ *
41
+ * @param {PositiveInteger} N - number of indexed elements
42
+ * @param {NumericArray} x - input array
43
+ * @param {integer} stride - stride length
44
+ * @param {NonNegativeInteger} offset - starting index
45
+ * @returns {number} arithmetic mean
46
+ *
47
+ * @example
48
+ * var floor = require( '@stdlib/math-base-special-floor' );
49
+ *
50
+ * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
51
+ * var N = floor( x.length / 2 );
52
+ *
53
+ * var v = meanpn( N, x, 2, 1 );
54
+ * // returns 1.25
55
+ */
56
+ function meanpn( N, x, stride, offset ) {
57
+ var mu;
58
+ var c;
59
+
60
+ if ( N <= 0 ) {
61
+ return NaN;
62
+ }
63
+ if ( N === 1 || stride === 0 ) {
64
+ return x[ offset ];
65
+ }
66
+ // Compute an estimate for the meanpn:
67
+ mu = gsumpw( N, x, stride, offset ) / N;
68
+
69
+ // Compute an error term:
70
+ c = gapxsumpw( N, -mu, x, stride, offset ) / N;
71
+
72
+ return mu + c;
73
+ }
74
+
75
+
76
+ // EXPORTS //
77
+
78
+ module.exports = meanpn;
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@ohos-ports/stats-base-meanpn",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.2-beta.1",
4
+ "description": "Calculate the arithmetic mean of a strided array using a two-pass error correction algorithm.",
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": "https://github.com/ohos-ports/ohos-ports.git",
28
+ "directory": "ports/@stdlib/stats-base-meanpn/0.2.2"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
32
+ },
33
+ "dependencies": {
34
+ "@stdlib/blas-ext-base-gapxsumpw": "^0.2.1",
35
+ "@stdlib/blas-ext-base-gsumpw": "^0.2.1",
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
+ "openharmony",
50
+ "openbsd",
51
+ "sunos",
52
+ "win32",
53
+ "windows"
54
+ ],
55
+ "keywords": [
56
+ "stdlib",
57
+ "stdmath",
58
+ "statistics",
59
+ "stats",
60
+ "mathematics",
61
+ "math",
62
+ "average",
63
+ "avg",
64
+ "mean",
65
+ "arithmetic mean",
66
+ "central tendency",
67
+ "strided",
68
+ "strided array",
69
+ "array"
70
+ ],
71
+ "__stdlib__": {},
72
+ "funding": {
73
+ "type": "opencollective",
74
+ "url": "https://opencollective.com/stdlib"
75
+ }
76
+ }