@stdlib/stats-base-dists-degenerate-mode 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 +1 -1
- package/README.md +103 -13
- package/include/stdlib/stats/base/dists/degenerate/mode.h +38 -0
- package/lib/native.js +58 -0
- package/manifest.json +76 -0
- package/package.json +9 -2
- package/src/addon.c +22 -0
- package/src/main.c +37 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -109,17 +109,103 @@ v = mode( -0.5 );
|
|
|
109
109
|
<!-- eslint no-undef: "error" -->
|
|
110
110
|
|
|
111
111
|
```javascript
|
|
112
|
-
var
|
|
112
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
113
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
113
114
|
var mode = require( '@stdlib/stats-base-dists-degenerate-mode' );
|
|
114
115
|
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
var opts = {
|
|
117
|
+
'dtype': 'float64'
|
|
118
|
+
};
|
|
119
|
+
var mu = uniform( 10, 0.0, 1.0, opts );
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
logEachMap( 'µ: %0.4f, mode(X;µ): %0.4f', mu, mode );
|
|
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/mode.h"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### stdlib_base_dists_degenerate_mode( mu )
|
|
155
|
+
|
|
156
|
+
Returns the [mode][mode] of a [degenerate][degenerate-distribution] distribution with constant value `mu`.
|
|
157
|
+
|
|
158
|
+
```c
|
|
159
|
+
double out = stdlib_base_dists_degenerate_mode( 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_mode( 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/mode.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 m;
|
|
202
|
+
int i;
|
|
203
|
+
|
|
204
|
+
for ( i = 0; i < 10; i++ ) {
|
|
205
|
+
mu = random_uniform( 0.0, 20.0 );
|
|
206
|
+
m = stdlib_base_dists_degenerate_mode( mu );
|
|
207
|
+
printf( "µ: %lf, mode(X;µ): %lf\n", mu, m );
|
|
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 © 2016-
|
|
262
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
173
263
|
|
|
174
264
|
</section>
|
|
175
265
|
|
|
@@ -182,8 +272,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
182
272
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-degenerate-mode.svg
|
|
183
273
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-degenerate-mode
|
|
184
274
|
|
|
185
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-degenerate-mode/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
186
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-degenerate-mode/actions/workflows/test.yml?query=branch:v0.
|
|
275
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-degenerate-mode/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
276
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-degenerate-mode/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-mode/main.svg
|
|
189
279
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-degenerate-mode?branch=main
|
|
@@ -195,8 +285,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
195
285
|
|
|
196
286
|
-->
|
|
197
287
|
|
|
198
|
-
[chat-image]: https://img.shields.io/
|
|
199
|
-
[chat-url]: https://
|
|
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_MODE_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_DEGENERATE_MODE_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 mode of a degenerate distribution with constant value `mu`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_degenerate_mode( const double mu );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_DEGENERATE_MODE_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 mode of a degenerate distribution with constant value `mu`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} mu - constant value of the distribution
|
|
33
|
+
* @returns {number} mode
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var y = mode( 0.1 );
|
|
37
|
+
* // returns 0.1
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var y = mode( 4.0 );
|
|
41
|
+
* // returns 4.0
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var y = mode( -4.0 );
|
|
45
|
+
* // returns -4.0
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var y = mode( NaN );
|
|
49
|
+
* // returns NaN
|
|
50
|
+
*/
|
|
51
|
+
function mode( mu ) {
|
|
52
|
+
return addon( mu );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = mode;
|
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-degenerate-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Degenerate distribution mode.",
|
|
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,11 @@
|
|
|
29
32
|
"bugs": {
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
|
-
"dependencies": {
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
37
|
+
"@stdlib/math-base-napi-unary": "^0.2.3",
|
|
38
|
+
"@stdlib/utils-library-manifest": "^0.2.2"
|
|
39
|
+
},
|
|
33
40
|
"devDependencies": {},
|
|
34
41
|
"engines": {
|
|
35
42
|
"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/math/base/napi/unary.h"
|
|
20
|
+
#include "stdlib/stats/base/dists/degenerate/mode.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_dists_degenerate_mode )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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/mode.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the mode of a degenerate distribution.
|
|
24
|
+
*
|
|
25
|
+
* @param mu constant value of the distribution
|
|
26
|
+
* @return mode
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* double v = stdlib_base_dists_degenerate_mode( 0.1 );
|
|
30
|
+
* // returns 0.1
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_degenerate_mode( const double mu ) {
|
|
33
|
+
if ( stdlib_base_is_nan( mu ) ) {
|
|
34
|
+
return 0.0 / 0.0; // NaN
|
|
35
|
+
}
|
|
36
|
+
return mu;
|
|
37
|
+
}
|