@stdlib/stats-base-dists-degenerate-mean 0.2.1 → 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
@@ -109,17 +109,103 @@ v = mean( -0.5 );
109
109
  <!-- eslint no-undef: "error" -->
110
110
 
111
111
  ```javascript
112
- var randu = require( '@stdlib/random-base-randu' );
112
+ var uniform = require( '@stdlib/random-array-uniform' );
113
+ var logEachMap = require( '@stdlib/console-log-each-map' );
113
114
  var mean = require( '@stdlib/stats-base-dists-degenerate-mean' );
114
115
 
115
- var mu;
116
- var v;
117
- var i;
116
+ var opts = {
117
+ 'dtype': 'float64'
118
+ };
119
+ var mu = uniform( 10, 0.0, 1.0, opts );
118
120
 
119
- for ( i = 0; i < 10; i++ ) {
120
- mu = randu();
121
- v = mean( mu );
122
- console.log( 'µ: %d, E(X;µ): %d', mu.toFixed( 4 ), v.toFixed( 4 ) );
121
+ logEachMap( 'µ: %0.4f, E(X;µ): %0.4f', mu, mean );
122
+ ```
123
+
124
+ </section>
125
+
126
+ <!-- /.examples -->
127
+
128
+ <!-- C interface documentation. -->
129
+
130
+ * * *
131
+
132
+ <section class="c">
133
+
134
+ ## C APIs
135
+
136
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
137
+
138
+ <section class="intro">
139
+
140
+ </section>
141
+
142
+ <!-- /.intro -->
143
+
144
+ <!-- C usage documentation. -->
145
+
146
+ <section class="usage">
147
+
148
+ ### Usage
149
+
150
+ ```c
151
+ #include "stdlib/stats/base/dists/degenerate/mean.h"
152
+ ```
153
+
154
+ #### stdlib_base_dists_degenerate_mean( mu )
155
+
156
+ Returns the [expected value][expected-value] of a [degenerate][degenerate-distribution] distribution with constant value `mu`.
157
+
158
+ ```c
159
+ double out = stdlib_base_dists_degenerate_mean( 0.1 );
160
+ // returns 0.1
161
+ ```
162
+
163
+ The function accepts the following arguments:
164
+
165
+ - **mu**: `[in] double` constant value of the distribution.
166
+
167
+ ```c
168
+ double stdlib_base_dists_degenerate_mean( const double mu );
169
+ ```
170
+
171
+ </section>
172
+
173
+ <!-- /.usage -->
174
+
175
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
176
+
177
+ <section class="notes">
178
+
179
+ </section>
180
+
181
+ <!-- /.notes -->
182
+
183
+ <!-- C API usage examples. -->
184
+
185
+ <section class="examples">
186
+
187
+ ### Examples
188
+
189
+ ```c
190
+ #include "stdlib/stats/base/dists/degenerate/mean.h"
191
+ #include <stdlib.h>
192
+ #include <stdio.h>
193
+
194
+ static double random_uniform( const double min, const double max ) {
195
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
196
+ return min + ( v*(max-min) );
197
+ }
198
+
199
+ int main( void ) {
200
+ double mu;
201
+ double v;
202
+ int i;
203
+
204
+ for ( i = 0; i < 25; i++ ) {
205
+ mu = random_uniform( 0.0, 1.0 );
206
+ v = stdlib_base_dists_degenerate_mean( mu );
207
+ printf( "µ: %lf, E(X;µ): %lf\n", mu, v );
208
+ }
123
209
  }
124
210
  ```
125
211
 
@@ -127,6 +213,10 @@ for ( i = 0; i < 10; i++ ) {
127
213
 
128
214
  <!-- /.examples -->
129
215
 
216
+ </section>
217
+
218
+ <!-- /.c -->
219
+
130
220
  <!-- 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. -->
131
221
 
132
222
  <section class="references">
@@ -169,7 +259,7 @@ See [LICENSE][stdlib-license].
169
259
 
170
260
  ## Copyright
171
261
 
172
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
262
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
173
263
 
174
264
  </section>
175
265
 
@@ -182,8 +272,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
182
272
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-degenerate-mean.svg
183
273
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-degenerate-mean
184
274
 
185
- [test-image]: https://github.com/stdlib-js/stats-base-dists-degenerate-mean/actions/workflows/test.yml/badge.svg?branch=v0.2.1
186
- [test-url]: https://github.com/stdlib-js/stats-base-dists-degenerate-mean/actions/workflows/test.yml?query=branch:v0.2.1
275
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-degenerate-mean/actions/workflows/test.yml/badge.svg?branch=v0.3.0
276
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-degenerate-mean/actions/workflows/test.yml?query=branch:v0.3.0
187
277
 
188
278
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-degenerate-mean/main.svg
189
279
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-degenerate-mean?branch=main
@@ -195,8 +285,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
195
285
 
196
286
  -->
197
287
 
198
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
199
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
288
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
289
+ [chat-url]: https://stdlib.zulipchat.com
200
290
 
201
291
  [stdlib]: https://github.com/stdlib-js/stdlib
202
292
 
@@ -0,0 +1,38 @@
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_DEGENERATE_MEAN_H
20
+ #define STDLIB_STATS_BASE_DISTS_DEGENERATE_MEAN_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 expected value of a degenerate distribution.
31
+ */
32
+ double stdlib_base_dists_degenerate_mean( const double mu );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_DEGENERATE_MEAN_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 expected value of a degenerate distribution.
30
+ *
31
+ * @private
32
+ * @param {number} mu - constant value of the distribution
33
+ * @returns {number} expected value
34
+ *
35
+ ** @example
36
+ * var v = mean( 0.1 );
37
+ * // returns 0.1
38
+ *
39
+ * @example
40
+ * var v = mean( 0.5 );
41
+ * // returns 0.5
42
+ *
43
+ * @example
44
+ * var v = mean( 10.0 );
45
+ * // returns 10.0
46
+ *
47
+ * @example
48
+ * var v = mean( NaN );
49
+ * // returns NaN
50
+ */
51
+ function mean( mu ) {
52
+ return addon( mu );
53
+ }
54
+
55
+
56
+ // EXPORTS //
57
+
58
+ module.exports = mean;
package/manifest.json ADDED
@@ -0,0 +1,72 @@
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
+
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
+ },
58
+ {
59
+ "task": "examples",
60
+ "wasm": false,
61
+ "src": [
62
+ "./src/main.c"
63
+ ],
64
+ "include": [
65
+ "./include"
66
+ ],
67
+ "libraries": [],
68
+ "libpath": [],
69
+ "dependencies": []
70
+ }
71
+ ]
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-degenerate-mean",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Degenerate distribution expected value.",
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",
@@ -29,7 +32,10 @@
29
32
  "bugs": {
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
- "dependencies": {},
35
+ "dependencies": {
36
+ "@stdlib/math-base-napi-unary": "^0.2.3",
37
+ "@stdlib/utils-library-manifest": "^0.2.2"
38
+ },
33
39
  "devDependencies": {},
34
40
  "engines": {
35
41
  "node": ">=0.10.0",
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/stats/base/dists/degenerate/mean.h"
20
+ #include "stdlib/math/base/napi/unary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_dists_degenerate_mean )
package/src/main.c ADDED
@@ -0,0 +1,33 @@
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/degenerate/mean.h"
20
+
21
+ /**
22
+ * Returns the expected value of a degenerate distribution.
23
+ *
24
+ * @param mu constant value of the distribution
25
+ * @return expected value
26
+ *
27
+ * @example
28
+ * double y = stdlib_base_dists_degenerate_mean( 0.1 );
29
+ * // returns 0.1
30
+ */
31
+ double stdlib_base_dists_degenerate_mean( const double mu ) {
32
+ return mu;
33
+ }