@stdlib/stats-strided-sstdevwd 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.
@@ -0,0 +1,53 @@
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 addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the standard deviation of a single-precision floating-point strided array using Welford's algorithm.
30
+ *
31
+ * @param {PositiveInteger} N - number of indexed elements
32
+ * @param {number} correction - degrees of freedom adjustment
33
+ * @param {Float32Array} x - input array
34
+ * @param {integer} strideX - stride length
35
+ * @param {NonNegativeInteger} offsetX - starting index
36
+ * @returns {number} standard deviation
37
+ *
38
+ * @example
39
+ * var Float32Array = require( '@stdlib/array-float32' );
40
+ *
41
+ * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
42
+ *
43
+ * var v = sstdevwd( 4, 1, x, 2, 1 );
44
+ * // returns 2.5
45
+ */
46
+ function sstdevwd( N, correction, x, strideX, offsetX ) {
47
+ return addon.ndarray( N, correction, x, strideX, offsetX );
48
+ }
49
+
50
+
51
+ // EXPORTS //
52
+
53
+ module.exports = sstdevwd;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2020 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
24
+ var svariancewd = require( '@stdlib/stats-strided-svariancewd' );
25
+ var sqrt = require( '@stdlib/math-base-special-sqrt' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * Computes the standard deviation of a single-precision floating-point strided array using Welford's algorithm.
32
+ *
33
+ * ## References
34
+ *
35
+ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022).
36
+ * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961).
37
+ *
38
+ * @param {PositiveInteger} N - number of indexed elements
39
+ * @param {number} correction - degrees of freedom adjustment
40
+ * @param {Float32Array} x - input array
41
+ * @param {integer} strideX - stride length
42
+ * @returns {number} standard deviation
43
+ *
44
+ * @example
45
+ * var Float32Array = require( '@stdlib/array-float32' );
46
+ *
47
+ * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
48
+ *
49
+ * var v = sstdevwd( x.length, 1, x, 1 );
50
+ * // returns ~2.0817
51
+ */
52
+ function sstdevwd( N, correction, x, strideX ) {
53
+ return float64ToFloat32( sqrt( svariancewd( N, correction, x, strideX ) ) );
54
+ }
55
+
56
+
57
+ // EXPORTS //
58
+
59
+ module.exports = sstdevwd;
@@ -0,0 +1,52 @@
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 addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Computes the standard deviation of a single-precision floating-point strided array using Welford's algorithm.
30
+ *
31
+ * @param {PositiveInteger} N - number of indexed elements
32
+ * @param {number} correction - degrees of freedom adjustment
33
+ * @param {Float32Array} x - input array
34
+ * @param {integer} strideX - stride length
35
+ * @returns {number} standard deviation
36
+ *
37
+ * @example
38
+ * var Float32Array = require( '@stdlib/array-float32' );
39
+ *
40
+ * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
41
+ *
42
+ * var v = sstdevwd( x.length, 1, x, 1 );
43
+ * // returns ~2.0817
44
+ */
45
+ function sstdevwd( N, correction, x, strideX ) {
46
+ return addon( N, correction, x, strideX );
47
+ }
48
+
49
+
50
+ // EXPORTS //
51
+
52
+ module.exports = sstdevwd;
package/manifest.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "options": {
3
+ "task": "build",
4
+ "wasm": false
5
+ },
6
+ "fields": [
7
+ {
8
+ "field": "src",
9
+ "resolve": true,
10
+ "relative": true
11
+ },
12
+ {
13
+ "field": "include",
14
+ "resolve": true,
15
+ "relative": true
16
+ },
17
+ {
18
+ "field": "libraries",
19
+ "resolve": false,
20
+ "relative": false
21
+ },
22
+ {
23
+ "field": "libpath",
24
+ "resolve": true,
25
+ "relative": false
26
+ }
27
+ ],
28
+ "confs": [
29
+ {
30
+ "task": "build",
31
+ "wasm": false,
32
+ "src": [
33
+ "./src/main.c"
34
+ ],
35
+ "include": [
36
+ "./include"
37
+ ],
38
+ "libraries": [],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/blas-base-shared",
42
+ "@stdlib/strided-base-stride2offset",
43
+ "@stdlib/math-base-special-sqrtf",
44
+ "@stdlib/stats-strided-svariancewd",
45
+ "@stdlib/napi-export",
46
+ "@stdlib/napi-argv",
47
+ "@stdlib/napi-argv-int64",
48
+ "@stdlib/napi-argv-float",
49
+ "@stdlib/napi-argv-strided-float32array",
50
+ "@stdlib/napi-create-double"
51
+ ]
52
+ },
53
+ {
54
+ "task": "benchmark",
55
+ "wasm": false,
56
+ "src": [
57
+ "./src/main.c"
58
+ ],
59
+ "include": [
60
+ "./include"
61
+ ],
62
+ "libraries": [],
63
+ "libpath": [],
64
+ "dependencies": [
65
+ "@stdlib/blas-base-shared",
66
+ "@stdlib/strided-base-stride2offset",
67
+ "@stdlib/math-base-special-sqrtf",
68
+ "@stdlib/stats-strided-svariancewd"
69
+ ]
70
+ },
71
+ {
72
+ "task": "examples",
73
+ "wasm": false,
74
+ "src": [
75
+ "./src/main.c"
76
+ ],
77
+ "include": [
78
+ "./include"
79
+ ],
80
+ "libraries": [],
81
+ "libpath": [],
82
+ "dependencies": [
83
+ "@stdlib/blas-base-shared",
84
+ "@stdlib/strided-base-stride2offset",
85
+ "@stdlib/math-base-special-sqrtf",
86
+ "@stdlib/stats-strided-svariancewd"
87
+ ]
88
+ },
89
+ {
90
+ "task": "build",
91
+ "wasm": true,
92
+ "src": [
93
+ "./src/main.c"
94
+ ],
95
+ "include": [
96
+ "./include"
97
+ ],
98
+ "libraries": [],
99
+ "libpath": [],
100
+ "dependencies": [
101
+ "@stdlib/blas-base-shared",
102
+ "@stdlib/strided-base-stride2offset",
103
+ "@stdlib/math-base-special-sqrtf",
104
+ "@stdlib/stats-strided-svariancewd"
105
+ ]
106
+ }
107
+ ]
108
+ }
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@stdlib/stats-strided-sstdevwd",
3
+ "version": "0.1.0",
4
+ "description": "Calculate the standard deviation of a single-precision floating-point strided array using Welford's 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
+ "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-sstdevwd.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.2.0",
39
+ "@stdlib/math-base-special-sqrt": "^0.2.2",
40
+ "@stdlib/math-base-special-sqrtf": "^0.2.2",
41
+ "@stdlib/napi-argv": "^0.2.2",
42
+ "@stdlib/napi-argv-float": "^0.2.2",
43
+ "@stdlib/napi-argv-int64": "^0.2.2",
44
+ "@stdlib/napi-argv-strided-float32array": "^0.2.2",
45
+ "@stdlib/napi-create-double": "^0.0.2",
46
+ "@stdlib/napi-export": "^0.3.0",
47
+ "@stdlib/number-float64-base-to-float32": "^0.2.2",
48
+ "@stdlib/stats-strided-svariancewd": "github:stdlib-js/stats-strided-svariancewd#main",
49
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
50
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
51
+ "@stdlib/utils-library-manifest": "^0.2.3",
52
+ "@stdlib/utils-try-require": "^0.2.2"
53
+ },
54
+ "devDependencies": {},
55
+ "engines": {
56
+ "node": ">=0.10.0",
57
+ "npm": ">2.7.0"
58
+ },
59
+ "os": [
60
+ "aix",
61
+ "darwin",
62
+ "freebsd",
63
+ "linux",
64
+ "macos",
65
+ "openbsd",
66
+ "sunos",
67
+ "win32",
68
+ "windows"
69
+ ],
70
+ "keywords": [
71
+ "stdlib",
72
+ "stdmath",
73
+ "statistics",
74
+ "stats",
75
+ "mathematics",
76
+ "math",
77
+ "variance",
78
+ "var",
79
+ "deviation",
80
+ "dispersion",
81
+ "spread",
82
+ "sample standard deviation",
83
+ "unbiased",
84
+ "stdev",
85
+ "std",
86
+ "standard deviation",
87
+ "welford",
88
+ "strided",
89
+ "strided array",
90
+ "typed",
91
+ "array",
92
+ "float32",
93
+ "float",
94
+ "single",
95
+ "float32array"
96
+ ],
97
+ "funding": {
98
+ "type": "opencollective",
99
+ "url": "https://opencollective.com/stdlib"
100
+ }
101
+ }
package/src/addon.c ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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/sstdevwd.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/napi/argv_float.h"
26
+ #include "stdlib/blas/base/shared.h"
27
+ #include <node_api.h>
28
+
29
+ /**
30
+ * Receives JavaScript callback invocation data.
31
+ *
32
+ * @param env environment under which the function is invoked
33
+ * @param info callback data
34
+ * @return Node-API value
35
+ */
36
+ static napi_value addon( napi_env env, napi_callback_info info ) {
37
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
38
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
39
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
40
+ STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 );
41
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2);
42
+ STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_sstdevwd)( N, correction, X, strideX ), v );
43
+ return v;
44
+ }
45
+
46
+ /**
47
+ * Receives JavaScript callback invocation data.
48
+ *
49
+ * @param env environment under which the function is invoked
50
+ * @param info callback data
51
+ * @return Node-API value
52
+ */
53
+ static napi_value addon_method( napi_env env, napi_callback_info info ) {
54
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 5 );
55
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
56
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
57
+ STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 );
58
+ STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 );
59
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 );
60
+ STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_sstdevwd_ndarray)( N, correction, X, strideX, offsetX ), v );
61
+ return v;
62
+ }
63
+
64
+ STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method );
package/src/main.c ADDED
@@ -0,0 +1,61 @@
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/sstdevwd.h"
20
+ #include "stdlib/stats/strided/svariancewd.h"
21
+ #include "stdlib/blas/base/shared.h"
22
+ #include "stdlib/math/base/special/sqrtf.h"
23
+ #include "stdlib/strided/base/stride2offset.h"
24
+
25
+ /**
26
+ * Computes the standard deviation of a single-precision floating-point strided array using Welford's algorithm.
27
+ *
28
+ * ## References
29
+ *
30
+ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022).
31
+ * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961).
32
+ *
33
+ * @param N number of indexed elements
34
+ * @param correction degrees of freedom adjustment
35
+ * @param X input array
36
+ * @param strideX stride length
37
+ * @return output value
38
+ */
39
+ float API_SUFFIX(stdlib_strided_sstdevwd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) {
40
+ const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
41
+ return API_SUFFIX(stdlib_strided_sstdevwd_ndarray)( N, correction, X, strideX, ox );
42
+ }
43
+
44
+ /**
45
+ * Computes the standard deviation of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics.
46
+ *
47
+ * ## References
48
+ *
49
+ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022).
50
+ * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961).
51
+ *
52
+ * @param N number of indexed elements
53
+ * @param correction degrees of freedom adjustment
54
+ * @param X input array
55
+ * @param strideX stride length
56
+ * @param offsetX starting index for X
57
+ * @return output value
58
+ */
59
+ float API_SUFFIX(stdlib_strided_sstdevwd_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
60
+ return stdlib_base_sqrtf( API_SUFFIX(stdlib_strided_svariancewd_ndarray)( N, correction, X, strideX, offsetX ) );
61
+ }