@stdlib/stats-strided-dstdevyc 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 dstdevyc = require( './dstdevyc.native.js' );
25
+ var ndarray = require( './ndarray.native.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ setReadOnly( dstdevyc, 'ndarray', ndarray );
31
+
32
+
33
+ // EXPORTS //
34
+
35
+ module.exports = dstdevyc;
package/lib/ndarray.js ADDED
@@ -0,0 +1,58 @@
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 dvarianceyc = require( '@stdlib/stats-strided-dvarianceyc' ).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 a one-pass algorithm proposed by Youngs and Cramer.
31
+ *
32
+ * ## References
33
+ *
34
+ * - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826).
35
+ *
36
+ * @param {PositiveInteger} N - number of indexed elements
37
+ * @param {number} correction - degrees of freedom adjustment
38
+ * @param {Float64Array} x - input array
39
+ * @param {integer} strideX - stride length
40
+ * @param {NonNegativeInteger} offsetX - starting index
41
+ * @returns {number} standard deviation
42
+ *
43
+ * @example
44
+ * var Float64Array = require( '@stdlib/array-float64' );
45
+ *
46
+ * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
47
+ *
48
+ * var v = dstdevyc( 4, 1.0, x, 2, 1 );
49
+ * // returns 2.5
50
+ */
51
+ function dstdevyc( N, correction, x, strideX, offsetX ) {
52
+ return sqrt( dvarianceyc( N, correction, x, strideX, offsetX ) );
53
+ }
54
+
55
+
56
+ // EXPORTS //
57
+
58
+ module.exports = dstdevyc;
@@ -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 a one-pass algorithm proposed by Youngs and Cramer.
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 = dstdevyc( 4, 1.0, x, 2, 1 );
44
+ * // returns 2.5
45
+ */
46
+ function dstdevyc( N, correction, x, strideX, offsetX ) {
47
+ return addon.ndarray( N, correction, x, strideX, offsetX );
48
+ }
49
+
50
+
51
+ // EXPORTS //
52
+
53
+ module.exports = dstdevyc;
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-dvarianceyc",
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-dvarianceyc"
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-dvarianceyc"
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-dvarianceyc"
105
+ ]
106
+ }
107
+ ]
108
+ }
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "@stdlib/stats-strided-dstdevyc",
3
+ "version": "0.1.0",
4
+ "description": "Calculate the standard deviation of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer.",
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-dstdevyc.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-dvarianceyc": "github:stdlib-js/stats-strided-dvarianceyc#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
+ "strided",
86
+ "strided array",
87
+ "typed",
88
+ "array",
89
+ "float64",
90
+ "double",
91
+ "float64array"
92
+ ],
93
+ "funding": {
94
+ "type": "opencollective",
95
+ "url": "https://opencollective.com/stdlib"
96
+ }
97
+ }
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/dstdevyc.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_dstdevyc)( 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_dstdevyc_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,55 @@
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/dstdevyc.h"
20
+ #include "stdlib/stats/strided/dvarianceyc.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 a one-pass algorithm proposed by Youngs and Cramer.
27
+ *
28
+ * ## References
29
+ *
30
+ * - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826).
31
+ *
32
+ * @param N number of indexed elements
33
+ * @param correction degrees of freedom adjustment
34
+ * @param X input array
35
+ * @param strideX stride length
36
+ * @return output value
37
+ */
38
+ double API_SUFFIX(stdlib_strided_dstdevyc)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) {
39
+ const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
40
+ return API_SUFFIX(stdlib_strided_dstdevyc_ndarray)( N, correction, X, strideX, ox );
41
+ }
42
+
43
+ /**
44
+ * Computes the standard deviation of a double-precision floating-point strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics.
45
+ *
46
+ * @param N number of indexed elements
47
+ * @param correction degrees of freedom adjustment
48
+ * @param X input array
49
+ * @param strideX stride length
50
+ * @param offsetX starting index for X
51
+ * @return output value
52
+ */
53
+ double API_SUFFIX(stdlib_strided_dstdevyc_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
54
+ return stdlib_base_sqrt( API_SUFFIX(stdlib_strided_dvarianceyc_ndarray)( N, correction, X, strideX, offsetX ) );
55
+ }