@stdlib/stats-base-dists-t-variance 0.2.2 → 0.3.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/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -129,18 +129,103 @@ y = variance( 0.8 );
129
129
  <!-- eslint no-undef: "error" -->
130
130
 
131
131
  ```javascript
132
- var randu = require( '@stdlib/random-base-randu' );
133
- var round = require( '@stdlib/math-base-special-round' );
132
+ var uniform = require( '@stdlib/random-array-uniform' );
133
+ var logEachMap = require( '@stdlib/console-log-each-map' );
134
134
  var variance = require( '@stdlib/stats-base-dists-t-variance' );
135
135
 
136
- var v;
137
- var y;
138
- var i;
136
+ var opts = {
137
+ 'dtype': 'float64'
138
+ };
139
+ var v = uniform( 10, 0.0, 20.0, opts );
139
140
 
140
- for ( i = 0; i < 10; i++ ) {
141
- v = randu() * 20.0;
142
- y = variance( v );
143
- console.log( 'v: %d, Var(X,v): %d', v.toFixed( 4 ), y.toFixed( 4 ) );
141
+ logEachMap( 'v: %0.4f, Var(X;v): %0.4f', v, variance );
142
+ ```
143
+
144
+ </section>
145
+
146
+ <!-- /.examples -->
147
+
148
+ <!-- C interface documentation. -->
149
+
150
+ * * *
151
+
152
+ <section class="c">
153
+
154
+ ## C APIs
155
+
156
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
157
+
158
+ <section class="intro">
159
+
160
+ </section>
161
+
162
+ <!-- /.intro -->
163
+
164
+ <!-- C usage documentation. -->
165
+
166
+ <section class="usage">
167
+
168
+ ### Usage
169
+
170
+ ```c
171
+ #include "stdlib/stats/base/dists/t/variance.h"
172
+ ```
173
+
174
+ #### stdlib_base_dists_t_variance( v )
175
+
176
+ Returns the variance for a Student's t-distribution.
177
+
178
+ ```c
179
+ double out = stdlib_base_dists_t_variance( 5.0 );
180
+ // returns ~1.667
181
+ ```
182
+
183
+ The function accepts the following arguments:
184
+
185
+ - **v**: `[in] double` degrees of freedom.
186
+
187
+ ```c
188
+ double stdlib_base_dists_t_variance( const double v );
189
+ ```
190
+
191
+ </section>
192
+
193
+ <!-- /.usage -->
194
+
195
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
196
+
197
+ <section class="notes">
198
+
199
+ </section>
200
+
201
+ <!-- /.notes -->
202
+
203
+ <!-- C API usage examples. -->
204
+
205
+ <section class="examples">
206
+
207
+ ### Examples
208
+
209
+ ```c
210
+ #include "stdlib/stats/base/dists/t/variance.h"
211
+ #include <stdlib.h>
212
+ #include <stdio.h>
213
+
214
+ static double random_uniform( const double min, const double max ) {
215
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
216
+ return min + ( v*(max-min) );
217
+ }
218
+
219
+ int main( void ) {
220
+ double v;
221
+ double y;
222
+ int i;
223
+
224
+ for ( i = 0; i < 25; i++ ) {
225
+ v = random_uniform( 2.1, 100.0 );
226
+ y = stdlib_base_dists_t_variance( v );
227
+ printf( "v: %.4f, Var(X;v): %.4f\n", v, y );
228
+ }
144
229
  }
145
230
  ```
146
231
 
@@ -148,6 +233,10 @@ for ( i = 0; i < 10; i++ ) {
148
233
 
149
234
  <!-- /.examples -->
150
235
 
236
+ </section>
237
+
238
+ <!-- /.c -->
239
+
151
240
  <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
152
241
 
153
242
  <section class="references">
@@ -190,7 +279,7 @@ See [LICENSE][stdlib-license].
190
279
 
191
280
  ## Copyright
192
281
 
193
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
282
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
194
283
 
195
284
  </section>
196
285
 
@@ -203,8 +292,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
203
292
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-t-variance.svg
204
293
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-t-variance
205
294
 
206
- [test-image]: https://github.com/stdlib-js/stats-base-dists-t-variance/actions/workflows/test.yml/badge.svg?branch=v0.2.2
207
- [test-url]: https://github.com/stdlib-js/stats-base-dists-t-variance/actions/workflows/test.yml?query=branch:v0.2.2
295
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-t-variance/actions/workflows/test.yml/badge.svg?branch=v0.3.0
296
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-t-variance/actions/workflows/test.yml?query=branch:v0.3.0
208
297
 
209
298
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-t-variance/main.svg
210
299
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-t-variance?branch=main
@@ -216,8 +305,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
216
305
 
217
306
  -->
218
307
 
219
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
220
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
308
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
309
+ [chat-url]: https://stdlib.zulipchat.com
221
310
 
222
311
  [stdlib]: https://github.com/stdlib-js/stdlib
223
312
 
@@ -0,0 +1,45 @@
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
+ #ifndef STDLIB_STATS_BASE_DISTS_T_VARIANCE_H
20
+ #define STDLIB_STATS_BASE_DISTS_T_VARIANCE_H
21
+
22
+ /*
23
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
24
+ */
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /**
30
+ * Returns the variance for a Student's t-distribution with degrees of freedom `v`.
31
+ *
32
+ * @param v degrees of freedom
33
+ * @return variance
34
+ *
35
+ * @example
36
+ * double y = stdlib_base_dists_t_variance( 5.0 );
37
+ * // returns ~1.667
38
+ */
39
+ double stdlib_base_dists_t_variance( const double v );
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
44
+
45
+ #endif // !STDLIB_STATS_BASE_DISTS_T_VARIANCE_H
package/lib/native.js ADDED
@@ -0,0 +1,58 @@
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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Returns the variance for a Student's t-distribution with degrees of freedom `v`.
30
+ *
31
+ * @private
32
+ * @param {number} v - degrees of freedom
33
+ * @returns {number} variance
34
+ *
35
+ * @example
36
+ * var y = variance( 5.0 );
37
+ * // returns ~1.667
38
+ *
39
+ * @example
40
+ * var y = variance( 3.0 );
41
+ * // returns 3.0
42
+ *
43
+ * @example
44
+ * var y = variance( NaN );
45
+ * // returns NaN
46
+ *
47
+ * @example
48
+ * var y = variance( 1.0 );
49
+ * // returns NaN
50
+ */
51
+ function variance( v ) {
52
+ return addon( v );
53
+ }
54
+
55
+
56
+ // EXPORTS //
57
+
58
+ module.exports = variance;
package/manifest.json ADDED
@@ -0,0 +1,76 @@
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/math-base-napi-unary",
42
+ "@stdlib/math-base-assert-is-nan"
43
+ ]
44
+ },
45
+ {
46
+ "task": "benchmark",
47
+ "wasm": false,
48
+ "src": [
49
+ "./src/main.c"
50
+ ],
51
+ "include": [
52
+ "./include"
53
+ ],
54
+ "libraries": [],
55
+ "libpath": [],
56
+ "dependencies": [
57
+ "@stdlib/math-base-assert-is-nan"
58
+ ]
59
+ },
60
+ {
61
+ "task": "examples",
62
+ "wasm": false,
63
+ "src": [
64
+ "./src/main.c"
65
+ ],
66
+ "include": [
67
+ "./include"
68
+ ],
69
+ "libraries": [],
70
+ "libpath": [],
71
+ "dependencies": [
72
+ "@stdlib/math-base-assert-is-nan"
73
+ ]
74
+ }
75
+ ]
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-t-variance",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Student's t distribution variance.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -14,9 +14,12 @@
14
14
  }
15
15
  ],
16
16
  "main": "./lib",
17
+ "gypfile": false,
17
18
  "directories": {
18
19
  "doc": "./docs",
20
+ "include": "./include",
19
21
  "lib": "./lib",
22
+ "src": "./src",
20
23
  "dist": "./dist"
21
24
  },
22
25
  "types": "./docs/types",
@@ -30,8 +33,10 @@
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
35
  "dependencies": {
33
- "@stdlib/constants-float64-pinf": "^0.2.1",
34
- "@stdlib/math-base-assert-is-nan": "^0.2.1"
36
+ "@stdlib/constants-float64-pinf": "^0.2.2",
37
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
38
+ "@stdlib/math-base-napi-unary": "^0.2.4",
39
+ "@stdlib/utils-library-manifest": "^0.2.3"
35
40
  },
36
41
  "devDependencies": {},
37
42
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,22 @@
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/math/base/napi/unary.h"
20
+ #include "stdlib/stats/base/dists/t/variance.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_dists_t_variance )
package/src/main.c ADDED
@@ -0,0 +1,40 @@
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/base/dists/t/variance.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+
22
+ /**
23
+ * Returns the variance for a Student's t-distribution with degrees of freedom `v`.
24
+ *
25
+ * @param v degrees of freedom
26
+ * @return variance
27
+ *
28
+ * @example
29
+ * double y = stdlib_base_dists_t_variance( 5.0 );
30
+ * // returns ~1.667
31
+ */
32
+ double stdlib_base_dists_t_variance( const double v ) {
33
+ if ( stdlib_base_is_nan( v ) || v <= 1.0 ) {
34
+ return 0.0 / 0.0; // NaN
35
+ }
36
+ if ( v <= 2.0 ) {
37
+ return 1.0 / 0.0; // Infinity
38
+ }
39
+ return v / ( v - 2.0 );
40
+ }