@stdlib/stats-base-dists-geometric-logcdf 0.2.2 → 0.3.1

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
@@ -138,19 +138,107 @@ y = mylogcdf( 1.0 );
138
138
  <!-- eslint no-undef: "error" -->
139
139
 
140
140
  ```javascript
141
- var randu = require( '@stdlib/random-base-randu' );
141
+ var uniform = require( '@stdlib/random-array-uniform' );
142
+ var logEachMap = require( '@stdlib/console-log-each-map' );
142
143
  var logcdf = require( '@stdlib/stats-base-dists-geometric-logcdf' );
143
144
 
144
- var p;
145
- var x;
146
- var y;
147
- var i;
145
+ var opts = {
146
+ 'dtype': 'float64'
147
+ };
148
+ var p = uniform( 10, 0.0, 1.0, opts );
149
+ var x = uniform( 10, 0.0, 5.0, opts );
148
150
 
149
- for ( i = 0; i < 10; i++ ) {
150
- x = randu() * 5.0;
151
- p = randu();
152
- y = logcdf( x, p );
153
- console.log( 'x: %d, p: %d, ln(F(x;p)): %d', x.toFixed( 4 ), p.toFixed( 4 ), y.toFixed( 4 ) );
151
+ logEachMap( 'x: %0.4f, p: %0.4f, F(x;p): %0.4f', x, p, logcdf );
152
+ ```
153
+
154
+ </section>
155
+
156
+ <!-- /.examples -->
157
+
158
+ <!-- C interface documentation. -->
159
+
160
+ * * *
161
+
162
+ <section class="c">
163
+
164
+ ## C APIs
165
+
166
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
167
+
168
+ <section class="intro">
169
+
170
+ </section>
171
+
172
+ <!-- /.intro -->
173
+
174
+ <!-- C usage documentation. -->
175
+
176
+ <section class="usage">
177
+
178
+ ### Usage
179
+
180
+ ```c
181
+ #include "stdlib/stats/base/dists/geometric/logcdf.h"
182
+ ```
183
+
184
+ #### stdlib_base_dists_geometric_logcdf( x, p )
185
+
186
+ Evaluates the logarithm of the [cumulative distribution function][cdf] of a [geometric][geometric-distribution] distribution with success probability `p`.
187
+
188
+ ```c
189
+ double out = stdlib_base_dists_geometric_logcdf( 2.0, 0.5 );
190
+ // returns ~-0.134
191
+ ```
192
+
193
+ The function accepts the following arguments:
194
+
195
+ - **x**: `[in] double` input value.
196
+ - **p**: `[in] double` probability of success.
197
+
198
+ ```c
199
+ double stdlib_base_dists_geometric_logcdf( const double x, const double p );
200
+ ```
201
+
202
+ </section>
203
+
204
+ <!-- /.usage -->
205
+
206
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
207
+
208
+ <section class="notes">
209
+
210
+ </section>
211
+
212
+ <!-- /.notes -->
213
+
214
+ <!-- C API usage examples. -->
215
+
216
+ <section class="examples">
217
+
218
+ ### Examples
219
+
220
+ ```c
221
+ #include "stdlib/stats/base/dists/geometric/logcdf.h"
222
+ #include <stdlib.h>
223
+ #include <stdio.h>
224
+
225
+ static double random_uniform( const double min, const double max ) {
226
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
227
+ return min + ( v*(max-min) );
228
+ }
229
+
230
+ int main( void ) {
231
+ double x;
232
+ double p;
233
+ double y;
234
+ int i;
235
+
236
+ for ( i = 0; i < 25; i++ ) {
237
+ x = random_uniform( 0.0, 40.0 );
238
+ p = random_uniform( 0.0, 1.0 );
239
+ y = stdlib_base_dists_geometric_logcdf( x, p );
240
+ printf( "x: %lf, p: %lf, ln(F(x;p)): %lf\n", x, p, y );
241
+ }
154
242
  }
155
243
  ```
156
244
 
@@ -158,6 +246,18 @@ for ( i = 0; i < 10; i++ ) {
158
246
 
159
247
  <!-- /.examples -->
160
248
 
249
+ </section>
250
+
251
+ <!-- /.c -->
252
+
253
+ <!-- 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. -->
254
+
255
+ <section class="references">
256
+
257
+ </section>
258
+
259
+ <!-- /.references -->
260
+
161
261
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
162
262
 
163
263
  <section class="related">
@@ -192,7 +292,7 @@ See [LICENSE][stdlib-license].
192
292
 
193
293
  ## Copyright
194
294
 
195
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
295
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
196
296
 
197
297
  </section>
198
298
 
@@ -205,8 +305,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
205
305
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-geometric-logcdf.svg
206
306
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-geometric-logcdf
207
307
 
208
- [test-image]: https://github.com/stdlib-js/stats-base-dists-geometric-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
209
- [test-url]: https://github.com/stdlib-js/stats-base-dists-geometric-logcdf/actions/workflows/test.yml?query=branch:v0.2.2
308
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-geometric-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.3.1
309
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-geometric-logcdf/actions/workflows/test.yml?query=branch:v0.3.1
210
310
 
211
311
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-geometric-logcdf/main.svg
212
312
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-geometric-logcdf?branch=main
@@ -218,8 +318,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
218
318
 
219
319
  -->
220
320
 
221
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
222
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
321
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
322
+ [chat-url]: https://stdlib.zulipchat.com
223
323
 
224
324
  [stdlib]: https://github.com/stdlib-js/stdlib
225
325
 
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;
@@ -106,9 +106,9 @@ interface LogCDF {
106
106
  * y = mylogcdf( 1.0 );
107
107
  * // returns ~-0.288
108
108
  */
109
- declare var logCDF: LogCDF;
109
+ declare var logcdf: LogCDF;
110
110
 
111
111
 
112
112
  // EXPORTS //
113
113
 
114
- export = logCDF;
114
+ export = logcdf;
@@ -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_GEOMETRIC_LOGCDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_GEOMETRIC_LOGCDF_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
+ * Evaluates the logarithm of the cumulative distribution function (LOGCDF) for the geometric distribution with probability `p` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_geometric_logcdf( const double x, const double p );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_GEOMETRIC_LOGCDF_H
package/lib/native.js ADDED
@@ -0,0 +1,68 @@
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 logarithm of the cumulative distribution function (CDF) for a geometric distribution with success probability `p` at a value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {Probability} p - success probability
34
+ * @returns {number} evaluated logCDF
35
+ *
36
+ * @example
37
+ * var y = logcdf( 2.0, 0.5 );
38
+ * // returns ~-0.134
39
+ *
40
+ * @example
41
+ * var y = logcdf( 2.0, 0.1 );
42
+ * // returns ~-1.306
43
+ *
44
+ * @example
45
+ * var y = logcdf( -1.0, 0.5 );
46
+ * // returns -Infinity
47
+ *
48
+ * @example
49
+ * var y = logcdf( NaN, 0.5 );
50
+ * // returns NaN
51
+ *
52
+ * @example
53
+ * var y = logcdf( 0.0, NaN );
54
+ * // returns NaN
55
+ *
56
+ * @example
57
+ * // Invalid probability
58
+ * var y = logcdf( 2.0, 1.4 );
59
+ * // returns NaN
60
+ */
61
+ function logcdf( x, p ) {
62
+ return addon( x, p );
63
+ }
64
+
65
+
66
+ // EXPORTS //
67
+
68
+ module.exports = logcdf;
package/manifest.json ADDED
@@ -0,0 +1,92 @@
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/constants-float64-pinf",
44
+ "@stdlib/constants-float64-ninf",
45
+ "@stdlib/math-base-special-log1p",
46
+ "@stdlib/math-base-special-floor",
47
+ "@stdlib/math-base-special-pow"
48
+ ]
49
+ },
50
+ {
51
+ "task": "benchmark",
52
+ "wasm": false,
53
+ "src": [
54
+ "./src/main.c"
55
+ ],
56
+ "include": [
57
+ "./include"
58
+ ],
59
+ "libraries": [],
60
+ "libpath": [],
61
+ "dependencies": [
62
+ "@stdlib/math-base-assert-is-nan",
63
+ "@stdlib/constants-float64-pinf",
64
+ "@stdlib/constants-float64-ninf",
65
+ "@stdlib/math-base-special-log1p",
66
+ "@stdlib/math-base-special-floor",
67
+ "@stdlib/math-base-special-pow",
68
+ "@stdlib/constants-float64-eps"
69
+ ]
70
+ },
71
+ {
72
+ "task": "examples",
73
+ "wasm": false,
74
+ "src": [
75
+ "./src/main.c"
76
+ ],
77
+ "include": [
78
+ "./include"
79
+ ],
80
+ "libraries": [],
81
+ "libpath": [],
82
+ "dependencies": [
83
+ "@stdlib/math-base-assert-is-nan",
84
+ "@stdlib/constants-float64-pinf",
85
+ "@stdlib/constants-float64-ninf",
86
+ "@stdlib/math-base-special-log1p",
87
+ "@stdlib/math-base-special-floor",
88
+ "@stdlib/math-base-special-pow"
89
+ ]
90
+ }
91
+ ]
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-geometric-logcdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Geometric distribution logarithm of cumulative distribution function (CDF).",
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,14 +33,16 @@
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
35
  "dependencies": {
33
- "@stdlib/constants-float64-ninf": "^0.2.2",
34
- "@stdlib/constants-float64-pinf": "^0.2.2",
35
- "@stdlib/math-base-assert-is-nan": "^0.2.2",
36
- "@stdlib/math-base-special-floor": "^0.2.3",
37
- "@stdlib/math-base-special-log1p": "^0.2.3",
36
+ "@stdlib/constants-float64-ninf": "^0.2.3",
37
+ "@stdlib/constants-float64-pinf": "^0.2.3",
38
+ "@stdlib/math-base-assert-is-nan": "^0.2.3",
39
+ "@stdlib/math-base-napi-binary": "^0.3.3",
40
+ "@stdlib/math-base-special-floor": "^0.2.4",
41
+ "@stdlib/math-base-special-log1p": "^0.2.4",
38
42
  "@stdlib/math-base-special-pow": "^0.3.0",
39
- "@stdlib/utils-constant-function": "^0.2.2",
40
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
43
+ "@stdlib/utils-constant-function": "^0.2.3",
44
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3",
45
+ "@stdlib/utils-library-manifest": "^0.2.4"
41
46
  },
42
47
  "devDependencies": {},
43
48
  "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/stats/base/dists/geometric/logcdf.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_geometric_logcdf )
package/src/main.c ADDED
@@ -0,0 +1,54 @@
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/geometric/logcdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/constants/float64/pinf.h"
22
+ #include "stdlib/constants/float64/ninf.h"
23
+ #include "stdlib/math/base/special/log1p.h"
24
+ #include "stdlib/math/base/special/floor.h"
25
+ #include "stdlib/math/base/special/pow.h"
26
+
27
+ /**
28
+ * Evaluates the logarithm of the cumulative distribution function (CDF) for a geometric distribution with success probability `p` at a value `x`.
29
+ *
30
+ * @param x input value
31
+ * @param p success probability
32
+ * @return evaluated logCDF
33
+ *
34
+ * @example
35
+ * double y = stdlib_base_dists_geometric_logcdf( 2.0, 0.5 );
36
+ * // returns ~-0.134
37
+ */
38
+ double stdlib_base_dists_geometric_logcdf( const double x, const double p ) {
39
+ if (
40
+ stdlib_base_is_nan( x ) ||
41
+ stdlib_base_is_nan( p ) ||
42
+ p < 0.0 ||
43
+ p > 1.0
44
+ ) {
45
+ return 0.0/0.0; // NaN
46
+ }
47
+ if ( x < 0.0 ) {
48
+ return STDLIB_CONSTANT_FLOAT64_NINF;
49
+ }
50
+ if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) {
51
+ return 0.0;
52
+ }
53
+ return stdlib_base_log1p( -stdlib_base_pow( 1.0 - p, stdlib_base_floor( x ) + 1.0 ) );
54
+ }