@stdlib/stats-strided-dsmeanpn 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 +429 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +7 -0
- package/docs/img/equation_arithmetic_mean.svg +42 -0
- package/docs/types/index.d.ts +92 -0
- package/include/stdlib/stats/strided/dsmeanpn.h +45 -0
- package/lib/dsmeanpn.js +61 -0
- package/lib/dsmeanpn.native.js +51 -0
- package/lib/index.js +68 -0
- package/lib/main.js +35 -0
- package/lib/native.js +35 -0
- package/lib/ndarray.js +77 -0
- package/lib/ndarray.native.js +52 -0
- package/manifest.json +107 -0
- package/package.json +91 -0
- package/src/addon.c +60 -0
- package/src/main.c +78 -0
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/stats-strided-dsmeanpn",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Calculate the arithmetic mean of a single-precision floating-point strided array using a two-pass error correction algorithm with extended accumulation and returning an extended precision result.",
|
|
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
|
+
"browser": "./lib/main.js",
|
|
18
|
+
"gypfile": false,
|
|
19
|
+
"directories": {
|
|
20
|
+
"doc": "./docs",
|
|
21
|
+
"include": "./include",
|
|
22
|
+
"lib": "./lib",
|
|
23
|
+
"src": "./src",
|
|
24
|
+
"dist": "./dist"
|
|
25
|
+
},
|
|
26
|
+
"types": "./docs/types",
|
|
27
|
+
"scripts": {},
|
|
28
|
+
"homepage": "https://stdlib.io",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git://github.com/stdlib-js/stats-strided-dsmeanpn.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@stdlib/assert-is-error": "^0.2.2",
|
|
38
|
+
"@stdlib/blas-base-shared": "^0.1.0",
|
|
39
|
+
"@stdlib/blas-ext-base-dsapxsum": "^0.2.2",
|
|
40
|
+
"@stdlib/blas-ext-base-dssum": "^0.2.2",
|
|
41
|
+
"@stdlib/napi-argv": "^0.2.2",
|
|
42
|
+
"@stdlib/napi-argv-int64": "^0.2.2",
|
|
43
|
+
"@stdlib/napi-argv-strided-float32array": "^0.2.2",
|
|
44
|
+
"@stdlib/napi-create-double": "^0.0.2",
|
|
45
|
+
"@stdlib/napi-export": "^0.3.0",
|
|
46
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
47
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
48
|
+
"@stdlib/utils-library-manifest": "^0.2.3",
|
|
49
|
+
"@stdlib/utils-try-require": "^0.2.2"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=0.10.0",
|
|
54
|
+
"npm": ">2.7.0"
|
|
55
|
+
},
|
|
56
|
+
"os": [
|
|
57
|
+
"aix",
|
|
58
|
+
"darwin",
|
|
59
|
+
"freebsd",
|
|
60
|
+
"linux",
|
|
61
|
+
"macos",
|
|
62
|
+
"openbsd",
|
|
63
|
+
"sunos",
|
|
64
|
+
"win32",
|
|
65
|
+
"windows"
|
|
66
|
+
],
|
|
67
|
+
"keywords": [
|
|
68
|
+
"stdlib",
|
|
69
|
+
"stdmath",
|
|
70
|
+
"statistics",
|
|
71
|
+
"stats",
|
|
72
|
+
"mathematics",
|
|
73
|
+
"math",
|
|
74
|
+
"average",
|
|
75
|
+
"avg",
|
|
76
|
+
"mean",
|
|
77
|
+
"arithmetic mean",
|
|
78
|
+
"central tendency",
|
|
79
|
+
"strided",
|
|
80
|
+
"strided array",
|
|
81
|
+
"typed",
|
|
82
|
+
"array",
|
|
83
|
+
"float32",
|
|
84
|
+
"float",
|
|
85
|
+
"float32array"
|
|
86
|
+
],
|
|
87
|
+
"funding": {
|
|
88
|
+
"type": "opencollective",
|
|
89
|
+
"url": "https://opencollective.com/stdlib"
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
#include "stdlib/stats/strided/dsmeanpn.h"
|
|
20
|
+
#include "stdlib/napi/export.h"
|
|
21
|
+
#include "stdlib/napi/argv.h"
|
|
22
|
+
#include "stdlib/napi/argv_int64.h"
|
|
23
|
+
#include "stdlib/napi/argv_strided_float32array.h"
|
|
24
|
+
#include "stdlib/napi/create_double.h"
|
|
25
|
+
#include "stdlib/blas/base/shared.h"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Receives JavaScript callback invocation data.
|
|
29
|
+
*
|
|
30
|
+
* @param env environment under which the function is invoked
|
|
31
|
+
* @param info callback data
|
|
32
|
+
* @return Node-API value
|
|
33
|
+
*/
|
|
34
|
+
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
35
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
|
|
36
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
37
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
38
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
39
|
+
STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsmeanpn)( N, X, strideX ), v );
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Receives JavaScript callback invocation data.
|
|
45
|
+
*
|
|
46
|
+
* @param env environment under which the function is invoked
|
|
47
|
+
* @param info callback data
|
|
48
|
+
* @return Node-API value
|
|
49
|
+
*/
|
|
50
|
+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
|
|
51
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
|
|
52
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
53
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
54
|
+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 );
|
|
55
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
56
|
+
STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsmeanpn_ndarray)( N, X, strideX, offsetX ), v );
|
|
57
|
+
return v;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method )
|
package/src/main.c
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
|
+
#include "stdlib/stats/strided/dsmeanpn.h"
|
|
20
|
+
#include "stdlib/blas/ext/base/dssum.h"
|
|
21
|
+
#include "stdlib/blas/ext/base/dsapxsum.h"
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
23
|
+
#include "stdlib/strided/base/stride2offset.h"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Computes the arithmetic mean of a single-precision floating-point strided array using a two-pass error correction algorithm with extended accumulation and returning an extended precision result.
|
|
27
|
+
*
|
|
28
|
+
* ## Method
|
|
29
|
+
*
|
|
30
|
+
* - This implementation uses a two-pass approach, as suggested by Neely (1966).
|
|
31
|
+
*
|
|
32
|
+
* ## References
|
|
33
|
+
*
|
|
34
|
+
* - 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).
|
|
35
|
+
* - 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).
|
|
36
|
+
*
|
|
37
|
+
* @param N number of indexed elements
|
|
38
|
+
* @param X input array
|
|
39
|
+
* @param strideX stride length
|
|
40
|
+
* @return output value
|
|
41
|
+
*/
|
|
42
|
+
double API_SUFFIX(stdlib_strided_dsmeanpn)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) {
|
|
43
|
+
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
|
|
44
|
+
return API_SUFFIX(stdlib_strided_dsmeanpn_ndarray)( N, X, strideX, ox );
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Computes the arithmetic mean of a single-precision floating-point strided array using a two-pass error correction algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result.
|
|
49
|
+
*
|
|
50
|
+
* @param N number of indexed elements
|
|
51
|
+
* @param X input array
|
|
52
|
+
* @param strideX stride length
|
|
53
|
+
* @param offsetX starting index for X
|
|
54
|
+
* @return output value
|
|
55
|
+
*/
|
|
56
|
+
double API_SUFFIX(stdlib_strided_dsmeanpn_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
|
|
57
|
+
double dN;
|
|
58
|
+
double mu;
|
|
59
|
+
double c;
|
|
60
|
+
|
|
61
|
+
if ( N <= 0 ) {
|
|
62
|
+
return 0.0 / 0.0; // NaN
|
|
63
|
+
}
|
|
64
|
+
if ( N == 1 || strideX == 0 ) {
|
|
65
|
+
return X[ offsetX ];
|
|
66
|
+
}
|
|
67
|
+
dN = (double)N;
|
|
68
|
+
|
|
69
|
+
// Compute an estimate for the mean:
|
|
70
|
+
mu = stdlib_strided_dssum_ndarray( N, X, strideX, offsetX );
|
|
71
|
+
mu /= dN;
|
|
72
|
+
|
|
73
|
+
// Compute an error term:
|
|
74
|
+
c = stdlib_strided_dsapxsum_ndarray( N, -mu, X, strideX, offsetX );
|
|
75
|
+
c /= dN;
|
|
76
|
+
|
|
77
|
+
return mu + c;
|
|
78
|
+
}
|