@stdlib/stats-strided-dstdevwd 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/lib/native.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 dstdevwd = require( './dstdevwd.native.js' );
25
+ var ndarray = require( './ndarray.native.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( dstdevwd, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = dstdevwd;
package/lib/ndarray.js ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2020 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var dvariancewd = require( '@stdlib/stats-strided-dvariancewd' ).ndarray;
24
+ var sqrt = require( '@stdlib/math-base-special-sqrt' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Computes the standard deviation of a double-precision floating-point strided array using Welford's algorithm.
31
+ *
32
+ * ## References
33
+ *
34
+ * - 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).
35
+ * - 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).
36
+ *
37
+ * @param {PositiveInteger} N - number of indexed elements
38
+ * @param {number} correction - degrees of freedom adjustment
39
+ * @param {Float64Array} x - input array
40
+ * @param {integer} strideX - stride length
41
+ * @param {NonNegativeInteger} offsetX - starting index
42
+ * @returns {number} standard deviation
43
+ *
44
+ * @example
45
+ * var Float64Array = require( '@stdlib/array-float64' );
46
+ *
47
+ * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
48
+ *
49
+ * var v = dstdevwd( 4, 1, x, 2, 1 );
50
+ * // returns 2.5
51
+ */
52
+ function dstdevwd( N, correction, x, strideX, offsetX ) {
53
+ return sqrt( dvariancewd( N, correction, x, strideX, offsetX ) );
54
+ }
55
+
56
+
57
+ // EXPORTS //
58
+
59
+ module.exports = dstdevwd;
@@ -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 double-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 {Float64Array} 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 Float64Array = require( '@stdlib/array-float64' );
40
+ *
41
+ * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
42
+ *
43
+ * var v = dstdevwd( 4, 1, x, 2, 1 );
44
+ * // returns 2.5
45
+ */
46
+ function dstdevwd( N, correction, x, strideX, offsetX ) {
47
+ return addon.ndarray( N, correction, x, strideX, offsetX );
48
+ }
49
+
50
+
51
+ // EXPORTS //
52
+
53
+ module.exports = dstdevwd;
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-sqrt",
44
+ "@stdlib/stats-strided-dvariancewd",
45
+ "@stdlib/napi-export",
46
+ "@stdlib/napi-argv",
47
+ "@stdlib/napi-argv-int64",
48
+ "@stdlib/napi-argv-double",
49
+ "@stdlib/napi-argv-strided-float64array",
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-sqrt",
68
+ "@stdlib/stats-strided-dvariancewd"
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-sqrt",
86
+ "@stdlib/stats-strided-dvariancewd"
87
+ ]
88
+ },
89
+ {
90
+ "task": "",
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-sqrt",
104
+ "@stdlib/stats-strided-dvariancewd"
105
+ ]
106
+ }
107
+ ]
108
+ }
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@stdlib/stats-strided-dstdevwd",
3
+ "version": "0.1.0",
4
+ "description": "Calculate the standard deviation of a double-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-dstdevwd.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/math-base-special-sqrt": "^0.2.2",
40
+ "@stdlib/napi-argv": "^0.2.2",
41
+ "@stdlib/napi-argv-double": "^0.2.1",
42
+ "@stdlib/napi-argv-int64": "^0.2.2",
43
+ "@stdlib/napi-argv-strided-float64array": "^0.2.2",
44
+ "@stdlib/napi-create-double": "^0.0.2",
45
+ "@stdlib/napi-export": "^0.3.0",
46
+ "@stdlib/stats-strided-dvariancewd": "github:stdlib-js/stats-strided-dvariancewd#main",
47
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
48
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
49
+ "@stdlib/utils-library-manifest": "^0.2.3",
50
+ "@stdlib/utils-try-require": "^0.2.2"
51
+ },
52
+ "devDependencies": {},
53
+ "engines": {
54
+ "node": ">=0.10.0",
55
+ "npm": ">2.7.0"
56
+ },
57
+ "os": [
58
+ "aix",
59
+ "darwin",
60
+ "freebsd",
61
+ "linux",
62
+ "macos",
63
+ "openbsd",
64
+ "sunos",
65
+ "win32",
66
+ "windows"
67
+ ],
68
+ "keywords": [
69
+ "stdlib",
70
+ "stdmath",
71
+ "statistics",
72
+ "stats",
73
+ "mathematics",
74
+ "math",
75
+ "variance",
76
+ "var",
77
+ "deviation",
78
+ "dispersion",
79
+ "spread",
80
+ "sample standard deviation",
81
+ "unbiased",
82
+ "stdev",
83
+ "std",
84
+ "standard deviation",
85
+ "welford",
86
+ "strided",
87
+ "strided array",
88
+ "typed",
89
+ "array",
90
+ "float64",
91
+ "double",
92
+ "float64array"
93
+ ],
94
+ "funding": {
95
+ "type": "opencollective",
96
+ "url": "https://opencollective.com/stdlib"
97
+ }
98
+ }
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/dstdevwd.h"
20
+ #include "stdlib/blas/base/shared.h"
21
+ #include "stdlib/napi/export.h"
22
+ #include "stdlib/napi/argv.h"
23
+ #include "stdlib/napi/argv_int64.h"
24
+ #include "stdlib/napi/argv_double.h"
25
+ #include "stdlib/napi/argv_strided_float64array.h"
26
+ #include "stdlib/napi/create_double.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_DOUBLE( env, correction, argv, 1 );
40
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
41
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 )
42
+ STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dstdevwd)( 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_DOUBLE( env, correction, argv, 1 );
57
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
58
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
59
+ STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 );
60
+ STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dstdevwd_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,56 @@
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/dstdevwd.h"
20
+ #include "stdlib/stats/strided/dvariancewd.h"
21
+ #include "stdlib/blas/base/shared.h"
22
+ #include "stdlib/math/base/special/sqrt.h"
23
+ #include "stdlib/strided/base/stride2offset.h"
24
+
25
+ /**
26
+ * Computes the standard deviation of a double-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
+ double API_SUFFIX(stdlib_strided_dstdevwd)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) {
40
+ const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
41
+ return API_SUFFIX(stdlib_strided_dstdevwd_ndarray)( N, correction, X, strideX, ox );
42
+ }
43
+
44
+ /**
45
+ * Computes the standard deviation of a double-precision floating-point strided array using Welford's algorithm and alternative indexing semantics.
46
+ *
47
+ * @param N number of indexed elements
48
+ * @param correction degrees of freedom adjustment
49
+ * @param X input array
50
+ * @param strideX stride length
51
+ * @param offsetX starting index for X
52
+ * @return output value
53
+ */
54
+ double API_SUFFIX(stdlib_strided_dstdevwd_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
55
+ return stdlib_base_sqrt( API_SUFFIX(stdlib_strided_dvariancewd_ndarray)( N, correction, X, strideX, offsetX ) );
56
+ }