@stdlib/stats-base-dists-kumaraswamy-mode 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
@@ -149,33 +149,117 @@ y = mode( 2.0, 0.0 );
149
149
  <!-- eslint no-undef: "error" -->
150
150
 
151
151
  ```javascript
152
- var randu = require( '@stdlib/random-base-randu' );
152
+ var uniform = require( '@stdlib/random-array-uniform' );
153
+ var logEachMap = require( '@stdlib/console-log-each-map' );
153
154
  var mode = require( '@stdlib/stats-base-dists-kumaraswamy-mode' );
154
155
 
155
- var a;
156
- var b;
157
- var v;
158
- var i;
156
+ var opts = {
157
+ 'dtype': 'float64'
158
+ };
159
+ var a = uniform( 10, 0.0, 10.0, opts );
160
+ var b = uniform( 10, 0.0, 10.0, opts );
159
161
 
160
- for ( i = 0; i < 10; i++ ) {
161
- a = randu() * 10.0;
162
- b = randu() * 10.0;
163
- v = mode( a, b );
164
- console.log( 'a: %d, b: %d, mode(X;a,b): %d', a.toFixed( 4 ), b.toFixed( 4 ), v.toFixed( 4 ) );
165
- }
162
+ logEachMap( 'a: %0.4f, b: %0.4f, mode(X;a,b): %0.4f', a, b, mode );
166
163
  ```
167
164
 
168
165
  </section>
169
166
 
170
167
  <!-- /.examples -->
171
168
 
172
- <!-- 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. -->
169
+ <!-- C interface documentation. -->
170
+
171
+ * * *
172
+
173
+ <section class="c">
174
+
175
+ ## C APIs
176
+
177
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
178
+
179
+ <section class="intro">
180
+
181
+ </section>
182
+
183
+ <!-- /.intro -->
184
+
185
+ <!-- C usage documentation. -->
186
+
187
+ <section class="usage">
188
+
189
+ ### Usage
190
+
191
+ ```c
192
+ #include "stdlib/stats/base/dists/kumaraswamy/mode.h"
193
+ ```
194
+
195
+ #### stdlib_base_dists_kumaraswamy_mode( a, b )
196
+
197
+ Returns the mode of a Kumaraswamy's double bounded distribution.
198
+
199
+ ```c
200
+ double out = stdlib_base_dists_kumaraswamy_mode( 1.5, 1.5 );
201
+ // returns ~0.543
202
+ ```
203
+
204
+ The function accepts the following arguments:
205
+
206
+ - **a**: `[in] double` first shape parameter.
207
+ - **b**: `[in] double` second shape parameter.
173
208
 
174
- <section class="references">
209
+ ```c
210
+ double stdlib_base_dists_kumaraswamy_mode( const double a, const double b );
211
+ ```
212
+
213
+ </section>
214
+
215
+ <!-- /.usage -->
216
+
217
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
218
+
219
+ <section class="notes">
220
+
221
+ </section>
222
+
223
+ <!-- /.notes -->
224
+
225
+ <!-- C API usage examples. -->
226
+
227
+ <section class="examples">
228
+
229
+ ### Examples
230
+
231
+ ```c
232
+ #include "stdlib/stats/base/dists/kumaraswamy/mode.h"
233
+ #include <stdlib.h>
234
+ #include <stdio.h>
235
+
236
+ static double random_uniform( const double min, const double max ) {
237
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
238
+ return min + ( v*(max-min) );
239
+ }
240
+
241
+ int main( void ) {
242
+ double mode;
243
+ double a;
244
+ double b;
245
+ int i;
246
+
247
+ for ( i = 0; i < 10; i++ ) {
248
+ a = random_uniform( 1.0, 10.0 );
249
+ b = random_uniform( 1.0, 10.0 );
250
+ mode = stdlib_base_dists_kumaraswamy_mode( a, b );
251
+ printf( "a: %.4f, b: %.4f, mode(X;a,b): %.4f\n", a, b, mode );
252
+ }
253
+ }
254
+ ```
255
+
256
+ </section>
257
+
258
+ <!-- /.examples -->
175
259
 
176
260
  </section>
177
261
 
178
- <!-- /.references -->
262
+ <!-- /.c -->
179
263
 
180
264
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
181
265
 
@@ -211,7 +295,7 @@ See [LICENSE][stdlib-license].
211
295
 
212
296
  ## Copyright
213
297
 
214
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
298
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
215
299
 
216
300
  </section>
217
301
 
@@ -224,8 +308,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
224
308
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-kumaraswamy-mode.svg
225
309
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-kumaraswamy-mode
226
310
 
227
- [test-image]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-mode/actions/workflows/test.yml/badge.svg?branch=v0.2.2
228
- [test-url]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-mode/actions/workflows/test.yml?query=branch:v0.2.2
311
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-mode/actions/workflows/test.yml/badge.svg?branch=v0.3.0
312
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-mode/actions/workflows/test.yml?query=branch:v0.3.0
229
313
 
230
314
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-kumaraswamy-mode/main.svg
231
315
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-kumaraswamy-mode?branch=main
@@ -237,8 +321,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
237
321
 
238
322
  -->
239
323
 
240
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
241
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
324
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
325
+ [chat-url]: https://stdlib.zulipchat.com
242
326
 
243
327
  [stdlib]: https://github.com/stdlib-js/stdlib
244
328
 
@@ -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_KUMARASWAMY_MODE_H
20
+ #define STDLIB_STATS_BASE_DISTS_KUMARASWAMY_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 Kumaraswamy's double bounded distribution.
31
+ */
32
+ double stdlib_base_dists_kumaraswamy_mode( const double a, const double b );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_KUMARASWAMY_MODE_H
package/lib/native.js ADDED
@@ -0,0 +1,75 @@
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 Kumaraswamy's double bounded distribution.
30
+ *
31
+ * @private
32
+ * @param {PositiveNumber} a - first shape parameter
33
+ * @param {PositiveNumber} b - second shape parameter
34
+ * @returns {PositiveNumber} mode
35
+ *
36
+ * @example
37
+ * var v = mode( 1.5, 1.5 );
38
+ * // returns ~0.543
39
+ *
40
+ * @example
41
+ * var v = mode( 4.0, 12.0 );
42
+ * // returns ~0.503
43
+ *
44
+ * @example
45
+ * var v = mode( 12.0, 2.0 );
46
+ * // returns ~0.94
47
+ *
48
+ * @example
49
+ * var v = mode( 1.0, 1.0 );
50
+ * // returns NaN
51
+ *
52
+ * @example
53
+ * var v = mode( 1.5, -0.1 );
54
+ * // returns NaN
55
+ *
56
+ * @example
57
+ * var v = mode( -0.1, 1.5 );
58
+ * // returns NaN
59
+ *
60
+ * @example
61
+ * var v = mode( 2.0, NaN );
62
+ * // returns NaN
63
+ *
64
+ * @example
65
+ * var v = mode( NaN, 2.0 );
66
+ * // returns NaN
67
+ */
68
+ function mode( a, b ) {
69
+ return addon( a, b );
70
+ }
71
+
72
+
73
+ // EXPORTS //
74
+
75
+ module.exports = mode;
package/manifest.json ADDED
@@ -0,0 +1,79 @@
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-binary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/math-base-special-pow"
44
+ ]
45
+ },
46
+ {
47
+ "task": "benchmark",
48
+ "wasm": false,
49
+ "src": [
50
+ "./src/main.c"
51
+ ],
52
+ "include": [
53
+ "./include"
54
+ ],
55
+ "libraries": [],
56
+ "libpath": [],
57
+ "dependencies": [
58
+ "@stdlib/math-base-assert-is-nan",
59
+ "@stdlib/math-base-special-pow"
60
+ ]
61
+ },
62
+ {
63
+ "task": "examples",
64
+ "wasm": false,
65
+ "src": [
66
+ "./src/main.c"
67
+ ],
68
+ "include": [
69
+ "./include"
70
+ ],
71
+ "libraries": [],
72
+ "libpath": [],
73
+ "dependencies": [
74
+ "@stdlib/math-base-assert-is-nan",
75
+ "@stdlib/math-base-special-pow"
76
+ ]
77
+ }
78
+ ]
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-kumaraswamy-mode",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Kumaraswamy's double bounded 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",
@@ -31,7 +34,9 @@
31
34
  },
32
35
  "dependencies": {
33
36
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
34
- "@stdlib/math-base-special-pow": "^0.2.1"
37
+ "@stdlib/math-base-napi-binary": "^0.3.1",
38
+ "@stdlib/math-base-special-pow": "^0.3.0",
39
+ "@stdlib/utils-library-manifest": "^0.2.3"
35
40
  },
36
41
  "devDependencies": {},
37
42
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,23 @@
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/kumaraswamy/mode.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ // cppcheck-suppress shadowFunction
23
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_kumaraswamy_mode )
package/src/main.c ADDED
@@ -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
+ #include "stdlib/stats/base/dists/kumaraswamy/mode.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/pow.h"
22
+
23
+ /**
24
+ * Returns the mode of a Kumaraswamy's double bounded distribution.
25
+ *
26
+ * @param a first shape parameter
27
+ * @param b second shape parameter
28
+ * @return mode
29
+ *
30
+ * @example
31
+ * double y = stdlib_base_dists_kumaraswamy_mode( 1.5, 1.5 );
32
+ * // returns ~0.543
33
+ */
34
+ double stdlib_base_dists_kumaraswamy_mode( const double a, const double b ) {
35
+ if (
36
+ stdlib_base_is_nan( a ) ||
37
+ stdlib_base_is_nan( b ) ||
38
+ a < 1.0 ||
39
+ b < 1.0 ||
40
+ ( a == 1.0 && b == 1.0 )
41
+ ) {
42
+ return 0.0/0.0; // NaN
43
+ }
44
+ return stdlib_base_pow( ( a-1.0 ) / ( (a*b) - 1.0 ), 1.0/a );
45
+ }