@stdlib/stats-base-dists-discrete-uniform-logcdf 0.2.0 → 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
@@ -141,24 +141,113 @@ y = myLogCDF( 8.0 );
141
141
  <!-- eslint no-undef: "error" -->
142
142
 
143
143
  ```javascript
144
- var randint = require( '@stdlib/random-base-discrete-uniform' );
145
- var randu = require( '@stdlib/random-base-randu' );
144
+ var uniform = require( '@stdlib/random-array-uniform' );
145
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
146
146
  var logcdf = require( '@stdlib/stats-base-dists-discrete-uniform-logcdf' );
147
147
 
148
- var randa = randint.factory( 0, 10 );
149
- var randb = randint.factory();
150
- var a;
151
- var b;
152
- var x;
148
+ var x = uniform( 10, -10.0, 10.0 );
149
+ var a = discreteUniform( 10, -10, 0 );
150
+ var b = discreteUniform( 10, 0, 10 );
151
+
153
152
  var v;
154
153
  var i;
154
+ for ( i = 0; i < x.length; i++ ) {
155
+ v = logcdf( x[ i ], a[ i ], b[ i ] );
156
+ console.log( 'x: %d, a: %d, b: %d, ln(F(x;a,b)): %d', x[ i ].toFixed( 4 ), a[ i ], b[ i ], v.toFixed( 4 ) );
157
+ }
158
+ ```
159
+
160
+ </section>
161
+
162
+ <!-- /.examples -->
163
+
164
+ <!-- C interface documentation. -->
165
+
166
+ <section class="c">
167
+
168
+ ## C APIs
169
+
170
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
171
+
172
+ <section class="intro">
173
+
174
+ </section>
175
+
176
+ <!-- /.intro -->
177
+
178
+ <!-- C usage documentation. -->
179
+
180
+ <section class="usage">
181
+
182
+ ### Usage
183
+
184
+ ```c
185
+ #include "stdlib/stats/base/dists/discrete-uniform/logcdf.h"
186
+ ```
187
+
188
+ #### stdlib_base_dists_discrete_uniform_logcdf( x, a, b )
189
+
190
+ Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [discrete uniform][discrete-uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
191
+
192
+ ```c
193
+ double out = stdlib_base_dists_discrete_uniform_logcdf( 9.0, 0, 10 );
194
+ // returns ~-0.095
195
+ ```
155
196
 
156
- for ( i = 0; i < 10; i++ ) {
157
- x = randu() * 15.0;
158
- a = randa();
159
- b = randb( a, a+randa() );
160
- v = logcdf( x, a, b );
161
- console.log( 'x: %d, a: %d, b: %d, ln(F(x;a,b)): %d', x.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), v.toFixed( 4 ) );
197
+ The function accepts the following arguments:
198
+
199
+ - **x**: `[in] double` input value.
200
+ - **a**: `[in] int32_t` minimum support.
201
+ - **b**: `[in] int32_t` maximum support.
202
+
203
+ ```c
204
+ double stdlib_base_dists_discrete_uniform_logcdf( const double x, const int32_t a, const int32_t b );
205
+ ```
206
+
207
+ </section>
208
+
209
+ <!-- /.usage -->
210
+
211
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
212
+
213
+ <section class="notes">
214
+
215
+ </section>
216
+
217
+ <!-- /.notes -->
218
+
219
+ <!-- C API usage examples. -->
220
+
221
+ <section class="examples">
222
+
223
+ ### Examples
224
+
225
+ ```c
226
+ #include "stdlib/stats/base/dists/discrete-uniform/logcdf.h"
227
+ #include "stdlib/math/base/special/round.h"
228
+ #include <stdint.h>
229
+ #include <stdlib.h>
230
+ #include <stdio.h>
231
+
232
+ static double random_uniform( const double min, const double max ) {
233
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
234
+ return min + ( v*(max-min) );
235
+ }
236
+
237
+ int main( void ) {
238
+ int32_t a;
239
+ int32_t b;
240
+ double x;
241
+ double y;
242
+ int i;
243
+
244
+ for ( i = 0; i < 10; i++ ) {
245
+ x = random_uniform( -10.0, 10.0 );
246
+ a = stdlib_base_round( random_uniform( 0.0, 5.0 ) );
247
+ b = stdlib_base_round( random_uniform( a, a + 5.0 ) );
248
+ y = stdlib_base_dists_discrete_uniform_logcdf( x, a, b );
249
+ printf( "x:%lf, a: %d, b: %d, ln(F(X;a,b)): %lf\n", x, a, b, y );
250
+ }
162
251
  }
163
252
  ```
164
253
 
@@ -166,6 +255,18 @@ for ( i = 0; i < 10; i++ ) {
166
255
 
167
256
  <!-- /.examples -->
168
257
 
258
+ </section>
259
+
260
+ <!-- /.c -->
261
+
262
+ <!-- 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. -->
263
+
264
+ <section class="references">
265
+
266
+ </section>
267
+
268
+ <!-- /.references -->
269
+
169
270
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
170
271
 
171
272
  <section class="related">
@@ -200,7 +301,7 @@ See [LICENSE][stdlib-license].
200
301
 
201
302
  ## Copyright
202
303
 
203
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
304
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
204
305
 
205
306
  </section>
206
307
 
@@ -213,8 +314,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
213
314
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-discrete-uniform-logcdf.svg
214
315
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-discrete-uniform-logcdf
215
316
 
216
- [test-image]: https://github.com/stdlib-js/stats-base-dists-discrete-uniform-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.2.0
217
- [test-url]: https://github.com/stdlib-js/stats-base-dists-discrete-uniform-logcdf/actions/workflows/test.yml?query=branch:v0.2.0
317
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-discrete-uniform-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
318
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-discrete-uniform-logcdf/actions/workflows/test.yml?query=branch:v0.3.0
218
319
 
219
320
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-discrete-uniform-logcdf/main.svg
220
321
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-discrete-uniform-logcdf?branch=main
@@ -226,8 +327,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
226
327
 
227
328
  -->
228
329
 
229
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
230
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
330
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
331
+ [chat-url]: https://stdlib.zulipchat.com
231
332
 
232
333
  [stdlib]: https://github.com/stdlib-js/stdlib
233
334
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="../docs/types/index.d.ts" />
2
- import logCDF from '../docs/types/index';
3
- export = logCDF;
2
+ import logcdf from '../docs/types/index';
3
+ export = logcdf;
@@ -114,9 +114,9 @@ interface LogCDF {
114
114
  * y = mylogcdf( 8.0 );
115
115
  * // returns ~-0.201
116
116
  */
117
- declare var logCDF: LogCDF;
117
+ declare var logcdf: LogCDF;
118
118
 
119
119
 
120
120
  // EXPORTS //
121
121
 
122
- export = logCDF;
122
+ export = logcdf;
@@ -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
+ #ifndef STDLIB_STATS_BASE_DISTS_DISCRETE_UNIFORM_LOGCDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_DISCRETE_UNIFORM_LOGCDF_H
21
+
22
+ #include <stdint.h>
23
+
24
+ /*
25
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
26
+ */
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /**
32
+ * Evaluates the natural logarithm of the cumulative distribution function (CDF) of a discrete uniform distribution with parameters `a` (minimum support) and `b` (maximum support).
33
+ */
34
+ double stdlib_base_dists_discrete_uniform_logcdf( const double x, const int32_t a, const int32_t b );
35
+
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif
39
+
40
+ #endif // !STDLIB_STATS_BASE_DISTS_DISCRETE_UNIFORM_LOGCDF_H
package/lib/native.js ADDED
@@ -0,0 +1,64 @@
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
+ * Evaluates the natural logarithm of the cumulative distribution function (CDF) for a discrete uniform distribution with minimum support `a` and maximum support `b` at a value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {integer} a - minimum support
34
+ * @param {integer} b - maximum support
35
+ * @returns {number} evaluated logCDF
36
+ *
37
+ * @example
38
+ * var y = logcdf( 9.0, 0, 10 );
39
+ * // returns ~-0.095
40
+ *
41
+ * @example
42
+ * var y = logcdf( 0.5, 0, 2 );
43
+ * // returns ~-1.099
44
+ *
45
+ * @example
46
+ * var y = logcdf( +Infinity, 2, 4 );
47
+ * // returns 0.0
48
+ *
49
+ * @example
50
+ * var y = logcdf( -Infinity, 2, 4 );
51
+ * // returns -Infinity
52
+ *
53
+ * @example
54
+ * var y = logcdf( 2.0, 1, 0 );
55
+ * // returns NaN
56
+ */
57
+ function logcdf( x, a, b ) {
58
+ return addon( x, a, b );
59
+ }
60
+
61
+
62
+ // EXPORTS //
63
+
64
+ module.exports = logcdf;
package/manifest.json ADDED
@@ -0,0 +1,87 @@
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-ternary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/math-base-special-floor",
44
+ "@stdlib/math-base-special-ln",
45
+ "@stdlib/constants-float64-ninf"
46
+ ]
47
+ },
48
+ {
49
+ "task": "benchmark",
50
+ "wasm": false,
51
+ "src": [
52
+ "./src/main.c"
53
+ ],
54
+ "include": [
55
+ "./include"
56
+ ],
57
+ "libraries": [],
58
+ "libpath": [],
59
+ "dependencies": [
60
+ "@stdlib/math-base-special-round",
61
+ "@stdlib/math-base-assert-is-nan",
62
+ "@stdlib/math-base-special-floor",
63
+ "@stdlib/math-base-special-ln",
64
+ "@stdlib/constants-float64-ninf"
65
+ ]
66
+ },
67
+ {
68
+ "task": "examples",
69
+ "wasm": false,
70
+ "src": [
71
+ "./src/main.c"
72
+ ],
73
+ "include": [
74
+ "./include"
75
+ ],
76
+ "libraries": [],
77
+ "libpath": [],
78
+ "dependencies": [
79
+ "@stdlib/math-base-special-round",
80
+ "@stdlib/math-base-assert-is-nan",
81
+ "@stdlib/math-base-special-floor",
82
+ "@stdlib/math-base-special-ln",
83
+ "@stdlib/constants-float64-ninf"
84
+ ]
85
+ }
86
+ ]
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-discrete-uniform-logcdf",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Natural logarithm of the cumulative distribution function (CDF)for a discrete uniform distribution.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -14,20 +14,16 @@
14
14
  }
15
15
  ],
16
16
  "main": "./lib",
17
+ "gypfile": false,
17
18
  "directories": {
18
- "benchmark": "./benchmark",
19
19
  "doc": "./docs",
20
- "example": "./examples",
20
+ "include": "./include",
21
21
  "lib": "./lib",
22
- "test": "./test"
22
+ "src": "./src",
23
+ "dist": "./dist"
23
24
  },
24
25
  "types": "./docs/types",
25
- "scripts": {
26
- "test": "make test",
27
- "test-cov": "make test-cov",
28
- "examples": "make examples",
29
- "benchmark": "make benchmark"
30
- },
26
+ "scripts": {},
31
27
  "homepage": "https://stdlib.io",
32
28
  "repository": {
33
29
  "type": "git",
@@ -37,27 +33,17 @@
37
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
34
  },
39
35
  "dependencies": {
40
- "@stdlib/constants-float64-ninf": "^0.2.0",
41
- "@stdlib/math-base-assert-is-integer": "^0.2.0",
42
- "@stdlib/math-base-assert-is-nan": "^0.2.0",
43
- "@stdlib/math-base-special-floor": "^0.2.0",
44
- "@stdlib/math-base-special-ln": "^0.2.0",
45
- "@stdlib/utils-constant-function": "^0.2.0",
46
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0"
47
- },
48
- "devDependencies": {
49
- "@stdlib/constants-float64-eps": "^0.1.1",
50
- "@stdlib/constants-float64-pinf": "^0.1.1",
51
- "@stdlib/math-base-special-abs": "^0.1.1",
52
- "@stdlib/math-base-special-round": "^0.1.1",
53
- "@stdlib/random-base-discrete-uniform": "^0.1.0",
54
- "@stdlib/random-base-randu": "^0.1.0",
55
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
56
- "istanbul": "^0.4.1",
57
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
58
- "@stdlib/bench-harness": "^0.1.2",
59
- "@stdlib/bench": "^0.3.1"
36
+ "@stdlib/constants-float64-ninf": "^0.2.2",
37
+ "@stdlib/math-base-assert-is-integer": "^0.2.6",
38
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
39
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
40
+ "@stdlib/math-base-special-floor": "^0.2.3",
41
+ "@stdlib/math-base-special-ln": "^0.2.4",
42
+ "@stdlib/utils-constant-function": "^0.2.2",
43
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
44
+ "@stdlib/utils-library-manifest": "^0.2.3"
60
45
  },
46
+ "devDependencies": {},
61
47
  "engines": {
62
48
  "node": ">=0.10.0",
63
49
  "npm": ">2.7.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/discrete-uniform/logcdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DII_D( stdlib_base_dists_discrete_uniform_logcdf )
package/src/main.c ADDED
@@ -0,0 +1,52 @@
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/discrete-uniform/logcdf.h"
20
+ #include "stdlib/math/base/special/floor.h"
21
+ #include "stdlib/math/base/assert/is_nan.h"
22
+ #include "stdlib/constants/float64/ninf.h"
23
+ #include "stdlib/math/base/special/ln.h"
24
+ #include <stdint.h>
25
+
26
+ /**
27
+ * Evaluates the natural logarithm of the cumulative distribution function (CDF) for a discrete uniform distribution with minimum support `a` and maximum support `b` at a value `x`.
28
+ *
29
+ * @param x input value
30
+ * @param a minimum support
31
+ * @param b maximum support
32
+ * @return logCDF
33
+ *
34
+ * @example
35
+ * double y = stdlib_base_dists_discrete_uniform_logcdf( 9.0, 0, 10 );
36
+ * // returns ~-0.095
37
+ */
38
+ double stdlib_base_dists_discrete_uniform_logcdf( const double x, const int32_t a, const int32_t b ) {
39
+ if (
40
+ stdlib_base_is_nan( x ) ||
41
+ a > b
42
+ ) {
43
+ return 0.0/0.0; // NaN
44
+ }
45
+ if ( x < a ) {
46
+ return STDLIB_CONSTANT_FLOAT64_NINF;
47
+ }
48
+ if ( x >= b ) {
49
+ return 0.0;
50
+ }
51
+ return stdlib_base_ln( stdlib_base_floor( x ) - a + 1.0 ) - stdlib_base_ln( b - a + 1.0 );
52
+ }